Repository navigation
fix(cost): bill a deployment's per-second rates on native Anthropic /v1/messages - #42417
Conversation
…m_per_second_chat_pricing
…aying at $0 The zero-cost diagnostic tests from #42345 used a per-second-only entry as their misconfigured fixture, which this branch now bills. Switch that fixture to a per-query-only entry, which is still selected as the deployment's own pricing and still prices chat usage at $0, and add a per-second test asserting the call duration is billed with no diagnostic Also let a caller's explicit total_time outrank the logging window in completion_cost, so the SDK precedence stays stamped response, caller, logging
…the mapped tests/unit file
…/v1/messages The proxy builds the request's logging state before the router picks a deployment, and only the chat path re-read the deployment's input_cost_per_second / output_cost_per_second afterwards. The shared update step every other route runs (Logging.update_from_kwargs) now seeds those custom pricing keys from the router-merged kwargs too, so custom_pricing flips on and the cost calculator prices the call against the router-registered deployment id on every surface.
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
Review for PR #42417: Bill a deployment's per-second rates on Endpoint Pricing Consistency Analysis
|
[Critical impact] The PR appears safe to merge, with the previously reported duration-unit issue conceded as originating outside this PR and no new actionable failures found Findings
SummaryThis PR propagates deployment per-second pricing into native Anthropic Messages calls and aligns non-streamed cost calculation with the response timing window used by spend logging
Reviews (9) · Last reviewed commit: "fix(cost): bill native /v1/messages from..." · Reviewed by Greptile |
| if isinstance(stamped, (int, float)): | ||
| return float(stamped) | ||
| if total_time: | ||
| return total_time |
There was a problem hiding this comment.
This helper lands in #42403, whose tip this branch starts from, so the seconds-vs-ms question is raised there and merges into this PR
There was a problem hiding this comment.
You’re right—the helper and its seconds-vs-milliseconds behavior come from the stacked #42403 change, not from the #42417 changes being reviewed here. This PR only reuses that helper for the newly covered routes, so the finding should be attributed to #42403 rather than block #42417.
The unit-handling issue should still be addressed in #42403 or a follow-up against that change.
Merging this PR will not alter performance1 warning
Comparing Footnotes |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…icing_responses_messages # Conflicts: # litellm/cost_calculator.py # tests/test_litellm/test_cost_calculator.py
|
bugbot run |
…reports A /v1/messages result is a plain dict, so the proxy keeps its response time on the logging object. The cost step now reads it there for a non-streamed call, so the cost header and the spend log bill the same duration.
…e /v1/messages route Move the custom pricing copy from the shared logging refresh into the native Messages handler, reusing the helper the Responses handler already had, so generateContent and other routes keep their current billing
…cking Other deployment overrides keep billing as on main, matching chat's per-second gate
…icing_responses_messages
…ith a long-context-rate deployment
…to the end the proxy reports
|
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 2383124. Configure here.
A deployment priced per second under
litellm_paramson a native Anthropic model now bills that rate on/v1/messages, as chat and Responses already do. Before, Messages billed the per-token priceA non-streamed native Messages call bills from logging setup, as main did, to the end of the response the proxy reports, so the cost header and
/spend/logsagree. Other overrides and routes bill as on mainAfter upgrading, Messages spend and the budgets it counts against move only for Claude deployments priced per second under
litellm_params, which billed the per-token price beforeOriginal
TLDR
Problem this solves:
/v1/messages, in the cost header and/spend/logsHow it solves it:
User Flow
Before: an admin who priced a Claude deployment per second sees
/v1/messagesbill the per-token priceclaude-per-secondforanthropic/claude-haiku-5-5with per-second rates of0.000420underlitellm_paramsx-litellm-response-cost: 6.5e-06, the per-token price, streamed or not, and GET https://litellm-domain/spend/logs?request_id= matchesAfter: the same Messages requests bill the per-second rate, like the other two routes
x-litellm-response-cost: 0.000401, which is 0.00042 × the call's 0.956 s, the spend log matches, and a stream bills its whole lengthRelevant issues
Follow-up to #42403, which made per-second rates bill on
/v1/chat/completionsDesign decisions
The native Messages handler passes only the deployment's per-second rates into its logging refresh, the set chat registers per call. Other overrides, such as a long-context rate, bill as on main. Per-second pricing bills once at the first rate set, per #43614
A non-streamed native Messages call bills from logging setup to the end of the response the proxy reports, read off the logging object since the plain-dict result cannot carry it. Main billed Messages from logging setup too, after auth, so a deployment priced per second under
model_infobills the same window as before, and the cost header now agrees with the spend log. A streamed call bills the whole streamAlternatives considered
model_info, which Messages already billed per second, then also billed auth and request reading, so their spend rose on upgrademodel_info: changes/model/info, the models page, and every consumer of the deployment, with two copies of one ratePre-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
Each leg is two 2-worker proxies at the named commit on one Postgres database, alternating requests, on real provider keys and the real Claude Code TUI
Config and shell setup
Before ran on ports 21115 and 29758, after on 30671 and 20716
The per-second price is 0.00042 × the call's duration in seconds, so around 0.0003 to 0.0008 for these calls, while claude-haiku-5-5's per-token price for them is around 1e-05. The 231k-token cases show a deployment's long-context rate bills the same on both legs and both routes, and the Gemini case shows generateContent bills the same way on both legs, since this PR leaves both alone
Claude Code, before (3f5e42d)
Count from one to thirty in words, nothing elseand press Entercurl -s "http://localhost:29758/spend/logs?api_key=$VKEY" "${H[@]}" | python3 -c "$CC_ROWS"Claude Code, after (2383124)
curl -s "http://localhost:20716/spend/logs?api_key=$VKEY" "${H[@]}" | python3 -c "$CC_ROWS"Before, curl cases (3f5e42d)
POST /v1/messages on the per-second Claude deployment
curl -s -D - http://localhost:29758/v1/messages "${H[@]}" -d '{"model": "claude-per-second", "max_tokens": 32, "messages": [{"role": "user", "content": "Say hi in three words"}]}' -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: f07ae05e-febc-4ff0-9610-822b0687c9b4,x-litellm-response-cost: 6.5e-06,x-litellm-response-duration-ms: 1397.279977798462,client_total_seconds: 2.006862curl -s "http://localhost:29758/spend/logs?request_id=f07ae05e-febc-4ff0-9610-822b0687c9b4" "${H[@]}" | python3 -c "$ROW"[{'model': 'anthropic/claude-haiku-5-5', 'call_type': 'anthropic_messages', 'spend': 6.5e-06, 'prompt_tokens': 15, 'total_tokens': 25}](the model's per-token price, so the per-second rate is ignored)POST /v1/messages with stream on the per-second Claude deployment
curl -s -N -D - http://localhost:21115/v1/messages "${H[@]}" -d '{"model": "claude-per-second", "max_tokens": 200, "stream": true, "messages": [{"role": "user", "content": "Count from 1 to 40 in words"}]}' -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: d96f4a4e-684d-4e38-80eb-c446133f3483,client_total_seconds: 1.717417(a streamed response sends its headers before the cost is known)curl -s "http://localhost:21115/spend/logs?request_id=d96f4a4e-684d-4e38-80eb-c446133f3483" "${H[@]}" | python3 -c "$ROW"[{'model': 'anthropic/claude-haiku-5-5', 'call_type': 'anthropic_messages', 'spend': 9.9e-05, 'prompt_tokens': 20, 'total_tokens': 214}](the model's per-token price, so the per-second rate is ignored)POST /v1/messages on a per-second Claude deployment on Vertex AI
curl -s -D - http://localhost:21115/v1/messages "${H[@]}" -d '{"model": "vertex-claude-per-second", "max_tokens": 32, "messages": [{"role": "user", "content": "Say hi in three words"}]}' -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: 591ab350-0d1d-4d58-bd73-7b34a2b11910,x-litellm-response-cost: 6.5e-06,x-litellm-response-duration-ms: 922.7819442749023,client_total_seconds: 0.946678curl -s "http://localhost:21115/spend/logs?request_id=591ab350-0d1d-4d58-bd73-7b34a2b11910" "${H[@]}" | python3 -c "$ROW"[{'model': 'vertex_ai/claude-haiku-5-5', 'call_type': 'anthropic_messages', 'spend': 6.5e-06, 'prompt_tokens': 15, 'total_tokens': 25}](the model's per-token price, so the per-second rate is ignored)POST /v1/messages with stream on the Vertex AI deployment
curl -s -N -D - http://localhost:29758/v1/messages "${H[@]}" -d '{"model": "vertex-claude-per-second", "max_tokens": 200, "stream": true, "messages": [{"role": "user", "content": "Count from 1 to 40 in words"}]}' -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: 61104ece-3ee4-4864-bdd9-21c6af762cae,client_total_seconds: 1.552626(a streamed response sends its headers before the cost is known)curl -s "http://localhost:29758/spend/logs?request_id=61104ece-3ee4-4864-bdd9-21c6af762cae" "${H[@]}" | python3 -c "$ROW"[{'model': 'vertex_ai/claude-haiku-5-5', 'call_type': 'anthropic_messages', 'spend': 9.9e-05, 'prompt_tokens': 20, 'total_tokens': 214}](the model's per-token price, so the per-second rate is ignored)POST /v1/messages with a 231k-token prompt on a long-context-priced deployment
curl -s -D - http://localhost:29758/v1/messages "${H[@]}" --data-binary @<(long_body) -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: 0002fce1-bb18-4d98-a8b4-d7d2a0bdb62d,x-litellm-response-cost: 0.1155155,x-litellm-response-duration-ms: 8347.465991973877,client_total_seconds: 8.375509curl -s "http://localhost:29758/spend/logs?request_id=0002fce1-bb18-4d98-a8b4-d7d2a0bdb62d" "${H[@]}" | python3 -c "$ROW"[{'model': 'anthropic/claude-haiku-5-5', 'call_type': 'anthropic_messages', 'spend': 0.1155155, 'prompt_tokens': 231016, 'total_tokens': 231019}](231016 prompt tokens at the model's own 100k-tier price, the same on both routes and both legs, since this PR leaves that rate alone)POST /v1/chat/completions with the same prompt and deployment
curl -s -D - http://localhost:21115/v1/chat/completions "${H[@]}" --data-binary @<(long_body) -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: 8a4585c1-38b9-484e-8a5a-98e9348a6bca,x-litellm-response-cost: 0.1155155,x-litellm-response-duration-ms: 3077.3379802703857,client_total_seconds: 3.098125curl -s "http://localhost:21115/spend/logs?request_id=8a4585c1-38b9-484e-8a5a-98e9348a6bca" "${H[@]}" | python3 -c "$ROW"[{'model': 'anthropic/claude-haiku-5-5', 'call_type': 'acompletion', 'spend': 0.1155155, 'prompt_tokens': 231016, 'total_tokens': 231019}](231016 prompt tokens at the model's own 100k-tier price, the same on both routes and both legs, since this PR leaves that rate alone)POST /v1/responses on the per-second Claude deployment
curl -s -D - http://localhost:21115/v1/responses "${H[@]}" -d '{"model": "claude-per-second", "input": "Say hi in three words"}' -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: ec28ed8f-a12a-4904-9f8c-f16ba4e4d032,x-litellm-response-cost: 0.001218663239479065,x-litellm-response-duration-ms: 3099.4319915771484,client_total_seconds: 3.183473curl -s "http://localhost:21115/spend/logs?request_id=ec28ed8f-a12a-4904-9f8c-f16ba4e4d032" "${H[@]}" | python3 -c "$ROW"[{'model': 'anthropic/claude-haiku-5-5', 'call_type': 'aresponses', 'spend': 0.001218663239479065, 'prompt_tokens': 15, 'total_tokens': 25}](0.00042 × 2.902 s, the per-second rate times the call's duration)POST /v1/chat/completions on the per-second Claude deployment
curl -s -D - http://localhost:29758/v1/chat/completions "${H[@]}" -d '{"model": "claude-per-second", "messages": [{"role": "user", "content": "Say hi in three words"}]}' -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: 7aebd4eb-a6d1-480f-b05c-c6a4725e6045,x-litellm-response-cost: 0.00037707558631896977,x-litellm-response-duration-ms: 897.799015045166,client_total_seconds: 0.953078curl -s "http://localhost:29758/spend/logs?request_id=7aebd4eb-a6d1-480f-b05c-c6a4725e6045" "${H[@]}" | python3 -c "$ROW"[{'model': 'anthropic/claude-haiku-5-5', 'call_type': 'acompletion', 'spend': 0.0003770755863189698, 'prompt_tokens': 15, 'total_tokens': 25}](0.00042 × 0.898 s, the per-second rate times the call's duration)POST /v1/messages on a Claude deployment without custom rates
curl -s -D - http://localhost:21115/v1/messages "${H[@]}" -d '{"model": "claude-cost-map", "max_tokens": 32, "messages": [{"role": "user", "content": "Say hi in three words"}]}' -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: 922a13a4-9716-42e6-aa37-6a1db749f704,x-litellm-response-cost: 6.5e-06,x-litellm-response-duration-ms: 933.466911315918,client_total_seconds: 0.962592curl -s "http://localhost:21115/spend/logs?request_id=922a13a4-9716-42e6-aa37-6a1db749f704" "${H[@]}" | python3 -c "$ROW"[{'model': 'anthropic/claude-haiku-5-5', 'call_type': 'anthropic_messages', 'spend': 6.5e-06, 'prompt_tokens': 15, 'total_tokens': 25}](the model's per-token price, unchanged)POST /v1/messages on the per-second OpenAI deployment
curl -s -D - http://localhost:29758/v1/messages "${H[@]}" -d '{"model": "per-second-priced", "max_tokens": 32, "messages": [{"role": "user", "content": "Say hi in three words"}]}' -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: 989bf660-4dc4-4c4b-957f-cd6cc26b501d,x-litellm-response-cost: 0.00030531987190246583,x-litellm-response-duration-ms: 770.9200382232666,client_total_seconds: 0.814789curl -s "http://localhost:29758/spend/logs?request_id=989bf660-4dc4-4c4b-957f-cd6cc26b501d" "${H[@]}" | python3 -c "$ROW"[{'model': 'openai/gpt-5.4-nano', 'call_type': 'anthropic_messages', 'spend': 0.0003053198719024658, 'prompt_tokens': 11, 'total_tokens': 18}](0.00042 × 0.727 s, the per-second rate times the call's duration)POST /v1/messages on a Claude deployment priced per second under model_info
curl -s -D - http://localhost:21115/v1/messages "${H[@]}" -d '{"model": "claude-per-second-model-info", "max_tokens": 32, "messages": [{"role": "user", "content": "Say hi in three words"}]}' -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: bf646a76-9822-4871-ac85-ca2967e50bbe,x-litellm-response-cost: 0.00040353186607360844,x-litellm-response-duration-ms: 960.8230590820312,client_total_seconds: 1.010143curl -s "http://localhost:21115/spend/logs?request_id=bf646a76-9822-4871-ac85-ca2967e50bbe" "${H[@]}" | python3 -c "$ROW"[{'model': 'anthropic/claude-haiku-5-5', 'call_type': 'anthropic_messages', 'spend': 0.0004003822946548462, 'prompt_tokens': 15, 'total_tokens': 24}](0.00042 × 0.953 s, the per-second rate times the call's duration, while the cost header said 0.000404 for the same call)POST /v1/chat/completions on the same model_info deployment
curl -s -D - http://localhost:29758/v1/chat/completions "${H[@]}" -d '{"model": "claude-per-second-model-info", "messages": [{"role": "user", "content": "Say hi in three words"}]}' -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: ea73b6b7-b78a-4af5-be0f-f6b8036dfbfc,x-litellm-response-cost: 0.0003413011693954468,x-litellm-response-duration-ms: 812.6218318939209,client_total_seconds: 0.824834curl -s "http://localhost:29758/spend/logs?request_id=ea73b6b7-b78a-4af5-be0f-f6b8036dfbfc" "${H[@]}" | python3 -c "$ROW"[{'model': 'anthropic/claude-haiku-5-5', 'call_type': 'acompletion', 'spend': 0.0003413011693954468, 'prompt_tokens': 15, 'total_tokens': 25}](0.00042 × 0.813 s, the per-second rate times the call's duration)POST generateContent on a per-second Gemini deployment
curl -s -D - http://localhost:21115/v1beta/models/gemini-per-second:generateContent "${H[@]}" -d '{"contents": [{"role": "user", "parts": [{"text": "Say hi in three words"}]}]}' -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: e49d5fa4-1e4c-483e-a130-af1a36edca72,x-litellm-response-cost: 0.001092,x-litellm-response-duration-ms: 4011.7578506469727,client_total_seconds: 4.061602curl -s "http://localhost:21115/spend/logs?request_id=e49d5fa4-1e4c-483e-a130-af1a36edca72" "${H[@]}" | python3 -c "$ROW"[{'model': 'gemini/gemini-3.8-flash', 'call_type': 'agenerate_content', 'spend': 0.001092, 'prompt_tokens': 6, 'total_tokens': 296}](per-token on both legs, since this PR leaves generateContent alone)After, curl cases (2383124)
POST /v1/messages on the per-second Claude deployment
curl -s -D - http://localhost:20716/v1/messages "${H[@]}" -d '{"model": "claude-per-second", "max_tokens": 32, "messages": [{"role": "user", "content": "Say hi in three words"}]}' -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: de846b7f-0d85-4035-befe-239c8669874d,x-litellm-response-cost: 0.0004013956689834595,x-litellm-response-duration-ms: 1112.9329204559326,client_total_seconds: 1.481285curl -s "http://localhost:20716/spend/logs?request_id=de846b7f-0d85-4035-befe-239c8669874d" "${H[@]}" | python3 -c "$ROW"[{'model': 'anthropic/claude-haiku-5-5', 'call_type': 'anthropic_messages', 'spend': 0.0004013956689834595, 'prompt_tokens': 15, 'total_tokens': 25}](0.00042 × 0.956 s, the per-second rate times the call's duration)POST /v1/messages with stream on the per-second Claude deployment
curl -s -N -D - http://localhost:30671/v1/messages "${H[@]}" -d '{"model": "claude-per-second", "max_tokens": 200, "stream": true, "messages": [{"role": "user", "content": "Count from 1 to 40 in words"}]}' -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: 61506593-5e84-4c6a-a647-1e98e9102972,client_total_seconds: 1.583149(a streamed response sends its headers before the cost is known)curl -s "http://localhost:30671/spend/logs?request_id=61506593-5e84-4c6a-a647-1e98e9102972" "${H[@]}" | python3 -c "$ROW"[{'model': 'anthropic/claude-haiku-5-5', 'call_type': 'anthropic_messages', 'spend': 0.0005472306489944459, 'prompt_tokens': 20, 'total_tokens': 214}](0.00042 × 1.303 s, the per-second rate times the call's duration)POST /v1/messages on a per-second Claude deployment on Vertex AI
curl -s -D - http://localhost:30671/v1/messages "${H[@]}" -d '{"model": "vertex-claude-per-second", "max_tokens": 32, "messages": [{"role": "user", "content": "Say hi in three words"}]}' -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: d3b4029e-1814-4178-9b8f-273b28db97f5,x-litellm-response-cost: 0.0004316108465194702,x-litellm-response-duration-ms: 1047.4748611450195,client_total_seconds: 1.070254curl -s "http://localhost:30671/spend/logs?request_id=d3b4029e-1814-4178-9b8f-273b28db97f5" "${H[@]}" | python3 -c "$ROW"[{'model': 'vertex_ai/claude-haiku-5-5', 'call_type': 'anthropic_messages', 'spend': 0.0004316108465194702, 'prompt_tokens': 15, 'total_tokens': 47}](0.00042 × 1.028 s, the per-second rate times the call's duration)POST /v1/messages with stream on the Vertex AI deployment
curl -s -N -D - http://localhost:20716/v1/messages "${H[@]}" -d '{"model": "vertex-claude-per-second", "max_tokens": 200, "stream": true, "messages": [{"role": "user", "content": "Count from 1 to 40 in words"}]}' -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: 2be26c60-7c8c-4160-b920-ed8641a999b4,client_total_seconds: 1.701180(a streamed response sends its headers before the cost is known)curl -s "http://localhost:20716/spend/logs?request_id=2be26c60-7c8c-4160-b920-ed8641a999b4" "${H[@]}" | python3 -c "$ROW"[{'model': 'vertex_ai/claude-haiku-5-5', 'call_type': 'anthropic_messages', 'spend': 0.000705567684173584, 'prompt_tokens': 20, 'total_tokens': 214}](0.00042 × 1.680 s, the per-second rate times the call's duration)POST /v1/messages with a 231k-token prompt on a long-context-priced deployment
curl -s -D - http://localhost:20716/v1/messages "${H[@]}" --data-binary @<(long_body) -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: 4db7c9d6-a70c-4842-a86e-b20b1416f65f,x-litellm-response-cost: 0.1155155,x-litellm-response-duration-ms: 6606.694221496582,client_total_seconds: 6.622003curl -s "http://localhost:20716/spend/logs?request_id=4db7c9d6-a70c-4842-a86e-b20b1416f65f" "${H[@]}" | python3 -c "$ROW"[{'model': 'anthropic/claude-haiku-5-5', 'call_type': 'anthropic_messages', 'spend': 0.1155155, 'prompt_tokens': 231016, 'total_tokens': 231019}](231016 prompt tokens at the model's own 100k-tier price, the same on both routes and both legs, since this PR leaves that rate alone)POST /v1/chat/completions with the same prompt and deployment
curl -s -D - http://localhost:30671/v1/chat/completions "${H[@]}" --data-binary @<(long_body) -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: ed2273db-bb6f-41a0-bb47-8f60e43477f6,x-litellm-response-cost: 0.1155155,x-litellm-response-duration-ms: 6715.348958969116,client_total_seconds: 6.735340curl -s "http://localhost:30671/spend/logs?request_id=ed2273db-bb6f-41a0-bb47-8f60e43477f6" "${H[@]}" | python3 -c "$ROW"[{'model': 'anthropic/claude-haiku-5-5', 'call_type': 'acompletion', 'spend': 0.1155155, 'prompt_tokens': 231016, 'total_tokens': 231019}](231016 prompt tokens at the model's own 100k-tier price, the same on both routes and both legs, since this PR leaves that rate alone)POST /v1/responses on the per-second Claude deployment
curl -s -D - http://localhost:30671/v1/responses "${H[@]}" -d '{"model": "claude-per-second", "input": "Say hi in three words"}' -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: e9b317c8-1e5e-4344-b06a-b8b8d259dd90,x-litellm-response-cost: 0.0006051506996154786,x-litellm-response-duration-ms: 1518.6598300933838,client_total_seconds: 1.578033curl -s "http://localhost:30671/spend/logs?request_id=e9b317c8-1e5e-4344-b06a-b8b8d259dd90" "${H[@]}" | python3 -c "$ROW"[{'model': 'anthropic/claude-haiku-5-5', 'call_type': 'aresponses', 'spend': 0.0006051506996154786, 'prompt_tokens': 15, 'total_tokens': 25}](0.00042 × 1.441 s, the per-second rate times the call's duration)POST /v1/chat/completions on the per-second Claude deployment
curl -s -D - http://localhost:20716/v1/chat/completions "${H[@]}" -d '{"model": "claude-per-second", "messages": [{"role": "user", "content": "Say hi in three words"}]}' -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: eb3e9b38-2422-4eb2-b26b-47238c44aa2f,x-litellm-response-cost: 0.0006133255863189698,x-litellm-response-duration-ms: 1460.299015045166,client_total_seconds: 1.490187curl -s "http://localhost:20716/spend/logs?request_id=eb3e9b38-2422-4eb2-b26b-47238c44aa2f" "${H[@]}" | python3 -c "$ROW"[{'model': 'anthropic/claude-haiku-5-5', 'call_type': 'acompletion', 'spend': 0.0006133255863189698, 'prompt_tokens': 15, 'total_tokens': 25}](0.00042 × 1.460 s, the per-second rate times the call's duration)POST /v1/messages on a Claude deployment without custom rates
curl -s -D - http://localhost:30671/v1/messages "${H[@]}" -d '{"model": "claude-cost-map", "max_tokens": 32, "messages": [{"role": "user", "content": "Say hi in three words"}]}' -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: ca52120c-17a3-4284-bd57-3e87f199e453,x-litellm-response-cost: 6.5e-06,x-litellm-response-duration-ms: 878.0059814453125,client_total_seconds: 0.913901curl -s "http://localhost:30671/spend/logs?request_id=ca52120c-17a3-4284-bd57-3e87f199e453" "${H[@]}" | python3 -c "$ROW"[{'model': 'anthropic/claude-haiku-5-5', 'call_type': 'anthropic_messages', 'spend': 6.5e-06, 'prompt_tokens': 15, 'total_tokens': 25}](the model's per-token price, unchanged)POST /v1/messages on the per-second OpenAI deployment
curl -s -D - http://localhost:20716/v1/messages "${H[@]}" -d '{"model": "per-second-priced", "max_tokens": 32, "messages": [{"role": "user", "content": "Say hi in three words"}]}' -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: 4e08d4ee-4752-4d23-a7d8-781bc2bd29c8,x-litellm-response-cost: 0.0003567110681533814,x-litellm-response-duration-ms: 882.375955581665,client_total_seconds: 0.926071curl -s "http://localhost:20716/spend/logs?request_id=4e08d4ee-4752-4d23-a7d8-781bc2bd29c8" "${H[@]}" | python3 -c "$ROW"[{'model': 'openai/gpt-5.4-nano', 'call_type': 'anthropic_messages', 'spend': 0.0003567110681533814, 'prompt_tokens': 11, 'total_tokens': 18}](0.00042 × 0.849 s, the per-second rate times the call's duration)POST /v1/messages on a Claude deployment priced per second under model_info
curl -s -D - http://localhost:30671/v1/messages "${H[@]}" -d '{"model": "claude-per-second-model-info", "max_tokens": 32, "messages": [{"role": "user", "content": "Say hi in three words"}]}' -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: e314b8b8-ddd6-4ccb-a1c3-dcf9f9248223,x-litellm-response-cost: 0.00034632227897644045,x-litellm-response-duration-ms: 836.169958114624,client_total_seconds: 0.850504curl -s "http://localhost:30671/spend/logs?request_id=e314b8b8-ddd6-4ccb-a1c3-dcf9f9248223" "${H[@]}" | python3 -c "$ROW"[{'model': 'anthropic/claude-haiku-5-5', 'call_type': 'anthropic_messages', 'spend': 0.0003463222789764405, 'prompt_tokens': 15, 'total_tokens': 25}](0.00042 × 0.825 s, the per-second rate times the call's duration)POST /v1/chat/completions on the same model_info deployment
curl -s -D - http://localhost:20716/v1/chat/completions "${H[@]}" -d '{"model": "claude-per-second-model-info", "messages": [{"role": "user", "content": "Say hi in three words"}]}' -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: fa4703f8-73d9-4655-8916-cec4fb3ef7c3,x-litellm-response-cost: 0.0003435339975357056,x-litellm-response-duration-ms: 817.9380893707275,client_total_seconds: 0.830839curl -s "http://localhost:20716/spend/logs?request_id=fa4703f8-73d9-4655-8916-cec4fb3ef7c3" "${H[@]}" | python3 -c "$ROW"[{'model': 'anthropic/claude-haiku-5-5', 'call_type': 'acompletion', 'spend': 0.0003435339975357056, 'prompt_tokens': 15, 'total_tokens': 25}](0.00042 × 0.818 s, the per-second rate times the call's duration)POST generateContent on a per-second Gemini deployment
curl -s -D - http://localhost:30671/v1beta/models/gemini-per-second:generateContent "${H[@]}" -d '{"contents": [{"role": "user", "parts": [{"text": "Say hi in three words"}]}]}' -o /dev/null -w 'client_total_seconds: %{time_total}\n' | grep -iE "$FILTER|^client_total_seconds"x-litellm-call-id: d341c210-1a5c-446a-b501-b5ca09007c38,x-litellm-response-cost: 0.0009645,x-litellm-response-duration-ms: 4130.451917648315,client_total_seconds: 4.316297curl -s "http://localhost:30671/spend/logs?request_id=d341c210-1a5c-446a-b501-b5ca09007c38" "${H[@]}" | python3 -c "$ROW"[{'model': 'gemini/gemini-3.8-flash', 'call_type': 'agenerate_content', 'spend': 0.0009645, 'prompt_tokens': 6, 'total_tokens': 262}](per-token on both legs, since this PR leaves generateContent alone)Type
🐛 Bug Fix
Caveats (if any)
Low
litellm.max_budgetpasses seconds as milliseconds, an older bugFinal Attestation
Bugbot summary