Skip to content

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

Description

@VarunMotiyani

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_tokens → max_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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions