Implement token management for OpenAI models by introducing methods to handle max_tokens and max_completion_tokens. Refactor API request construction to streamline parameter handling, ensuring compatibility with both older and newer model versions. Enhance readability and maintainability of the code.#189
Implement token management for OpenAI models by introducing methods to handle max_tokens and max_completion_tokens. Refactor API request construction to streamline parameter handling, ensuring compatibility with both older and newer model versions. Enhance readability and maintainability of the code.#189veithly merged 5 commits intoXSpoonAi:mainfrom
Conversation
…o handle max_tokens and max_completion_tokens. Refactor API request construction to streamline parameter handling, ensuring compatibility with both older and newer model versions. Enhance readability and maintainability of the code.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| def _uses_completion_token_param(self, model: str) -> bool: | ||
| """Whether this model expects max_completion_tokens instead of max_tokens.""" | ||
| model_lower = (model or "").lower() | ||
| return model_lower.startswith("gpt-5") or model_lower.startswith("o") |
There was a problem hiding this comment.
Avoid treating OpenRouter models as max_completion_tokens-only
The new _uses_completion_token_param marks any model starting with "o" as requiring max_completion_tokens. OpenRouter models are named like openai/gpt-3.5-turbo, so _max_token_kwargs will now send max_completion_tokens to the OpenRouter API instead of the max_tokens parameter its OpenAI-compatible endpoint expects, causing chat requests to be rejected for the default OpenRouter configuration. This predicate should be narrowed to the actual OpenAI o* models or be provider-aware.
Useful? React with 👍 / 👎.
…ectly identify models using max_completion_tokens. Update documentation to clarify which models require this parameter, ensuring accurate handling of both new and legacy OpenAI models.
No description provided.