Commit 69a9a55
fix(openai): translate max_tokens to max_completion_tokens for reasoning models (#5847)
## What does this PR do?
OpenAI is deprecating `max_tokens` in favor of `max_completion_tokens`.
Reasoning models (o1, o3, o4-mini) and gpt-5+ already reject
`max_tokens` outright with:
```
Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.
```
This PR translates `max_tokens` to `max_completion_tokens`
unconditionally for all OpenAI models, since all current models accept
`max_completion_tokens`. This avoids maintaining a hardcoded prefix list
that would need updating with every new model family.
A `DeprecationWarning` is emitted when the translation occurs, so users
are informed that their code should migrate to `max_completion_tokens`.
Code using `max_tokens` through OGX will continue to work, but the same
code run directly against OpenAI will fail for newer models.
The translation runs before the existing clamping logic and only applies
when `max_completion_tokens` is not already set by the caller.
Closes #5845
## Test Plan
Unit tests in `tests/unit/providers/inference/test_remote_openai.py`:
```bash
uv run pytest tests/unit/providers/inference/test_remote_openai.py -x --tb=short
```
```
tests/unit/providers/inference/test_remote_openai.py ...................... [100%]
22 passed in 0.29s
```
Tests cover:
- Translation applies to all models (gpt-4o-mini, gpt-4.1, o3, gpt-5,
dated variants)
- No translation when `max_completion_tokens` is already set by the
caller
- Original params object is not mutated
- Existing clamping logic still works after translation
Manually verified with a multi-model test script against a live OGX
server with `OPENAI_API_KEY`:
- Before fix: gpt-5, o1, o3, o3-mini, o4-mini all return 400
- After fix: all pass via `/v1/chat/completions` with deprecation
warning logged
---------
Signed-off-by: Adel Zaalouk <azaalouk@redhat.com>
Co-authored-by: Francisco Javier Arceo <arceofrancisco@gmail.com>
Co-authored-by: Matthew Farrellee <matt@cs.wisc.edu>1 parent 9e63b84 commit 69a9a55
22 files changed
Lines changed: 3534 additions & 7 deletions
File tree
- src/ogx/providers/remote/inference/openai
- tests
- integration
- common/recordings
- messages/recordings
- unit/providers/inference
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
113 | 114 | | |
114 | 115 | | |
115 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
116 | 131 | | |
117 | 132 | | |
118 | 133 | | |
| |||
Lines changed: 1085 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 358 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments