diff --git a/.changeset/drop-max-tokens-gpt5-openai-compatible.md b/.changeset/drop-max-tokens-gpt5-openai-compatible.md new file mode 100644 index 00000000000..cdf54e8d48d --- /dev/null +++ b/.changeset/drop-max-tokens-gpt5-openai-compatible.md @@ -0,0 +1,5 @@ +--- +"@kilocode/cli": patch +--- + +Fix gpt-5 models failing with `Unsupported parameter: max_tokens` when accessed through custom OpenAI-compatible providers such as LiteLLM. diff --git a/packages/opencode/src/session/llm.ts b/packages/opencode/src/session/llm.ts index 39164727d12..7cdb5e85c05 100644 --- a/packages/opencode/src/session/llm.ts +++ b/packages/opencode/src/session/llm.ts @@ -186,7 +186,14 @@ const live: Layer.Layer< : undefined, topP: input.agent.topP ?? ProviderTransform.topP(input.model), topK: ProviderTransform.topK(input.model), - maxOutputTokens: ProviderTransform.maxOutputTokens(input.model), + // kilocode_change start - gpt-5 via @ai-sdk/openai-compatible proxies (e.g. LiteLLM) + // rejects `max_tokens`; OpenAI requires `max_completion_tokens` and the compatible + // SDK cannot rename the field, so drop the cap and let the upstream default apply. + maxOutputTokens: + input.model.api.npm === "@ai-sdk/openai-compatible" && input.model.api.id.toLowerCase().includes("gpt-5") + ? undefined + : ProviderTransform.maxOutputTokens(input.model), + // kilocode_change end options, }, )