Repository navigation
Conversation
…ng payload OpenRouter returns the provider that actually served a request as the top-level `provider` field, on the response body and on every streaming chunk. Since cost for openrouter/* became provider-reported per call, the same model's cost varies call to call and nothing in the logging payload said why. Pass the field through as the `upstream_provider` hidden param and carry it into StandardLoggingHiddenParams for both non-streaming and streaming completions. - types/utils.py: StandardLoggingHiddenParams gains upstream_provider (ReadOnly[str | None]); the three literal constructions set it to None. - openrouter/chat/transformation.py: transform_response reads the body's `provider` next to the existing usage.cost read; chunk_parser records it on each parsed chunk. - streaming_handler.py: _ParsedChunkHiddenParams/_provider_hidden_params forward it onto the chunks returned to the caller. - streaming_chunk_builder_utils.py: the assembled response takes it from whichever chunk carries it, without mutating a chunk's dict. The value is OpenRouter's provider display name for that call; it names the provider, not the endpoint. Nothing is computed from it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Contributor
The strict-rule gate flagged TRY300 on chunk_parser: returning a name from inside the try body. The base returned a call expression, which the rule exempts. Keep the parsing and the upstream_provider hidden param inside the try, and return from the else clause, as the rule suggests. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…er change Keep the cast-ok markers the discipline gate requires; remove the narrative comments and restore the original except-clause comment. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
BeWayllar
marked this pull request as ready for review
October 13, 2026 18:30
Covers the no-hidden-params branch of _with_upstream_provider that codecov flagged, and the chunk scan skipping chunks without the field. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Resolve the conflict in litellm/llms/openrouter/chat/transformation.py with upstream BerriAI#45388: keep the validated response mapping and the isinstance guard on the cost, and read the top-level provider key directly from the validated body instead of through a cast. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Resolves three end-of-file conflicts in the unit test modules where both sides appended tests; both sets are kept. No change to the feature. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Closed
1 task done
4 of 6 tasks
Contributor
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.
TLDR
Problem this solves:
providerfield; LiteLLM drops itHow it solves it:
upstream_providerhidden param on every responseusage.costreadStandardLoggingHiddenParamsgainsupstream_provider, so every logging callback receives itUser Flow
Before: a developer logging spend per request through OpenRouter gets a provider-reported cost in every payload, but nothing says which provider produced it, so cost variation across calls has no explanation in their own logs
"model": "openrouter/z-ai/glm-5.3-flash", once plain and once with"stream": trueresponse_costset from OpenRouter's reported costhidden_paramscarrymodel_id,api_base,response_costand the usage object, and no field naming the provider that served the callAfter: the same payloads name the provider beside the cost
hidden_paramsnow carriesupstream_provider, the serving provider's name, next toresponse_costRelevant issues
Closes #48038 (record which provider served an OpenRouter request, next to its reported cost)
Related: #16021 (provider-reported cost in streaming, now on
main), #38802 (the same pass-through for DeepInfra's reported cost, a follow-up)Pre-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 moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Real OpenRouter calls through the LiteLLM SDK with
OPENROUTER_API_KEYset, modelopenrouter/z-ai/glm-5.3-flash, promptReply with the single word: ok,max_tokens=1024,reasoning_effort="low". A custom logger records what the standard logging payload'shidden_paramscarry for one non-streaming and one streaming call; the same script runs at both commits withPYTHONPATHpointed at the checkout.Before (cb94567)
Non-streaming
PYTHONPATH=. python proof_upstream_provider.py(first call)'ok',response_cost1.48e-06,hidden_params.upstream_provider<field absent>;hidden_params.keysareadditional_headers, api_base, batch_failed_requests, batch_models, batch_successful_requests, cache_key, litellm_model_name, litellm_overhead_time_ms, model_id, response_cost, usage_objectStreaming
stream=True)'ok',response_cost1.48e-06,hidden_params.upstream_provider<field absent>; the same eleven keysAfter (244e0c1)
Non-streaming
PYTHONPATH=. python proof_upstream_provider.py(first call)'ok',response_cost1.48e-06,hidden_params.upstream_providerInferenceNet;hidden_params.keysnow also includeupstream_providerStreaming
stream=True)'ok',response_cost1.48e-06,hidden_params.upstream_providerInferenceNet;upstream_providerpresent among the keysBoth runs routed to the same provider at the same reported cost; the field is what changed.
Type
🆕 New Feature
Caveats (if any)
Low
provider; a chunk without it is skipped and the field is simply absent, never wrongFinal Attestation