summaryrefslogtreecommitdiffhomepage
path: root/packages
diff options
context:
space:
mode:
authorRohan Mukherjee <[email protected]>2026-01-13 07:38:27 +0530
committerGitHub <[email protected]>2026-01-12 20:08:27 -0600
commit20088a87b0ef37f769eb8096faac89dd4a190af3 (patch)
tree23443666fd706885089333c3879228eb499f8cce /packages
parent05019dae7607451aab33c593875438f0cc88b199 (diff)
downloadopencode-20088a87b0ef37f769eb8096faac89dd4a190af3.tar.gz
opencode-20088a87b0ef37f769eb8096faac89dd4a190af3.zip
fix: max completion tokens error for cloudflare (#7970)
Diffstat (limited to 'packages')
-rw-r--r--packages/opencode/src/provider/provider.ts19
1 files changed, 17 insertions, 2 deletions
diff --git a/packages/opencode/src/provider/provider.ts b/packages/opencode/src/provider/provider.ts
index 4ccaacd54..3b76b1e02 100644
--- a/packages/opencode/src/provider/provider.ts
+++ b/packages/opencode/src/provider/provider.ts
@@ -419,11 +419,26 @@ export namespace Provider {
"HTTP-Referer": "https://opencode.ai/",
"X-Title": "opencode",
},
- // Custom fetch to strip Authorization header - AI Gateway uses cf-aig-authorization instead
- // Sending Authorization header with invalid value causes auth errors
+ // Custom fetch to handle parameter transformation and auth
fetch: async (input: RequestInfo | URL, init?: RequestInit) => {
const headers = new Headers(init?.headers)
+ // Strip Authorization header - AI Gateway uses cf-aig-authorization instead
headers.delete("Authorization")
+
+ // Transform max_tokens to max_completion_tokens for newer models
+ if (init?.body && init.method === "POST") {
+ try {
+ const body = JSON.parse(init.body as string)
+ if (body.max_tokens !== undefined && !body.max_completion_tokens) {
+ body.max_completion_tokens = body.max_tokens
+ delete body.max_tokens
+ init = { ...init, body: JSON.stringify(body) }
+ }
+ } catch (e) {
+ // If body parsing fails, continue with original request
+ }
+ }
+
return fetch(input, { ...init, headers })
},
},