Repository navigation
refactor(cost-map): drop the legacy max_tokens field in favor of max_input_tokens and max_output_tokens - #48471
Merged
Merged
Conversation
…input_tokens and max_output_tokens Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
kerry-berri
requested review from
joshua-berri,
mateo-berri and
ryan-crabbe-berri
as code owners
October 26, 2026 21:45
Contributor
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Contributor
Merging this PR will not alter performance1 warning
Comparing Footnotes |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…ax_tokens Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> # Conflicts: # .github/scripts/auto_update_price_and_context_window_file.py # scripts/sync_together_ai_models.py # tests/unit/test_auto_update_price_and_context_window_file.py # tests/unit/test_sync_together_ai_models.py
Contributor
Author
|
@BugBot run |
Contributor
|
This PR is too large for Bugbot to review. It changes 7,062 lines and 4,036,159 characters. Split the change into smaller pull requests to get a review. |
yuneng-berri
approved these changes
Oct 26, 2026
kerry-berri
enabled auto-merge (squash)
October 26, 2026 23:00
3 of 5 tasks
StudioPlatforms
added a commit
to StudioPlatforms/litellm
that referenced
this pull request
Oct 27, 2026
…ap rows Upstream BerriAI#48471 retired max_tokens in favor of max_input_tokens and max_output_tokens; our routing-mode rows already carry both.
2 of 4 tasks
mateo-berri
added a commit
to vansh-one/litellm
that referenced
this pull request
Oct 28, 2026
Keeps both main's new providers.json entries (refuseless, openinfer) and vispark, and drops max_tokens from the three vispark cost-map rows since main retired that field in BerriAI#48471 (max_output_tokens already carries the same value)
4 of 7 tasks
amaan-ai20
added a commit
to zerogpu/litellm
that referenced
this pull request
Oct 28, 2026
Upstream BerriAI#48471 retired max_tokens from the cost map in favor of max_input_tokens and max_output_tokens, and test_no_row_carries_the_retired_max_tokens_field failed on all 13 zerogpu rows. Every row already carries the same value in max_output_tokens, so nothing is lost. The zerogpu limits test now checks that each row's output limit fits its context window
mateo-berri
pushed a commit
that referenced
this pull request
Oct 28, 2026
* feat(providers): add ZeroGPU as an OpenAI-compatible provider Registers zerogpu through the JSON provider registry so zerogpu/<model> routes to https://api.zerogpu.ai/v1/chat/completions with ZEROGPU_API_KEY and an optional ZEROGPU_API_BASE. Adds LlmProviders.ZEROGPU, the constants.py provider and endpoint lists, cost map entries for the 10 ZeroGPU text generation models, the endpoint matrix, the Add Model form fields, the README row and the dashboard provider entry * feat(zerogpu): add capability flags verified against the live API Live calls to https://api.zerogpu.ai/v1/chat/completions confirmed tools, tool_choice and json_schema response_format on 8 of the 10 catalog text models, cached token reporting on deepseek-v4.1-flash, gpt-4.1-mini, gpt-5.4-nano and gpt-5.6-luna, and reasoning_effort on gpt-5.6-luna. LFM2.5-1.2B-Instruct answers stream requests with plain JSON instead of SSE and LFM2.5-1.2B-Thinking returns 500 on every request, so both stay out of the cost map until the API serves them correctly * feat(zerogpu): price LFM2.5-1.2B-Instruct Adds zerogpu/LFM2.5-1.2B-Instruct to the cost map with the catalog prices and context window. It gets no capability flags because the live API ignores tools, response_format and max_completion_tokens for this model, so LiteLLM drops tool params for it instead of sending them. LFM2.5-1.2B-Thinking stays out of the cost map * fix(zerogpu): reject transcription requests before calling the upstream API ZeroGPU only serves chat completions, so drop it from the OpenAI transcription transport set. A zerogpu transcription request now fails locally instead of hitting an /audio/transcriptions endpoint that does not exist * test(zerogpu): cover the responses and messages bridges Both endpoints reach ZeroGPU through chat completions, so assert the request each one sends upstream and the reply it returns * refactor(zerogpu): move zerogpu out of the provider list tails New upstream providers append to the end of openai_compatible_endpoints, openai_compatible_providers and providers.json, so an entry at the tail conflicts with every one of them. Placing zerogpu next to long-stable entries keeps those merges clean. No behavior change * fix(zerogpu): price cached input for qwen3-30b-a3b-fp8 The ZeroGPU model catalog (https://docs.zerogpu.ai/docs/model-catalog, checked 2026-10-09) lists cached input for qwen3-30b-a3b-fp8 at $0.05 per 1M tokens. Without cache_read_input_token_cost, cached tokens were billed at the full $0.10 input rate * revert(zerogpu): leave the audio transcription provider set unchanged Per review, keep OPENAI_AUDIO_TRANSCRIPTION_PROVIDERS as upstream defines it. This PR only covers chat completions, and ZeroGPU now serves /audio/transcriptions anyway, so the local refusal and its test are removed * fix(zerogpu): add max_tokens so trim_messages can size ZeroGPU history trim_messages reads max_tokens as the fallback for max_input_tokens and evaluates it eagerly, so without it the lookup raised, got swallowed, and the full history came back untrimmed. max_tokens matches each model's maxTokens in ZeroGPU's models API (https://api-dashboard.zerogpu.ai/api/models, checked 2026-10-10) * test(zerogpu): record mocked requests on a recorder object The mock handler appended to a list the caller passed in, which AGENTS.md forbids. A recorder now owns the captured requests as a tuple * fix(zerogpu): cap max_tokens at each model's output limit Each cap is the max_output_tokens ZeroGPU stores for the model in its production models table (read 2026-10-20), the same column its /v1/models serves as max_length. That gives 65536 for deepseek-v4.1-flash, 32768 for gpt-4.1-mini and gpt-oss-120b, 128000 for gpt-5.4-nano and gpt-5.6-luna, 8192 for LFM2.5-1.2B-Instruct and llama-3.1-8b-instruct-fast, and 16384 for qwen3-30b-a3b-fp8. glm-5.3-flash is stored as 32786, which reads as a typo for 32768, so that row uses 32768 trim_messages sizes history from max_input_tokens, so lowering max_tokens leaves it unaffected * fix(zerogpu): flag prompt caching on glm-5.3-flash Repeating the same ~4.3K-token prompt against ZeroGPU on 2026-10-20 returned cached_tokens of 4320 on some glm-5.3-flash calls. gpt-oss-120b and llama-3.1-8b-instruct-fast returned 0 on all nine calls, and qwen3-30b-a3b-fp8 never returned cached_tokens, so they stay unflagged. Their cached prices stay as ZeroGPU publishes them, so any cache hit is still billed at the right rate * fix(zerogpu): set gpt-5.4-nano context window to 272000 ZeroGPU accepts a 271001-token gpt-5.4-nano prompt and rejects 273000 tokens as over the context window (checked 2026-10-21), so max_input_tokens is 272000 rather than the 400000 its catalog lists * fix(zerogpu): list zerogpu models for zerogpu/* wildcards zerogpu had no models_by_provider entry, so get_provider_models("zerogpu") returned None and a zerogpu/* wildcard listed no models. zerogpu_models is now filled from the cost map rows like openinfer_models and registered in models_by_provider * fix(zerogpu): flag gpt-5.4-nano as a reasoning model ZeroGPU honors reasoning_effort on gpt-5.4-nano (checked 2026-10-21). Without it the model spends 0 reasoning tokens, and with low or high it spends 32 or more. LiteLLM only treated it as a reasoning model by falling back to OpenAI's bare gpt-5.4-nano row, so get_model_info and /model/info reported supports_reasoning as null. The row now carries the flag itself * fix(zerogpu): flag deepseek, glm, gpt-oss and qwen3 as reasoning models ZeroGPU's /v1/models marks these four as reasoning models and accepts reasoning_effort on all of them (checked 2026-10-21), but LiteLLM rejected the param with UnsupportedParamsError because their rows had no supports_reasoning flag. glm reports reasoning_tokens under reasoning_effort, and gpt-oss and qwen3 spend hidden reasoning tokens on every reply. The gpt-oss test case now expects reasoning_effort to reach ZeroGPU * fix(zerogpu): set gpt-oss-120b context window to 128000 ZeroGPU routes gpt-oss-120b across several upstream backends, and at least one of them returns 413 past a 128000-token window, so max_input_tokens uses that as the safe floor. The backends reached on 2026-10-21 accepted up to about 131K prompt tokens, so this only gives up a little headroom on the larger ones * feat(zerogpu): call ZeroGPU's Responses API natively ZeroGPU serves /v1/responses for all nine catalog models, so LiteLLM no longer bridges Responses requests through chat completions. Native calls return ZeroGPU's reasoning output items for glm, gpt-oss and qwen3, which the bridge dropped. Checked live on 2026-10-22 through litellm.responses for every model, non-streaming and streaming, plus a gpt-oss tool call. LFM2.5-1.2B-Instruct streams correctly now that ZeroGPU's text_generation lane emits Responses SSE * fix(zerogpu): stop inferring the zerogpu provider from api_base alone Listing https://api.zerogpu.ai/v1 in openai_compatible_endpoints rerouted bare model names on that api_base from openai to zerogpu. A bare gpt-5.6-luna call with verbosity used to return 200 and started raising UnsupportedParamsError. Drop the entry and its api_base-alone test, so zerogpu is only selected through the zerogpu/ prefix * fix(zerogpu): price gpt-6-luna, llama-3.2-3b, LFM2.5-1.2B-Thinking and qwen3.6 A zerogpu/* wildcard served these four chat models with no cost-map row, so their calls logged $0 spend. Add rows at ZeroGPU's catalog prices from https://api-dashboard.zerogpu.ai/api/models, with context windows and output caps from ZeroGPU's models table. LFM2.5-1.2B-Thinking has no cached price, like LFM2.5-1.2B-Instruct. gpt-6-luna is flagged supports_reasoning because LiteLLM already routes gpt-6 names as reasoning models. Checked live on 2026-10-28, all four now report nonzero response_cost * fix(zerogpu): drop the retired max_tokens field from the zerogpu rows Upstream #48471 retired max_tokens from the cost map in favor of max_input_tokens and max_output_tokens, and test_no_row_carries_the_retired_max_tokens_field failed on all 13 zerogpu rows. Every row already carries the same value in max_output_tokens, so nothing is lost. The zerogpu limits test now checks that each row's output limit fits its context window * chore(zerogpu): regenerate provider endpoint support for zerogpu Upstream #48619 generates provider_endpoints_support.json from the cost map and checks it in CI, and the hand-written zerogpu entry no longer matched. Regenerated with scripts/generate_provider_endpoints_support.py. Only the zerogpu entry changed, and it now matches what the generator emits for other JSON-registry providers such as openinfer * fix(zerogpu): flag tools, json_schema and prompt caching on gpt-6-luna ZeroGPU serves function calling, tool_choice, json_schema response_format and prompt caching on gpt-6-luna, so set supports_function_calling, supports_tool_choice, supports_response_schema and supports_prompt_caching on its row in both cost maps. Checked live on 2026-10-28, a weather tool call came back with the right arguments, json_schema output validated, and repeated prompts reported 3260 of 3263 tokens cached * fix(zerogpu): set qwen3.6-35b-a3b context to 262144 and flag its tools and reasoning ZeroGPU accepts up to 262,144 input tokens on qwen3.6-35b-a3b and serves tools, tool_choice, json_schema response_format and reasoning_effort on it. Raise max_input_tokens from 16384 and set supports_function_calling, supports_tool_choice, supports_response_schema and supports_reasoning in both cost maps. Before this, LiteLLM rejected tools and reasoning_effort for the model. Checked live on 2026-10-28, a 209,905-token prompt succeeded, an oversized one was refused with a 262144-token limit, and tool calls, json_schema output and reasoning_effort all worked * fix(zerogpu): flag vision on gpt-6-luna and qwen3.6-35b-a3b ZeroGPU reads image inputs on gpt-6-luna and qwen3.6-35b-a3b, so set supports_vision on both rows in both cost maps. Checked live on 2026-10-28, both models named the animal in an image_url photo, and the image showed up in their prompt token counts
This was referenced Oct 28, 2026
2 of 6 tasks
sundar-flex
added a commit
to sundar-flex/litellm
that referenced
this pull request
Nov 17, 2026
- Remove DeepSeek-V4.1-Flash and Qwen3-8B-FP8, which FlexAI no longer serves (absent from GET /v1/models on 2026-10-29). - GLM-5.2 prices follow the catalog: $0.70 input, $2.20 output, $0.105 cached input per 1M tokens. - Drop the legacy max_tokens field from every flexai/* row, following BerriAI#48471; max_input_tokens and max_output_tokens already carry the limits. - Main and backup cost maps stay identical for flexai/* rows. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
4 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The cost map carried a legacy
max_tokensfield on 3,325 rows that duplicated eithermax_output_tokensormax_input_tokens, and five code paths read it as a fallback when the specific field was missing. This PR copies the legacy value into the missing specific field on the 231 rows that only had the legacy one, deletes the field from both bundled JSON files, and drops the fallback reads./model/infostill returnsmax_tokens, now derived frommax_output_tokens(ormax_input_tokensfor rows with no output cap), so API clients see the same numbers as beforeDetails
TLDR
Problem this solves:
max_tokensin the cost map meant output cap on some rows and context window on othersHow it solves it:
max_output_tokensget it from the legacy valuemax_input_tokensget it from the legacy valuemax_tokensremoved from every row and fromsample_specin both JSON filesget_max_tokens,trim_messages, OTPM reservation, MCP sampling and the Router azure fallback read only the specific fieldget_model_infoderivesModelInfoBase.max_tokensasmax_output_tokens or max_input_tokensmax_tokensrow["max_tokens"] == row["max_output_tokens"]assertion andtest_together_chat_entries_never_carry_context_length_as_output_ceiling, which forbade the shape the port creates on 71 together_ai rowsUser Flow
Before: a proxy admin reading
/model/infofor a hosted model seesmax_output_tokens: nulleven though the row has a cap under the legacy namemistral/mistral-large-4in the configmax_tokens: 1048576,max_input_tokens: 1048576,max_output_tokens: nullmax_tokensis the output cap here, while ongpt-5.5it is also the output cap but on an embedding row it is the context windowAfter: the same request returns the cap under its real name and
max_tokensunchangedmistral/mistral-large-4in the configmax_tokens: 1048576,max_input_tokens: 1048576,max_output_tokens: 1048576max_input_tokensandmax_output_tokensdirectly, andmax_tokenskeeps its old value for existing clientsPre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreScreenshots / Proof of Fix
Shared setup: proxy started with
LITELLM_LOCAL_MODEL_COST_MAP=Trueand this config, no databaseCommand on both sides, printing the three limit fields of each
model_infoBefore (ccd783d)
After (eb80d51)
Type
🧹 Refactoring
Caveats (if any)
Medium
max_output_tokensoverstates the real output cap. It is the same numberget_max_tokensreturned for them before, now under a truthful key, chosen over leaving the field unset so no caller sees a different value. The provider sync bots can tighten them, and the together_ai sync script still writes nomax_output_tokenson new rowsmax_tokensstraight out of the raw JSON on GitHub loses the field./model/infoandget_model_infokeep returning itLow
trim_messagesnow indexesmax_input_tokensdirectly. Rows without it raisedKeyErrorbefore too, because they had nomax_tokenseithermodel_info: {max_tokens: X}set on a deployment is still stored byregister_modelbut no longer feedsget_model_info'smax_tokens. The proxy's/model/infomerges deploymentmodel_infoon top, so the value still shows thereFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/fbc55eed538941be81e05f1a5ff56d22
Open in Devin Desktop: https://app.devin.ai/desktop/session/fbc55eed538941be81e05f1a5ff56d22?variant=devin
Requested by: @kerry-berri