Mistral AI API `max_completion_tokens` issue.
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"))
@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}
}
}
}
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/completionsstill expects the older OpenAI-style parametermax_tokensand rejects unknown fields likemax_completion_tokenswith anextra_forbiddenerror, 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.
@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
@CsBigDataHub Just made deep-merge remove null values from body, LMK if that fixes the issue with the config i provided
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"}
That seems to be a different issue?
Probably, should I open a different issue to mitigate this?