Repository navigation
fix(decisions): bill unpriced returned TypeSafe versions at the requested model and name a missing answers field - #47508
Conversation
…cision models at the requested model Co-authored-by: Joshua Valluru <326636767+joshua-berri@users.noreply.github.com>
|
@litellm-stampbot |
litellm-stampbot: risk lowApproved at Rules (
Judge: skipped, the rules alone decided. Pushes do not re-run this check. Comment |
kerry-berri
left a comment
There was a problem hiding this comment.
Low risk by rule and by judgement at 3c43bce
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…ision models only when they carry rates Co-authored-by: Joshua Valluru <326636767+joshua-berri@users.noreply.github.com>
Merging this PR will not alter performance
|
|
@litereview code-review |
|
[Medium impact] The PR appears safe to merge, with no actionable issues found SummaryThis PR bills unpriced returned decisions models at the requested model’s rates. Returned models with declared rates still use their own prices It also names malformed response fields and returns 500 for schema failures. The Arize tests now find cache-hit spans by The earlier, unnumbered finding about missing live error-path proof is addressed by the proxy examples supplied by
Reviews (6) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile |
…ecisions pricing and missing-answers fixes
|
@litereview code-review |
1 similar comment
|
@litereview code-review |
Review already requestedcode-review is already reviewing |
| ) | ||
| assert len(marker_spans) == 2, spans | ||
| _assert_tool_span_for_marker(marker_spans[1], marker) | ||
| assert marker_spans[1]["litellm.cache_hit"] == "True", marker_spans |
There was a problem hiding this comment.
Medium · New cache-hit span assertion fails because the test picks the span by arrival order
test_arize_otel_v2_cache_hit_exports_llm_spanmakes a chat call formarker, then repeats it as a cache hit.- The test gathers the two
markerLLM spans in the order the OTLP receiver drained them. It assumesmarker_spans[1]is the cache hit. - In practice, the cache-hit span gets exported first, so
marker_spans[0]is the hit (cache_hit="True", cost0.0) andmarker_spans[1]is the original call ("False",4.05e-06). - The new
assert marker_spans[1]["litellm.cache_hit"] == "True"fails. I saw it fail in 3 of 3 runs against this head. The extensions group runs this file on main, so the suite this PR is meant to turn green would gain a new red.
Smallest fix: pick the span with litellm.cache_hit == "True", the same way this PR's test_arize_otel_v2_a_cache edit does, instead of indexing by position.
Evidence
Command: INTEGRATION_WORKERS=2 python tests/integration/run.py extensions tests/integration/observability/test_arize_otel_v2_openinference_spans.py::test_arize_otel_v2_cache_hit_exports_llm_span with local Postgres 15 and Redis.
Result: E assert 'False' == 'True' at assert marker_spans[1]["litellm.cache_hit"] == "True". It failed once in the batch run (11 other selected Arize cases passed) and in 2 of 2 isolated reruns.
A temporary debug print, since removed, showed [(cache_hit, cost.total) for s in marker_spans] == [('True', '0.0'), ('False', '4.05e-06')] on both reruns. The hit is at index 0.
The existing _assert_tool_span_for_marker(marker_spans[1], marker) passes for either span, so the ordering assumption had never been tested until this PR added attribute assertions on [1].
tests/integration/AGENTS.md: CircleCI integration groups run on main, not on pull requests, so this failure first shows up after merge.
Latest summary by code-review · View this review · Reviewed 62058c4492cc
…e-hit span by attribute
…d_callbacks_once # Conflicts: # litellm/cost_calculator.py
|
@litereview code-review |
1 similar comment
|
@litereview code-review |
Review already requestedcode-review is already reviewing |
|
@litereview code-review |
|
@litereview code-review |
Review already requestedcode-review is already reviewing |
|
@litereview code-review |
…tever text it carries A reply that fails the decisions response schema now raises DecisionsResponseValidationError, which the decisions call maps straight to InternalServerError instead of passing it through exception_type. Its text matching read an answer key like rate_limit, or a value like "Request timed out", as a 429 or a 408, so the router cooled down a deployment for a reply that fails the same way on every retry. The message also drops the empty location for a reply that is not an object, the Arize family test loses the cache_hit entries main already added, and the Bedrock Mantle count-tokens wire test calls _metadata_deployment, since main renamed the _deployment helper under it.
…d_callbacks_once # Conflicts: # tests/integration/providers/test_bedrock_mantle_count_tokens_wire.py
|
@litereview code-review |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit bba5033. Configure here.
|
The post-merge audit of this change is #48777, and every behavior it fixed holds at the merge commit and fails at its parent |
… on main Drop the Router override that let a caller base_url replace a deployment's own api_base. Main's prepare_call reads base_url only when no api_base is set, and the router now merges the caller kwargs the same way, so the LTS line matches main's precedence. Also drop the list-form score legend normalization from the #47508 port. It came from #46523 on main, and neither LTS provider that reaches it (Gemini, TypeSafe) sends a list legend. Cover the sync Router credential guard for both URL parameter names.
Backport of BerriAI#47508 to lts/1.108.x (prerequisite of BerriAI#51220). Cherry-picked from 81d8c9a (main). Minimal hand-port of response validation, omitting unrelated pricing and observability changes. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
A
typesafe/jev-latestdecision bills $0 when TypeSafe answers as a version the proxy serves but the cost map does not price yet, since pricing used the empty row the router registers for every served deployment. This PR still prices by the returned version when its row has rates, and falls back to the requested deployment's rates when it has noneIt also answers every System One reply that fails the response schema with a 500 naming the field at fault, so reply text such as an answer named
rate_limitno longer turns it into a 429. The Arize tests now expectlitellm.cache_hitand one cache-hit span carrying it, as #47364 set upOriginal
TLDR
Problem this solves:
litellm.cache_hitattributeHow it solves it:
User Flow
Before, a TypeSafe call bills $0 when TypeSafe answers as a version the cost map does not price yet
typesafe/jev-latestandtypesafe/jev-1.13.0, and its cost map has notypesafe/jev-1.13.0row"model":"typesafe/jev-latest"is answered asjev-1.13.0, with nox-litellm-response-costheader0.0for 287 input tokensAfter, the same call bills at
typesafe/jev-latest's ratesx-litellm-response-cost: 1.2054e-051.2054e-05Before, a TypeSafe deployment whose
api_baseanswers 200 withoutanswersfails with an error naming no field1 validation error for dict[str,any] ... input_value=NoneAfter, the same call says
answersis missingDecisionsResponse answers: Field requiredRelevant issues
Replaces #47047, which stampbot rated high risk. #47510 now carries its double-billing fix
CircleCI
Red on
main's scheduled integration workflow since pipeline 91315: the twotypesafe/jev-latestcases of integration-cost, the decisions wire test in integration-providers, and 11 Arize cases in integration-extensions. Throughtests/integration/run.pythey pass here and fail on the merge basePre-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
Proxies from 2c6b280 (merge base) and bba5033 (head), 2 uvicorn workers each, own Postgres and Redis, the same config, real TypeSafe, OpenAI and OpenRouter calls, and a fresh key per case, with raw outputs
answersanswersanswersrate_limit, both routesanswers.rate_limitbase_modelbase_modelBefore (2c6b280)
TypeSafe unlisted version
The proxy loads its cost map from
LITELLM_MODEL_COST_MAP_URL, this commit's own map minus thetypesafe/jev-1.13.0andtypesafe/jev-1.14.0rowscurl -s localhost:$PORT/model/info -H "Authorization: Bearer $MASTER"showsinput_cost_per_token4.2e-08fortypesafe/jev-latestandnullfortypesafe/jev-1.13.0curl -si localhost:$PORT/v1/decisions -H "Authorization: Bearer $KEY" -H 'content-type: application/json' -d '{"model":"typesafe/jev-latest","input":"Ticket (billing): The export job hangs at 99% and never finishes","questions":[{"type":"predicate","name":"defect","instructions":"Is this a defect?"}]}'curl -s "localhost:$PORT/spend/logs?api_key=$KEY" -H "Authorization: Bearer $MASTER"Raw output
After (bba5033)
TypeSafe unlisted version
The same three steps and the same map edit
Raw output
Every other case
Same, through System One
The same proxy, then
curl -si localhost:$PORT/v1/systemone -H "Authorization: Bearer $KEY" -H 'content-type: application/json' -d '{"model":"typesafe/jev-latest","state":"Ticket (billing): The export job hangs at 99% and never finishes","questions":{"defect":{"type":"noul","instructions":"Is this a defect?"}}}'with a fresh key. TypeSafe answers asjev-1.13.0with 287 input tokens on both commits. Before, there is nox-litellm-response-costheader and the spend-log row reads 0.0. After, the header and the row read1.2054e-05. Before, afterTypeSafe priced version
This is the control for a returned version whose row has rates. The proxy loads a map where only
typesafe/jev-1.13.0'sinput_cost_per_tokenis1e-07, and/model/infoshows4.2e-08fortypesafe/jev-latestand1e-07fortypesafe/jev-1.13.0. The same/v1/decisionscall, answered asjev-1.13.0with 287 input tokens, costs2.87e-05(287 x1e-07) on both commits, never1.2054e-05atjev-latest's rate, and its spend-log row matches. Before, afterReply without
answersA deployment
typesafe-misroutedwithmodel: typesafe/jev-latestandapi_base: https://httpbin.org/anything, a real server that answers 200 with an echo of the request and noanswersfield, stands in for anapi_basepointed at a host that is not TypeSafe.curl -si localhost:$PORT/v1/decisions -H "Authorization: Bearer $KEY" -H 'content-type: application/json' -d '{"model":"typesafe-misrouted","input":"Ticket (billing): The export job hangs at 99% and never finishes","questions":[{"type":"predicate","name":"defect","instructions":"Is this a defect?"}]}'returns 500internal_server_erroron both commits. Before, the message reads1 validation error for dict[str,any] Input should be a valid dictionary [type=dict_type, input_value=None, input_type=NoneType]. After, it readsDecisionsResponse answers: Field required. Before, afterReply without
answerswhose text reads like a rate limit or a timeoutTwo Perplexity deployments on
perplexity/pplx-decider-v1-27bpointapi_baseathttps://httpbin.org/response-headers?error=<text>#, which answers 200 with{"error": "Rate limit reached"}or{"error": "Request timed out"}and noanswers. Perplexity's error mapping reads message text, so these are the replies a text match could turn into a 429 or a 408.curl -si localhost:$PORT/v1/systemone -H "Authorization: Bearer $KEY" -H 'content-type: application/json' -d '{"model":"pplx-ratelimit-text","state":"Ticket (billing): The invoice PDF download returns a blank page","questions":{"defect":{"type":"noul","instructions":"Is this a defect?"}}}', and the same withpplx-timeout-text, return 500internal_server_erroron both commits. After, the message readsDecisionsResponse answers: Field requiredwith none of the upstream text. Before, afterNull answer named
rate_limitDeployment
pplx-null-rate-limitonperplexity/pplx-decider-v1-27bpointsapi_baseat a hosted endpoint that answers 200 with{"model":"pplx-decider-v1-27b","answers":{"rate_limit":null},"usage":{"input_tokens":10,"output_tokens":0}}.curl -si localhost:$PORT/v1/systemone -H "Authorization: Bearer $KEY" -H 'content-type: application/json' -d '{"model":"pplx-null-rate-limit","state":"Ticket (billing): The card was charged twice after a retry","questions":{"rate_limit":{"type":"noul","instructions":"Is this about a rate limit?"}}}', and the same question through/v1/decisions, return 500internal_server_erroron both commits, never 429. Before, the message names no field. After, it readsDecisionsResponse answers.rate_limit: Input should be a valid dictionary or object to extract fields from. Before, afterChat through
base_modelThis PR also touches the helper that checks whether a cost-map row has rates when a deployment sets
base_model. Two deployments setbase_model: gpt-5.4-mini, one onopenrouter/openai/gpt-5.4-mini(no cost-map row of its own) and one onopenai/gpt-5.4-mini.curl -si localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'content-type: application/json' -d '{"model":"<model>","messages":[{"role":"user","content":"Reply with BASE and nothing else."}],"max_completion_tokens":32}'costs3.225e-05through OpenRouter and2.775e-05through OpenAI on both commits, which isgpt-5.4-mini's7.5e-07and4.5e-06rates, and each spend-log row matches. Before, afterThings the run saw that this PR leaves alone
Type
🐛 Bug Fix
✅ Test
Caveats (if any)
Low
/live-pr-risk at bba5033
Both legs ran 2 uvicorn workers with their own Postgres and Redis, and forwarding recorders sat in front of httpbin.org and api.typesafe.ai, so every upstream attempt was counted. A third leg ran the head merged with main 4b19283
Breaking
None. Every cell that answers differently at bba5033 maps to a change listed below, and the merged leg matched the head on every cell
Backward incompatible
internal_server_errorwhatever its text. Live,{"answers": "Request timed out"}went from 408 to 500 on TypeSafe and a rate-limit text from 429 to 500 on Fireworks AI, and in-process 68 of 264 provider and reply pairs changed class. Decided in af1f588 by mateo-berri, the PR author, in line withtest_upstream_success_without_answers_is_a_gateway_side_server_errorfrom feat(decisions): add unified /v1/decisions endpoint for Jev-compatible providers #44236, which already holds a reply withoutanswersto a gateway-side 5xxOpenaiExceptioninstead ofOpenAIException. Fixed in 1c347fb and af1f588, decided by mateo-berrimodel_group_retry_policyreads the new class, so a group withTimeoutErrorRetries: 2, InternalServerErrorRetries: 0sends 1 attempt instead of 3. Decided in af1f588 by mateo-berri, since a malformed reply is a provider fault and a retry gets the same replyexception_classandexception_status, the spend log'serror_classanderror_code, and the/healthtext move fromTimeout408 orRateLimitError429 toInternalServerError500. Decided in af1f588 by mateo-berri for the same reasonRequest timed out, since it opens only on a reallitellm.Timeout. Every request still answered 200. Decided in af1f588 by mateo-berri, as this matches the breaker's designcost_map_key_prices_anythingis a new public helper inlitellm/cost_calculator.py, which is additiveRegression risk
Request timed outis a 408. This was seen in-process, and live an empty body answered 500 on both trees. It is pre-existing and filed as a follow-upallowed_fails_policynow counts these failures underInternalServerErrorAllowedFails. This was traced, not observederror.typeand theinclude_fallback_errorsheaders should follow the spend row'serror_class, but no exporter was wiredfloat(cost)can raise OverflowError on a huge integer. This is pre-existing and was reasoned, not runDependency graph
/v1/systemonestatus and body/v1/decisionsstatus and bodymodel_group_retry_policyallowed_fails_policyerror_classerror.type/healthtext_pricing_modelUnit tests at the head gave 3360 passed and 2 failed, and both failures are timing tests that pass alone on both trees. The integration lanes for decisions, cost, Arize, proxy logs, spend and management had 10 reds at the head, and all 10 fail on the base too
Not verified
The Fireworks AI happy path, since its router answers 404 on both trees. Live calls for
azure_ai,hosted_vllm,cloudflare,bespoke,laya,naceandstrands_decider, which ran in-process and on the integration lane's scripted upstream only. A raw-text 2xx body live,allowed_fails_policylive, the exporters'error.type, and the decisions playground UI specFinal Attestation
Bugbot summary