Skip to content

OpenAI newer models fail because requests use max_tokens instead of max_completion_tokens #1

Description

@xwbcl123

Summary

The OpenAI-compatible provider fails its connection test with newer OpenAI models because the request body sends the deprecated max_tokens parameter.

OpenAI returns:

API error (400): {
  "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"
  }
}

Environment

  • Easy-Translater extension version: 1.0.0
  • Upstream commit tested: 8d0378258c255dcde8c479e7da0d91aee9cefa3f
  • Provider: OpenAI compatible
  • API base URL: https://api.openai.com/v1/
  • Model: gpt-5.4-mini
  • Browser: Google Chrome on macOS

Steps to reproduce

  1. Open the extension settings.
  2. Select OpenAI compatible as the API provider.
  3. Set the API URL to https://api.openai.com/v1/.
  4. Enter a valid OpenAI API key.
  5. Set the model to gpt-5.4-mini.
  6. Run the connection test.

Actual behavior

The connection test fails with HTTP 400 and reports that max_tokens is unsupported.

Expected behavior

The connection test and translations should succeed with newer OpenAI models that require max_completion_tokens.

Root cause

lib/translator.js hardcodes max_tokens: 4096 in the OpenAI request body (around line 84). The same parameter is also hardcoded in other OpenAI-compatible request paths (around lines 103 and 152).

OpenAI's current Chat Completions API reference marks max_tokens as deprecated in favor of max_completion_tokens, and notes that parameter support differs by model:

https://developers.openai.com/api/reference/resources/chat/subresources/completions/methods/create

Suggested fix

Please consider:

  1. Using max_completion_tokens for native OpenAI requests and models that require it.
  2. Preserving compatibility with third-party OpenAI-compatible endpoints that may still expect max_tokens, for example through provider/model-aware parameter selection or a targeted retry when the API returns unsupported_parameter.
  3. Centralizing construction of the token-limit parameter instead of hardcoding it in multiple request paths.
  4. Adding a regression test covering both parameter variants.

No API key or other credential is included in this report.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions