Commit 8228c13
refactor: move the max_tokens resolution into an h2o hook, reverting the core edits
#26 implemented the max_tokens / max_completion_tokens resolution in core
litellm — `get_optional_params` plus a `get_preferred_max_tokens_param` method on
BaseConfig and four provider configs, a param threaded through `main.py`, entries
in `types/utils.py` and `types/router.py`, a constant in `types/llms/azure.py`,
and the regenerated dashboard `schema.d.ts` that the types change forced. Eleven
upstream files.
That is the wrong trade for this fork. `h2o-main` is rebuilt as
`<upstream-tag>` + the h2o file delta on every version bump, so each of those
eleven is re-applied by hand every time, while a file added under
`integrations/h2o/` is additive and costs nothing. Reviewer feedback on #26 was
exactly this.
So: all eleven core files are reverted to their upstream state, the core-utils
module and its tests are removed, and the entire behaviour now lives in
`litellm/integrations/h2o/litellm_max_tokens_resolution_hook.py`. Net change
against the upstream base is two new files and zero edits.
Nothing was given up to do it. Verified against the UNMODIFIED tree that
`async_pre_call_deployment_hook` can reach everything the core version used:
* `api_version`, `additional_drop_params`, `model_info` and the
`use_max_completion_tokens` directive are all in its kwargs for the SELECTED
deployment (the directive survives `LiteLLM_Params`' extra="allow"), so a
mixed model group is still judged per member;
* it runs BEFORE param mapping, so collapsing there still fixes the last-wins
ordering rather than only renaming a field — confirmed by driving real
`acompletion` and reading the mapped params;
* `types/*` was only needed to stop the directive leaking to the provider; the
hook pops it instead, on EVERY call type, which removes that need entirely;
* reasoning-model detection asks litellm's own `is_o_series_model` /
`is_model_gpt_5_model` rather than adding methods to those configs, so there
is no hardcoded model-name list here either;
* `get_supported_openai_params` is called directly, so a target the provider
does not accept is still never forced.
The one capability a core implementation has that this does not: the deployment
hook dispatch lives only in the `@client` decorator's ASYNC wrapper, so a direct
sync in-process `litellm.completion()` bypasses it. Not a capability we use —
this hook is registered only in the proxy config and the proxy maps
/chat/completions to `acompletion`.
The risk that comes back with a hook is the one that broke #25, and it is now
gated from evidence rather than guesswork. That dispatch is NOT chat-specific;
observed call types reaching it are `acompletion`, `anthropic_messages` and
`atext_completion`. `litellm.anthropic_messages` declares `max_tokens` as a
REQUIRED parameter, so popping it raises
`TypeError: anthropic_messages() missing 1 required positional argument`
outside the hook's try/except. Gated on `call_type` in
{completion, acompletion}, with tests pinning that /v1/messages returns
normally, /v1/completions keeps its `max_tokens`, and the directive is stripped
even on the gated types so it cannot leak there.
Carries forward every hardening from #27 (which this supersedes): floats coerced
the way AnthropicConfig already coerces them, unusable values left exactly as
they arrived, a dropped field never used as a target, non-str api_version
treated as unrecognizable rather than raising.
Verification, all measured:
* 136 unit + end-to-end tests in the new file.
* The h2ogpte#11992 model matrix through the hook: 214/214, including 182
with-limit/without-limit comparisons across 26 model routes x 7 param sets
with 0 perturbed — so function calling, tool_choice, parallel_tool_calls,
response_format and every sampling param are untouched.
* Per-provider, client 50 against a 64000 ceiling: azure
max_completion_tokens 50, anthropic max_tokens 50, bedrock maxTokens 50,
gemini max_output_tokens 50, o3/gpt-5 max_completion_tokens 50.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 60f5ee9 commit 8228c13
15 files changed
Lines changed: 963 additions & 875 deletions
File tree
- litellm
- integrations/h2o
- litellm_core_utils
- llms
- azure/chat
- base_llm/chat
- openai/chat
- types
- llms
- tests/test_litellm
- integrations/h2o
- litellm_core_utils
- ui/litellm-dashboard/src/lib/http
Lines changed: 390 additions & 0 deletions
Large diffs are not rendered by default.
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | 59 | | |
71 | 60 | | |
72 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| |||
149 | 148 | | |
150 | 149 | | |
151 | 150 | | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | 151 | | |
181 | 152 | | |
182 | 153 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | 195 | | |
212 | 196 | | |
213 | 197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | 191 | | |
202 | 192 | | |
203 | 193 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | 90 | | |
103 | 91 | | |
104 | 92 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5254 | 5254 | | |
5255 | 5255 | | |
5256 | 5256 | | |
5257 | | - | |
5258 | | - | |
5259 | | - | |
5260 | | - | |
5261 | 5257 | | |
5262 | 5258 | | |
5263 | 5259 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | 248 | | |
255 | 249 | | |
256 | 250 | | |
| |||
0 commit comments