eca icon indicating copy to clipboard operation
eca copied to clipboard

Mistral AI API `max_completion_tokens` issue.

Open ChetanKoneru opened this issue 11 months ago • 7 comments

Describe the bug Just running a test "this is a test" against Mistral AI API is giving this error-

LLM response status: 422 body: {"object":"error","message":{"detail":[{"type":"extra_forbidden","loc":["body","max_completion_tokens"],"msg":"Extra inputs are not permitted","input":32000}]},"type":"invalid_request_error","param":null,"code":null}

Mistral AI config

"mistral": {
      "api": "openai-chat",
      "url": "https://api.mistral.ai",
      "completionUrlRelativePath": "/v1/chat/completions",
      "key": "XXXXXXXXX",
      "models": {
        "labs-devstral-small-2512": {}
      }
    }

look like it is a know issue caused when max_completion_tokens property is sent.

can I remove that?

Tested API with GPTEL and Curl and it works fine.

(gptel-make-openai "MistralLeChat" 
      :host "api.mistral.ai"
      :endpoint "/v1/chat/completions"
      :protocol "https"
      :key "XXXXXXXXXX"
      :models '("labs-devstral-small-2512"))

ChetanKoneru avatar Dec 12 '25 23:12 ChetanKoneru

@CsBigDataHub can you try with:

"mistral": {
      "api": "openai-chat",
      "url": "https://api.mistral.ai",
      "completionUrlRelativePath": "/v1/chat/completions",
      "key": "XXXXXXXXX",
      "models": {
        "labs-devstral-small-2512": {
            "extraPayload": {"max_completion_tokens": null}
        }
      }
    }

ericdallo avatar Dec 13 '25 01:12 ericdallo

Hello @ericdallo ,

Looks like max_completion_tokens is hard-coded https://github.com/editor-code-assistant/eca/blob/ea71fa86f2232c2ab3e26e9e7259f0ffe69ce401/src/eca/llm_providers/openai_chat.clj#L313

Mistral’s OpenAI-compatible chat endpoint does not accept the max_completion_tokens parameter, only max_tokens, so ECA’s current openai-chat provider will always hit this 422 as long as it sends max_completion_tokens in the body.

  • OpenAI’s newer APIs (o1, Responses, etc.) use max_completion_tokens, and many OpenAI-focused clients have been updated to send that field.
  • Mistral’s /v1/chat/completions still expects the older OpenAI-style parameter max_tokens and rejects unknown fields like max_completion_tokens with an extra_forbidden error, which is what we are seeing.

With the current openai-chat provider implementation in ECA, we cannot disable or override that single field from config.json; it is hard-coded in the Clojure layer I linked, so every request will include it.

Let me know how you want to handle it,

  • Provide multiple versions of openai-chat (my recommendation)
  • Create a new provider mistral-chat.

ChetanKoneru avatar Dec 13 '25 14:12 ChetanKoneru

@CsBigDataHub I believe our deep-merge function is not aware of merging a value with a null field, removing it, I believe we can just fix that and then it should work with the config I mentioned

ericdallo avatar Dec 13 '25 18:12 ericdallo

@CsBigDataHub Just made deep-merge remove null values from body, LMK if that fixes the issue with the config i provided

ericdallo avatar Dec 13 '25 18:12 ericdallo

Hi @ericdallo ,

Calling the api works with "extraPayload": {"max_completion_tokens": null} but tool calls still fail.

LLM response status: 400 body: {"object":"error","message":"Tool call id was 2968-LWy3uasib but must be a-z, A-Z, 0-9, with a length of 9.","type":"invalid_function_call","param":null,"code":"3280"}

ChetanKoneru avatar Dec 13 '25 18:12 ChetanKoneru

That seems to be a different issue?

ericdallo avatar Dec 13 '25 18:12 ericdallo

Probably, should I open a different issue to mitigate this?

ChetanKoneru avatar Dec 13 '25 18:12 ChetanKoneru