@ai-sdk/openai-compatible max_tokens error for GPT 5.x #3492

Open
opened 2026-02-16 17:40:19 -05:00 by yindo · 27 comments
Owner

Originally created by @junmediatek on GitHub (Dec 12, 2025).

Originally assigned to: @rekram1-node on GitHub.

Description

when I use @ai-sdk/openai-compatible to create a provider, and ues the GPT 5.x model, the body of the request contains max_tokens, not max_completion_tokens, so the LLM returned an error as below:

ERROR 2025-12-12T05:44:36 +2ms service=session.processor error=Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead. stack="AI_APICallError: Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.\n at <anonymous> (/Users/mtk/AI_Coding/OSS/opencode/node_modules/.bun/@ai-sdk+provider-utils@3.0.17+d6123d32214422cb/node_modules/@ai-sdk/provider-utils/dist/index.mjs:889:18)\n at processTicksAndRejections (native:7:39)" process

I find the ’max_tokens‘ is deprecated in the openai API reference for reasoning models.
https://platform.openai.com/docs/api-reference/chat/create#chat_create-max_tokens

My provider as below

"gaisf-openai-compatible": { "npm": "@ai-sdk/openai-compatible", "name": "gaisf-openai-compatible", "options": { "baseURL": "https://mlop-azure-gateway.xxxx.inc/v1", "apiKey": "{env:MY_GAISF_KEY}", "timeout": 300000 }, "models": { "gpt-5.1-high": { "id": "azure/gpt-5.1", "name": "gpt-5.1-high-test", "attachment": true, "modalities": { "input": ["text", "image"], "output": ["text"] }, "options": { "reasoningEffort": "high" }, "limit": { "context": 400000, "output": 128000 }, "cost": { "input": 1.25, "output": 10, "cache_read": 0.13 } } }

@rekram1-node Could you help to check this issue?

OpenCode version

1.0.150

Steps to reproduce

use @ai-sdk/openai-compatible for gpt 5.x model to create provider

Screenshot and/or share link

NA

Operating System

ubuntu 24.4

Terminal

VSCode remoteSSH

Originally created by @junmediatek on GitHub (Dec 12, 2025). Originally assigned to: @rekram1-node on GitHub. ### Description when I use @ai-sdk/openai-compatible to create a provider, and ues the GPT 5.x model, the body of the request contains max_tokens, not max_completion_tokens, so the LLM returned an error as below: `ERROR 2025-12-12T05:44:36 +2ms service=session.processor error=Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead. stack="AI_APICallError: Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.\n at <anonymous> (/Users/mtk/AI_Coding/OSS/opencode/node_modules/.bun/@ai-sdk+provider-utils@3.0.17+d6123d32214422cb/node_modules/@ai-sdk/provider-utils/dist/index.mjs:889:18)\n at processTicksAndRejections (native:7:39)" process` I find the ’max_tokens‘ is deprecated in the openai API reference for reasoning models. https://platform.openai.com/docs/api-reference/chat/create#chat_create-max_tokens My provider as below ` "gaisf-openai-compatible": { "npm": "@ai-sdk/openai-compatible", "name": "gaisf-openai-compatible", "options": { "baseURL": "https://mlop-azure-gateway.xxxx.inc/v1", "apiKey": "{env:MY_GAISF_KEY}", "timeout": 300000 }, "models": { "gpt-5.1-high": { "id": "azure/gpt-5.1", "name": "gpt-5.1-high-test", "attachment": true, "modalities": { "input": ["text", "image"], "output": ["text"] }, "options": { "reasoningEffort": "high" }, "limit": { "context": 400000, "output": 128000 }, "cost": { "input": 1.25, "output": 10, "cache_read": 0.13 } } }` @rekram1-node Could you help to check this issue? ### OpenCode version 1.0.150 ### Steps to reproduce use @ai-sdk/openai-compatible for gpt 5.x model to create provider ### Screenshot and/or share link NA ### Operating System ubuntu 24.4 ### Terminal VSCode remoteSSH
yindo added the bug label 2026-02-16 17:40:19 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Dec 12, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #1697: BUG: gpt-5 azure Unsupported parameter: 'max_tokens' - Same error about max_tokens needing to be replaced with max_completion_tokens for GPT-5
  • #1735: max_tokens defaults to 32000 when using a custom provider - Related issue about max_tokens parameter defaults and custom OpenAI-compatible providers

The core issue appears to be that OpenCode (via the Vercel AI SDK) is using the deprecated 'max_tokens' parameter instead of 'max_completion_tokens' for GPT-5.x models, which newer versions of GPT-5 require.

Feel free to ignore if your specific case involves different details.

@github-actions[bot] commented on GitHub (Dec 12, 2025): This issue might be a duplicate of existing issues. Please check: - #1697: BUG: gpt-5 azure Unsupported parameter: 'max_tokens' - Same error about max_tokens needing to be replaced with max_completion_tokens for GPT-5 - #1735: max_tokens defaults to 32000 when using a custom provider - Related issue about max_tokens parameter defaults and custom OpenAI-compatible providers The core issue appears to be that OpenCode (via the Vercel AI SDK) is using the deprecated 'max_tokens' parameter instead of 'max_completion_tokens' for GPT-5.x models, which newer versions of GPT-5 require. Feel free to ignore if your specific case involves different details.
Author
Owner

@junmediatek commented on GitHub (Dec 12, 2025):

@rekram1-node & @thdxr could you help to check this issue?

@junmediatek commented on GitHub (Dec 12, 2025): @rekram1-node & @thdxr could you help to check this issue?
Author
Owner

@rekram1-node commented on GitHub (Dec 12, 2025):

I don't know anything about your custom provider but if you are using azure you may wanna use the azure ai sdk providers instead.

@rekram1-node commented on GitHub (Dec 12, 2025): I don't know anything about your custom provider but if you are using azure you may wanna use the azure ai sdk providers instead.
Author
Owner

@junmediatek commented on GitHub (Dec 12, 2025):

hi @rekram1-node

Our provider is azure , so I change to the azure ai sdk provider, however, the gpt 4.1 is ok, the gpt 5.1 failed.

"gaisf-azure": {
"npm": "@ai-sdk/azure",
"name": "gaisf-azure",
"options": {
"baseURL": "https://mlop-azure-gateway.mediatek.inc",
"apiKey": "{env:MY_GAISF_KEY}",
"timeout": 300000,
"apiVersion": "2024-10-21"
},
"models": {
"gpt-5.1-high": {
"id": "azure/gpt-5.1",
"name": "gpt-5.1-high-test",
"attachment": true,
"modalities": {
"input": ["text", "image"],
"output": ["text"]
},
"options": {
"reasoningEffort": "high",
"reasoningSummary": "auto"
},
"limit": {
"context": 400000,
"output": 128000
},
"cost": {
"input": 1.25,
"output": 10,
"cache_read": 0.13
}
},
"gpt-4.1": {
"id": "azure/aide-gpt-4.1",
"name": "gpt-4.1-test",
"modalities": {
"input": ["text", "image"],
"output": ["text"]
},
"limit": {
"context": 1047576,
"output": 32768
},
"cost": {
"input": 2,
"output": 8,
"cache_read": 0.5
}
}
}
}

error log is below:

ERROR 2025-12-12T05:44:36 +2ms service=session.processor error=Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead. stack="AI_APICallError: Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.\n at <anonymous> (/Users/mtk/AI_Coding/OSS/opencode/node_modules/.bun/@ai-sdk+provider-utils@3.0.17+d6123d32214422cb/node_modules/@ai-sdk/provider-utils/dist/index.mjs:889:18)\n at processTicksAndRejections (native:7:39)" process

@junmediatek commented on GitHub (Dec 12, 2025): hi @rekram1-node Our provider is azure , so I change to the azure ai sdk provider, however, the gpt 4.1 is ok, the gpt 5.1 failed. "gaisf-azure": { "npm": "@ai-sdk/azure", "name": "gaisf-azure", "options": { "baseURL": "https://mlop-azure-gateway.mediatek.inc", "apiKey": "{env:MY_GAISF_KEY}", "timeout": 300000, "apiVersion": "2024-10-21" }, "models": { "gpt-5.1-high": { "id": "azure/gpt-5.1", "name": "gpt-5.1-high-test", "attachment": true, "modalities": { "input": ["text", "image"], "output": ["text"] }, "options": { "reasoningEffort": "high", "reasoningSummary": "auto" }, "limit": { "context": 400000, "output": 128000 }, "cost": { "input": 1.25, "output": 10, "cache_read": 0.13 } }, "gpt-4.1": { "id": "azure/aide-gpt-4.1", "name": `"gpt-4.1-test",` "modalities": { "input": ["text", "image"], "output": ["text"] }, "limit": { "context": 1047576, "output": 32768 }, "cost": { "input": 2, "output": 8, "cache_read": 0.5 } } } } error log is below: `ERROR 2025-12-12T05:44:36 +2ms service=session.processor error=Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead. stack="AI_APICallError: Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.\n at <anonymous> (/Users/mtk/AI_Coding/OSS/opencode/node_modules/.bun/@ai-sdk+provider-utils@3.0.17+d6123d32214422cb/node_modules/@ai-sdk/provider-utils/dist/index.mjs:889:18)\n at processTicksAndRejections (native:7:39)" process`
Author
Owner

@junmediatek commented on GitHub (Dec 12, 2025):

The root cause is the ’max_tokens‘ is deprecated in the openai API reference for reasoning models. So I think the Opencode needs to adapted this.
https://platform.openai.com/docs/api-reference/chat/create#chat_create-max_tokens

https://learn.microsoft.com/en-us/azure/ai-foundry/openai/how-to/reasoning?view=foundry-classic&tabs=REST%2Cgpt-5#api--feature-support
2 Reasoning models will only work with the max_completion_tokens parameter when using the Chat Completions API.

@rekram1-node Can you confirm for this issue?

@junmediatek commented on GitHub (Dec 12, 2025): The root cause is the ’max_tokens‘ is deprecated in the openai API reference for reasoning models. So I think the Opencode needs to adapted this. https://platform.openai.com/docs/api-reference/chat/create#chat_create-max_tokens https://learn.microsoft.com/en-us/azure/ai-foundry/openai/how-to/reasoning?view=foundry-classic&tabs=REST%2Cgpt-5#api--feature-support 2 Reasoning models will only work with the max_completion_tokens parameter when using the Chat Completions API. @rekram1-node Can you confirm for this issue?
Author
Owner

@rekram1-node commented on GitHub (Dec 12, 2025):

hm can you try clearing your cache maybe?

rm -rf ~/.cache/opencode

@rekram1-node commented on GitHub (Dec 12, 2025): hm can you try clearing your cache maybe? rm -rf ~/.cache/opencode
Author
Owner

@junmediatek commented on GitHub (Dec 12, 2025):

hm can you try clearing your cache maybe?

rm -rf ~/.cache/opencode

I have remove all caches, however, the problem still exist.ink

rm -rf ~/.local/share/opencode/
rm -rf ~/.cache/opencode/
rm -rf ~/.bun/install/cache/
rm -rf ~/.config/opencode/node_modules

I have checked the opencode code, and by default it sends max_tokens instead of max_completion_tokens, this part of the code flow may need to be modified.

@junmediatek commented on GitHub (Dec 12, 2025): > hm can you try clearing your cache maybe? > > rm -rf ~/.cache/opencode I have remove all caches, however, the problem still exist.ink rm -rf ~/.local/share/opencode/ rm -rf ~/.cache/opencode/ rm -rf ~/.bun/install/cache/ rm -rf ~/.config/opencode/node_modules I have checked the opencode code, and by default it sends max_tokens instead of max_completion_tokens, this part of the code flow may need to be modified.
Author
Owner

@rekram1-node commented on GitHub (Dec 12, 2025):

Well I think that's because you have your custom provider hooked up to use the completions api instead of the responses api.

The completions api doesn't support max_completion_tokens and openai-compatible just means use the completions api.

If you use the responses api w/ @ai-sdk/openai package it will send max_completion_tokens

@rekram1-node commented on GitHub (Dec 12, 2025): Well I think that's because you have your custom provider hooked up to use the completions api instead of the responses api. The completions api doesn't support `max_completion_tokens` and openai-compatible just means use the completions api. If you use the responses api w/ @ai-sdk/openai package it will send `max_completion_tokens`
Author
Owner

@junmediatek commented on GitHub (Dec 12, 2025):

If I configure @ai-sdk/openai as the provider, the default is to use the Response API. How should you modify the opencode.json file to use the Chat Completion API instead?
I must use GPT 5.1 through the Chat Completion API.

@junmediatek commented on GitHub (Dec 12, 2025): If I configure @ai-sdk/openai as the provider, the default is to use the Response API. How should you modify the opencode.json file to use the Chat Completion API instead? I must use GPT 5.1 through the Chat Completion API.
Author
Owner

@junmediatek commented on GitHub (Dec 12, 2025):

The completions api doesn't support max_completion_tokens and openai-compatible just means use the completions api.

I think the Completions API does support max_completion_tokens, but opencode only sends max_tokens by default when making requests, so opencode needs to modify its code for different gpt models

https://platform.openai.com/docs/api-reference/chat/create#chat_create-max_completion_tokens

@junmediatek commented on GitHub (Dec 12, 2025): The completions api doesn't support max_completion_tokens and openai-compatible just means use the completions api. I think the Completions API does support max_completion_tokens, but opencode only sends max_tokens by default when making requests, so opencode needs to modify its code for different gpt models https://platform.openai.com/docs/api-reference/chat/create#chat_create-max_completion_tokens
Author
Owner

@rekram1-node commented on GitHub (Dec 12, 2025):

Openai compatible ai sdk provider sends max_tokens. Openai has their own set of rules right so they will have different deprecations and the ai-sdk/openai respects that.

I know i've helped someone get this resolved before but I just can't find what we did to fix it

@rekram1-node commented on GitHub (Dec 12, 2025): Openai compatible ai sdk provider sends max_tokens. Openai has their own set of rules right so they will have different deprecations and the ai-sdk/openai respects that. I know i've helped someone get this resolved before but I just can't find what we did to fix it
Author
Owner

@junmediatek commented on GitHub (Dec 12, 2025):

Openai compatible ai sdk provider sends max_tokens. Openai has their own set of rules right so they will have different deprecations and the ai-sdk/openai respects that.

I know i've helped someone get this resolved before but I just can't find what we did to fix it

  1. If this issue has been fixed, why am I still encountering this issue? Is it because there's an issue with my opencode.json? By the way, opencode can send max_completion_tokens instead of max_tokens in the openai compatible ai sdk provider. (Opencode must modify the relevant code)
  2. If I use ai-sdk/openai, the default is to use the Response API flow in the opencode
    how should I configure the provider with ai-sdk/openai so that the model uses the chat completion flow in opencode?

@rekram1-node could you help to check this issue?

@junmediatek commented on GitHub (Dec 12, 2025): > Openai compatible ai sdk provider sends max_tokens. Openai has their own set of rules right so they will have different deprecations and the ai-sdk/openai respects that. > > I know i've helped someone get this resolved before but I just can't find what we did to fix it 1. If this issue has been fixed, why am I still encountering this issue? Is it because there's an issue with my opencode.json? By the way, opencode can send max_completion_tokens instead of max_tokens in the openai compatible ai sdk provider. (Opencode must modify the relevant code) 2. If I use ai-sdk/openai, the default is to use the Response API flow in the opencode how should I configure the provider with ai-sdk/openai so that the model uses the chat completion flow in opencode? @rekram1-node could you help to check this issue?
Author
Owner

@junmediatek commented on GitHub (Dec 13, 2025):

I know i've helped someone get this resolved before but I just can't find what we did to fix it

@rekram1-node Could you help to find the solution? Thank you.

@junmediatek commented on GitHub (Dec 13, 2025): > I know i've helped someone get this resolved before but I just can't find what we did to fix it @rekram1-node Could you help to find the solution? Thank you.
Author
Owner

@rekram1-node commented on GitHub (Dec 13, 2025):

what error did you get when you tried to use gpt 5 witb the azure provider? was it related to using wrong endpoint?

@rekram1-node commented on GitHub (Dec 13, 2025): what error did you get when you tried to use gpt 5 witb the azure provider? was it related to using wrong endpoint?
Author
Owner

@junmediatek commented on GitHub (Dec 14, 2025):

what error did you get when you tried to use gpt 5 witb the azure provider? was it related to using wrong endpoint?

The error message is below:

ERROR 2025-12-12T05:44:36 +2ms service=session.processor error=Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead. stack="AI_APICallError: Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.\n at <anonymous> (/Users/mtk/AI_Coding/OSS/opencode/node_modules/.bun/@ai-sdk+provider-utils@3.0.17+d6123d32214422cb/node_modules/@ai-sdk/provider-utils/dist/index.mjs:889:18)\n at processTicksAndRejections (native:7:39)" process

The endpoint is a standard Azure provider, so I think the problem shouldn't be with the provider.

@junmediatek commented on GitHub (Dec 14, 2025): > what error did you get when you tried to use gpt 5 witb the azure provider? was it related to using wrong endpoint? The error message is below: `ERROR 2025-12-12T05:44:36 +2ms service=session.processor error=Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead. stack="AI_APICallError: Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.\n at <anonymous> (/Users/mtk/AI_Coding/OSS/opencode/node_modules/.bun/@ai-sdk+provider-utils@3.0.17+d6123d32214422cb/node_modules/@ai-sdk/provider-utils/dist/index.mjs:889:18)\n at processTicksAndRejections (native:7:39)" process ` The endpoint is a standard Azure provider, so I think the problem shouldn't be with the provider.
Author
Owner

@junmediatek commented on GitHub (Dec 14, 2025):

Hi @rekram1-node

I have create a PR for this issue, could you help to check?
https://github.com/sst/opencode/pull/5541

@junmediatek commented on GitHub (Dec 14, 2025): Hi @rekram1-node I have create a PR for this issue, could you help to check? https://github.com/sst/opencode/pull/5541
Author
Owner

@apigban commented on GitHub (Dec 18, 2025):

I had the similar issue, I was working with a weird provider that used custom keys for gpt-5 where there are params incompatible with the current api version of open ai.

what I did was use litellm-proxy to drop the incompatible parameters - https://docs.litellm.ai/docs/completion/drop_params

@apigban commented on GitHub (Dec 18, 2025): I had the similar issue, I was working with a weird provider that used custom keys for gpt-5 where there are params incompatible with the current api version of open ai. what I did was use litellm-proxy to drop the incompatible parameters - https://docs.litellm.ai/docs/completion/drop_params
Author
Owner

@junmediatek commented on GitHub (Dec 18, 2025):

I had the similar issue, I was working with a weird provider that used custom keys for gpt-5 where there are params incompatible with the current api version of open ai.

what I did was use litellm-proxy to drop the incompatible parameters - https://docs.litellm.ai/docs/completion/drop_params

The correct solution is update the opencode source code for this issue

@junmediatek commented on GitHub (Dec 18, 2025): > I had the similar issue, I was working with a weird provider that used custom keys for gpt-5 where there are params incompatible with the current api version of open ai. > > what I did was use litellm-proxy to drop the incompatible parameters - https://docs.litellm.ai/docs/completion/drop_params The correct solution is update the opencode source code for this issue
Author
Owner

@apigban commented on GitHub (Dec 19, 2025):

Agreed, I was just pointing out that there can be a solution for providers that isn't really "compatible" with the openai parameters.

It might help others immediately and doesn't really redirect the dev's attention to (in my case) supporting something that would not benefit more users.

@apigban commented on GitHub (Dec 19, 2025): Agreed, I was just pointing out that there can be a solution for providers that isn't really "compatible" with the openai parameters. It might help others immediately and doesn't really redirect the dev's attention to (in my case) supporting something that would not benefit more users.
Author
Owner

@GhOsT00712 commented on GitHub (Jan 23, 2026):

Is this fixed? I am still getting this issue on @ai-sdk/openai-compatible provider . I am using OCI GenAI endpoint which support OpenAI compatibility.

@GhOsT00712 commented on GitHub (Jan 23, 2026): Is this fixed? I am still getting this issue on @ai-sdk/openai-compatible provider . I am using OCI GenAI endpoint which support OpenAI compatibility.
Author
Owner

@Xavierqwb commented on GitHub (Jan 29, 2026):

I also encountered the same issue when using Azure's GPT-5.2 model, so when can this problem be resolved?

@Xavierqwb commented on GitHub (Jan 29, 2026): I also encountered the same issue when using Azure's GPT-5.2 model, so when can this problem be resolved?
Author
Owner

@profyan99 commented on GitHub (Feb 3, 2026):

Also have the same bug with openai/gpt-5.1

@profyan99 commented on GitHub (Feb 3, 2026): Also have the same bug with openai/gpt-5.1
Author
Owner

@aizigao commented on GitHub (Feb 6, 2026):

some issue

@aizigao commented on GitHub (Feb 6, 2026): some issue
Author
Owner

@DaveSun-SG commented on GitHub (Feb 9, 2026):

some issue with azure and gpt 5.2

@DaveSun-SG commented on GitHub (Feb 9, 2026): some issue with azure and gpt 5.2
Author
Owner

@8-unlimit commented on GitHub (Feb 10, 2026):

Placing the following code in this directory will solve the problem. Note that you need to modify it to use your own provider.

If the plugin directory does not exist, please create it yourself.
You can name the.tsfile whatever you like; the following is just my own configuration.
Hope this helps everyone !!!!

cd ~/.config/opencode/plugin
touch max_completion_tokens.ts
import { Plugin } from "@opencode-ai/plugin"

export const AzurePatch: Plugin = async (ctx) => {
  return {
    auth: {
      provider: "<You Provider>",
      methods: [],
      loader: async (getAuth, provider) => {
        return {
          async fetch(input, init) {
            const opts = init ?? {}
            if (opts.body && typeof opts.body === "string") {
              try {
                const body = JSON.parse(opts.body)
                if (body.max_tokens !== undefined) {
                  body.max_completion_tokens = body.max_tokens
                  delete body.max_tokens
                  opts.body = JSON.stringify(body)
                }
              } catch (e) {}
            }
            return fetch(input, {
              ...opts,
              timeout: false,
            })
          },
        }
      },
    },
  }
}

@8-unlimit commented on GitHub (Feb 10, 2026): Placing the following code in this directory will solve the problem. Note that you need to modify it to use your own `provider.` If the `plugin` directory does not exist, please create it yourself. You can name the` .ts `file whatever you like; the following is just my own configuration. Hope this helps everyone !!!! ``` cd ~/.config/opencode/plugin touch max_completion_tokens.ts ``` ``` import { Plugin } from "@opencode-ai/plugin" export const AzurePatch: Plugin = async (ctx) => { return { auth: { provider: "<You Provider>", methods: [], loader: async (getAuth, provider) => { return { async fetch(input, init) { const opts = init ?? {} if (opts.body && typeof opts.body === "string") { try { const body = JSON.parse(opts.body) if (body.max_tokens !== undefined) { body.max_completion_tokens = body.max_tokens delete body.max_tokens opts.body = JSON.stringify(body) } } catch (e) {} } return fetch(input, { ...opts, timeout: false, }) }, } }, }, } } ```
Author
Owner

@Notworking-fun commented on GitHub (Feb 10, 2026):

Placing the following code in this directory will solve the problem. Note that you need to modify it to use your own provider.

If the plugin directory does not exist, please create it yourself. You can name the.tsfile whatever you like; the following is just my own configuration. Hope this helps everyone !!!!

cd ~/.config/opencode/plugin
torch max_completion_tokens.ts
import { Plugin } from "@opencode-ai/plugin"

export const AzurePatch: Plugin = async (ctx) => {
  return {
    auth: {
      provider: "<You Provider>",
      methods: [],
      loader: async (getAuth, provider) => {
        return {
          async fetch(input, init) {
            const opts = init ?? {}
            if (opts.body && typeof opts.body === "string") {
              try {
                const body = JSON.parse(opts.body)
                if (body.max_tokens !== undefined) {
                  body.max_completion_tokens = body.max_tokens
                  delete body.max_tokens
                  opts.body = JSON.stringify(body)
                }
              } catch (e) {}
            }
            return fetch(input, {
              ...opts,
              timeout: false,
            })
          },
        }
      },
    },
  }
}

Thank you very much, I tried the method you provided, and it can solve my problem. I would like to add a few points:

  1. A small typo in touch max_completion_tokens.ts
  2. Fill in the methods field: methods: "api_key"
  3. Some parameters are incompatible and need to be removed, for example: delete body.reasoningSummary
    Hope this helps!
@Notworking-fun commented on GitHub (Feb 10, 2026): > Placing the following code in this directory will solve the problem. Note that you need to modify it to use your own `provider.` > > If the `plugin` directory does not exist, please create it yourself. You can name the`.ts`file whatever you like; the following is just my own configuration. Hope this helps everyone !!!! > > ``` > cd ~/.config/opencode/plugin > torch max_completion_tokens.ts > ``` > > ``` > import { Plugin } from "@opencode-ai/plugin" > > export const AzurePatch: Plugin = async (ctx) => { > return { > auth: { > provider: "<You Provider>", > methods: [], > loader: async (getAuth, provider) => { > return { > async fetch(input, init) { > const opts = init ?? {} > if (opts.body && typeof opts.body === "string") { > try { > const body = JSON.parse(opts.body) > if (body.max_tokens !== undefined) { > body.max_completion_tokens = body.max_tokens > delete body.max_tokens > opts.body = JSON.stringify(body) > } > } catch (e) {} > } > return fetch(input, { > ...opts, > timeout: false, > }) > }, > } > }, > }, > } > } > ``` Thank you very much, I tried the method you provided, and it can solve my problem. I would like to add a few points: 1. A small typo in touch max_completion_tokens.ts 2. Fill in the methods field: methods: "api_key" 3. Some parameters are incompatible and need to be removed, for example: delete body.reasoningSummary Hope this helps!
Author
Owner

@ricmestre commented on GitHub (Feb 13, 2026):

This doesn't work for me, I assigned provider to the name of the provider I created, methods to ["api_key"] and I can see the plugin being loaded in the debug logs but then it doesn't get called so opencode still fails with exactly the same error message.

@ricmestre commented on GitHub (Feb 13, 2026): This doesn't work for me, I assigned `provider` to the name of the provider I created, `methods` to ["api_key"] and I can see the plugin being loaded in the debug logs but then it doesn't get called so opencode still fails with exactly the same error message.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3492