File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed
packages/opencode/src/provider Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -419,11 +419,26 @@ export namespace Provider {
419419 "HTTP-Referer" : "https://opencode.ai/" ,
420420 "X-Title" : "opencode" ,
421421 } ,
422- // Custom fetch to strip Authorization header - AI Gateway uses cf-aig-authorization instead
423- // Sending Authorization header with invalid value causes auth errors
422+ // Custom fetch to handle parameter transformation and auth
424423 fetch : async ( input : RequestInfo | URL , init ?: RequestInit ) => {
425424 const headers = new Headers ( init ?. headers )
425+ // Strip Authorization header - AI Gateway uses cf-aig-authorization instead
426426 headers . delete ( "Authorization" )
427+
428+ // Transform max_tokens to max_completion_tokens for newer models
429+ if ( init ?. body && init . method === "POST" ) {
430+ try {
431+ const body = JSON . parse ( init . body as string )
432+ if ( body . max_tokens !== undefined && ! body . max_completion_tokens ) {
433+ body . max_completion_tokens = body . max_tokens
434+ delete body . max_tokens
435+ init = { ...init , body : JSON . stringify ( body ) }
436+ }
437+ } catch ( e ) {
438+ // If body parsing fails, continue with original request
439+ }
440+ }
441+
427442 return fetch ( input , { ...init , headers } )
428443 } ,
429444 } ,
You can’t perform that action at this time.
0 commit comments