@ai-sdk/openai-compatible max_tokens error for GPT 5.x
Description
when I use @ai-sdk/openai-compatible to create a provider, and ues the GPT 5.x model, the body of the request contains max_tokens, not max_completion_tokens, so the LLM returned an error as below:
ERROR 2025-12-12T05:44:36 +2ms service=session.processor error=Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead. stack="AI_APICallError: Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.\n at <anonymous> (/Users/mtk/AI_Coding/OSS/opencode/node_modules/.bun/@[email protected]+d6123d32214422cb/node_modules/@ai-sdk/provider-utils/dist/index.mjs:889:18)\n at processTicksAndRejections (native:7:39)" process
I find the ’max_tokens‘ is deprecated in the openai API reference for reasoning models. https://platform.openai.com/docs/api-reference/chat/create#chat_create-max_tokens
My provider as below
"gaisf-openai-compatible": { "npm": "@ai-sdk/openai-compatible", "name": "gaisf-openai-compatible", "options": { "baseURL": "https://mlop-azure-gateway.xxxx.inc/v1", "apiKey": "{env:MY_GAISF_KEY}", "timeout": 300000 }, "models": { "gpt-5.1-high": { "id": "azure/gpt-5.1", "name": "gpt-5.1-high-test", "attachment": true, "modalities": { "input": ["text", "image"], "output": ["text"] }, "options": { "reasoningEffort": "high" }, "limit": { "context": 400000, "output": 128000 }, "cost": { "input": 1.25, "output": 10, "cache_read": 0.13 } } }
@rekram1-node Could you help to check this issue?
OpenCode version
1.0.150
Steps to reproduce
use @ai-sdk/openai-compatible for gpt 5.x model to create provider
Screenshot and/or share link
NA
Operating System
ubuntu 24.4
Terminal
VSCode remoteSSH
This issue might be a duplicate of existing issues. Please check:
- #1697: BUG: gpt-5 azure Unsupported parameter: 'max_tokens' - Same error about max_tokens needing to be replaced with max_completion_tokens for GPT-5
- #1735: max_tokens defaults to 32000 when using a custom provider - Related issue about max_tokens parameter defaults and custom OpenAI-compatible providers
The core issue appears to be that OpenCode (via the Vercel AI SDK) is using the deprecated 'max_tokens' parameter instead of 'max_completion_tokens' for GPT-5.x models, which newer versions of GPT-5 require.
Feel free to ignore if your specific case involves different details.
@rekram1-node & @thdxr could you help to check this issue?
I don't know anything about your custom provider but if you are using azure you may wanna use the azure ai sdk providers instead.
hi @rekram1-node
Our provider is azure , so I change to the azure ai sdk provider, however, the gpt 4.1 is ok, the gpt 5.1 failed.
"gaisf-azure": {
"npm": "@ai-sdk/azure",
"name": "gaisf-azure",
"options": {
"baseURL": "https://mlop-azure-gateway.mediatek.inc",
"apiKey": "{env:MY_GAISF_KEY}",
"timeout": 300000,
"apiVersion": "2024-10-21"
},
"models": {
"gpt-5.1-high": {
"id": "azure/gpt-5.1",
"name": "gpt-5.1-high-test",
"attachment": true,
"modalities": {
"input": ["text", "image"],
"output": ["text"]
},
"options": {
"reasoningEffort": "high",
"reasoningSummary": "auto"
},
"limit": {
"context": 400000,
"output": 128000
},
"cost": {
"input": 1.25,
"output": 10,
"cache_read": 0.13
}
},
"gpt-4.1": {
"id": "azure/aide-gpt-4.1",
"name": "gpt-4.1-test",
"modalities": {
"input": ["text", "image"],
"output": ["text"]
},
"limit": {
"context": 1047576,
"output": 32768
},
"cost": {
"input": 2,
"output": 8,
"cache_read": 0.5
}
}
}
}
error log is below:
ERROR 2025-12-12T05:44:36 +2ms service=session.processor error=Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead. stack="AI_APICallError: Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.\n at <anonymous> (/Users/mtk/AI_Coding/OSS/opencode/node_modules/.bun/@[email protected]+d6123d32214422cb/node_modules/@ai-sdk/provider-utils/dist/index.mjs:889:18)\n at processTicksAndRejections (native:7:39)" process
The root cause is the ’max_tokens‘ is deprecated in the openai API reference for reasoning models. So I think the Opencode needs to adapted this. https://platform.openai.com/docs/api-reference/chat/create#chat_create-max_tokens
https://learn.microsoft.com/en-us/azure/ai-foundry/openai/how-to/reasoning?view=foundry-classic&tabs=REST%2Cgpt-5#api--feature-support 2 Reasoning models will only work with the max_completion_tokens parameter when using the Chat Completions API.
@rekram1-node Can you confirm for this issue?
hm can you try clearing your cache maybe?
rm -rf ~/.cache/opencode
hm can you try clearing your cache maybe?
rm -rf ~/.cache/opencode
I have remove all caches, however, the problem still exist.ink
rm -rf ~/.local/share/opencode/ rm -rf ~/.cache/opencode/ rm -rf ~/.bun/install/cache/ rm -rf ~/.config/opencode/node_modules
I have checked the opencode code, and by default it sends max_tokens instead of max_completion_tokens, this part of the code flow may need to be modified.
Well I think that's because you have your custom provider hooked up to use the completions api instead of the responses api.
The completions api doesn't support max_completion_tokens and openai-compatible just means use the completions api.
If you use the responses api w/ @ai-sdk/openai package it will send max_completion_tokens
If I configure @ai-sdk/openai as the provider, the default is to use the Response API. How should you modify the opencode.json file to use the Chat Completion API instead? I must use GPT 5.1 through the Chat Completion API.
The completions api doesn't support max_completion_tokens and openai-compatible just means use the completions api.
I think the Completions API does support max_completion_tokens, but opencode only sends max_tokens by default when making requests, so opencode needs to modify its code for different gpt models
https://platform.openai.com/docs/api-reference/chat/create#chat_create-max_completion_tokens
Openai compatible ai sdk provider sends max_tokens. Openai has their own set of rules right so they will have different deprecations and the ai-sdk/openai respects that.
I know i've helped someone get this resolved before but I just can't find what we did to fix it
Openai compatible ai sdk provider sends max_tokens. Openai has their own set of rules right so they will have different deprecations and the ai-sdk/openai respects that.
I know i've helped someone get this resolved before but I just can't find what we did to fix it
- If this issue has been fixed, why am I still encountering this issue? Is it because there's an issue with my opencode.json? By the way, opencode can send max_completion_tokens instead of max_tokens in the openai compatible ai sdk provider. (Opencode must modify the relevant code)
- If I use ai-sdk/openai, the default is to use the Response API flow in the opencode how should I configure the provider with ai-sdk/openai so that the model uses the chat completion flow in opencode?
@rekram1-node could you help to check this issue?
I know i've helped someone get this resolved before but I just can't find what we did to fix it
@rekram1-node Could you help to find the solution? Thank you.
what error did you get when you tried to use gpt 5 witb the azure provider? was it related to using wrong endpoint?
what error did you get when you tried to use gpt 5 witb the azure provider? was it related to using wrong endpoint?
The error message is below:
ERROR 2025-12-12T05:44:36 +2ms service=session.processor error=Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead. stack="AI_APICallError: Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.\n at <anonymous> (/Users/mtk/AI_Coding/OSS/opencode/node_modules/.bun/@[email protected]+d6123d32214422cb/node_modules/@ai-sdk/provider-utils/dist/index.mjs:889:18)\n at processTicksAndRejections (native:7:39)" process
The endpoint is a standard Azure provider, so I think the problem shouldn't be with the provider.
Hi @rekram1-node
I have create a PR for this issue, could you help to check? https://github.com/sst/opencode/pull/5541
I had the similar issue, I was working with a weird provider that used custom keys for gpt-5 where there are params incompatible with the current api version of open ai.
what I did was use litellm-proxy to drop the incompatible parameters - https://docs.litellm.ai/docs/completion/drop_params
I had the similar issue, I was working with a weird provider that used custom keys for gpt-5 where there are params incompatible with the current api version of open ai.
what I did was use litellm-proxy to drop the incompatible parameters - https://docs.litellm.ai/docs/completion/drop_params
The correct solution is update the opencode source code for this issue
Agreed, I was just pointing out that there can be a solution for providers that isn't really "compatible" with the openai parameters.
It might help others immediately and doesn't really redirect the dev's attention to (in my case) supporting something that would not benefit more users.