anomalyco / anomalyco/opencode

OpenAI-compatible chat providers fail when the endpoint requires max_completion_tokens instead of max_tokens

Open
#45,223 3 comments 0 reactions 1 assignee View on GitHub

@neriousy is already working on this.

Since Aug 26, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

The generic OpenAI-compatible chat protocol (packages/llm/src/protocols/openai-chat.ts) always sends max_tokens in the request body. Some OpenAI-compatible deployments reject this and require max_completion_tokens instead, returning a standard error like:

{
  "error": {
    "message": "Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.",
    "type": "invalid_request_error",
    "param": "max_tokens",
    "code": "unsupported_parameter"
  }
}

Right now this makes the provider unusable out of the box — the only workaround is writing a custom plugin that intercepts chat.params and rewrites the field manually.

This isn't a one-off case: OpenCode already ships two provider-specific patches for the same underlying issue (Cerebras: packages/core/src/plugin/provider/cerebras.ts, Snowflake Cortex: packages/core/src/plugin/provider/snowflake-cortex.ts, both rewriting max_tokensmax_completion_tokens). Those are hardcoded to specific npm packages / provider IDs, so they don't help anyone using a custom openai-compatible provider pointed at a gateway with this same requirement.

Plugins

None required for this fix — it replaces the need for a custom chat.params plugin.

OpenCode version

1.18.23

Steps to reproduce
  1. Configure a custom provider using @ai-sdk/openai-compatible pointed at any OpenAI-compatible endpoint that rejects max_tokens and requires max_completion_tokens.
  2. Send a chat request through that provider.
  3. Request fails instead of retrying with the corrected field.
Screenshot and/or share link

No response

Operating System

macOS 26.6.2

Terminal

Terminal

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.