File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
packages/opencode/src/provider Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments