Commit fb602a1
committed
fix(openai): use max_completion_tokens for gpt-5 + o-series models
Production paracosm broke after the per-call maxTokens caps shipped:
OpenAI's gpt-5.x and o-series (reasoning) models reject max_tokens with
HTTP 400 "Unsupported parameter: 'max_tokens' is not supported with
this model. Use 'max_completion_tokens' instead."
OpenAIProvider.buildPayload always sent max_tokens. Now sniffs the
model id via modelRequiresMaxCompletionTokens() and routes to either
max_tokens (legacy: gpt-4o, gpt-4-turbo, gpt-4.1, gpt-3.5) or
max_completion_tokens (new: gpt-5.x, o1, o3, o4). Same value,
different param name — the two are semantically equivalent within
each generation.
Errs conservative: unknown model ids (Anthropic, Llama, etc — not
that they reach this code path, but defensively) fall through to
max_tokens. Older deployments don't silently break when the param
flag changes.
6 vitest cases pin the routing decision across known model families
(gpt-5.x, o1/o3/o4, gpt-4o, gpt-4.1, gpt-3.5) and the case-insensitive
match logic. Streaming + non-streaming completions both flow through
the shared buildPayload path so the fix covers both.1 parent 9f25c28 commit fb602a1
2 files changed
Lines changed: 82 additions & 1 deletion
File tree
- src/core/llm/providers
- implementations
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
169 | 192 | | |
170 | 193 | | |
171 | 194 | | |
| |||
614 | 637 | | |
615 | 638 | | |
616 | 639 | | |
617 | | - | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
618 | 652 | | |
619 | 653 | | |
620 | 654 | | |
| |||
Lines changed: 47 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
0 commit comments