Skip to content

Commit f01bb52

Browse files
committed
fix: use max_completion_tokens for Azure reasoning models
1 parent fdf560c commit f01bb52

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

packages/opencode/src/provider/provider.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,26 @@ export namespace Provider {
791791
opts.signal = combined
792792
}
793793

794+
// Reasoning models require max_completion_tokens instead of max_tokens
795+
// when using openai-compatible provider
796+
// Check if model has reasoning capability OR has reasoningEffort option
797+
const isReasoningModel =
798+
model.capabilities.reasoning || (model.options && "reasoningEffort" in model.options)
799+
if (model.api.npm === "@ai-sdk/azure" && isReasoningModel) {
800+
if (opts.body && typeof opts.body === "string") {
801+
try {
802+
const body = JSON.parse(opts.body)
803+
if (body.max_tokens !== undefined) {
804+
body.max_completion_tokens = body.max_tokens
805+
delete body.max_tokens
806+
opts.body = JSON.stringify(body)
807+
}
808+
} catch (e) {
809+
// Ignore JSON parse errors
810+
}
811+
}
812+
}
813+
794814
return fetchFn(input, {
795815
...opts,
796816
// @ts-ignore see here: https://github.com/oven-sh/bun/issues/16682

0 commit comments

Comments
 (0)