Skip to content

fix(cost): price exact cost-map names before capability-only Claude rules, and fix SCIM and MCP integration tests on CircleCI - #46763

Closed
mateo-berri wants to merge 15 commits into
mainfrom
litellm_circleci_heal_bedrock_cost_scim
Closed

mateo-berri wants to merge 15 commits into
mainfrom
litellm_circleci_heal_bedrock_cost_scim

Conversation

@mateo-berri

@mateo-berri mateo-berri commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Bedrock calls bill $0 when a price-free Claude rule matches first
  • integration-mcp proxies with a custom auth module die at boot on CircleCI
  • MCP connect-flow tests pin a description without the new servers field
  • The SCIM worker-kill test cannot find its worker on CircleCI
  • integration-accounting pins daily activity metrics without the new ptu_hours field
  • integration-providers cannot collect the Nova Sonic realtime tests because their peer imports a removed _free_port
  • A Bedrock application inference profile with a one-hour base_model sends a one-hour cache TTL but the router pins the prefix for five minutes

How it solves it:

  • Cost lookup tries names with a real cost-map entry before price-free capability rule matches
  • A capability rule that carries prices keeps its place, and explicit pricing skips the lookups
  • Isolated worker configs now carry the auth modules that sat beside the original config
  • The SCIM test kills every serving worker once the push is blocked on the row lock
  • Test expectations add servers and ptu_hours, still exact
  • The Bedrock realtime peer takes its port from allocate_port
  • The prompt caching pin decides one-hour support with the same bedrock_capability_model and bedrock_cache_point_ttl_supported the wire uses

User Flow

Before: a proxy admin whose cost map prices a Bedrock model only under its route name sees the request logged at $0

  1. They add a deployment bedrock/invoke/anthropic.claude-haiku-4-5-20251001-v1:0 and the cost map prices that route name
  2. They send POST http://localhost:4000/v1/chat/completions (also /v1/messages and /v1/responses) and get a 200 with no x-litellm-response-cost header
  3. http://localhost:4000/ui/?page=logs shows the request at $0 spend

After: the same request is billed at the route's price

  1. They add the same deployment with the same cost map
  2. They send the same POST http://localhost:4000/v1/chat/completions and the 200 carries x-litellm-response-cost at the route's rates
  3. http://localhost:4000/ui/?page=logs shows the request at that cost

CircleCI context

Red on main in the scheduled integration workflow of pipeline 91272 at 54ff82dd14, and also in pipeline 91270

integration-cost fails tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[bedrock-converse-apac-bare-fallback] and [bedrock-invoke-haiku-json] with x-litellm-response-cost None. Culprit is c3da442 (#46708), which made the scripted cost map serve the production claude-family-baseline capability rule. completion_cost tries the response-derived name first, that name matches only the price-free rule, so it bills $0 and never tries the priced route name. The same shadowing happens in production for any route-priced Bedrock id whose bare id is unmapped. The fix orders cost candidates so exact cost-map names come before rule-only matches, keeping the existing order inside each group

integration-management and integration-management-replica fail tests/integration/management/test_scim_group_bulk_roster.py::test_a_worker_killed_mid_push_leaves_the_old_roster_and_a_retry_lands_the_new_one with ValueError: not enough values to unpack. The test came in with 622daf3 (#45197) and matched Postgres client_port against host sockets of the workers. Postgres runs in Docker on CircleCI, so the port it sees is NAT'd and never belongs to a worker. The test now waits for a session blocked on the held row lock and kills every serving worker, so the one holding the push's transaction is always killed and every roster assertion stays as strict

integration-accounting fails tests/integration/spend/test_daily_rollup_retry.py::test_failed_daily_user_rollup_commit_is_retried_so_spend_report_and_daily_activity_agree on main pipelines 91272 and 91275 with Left contains 1 more item: {'ptu_hours': 0.0}. Culprit is e344dbd (#43043), which intentionally added ptu_hours to daily activity SpendMetrics. The test's exact metrics dict now expects ptu_hours at 0.0 and stays otherwise strict

integration-mcp fails 53 tests on main 91293, 91291 and 91290. 50 of them, every tests/integration/mcp/test_interactions.py::test_modern_subscription_delivers_changes_between_calls_and_refreshes_tools[*] and ::test_continuation_reauthenticates_caller_and_rechecks_revoked_permissions[*], fail with Owned proxy exited before readiness. The proxy log shows ImportError: Could not import authenticate from subscription_auth. With INTEGRATION_WORKER_ISOLATION=1, worker_configuration (from 3090f4b, #45863) rewrites the config into a temp dir, but the custom auth module the test writes beside the config stays behind, and the loader only looks next to the config. The modern subscription cases came in with 4a4a0e8 (#46153). Isolated configs now go in their own directory with the sibling .py modules copied and their .json state files linked

test_mcp_oauth_flows.py::test_per_server_resource_scopes_the_session_bearer_to_the_named_server and ::test_spec_client_discovers_the_aggregate_authorization_server_and_signs_in_to_a_session_bearer fail with an extra 'servers': None. Culprit is 1ddaa54 (#44957), which intentionally added servers to the connect-flow description. The expected dicts add it and stay exact

Greptile review on e0fe962: a capability rule that carries prices is no longer demoted behind exact names, and custom_pricing or base_model calls skip the up-front cost-map lookups and keep the original candidate order

PR branch pipeline 91297 at the tip b2c054f (workflow, rerun of failed jobs). integration-cost, integration-accounting, integration-management, integration-management-replica and e2e_ui_testing passed on the first run. integration-mcp went from 53 failures on main to the one deferred test below. integration-sdk and integration-extensions failed one test each on the first run and passed on the rerun, test_sdk_native_messages_stream_delivers_one_success_callback_with_usage is also red on main 91294. Earlier PR pipelines were 91276, 91277, 91286, 91287, 91295 and 91296

integration-providers on main 91291, 91293 and 91294 fails to collect tests/integration/providers/test_bedrock_nova_sonic_realtime_tool_calls.py with ImportError: cannot import name '_free_port' from 'integration._support.process'. b602209 (#46761) replaced every _free_port with integration._support.ports.allocate_port, then bd60cc8 (#46214) landed a peer that still imports it. The peer now uses allocate_port. Once collected, the tool-call case also expects the response.function_call_arguments.delta event #46214 intentionally emits before .done

The same job fails tests/integration/routing/test_prompt_cache_pin_ttl.py::test_provider_family_pin_lifetime_agrees_with_the_ttl_the_wire_carries[pin-bedrock-arn-base] on 5 of the last 6 main runs. 6c78089 (#46569) made Bedrock capability checks on application inference profile ARNs follow base_model, so the wire carries ttl: "1h", but the pin from e136e91 (#46084) still checked the ARN and pinned for 300 seconds. _honors_one_hour_cache_ttl now resolves the capability model from the deployment model and base_model, and the case expects a one-hour pin and wire TTL

PR branch pipeline 91301 ran at c714d01. The tip 2643fff merges current main with no conflicts and runs in PR branch pipeline 91309. There every claimed job passed, and the remaining reds are the deferred ones plus test_bridged_request_bills_the_same_row_as_the_native_request[gpt-5.6-responses_reasoning-messages_bridged] in integration-cost, which also fails on main 3 of 3 when run alone because the messages bridge sometimes drops reasoning tokens from usage, so it is deferred too

Deferred, each equally red on main

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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 more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Screenshots / Proof of Fix

Last updated: b2c054f. Before ran at merge base ecbea93 and After at d1f2333. The After leg re-ran at b2c054f, the last commit with a product diff, and matched d1f2333 on every case, shown last

Shared setup

  • Before used /home/ubuntu/repos/litellm-mcpdiag at ecbea93381782591e3e8bf90af145aa68163484a. After used /home/ubuntu/repos/litellm at d1f233306775b6b53a349b5fa08fe32388b57816
  • Each revision ran a two-worker LiteLLM proxy, base on 127.0.0.1:46763 and tip on 127.0.0.1:46764, with LITELLM_LOCAL_MODEL_COST_MAP=True
  • Each proxy used a separate PostgreSQL 16.15 database, on ports 56763 and 56764. The Python import path resolved to the corresponding worktree
  • Bedrock calls used the real Shared-vault Bedrock API-key item in us-east-1. OpenAI calls used the real Shared-vault OpenAI item. Provider values were not printed, recorder authorization fields were redacted, and a scan found no credential values in the QA artifacts
  • Local recorders forwarded to bedrock-runtime.us-east-1.amazonaws.com and api.openai.com. All final measured provider calls returned HTTP 200
  • The route alias used bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0. Both revisions' price maps gave that key input 1.1e-6 and output 5.5e-6. The bare anthropic.claude-haiku-4-5-20251001-v1:0 key was 1e-6 and 5e-6. gpt-4o-mini was 1.5e-7 and 6e-7
  • bedrock-explicit set input_cost_per_token: 0.001 and output_cost_per_token: 0.002. bedrock-base-model used the same routable inference-profile model with model_info.base_model: anthropic.claude-haiku-4-5-20251001-v1:0
  • Chat requests used the prompt Reply with the word OK., max_tokens: 24, and temperature: 0. Commands use $LITELLM_MASTER_KEY for the local proxy key
  • The initial bare Bedrock on-demand model request returned HTTP 400 because the provider requires an inference profile. The successful runs used the us. inference profile. The first OpenAI recorder setup duplicated /v1 and returned HTTP 404. Its upstream base was corrected before the successful OpenAI measurements. These setup attempts are excluded from the cases below
  • The streaming recorder buffers the upstream body before forwarding it. The run verifies the real upstream stream request, returned SSE usage/cost, and spend row, but not incremental end-to-end stream timing
  • The headroom, remote_rig.py, and mitmdump helpers were unavailable. Manual host resource checks were used, and the supplied local recorder was used for real provider traffic
  • Recorder logs are under /home/ubuntu/work/qa_46763_artifacts/. Both proxy worktrees were clean, and all QA proxy, recorder, and PostgreSQL services were stopped after the measurements

Before (ecbea93)

Bedrock route-priced Claude chat completions

  1. Command

    curl --noproxy '*' -i -sS \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"model":"bedrock-route","messages":[{"role":"user","content":"Reply with the word OK."}],"max_tokens":24,"temperature":0}' \
      http://127.0.0.1:46763/v1/chat/completions
  2. HTTP 200. Usage was 13 prompt tokens and 4 completion tokens. x-litellm-response-cost was 3.63e-05

  3. Expected 13 * 1.1e-6 + 4 * 5.5e-6 = 3.63e-05. /spend/logs row chatcmpl-c3c828b3-11c7-40eb-9d84-d194ed386bb1 recorded 13 prompt tokens, 4 completion tokens, and spend 3.63e-05. Pass

Bedrock route-priced Claude streaming chat completions

  1. Command

    curl --noproxy '*' -i -N -sS \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"model":"bedrock-route","messages":[{"role":"user","content":"Reply with the word OK."}],"max_tokens":24,"temperature":0,"stream":true,"stream_options":{"include_usage":true}}' \
      http://127.0.0.1:46763/v1/chat/completions
  2. HTTP 200 SSE. The final usage event reported 13 prompt tokens, 4 completion tokens, and cost: 0.0000363. x-litellm-response-cost was absent and x-litellm-response-cost-original was 0.0

  3. Expected 13 * 1.1e-6 + 4 * 5.5e-6 = 3.63e-05. /spend/logs row chatcmpl-8a458ec0-8fa4-4476-a0ff-b83e72d9f70e recorded 13 prompt tokens, 4 completion tokens, and spend 3.63e-05. Pass for SSE cost and spend, with no nonzero response-cost header

Bedrock Claude explicit deployment pricing

  1. Command

    curl --noproxy '*' -i -sS \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"model":"bedrock-explicit","messages":[{"role":"user","content":"Reply with the word OK."}],"max_tokens":24,"temperature":0}' \
      http://127.0.0.1:46763/v1/chat/completions
  2. HTTP 200. Usage was 13 prompt tokens and 4 completion tokens. x-litellm-response-cost was 0.021

  3. Expected 13 * 0.001 + 4 * 0.002 = 0.021. /spend/logs row chatcmpl-d78da653-9c19-4264-ba65-76160297d131 recorded 13 prompt tokens, 4 completion tokens, and spend 0.021. Pass

Bedrock Claude base_model pricing

  1. Command

    curl --noproxy '*' -i -sS \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"model":"bedrock-base-model","messages":[{"role":"user","content":"Reply with the word OK."}],"max_tokens":24,"temperature":0}' \
      http://127.0.0.1:46763/v1/chat/completions
  2. HTTP 200. Usage was 13 prompt tokens and 4 completion tokens. x-litellm-response-cost was 3.3e-05

  3. Expected under base_model anthropic.claude-haiku-4-5-20251001-v1:0 is 13 * 1e-6 + 4 * 5e-6 = 3.3e-05. /spend/logs row chatcmpl-8d6af7da-470e-452c-b490-a9917f0b9822 recorded 13 prompt tokens, 4 completion tokens, and spend 3.3e-05. Pass

OpenAI gpt-4o-mini sanity check

  1. Command

    curl --noproxy '*' -i -sS \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"Reply with the word OK."}],"max_tokens":24,"temperature":0}' \
      http://127.0.0.1:46763/v1/chat/completions
  2. HTTP 200. Usage was 13 prompt tokens and 1 completion token. x-litellm-response-cost was 2.55e-06

  3. Expected 13 * 1.5e-7 + 1 * 6e-7 = 2.55e-06. /spend/logs row chatcmpl-EZZB1EOiYxTwWuoyppd4cUdDEgTB5 recorded 13 prompt tokens, 1 completion token, and spend 2.55e-06. Pass

Bedrock Claude /v1/messages

  1. Command

    curl --noproxy '*' -i -sS \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -H 'anthropic-version: 2023-06-01' \
      -d '{"model":"bedrock-route","messages":[{"role":"user","content":"Reply with the word OK."}],"max_tokens":24}' \
      http://127.0.0.1:46763/v1/messages
  2. HTTP 200. Usage was 13 input tokens and 4 output tokens. x-litellm-response-cost was 3.3e-05

  3. Expected for the configured us.anthropic... inference-profile key is 13 * 1.1e-6 + 4 * 5.5e-6 = 3.63e-05. /spend/logs row msg_bdrk_pb62y3lxeubzrwnenosprh7w5mstuel5qkkx3d2rh6uo4lr3hyyq recorded spend 3.3e-05, matching the bare-model rate instead. Fail

Bedrock Claude /v1/responses

  1. Command

    curl --noproxy '*' -i -sS \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"model":"bedrock-route","input":"Reply with the word OK.","max_output_tokens":24}' \
      http://127.0.0.1:46763/v1/responses
  2. HTTP 200. Usage was 13 input tokens and 4 output tokens. The response body had usage.cost: null, while x-litellm-response-cost was 3.63e-05

  3. Expected 13 * 1.1e-6 + 4 * 5.5e-6 = 3.63e-05. /spend/logs row chatcmpl-e678d383-bddb-407d-8a0e-6c6b95cb45b9 recorded 13 prompt tokens, 4 completion tokens, and spend 3.63e-05. Pass for header and spend

After (d1f2333)

Bedrock route-priced Claude chat completions

  1. Command

    curl --noproxy '*' -i -sS \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"model":"bedrock-route","messages":[{"role":"user","content":"Reply with the word OK."}],"max_tokens":24,"temperature":0}' \
      http://127.0.0.1:46764/v1/chat/completions
  2. HTTP 200. Usage was 13 prompt tokens and 4 completion tokens. x-litellm-response-cost was 3.63e-05

  3. Expected 13 * 1.1e-6 + 4 * 5.5e-6 = 3.63e-05. /spend/logs row chatcmpl-a54740db-e318-4e31-b20c-41cb8c65e9a9 recorded 13 prompt tokens, 4 completion tokens, and spend 3.63e-05. Pass

Bedrock route-priced Claude streaming chat completions

  1. Command

    curl --noproxy '*' -i -N -sS \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"model":"bedrock-route","messages":[{"role":"user","content":"Reply with the word OK."}],"max_tokens":24,"temperature":0,"stream":true,"stream_options":{"include_usage":true}}' \
      http://127.0.0.1:46764/v1/chat/completions
  2. HTTP 200 SSE. The final usage event reported 13 prompt tokens, 4 completion tokens, and cost: 0.0000363. x-litellm-response-cost was absent and x-litellm-response-cost-original was 0.0

  3. Expected 13 * 1.1e-6 + 4 * 5.5e-6 = 3.63e-05. /spend/logs row chatcmpl-faf74629-2a01-4a82-bc27-2a81f8bc7e89 recorded 13 prompt tokens, 4 completion tokens, and spend 3.63e-05. Pass for SSE cost and spend, with no nonzero response-cost header

Bedrock Claude explicit deployment pricing

  1. Command

    curl --noproxy '*' -i -sS \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"model":"bedrock-explicit","messages":[{"role":"user","content":"Reply with the word OK."}],"max_tokens":24,"temperature":0}' \
      http://127.0.0.1:46764/v1/chat/completions
  2. HTTP 200. Usage was 13 prompt tokens and 4 completion tokens. x-litellm-response-cost was 0.021

  3. Expected 13 * 0.001 + 4 * 0.002 = 0.021. /spend/logs row chatcmpl-f52a42cd-7e18-407f-8394-08f05b04cb79 recorded 13 prompt tokens, 4 completion tokens, and spend 0.021. Pass

Bedrock Claude base_model pricing

  1. Command

    curl --noproxy '*' -i -sS \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"model":"bedrock-base-model","messages":[{"role":"user","content":"Reply with the word OK."}],"max_tokens":24,"temperature":0}' \
      http://127.0.0.1:46764/v1/chat/completions
  2. HTTP 200. Usage was 13 prompt tokens and 4 completion tokens. x-litellm-response-cost was 3.3e-05

  3. Expected under base_model anthropic.claude-haiku-4-5-20251001-v1:0 is 13 * 1e-6 + 4 * 5e-6 = 3.3e-05. /spend/logs row chatcmpl-f9cc6ec9-d7eb-45a6-81be-bfd41e49c17b recorded 13 prompt tokens, 4 completion tokens, and spend 3.3e-05. Pass

OpenAI gpt-4o-mini sanity check

  1. Command

    curl --noproxy '*' -i -sS \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"Reply with the word OK."}],"max_tokens":24,"temperature":0}' \
      http://127.0.0.1:46764/v1/chat/completions
  2. HTTP 200. Usage was 13 prompt tokens and 1 completion token. x-litellm-response-cost was 2.55e-06

  3. Expected 13 * 1.5e-7 + 1 * 6e-7 = 2.55e-06. /spend/logs row chatcmpl-EZZB22QqYsuT5Kmm991nYWRT9HpTh recorded 13 prompt tokens, 1 completion token, and spend 2.55e-06. Pass with unchanged base/tip cost

Bedrock Claude /v1/messages

  1. Command

    curl --noproxy '*' -i -sS \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -H 'anthropic-version: 2023-06-01' \
      -d '{"model":"bedrock-route","messages":[{"role":"user","content":"Reply with the word OK."}],"max_tokens":24}' \
      http://127.0.0.1:46764/v1/messages
  2. HTTP 200. Usage was 13 input tokens and 4 output tokens. x-litellm-response-cost was 3.3e-05

  3. Expected for the configured us.anthropic... inference-profile key is 13 * 1.1e-6 + 4 * 5.5e-6 = 3.63e-05. /spend/logs row msg_bdrk_2bq5mjk3ti3aia5t4uz75fadcrkv5uv4oozrgvqvquaupeyjtigq recorded spend 3.3e-05, matching the bare-model rate instead. Fail

Bedrock Claude /v1/responses

  1. Command

    curl --noproxy '*' -i -sS \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"model":"bedrock-route","input":"Reply with the word OK.","max_output_tokens":24}' \
      http://127.0.0.1:46764/v1/responses
  2. HTTP 200. Usage was 13 input tokens and 4 output tokens. The response body had usage.cost: null, while x-litellm-response-cost was 3.63e-05

  3. Expected 13 * 1.1e-6 + 4 * 5.5e-6 = 3.63e-05. /spend/logs row chatcmpl-6cdaf0bb-0000-4e82-b5c6-23c1bf9e2808 recorded 13 prompt tokens, 4 completion tokens, and spend 3.63e-05. Pass for header and spend

After (b2c054f43e0affb0bc471ff6de90d6f41c906d65)

1. Bedrock route-priced Claude chat completions

  1. Command

    curl --noproxy '*' -i -sS \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"model":"bedrock-route","messages":[{"role":"user","content":"Reply with the word OK."}],"max_tokens":24,"temperature":0}' \
      http://127.0.0.1:46765/v1/chat/completions
  2. HTTP 200. Usage was 13 prompt tokens and 4 completion tokens. x-litellm-response-cost was 3.63e-05

  3. Expected 13 * 1.1e-6 + 4 * 5.5e-6 = 3.63e-05. Spend row chatcmpl-e0542e1e-9c08-48f9-be3f-b8dfb4fa7e1c recorded 13 prompt tokens, 4 completion tokens, and 3.63e-05

  4. Outbound count was one Bedrock POST /model/us.anthropic.claude-haiku-4-5-20251001-v1%3A0/converse, with body keys inferenceConfig and messages. Compared with d1f2333, status, header cost, spend, and request shape/count were unchanged. Its spend row was chatcmpl-a54740db-e318-4e31-b20c-41cb8c65e9a9 at 3.63e-05. Pass

2. Bedrock route-priced Claude streaming chat completions

  1. Command

    curl --noproxy '*' -i -N -sS \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"model":"bedrock-route","messages":[{"role":"user","content":"Reply with the word OK."}],"max_tokens":24,"temperature":0,"stream":true,"stream_options":{"include_usage":true}}' \
      http://127.0.0.1:46765/v1/chat/completions
  2. HTTP 200 SSE. The final usage event reported 13 prompt tokens, 4 completion tokens, and cost: 0.0000363. x-litellm-response-cost was absent and x-litellm-response-cost-original was 0.0

  3. Expected 13 * 1.1e-6 + 4 * 5.5e-6 = 3.63e-05. Spend row chatcmpl-4ffdc660-4ae9-422d-bcf8-1d4bae112d50 recorded 13 prompt tokens, 4 completion tokens, and 3.63e-05

  4. Outbound count was one Bedrock POST /model/us.anthropic.claude-haiku-4-5-20251001-v1%3A0/converse-stream, with body keys inferenceConfig and messages. Compared with d1f2333, status, absent cost header, SSE cost, spend, and request shape/count were unchanged. Its spend row was chatcmpl-faf74629-2a01-4a82-bc27-2a81f8bc7e89 at 3.63e-05. Pass for SSE cost and spend, with no nonzero response-cost header

3. Bedrock explicit deployment pricing

  1. Command

    curl --noproxy '*' -i -sS \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"model":"bedrock-explicit","messages":[{"role":"user","content":"Reply with the word OK."}],"max_tokens":24,"temperature":0}' \
      http://127.0.0.1:46765/v1/chat/completions
  2. HTTP 200. Usage was 13 prompt tokens and 4 completion tokens. x-litellm-response-cost was 0.021

  3. Expected 13 * 0.001 + 4 * 0.002 = 0.021. Spend row chatcmpl-73260f04-ae7a-4715-8b80-2d103aba9cff recorded 13 prompt tokens, 4 completion tokens, and 0.021

  4. Outbound count was one Bedrock POST /model/us.anthropic.claude-haiku-4-5-20251001-v1%3A0/converse, with body keys inferenceConfig and messages. Compared with d1f2333, status, header, spend, and request shape/count were unchanged. Its spend row was chatcmpl-f52a42cd-7e18-407f-8394-08f05b04cb79 at 0.021. Pass

4. Bedrock base_model pricing

  1. Command

    curl --noproxy '*' -i -sS \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"model":"bedrock-base-model","messages":[{"role":"user","content":"Reply with the word OK."}],"max_tokens":24,"temperature":0}' \
      http://127.0.0.1:46765/v1/chat/completions
  2. HTTP 200. Usage was 13 prompt tokens and 4 completion tokens. x-litellm-response-cost was 3.3e-05

  3. Expected under base_model anthropic.claude-haiku-4-5-20251001-v1:0 is 13 * 1e-6 + 4 * 5e-6 = 3.3e-05. Spend row chatcmpl-4191a7ed-46df-438b-8084-cf484f20a810 recorded 13 prompt tokens, 4 completion tokens, and 3.3e-05

  4. Outbound count was one Bedrock POST /model/us.anthropic.claude-haiku-4-5-20251001-v1%3A0/converse, with body keys inferenceConfig and messages. Compared with d1f2333, status, header, spend, and request shape/count were unchanged. Its spend row was chatcmpl-f9cc6ec9-d7eb-45a6-81be-bfd41e49c17b at 3.3e-05. Pass

5. OpenAI gpt-4o-mini sanity check

  1. Command

    curl --noproxy '*' -i -sS \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"Reply with the word OK."}],"max_tokens":24,"temperature":0}' \
      http://127.0.0.1:46765/v1/chat/completions
  2. HTTP 200. Usage was 13 prompt tokens and 1 completion token. x-litellm-response-cost was 2.55e-06

  3. Expected 13 * 1.5e-7 + 1 * 6e-7 = 2.55e-06. Spend row chatcmpl-EZaVgRdLvOiIsZJSzbQ7qKIDLrWUh recorded 13 prompt tokens, 1 completion token, and 2.55e-06

  4. The case emitted one OpenAI POST /v1/chat/completions, with body keys max_tokens, messages, model, and temperature. Compared with d1f2333, status, header, spend, and case request shape/count were unchanged. Its spend row was chatcmpl-EZZB22QqYsuT5Kmm991nYWRT9HpTh at 2.55e-06. Pass

6. Bedrock Claude /v1/messages

  1. Command

    curl --noproxy '*' -i -sS \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -H 'anthropic-version: 2023-06-01' \
      -d '{"model":"bedrock-route","messages":[{"role":"user","content":"Reply with the word OK."}],"max_tokens":24}' \
      http://127.0.0.1:46765/v1/messages
  2. HTTP 200. Usage was 13 input tokens and 4 output tokens. x-litellm-response-cost was 3.3e-05

  3. Expected for the configured inference-profile key is 13 * 1.1e-6 + 4 * 5.5e-6 = 3.63e-05. Spend row msg_bdrk_xdfzfhxstkt43ozuets7fegqiekrokivl3uf6nwbcd7dxrriuwua recorded 13 input tokens, 4 output tokens, and 3.3e-05, matching the bare-model rate. Fail

  4. Outbound count was one Bedrock POST /model/us.anthropic.claude-haiku-4-5-20251001-v1:0/invoke, with body keys anthropic_version, max_tokens, and messages. Compared with d1f2333, status, header, spend, and request shape/count were unchanged. Its spend row was msg_bdrk_2bq5mjk3ti3aia5t4uz75fadcrkv5uv4oozrgvqvquaupeyjtigq at 3.3e-05. The inference-profile cost discrepancy remains

7. Bedrock Claude /v1/responses

  1. Command

    curl --noproxy '*' -i -sS \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"model":"bedrock-route","input":"Reply with the word OK.","max_output_tokens":24}' \
      http://127.0.0.1:46765/v1/responses
  2. HTTP 200. Usage was 13 input tokens and 4 output tokens. The response body had usage.cost: null, while x-litellm-response-cost was 3.63e-05

  3. Expected 13 * 1.1e-6 + 4 * 5.5e-6 = 3.63e-05. Spend row chatcmpl-2a0a0f5c-a1d9-43c0-92ad-3ba890f30cbc recorded 13 prompt tokens, 4 completion tokens, and 3.63e-05

  4. Outbound count was one Bedrock POST /model/us.anthropic.claude-haiku-4-5-20251001-v1%3A0/converse, with body keys inferenceConfig and messages. Compared with d1f2333, status, header, spend, and request shape/count were unchanged. Its spend row was chatcmpl-6cdaf0bb-0000-4e82-b5c6-23c1bf9e2808 at 3.63e-05. Pass for header and spend, with response-body usage.cost still null

Type

🐛 Bug Fix
✅ Test

Caveats (if any)

Low

  • test_stream_chunk_builder_skips_stamp_when_cost_is_unpriceable now uses an unmapped model so it still pins the unpriceable path
  • Without explicit pricing, cost lookup resolves each candidate name once up front, at most three extra get_model_info lookups per call
  • Live QA used a Bedrock route already priced on base, so the before leg did not reproduce $0. integration-cost on main vs this branch is the before and after proof
  • /v1/messages bills the bare model rate instead of the inference-profile rate on both base and tip, unchanged by this PR

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Link to Devin session: https://app.devin.ai/sessions/d72818716aa244298b2930abebb17387
Open in Devin Desktop: https://app.devin.ai/desktop/session/d72818716aa244298b2930abebb17387?variant=devin
Requested by: @mateo-berri


Note

Medium Risk
Changes core spend calculation ordering and Bedrock prompt-cache pin lifetime, which can shift logged costs and routing pins; scope is well covered by new unit and integration tests.

Overview
Fixes $0 billing when a response-derived model name matches a price-free Claude capability rule before a route-priced Bedrock (or similar) entry in the cost map. completion_cost now ranks candidates as (model, pricing provider) pairs, classifies unpriced generalized matches, and tries exact cost-map names before capability-only fallbacks (priced generalization rules keep their place; explicit custom_pricing / base_model skips reordering). Provider passed into cost_per_token is resolved via _pricing_provider_for_cost_candidate.

Bedrock prompt-cache pinning now decides one-hour TTL with the same bedrock_capability_model + bedrock_cache_point_ttl_supported path as the wire, using deployment model and base_model from litellm_params (fixes ARN + base_model profiles pinned at 5m while sending ttl: 1h).

Integration/CI hardening: isolated worker configs copy sibling auth .py modules (and symlink .json state); SCIM chaos test kills all serving workers after a row-lock block instead of matching Postgres client_port to host sockets; MCP OAuth expectations add servers: null; spend rollup expects ptu_hours; Bedrock realtime peer uses allocate_port; Nova Sonic test asserts response.function_call_arguments.delta.

Unit tests cover cost candidate ordering, Bedrock profile 1h TTL, worker config isolation, and stream chunk builder pricing for priced deployment aliases.

Reviewed by Cursor Bugbot for commit 2643fff. Bugbot is set up for automated code reviews on this repo. Configure here.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@codspeed

codspeed Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 32 untouched benchmarks


Comparing litellm_circleci_heal_bedrock_cost_scim (2643fff) with main (f02449a)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (33b7320) during the generation of this report, so f02449a was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@litereview

litereview Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

⚠️ code-review

5/5 · Ready for human review

Scope: full · Full PR review.

Completed · Some checks not run.

No correctness findings.

Checks and execution details
  • Passed · Real testing evidence (required): Not applicable: no LLM translation changes in the scoped paths. The PR changes no file under litellm/llms/** or litellm/litellm_core_utils/prompt_templates/**. The production changes are litellm/cost_calculator.py and litellm/router_utils/pre_call_checks/prompt_caching_deployment_check.py. The rest are tests and integration support.
  • Passed · Compatibility requirements (required): No supported behavior breaks. Before this PR, a call with no explicit pricing whose first candidate name matched only the price-free claude-family-baseline rule billed $0. The candidate loop never reached a priced route name. Now the loop tries exact cost-map names first and bills at the route's rate. When custom_pricing or base_model is set, raw_candidates keeps its original order. A capability rule that carries token rates keeps its place. For a Bedrock application-inference-profile ARN with a one-hour-capable base_model, the prompt-cache pin changes from 5m to 1h to match the TTL the wire already sends. Both changes fix behavior. Neither rejects a previously valid input or changes config or persisted data, so the PR needs no ! marker.
  • Passed · Changed behavior and result consistency (required): I read tests/integration/AGENTS.md. I traced completion_cost through raw_candidates, _cost_map_model_info, _is_unpriced_generalized_model_info and the exact-before-generalized ordering, down to cost_per_token and get_token_type_cost_breakdown. Each candidate now carries its own provider through _pricing_provider_for_cost_candidate, and the old idx == 0 coupling is gone. The only remaining use of idx is the last-candidate re-raise.

Boundary cases I checked:

  • Explicit pricing (custom_pricing or base_model) skips the lookups and keeps the original order.
  • A priced capability rule keeps its place.
  • Capability-only matches with no exact name still return 0.0 (test_completion_cost_returns_zero_for_capability_only_generalization).
  • The base model is priced under its own provider for openai and hosted_vllm (test_completion_cost_prices_base_model_under_its_own_provider).

For the prompt-cache pin, _honors_one_hour_cache_ttl now calls bedrock_capability_model(model, base_model) and bedrock_cache_point_ttl_supported. The converse transformation uses the same helpers at converse_transformation.py:2073/2153. litellm_params.base_model comes from get_litellm_params (model_info.base_model fallback). If litellm_params.model is missing, the code falls back to standard_logging_object['model'].

The SCIM test now kills every serving worker after a session blocks on the held row lock. That always includes the transaction holder, and the roster assertions are unchanged. The worker-config isolation copies sibling .py modules and symlinks their .json files into a per-worker directory.

  • Passed · Unit tests for changed cost/pin/process logic (optional): .venv/bin/python -m pytest -q tests/unit/test_cost_calculator.py tests/unit/router_utils/pre_call_checks/test_prompt_caching_deployment_check.py tests/unit/integration_support/test_process.py -n 8 gave 433 passed.
  • Not run · Integration shards (integration-cost, routing pin TTL, SCIM, MCP) (optional): I did not run these locally because they need the full proxy, Postgres and Redis stack. The PR cites CircleCI runs for these shards. Correctness of the reviewed logic does not depend on them.

View review · Reviewed 2643fff7e21e

@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.36842% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/cost_calculator.py 95.65% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

…and keep the unpriceable case unmapped

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@mateo-berri
mateo-berri enabled auto-merge (squash) October 15, 2026 22:27
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litellm-stampbot

@litellm-stampbot

litellm-stampbot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

litellm-stampbot: risk high

Not approved at 2643fff. risk is high, a human reviewer is needed.

Rules (stampbot/risk_rules.yml):

  • low: no rule flagged it

Judge (gpt-6-luna): high, probability of high 1.00 (high at or above 0.75)

  • risk: high (probability of high 1.00)

Pushes do not re-run this check. Comment @litellm-stampbot again to re-check the new head.

@litellm-stampbot litellm-stampbot Bot added the risk:high Sensitive, broad, or high-risk change label Oct 15, 2026
mateo-berri and others added 2 commits October 16, 2026 02:07
…43043

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

Comment thread litellm/cost_calculator.py Outdated
for candidate, is_generalized in zip(raw_candidate_names, candidate_is_generalized, strict=True)
if is_generalized
)
potential_model_names: Final = (*exact_model_names, *generalized_model_names)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High · Claude base_model on an OpenAI-compatible deployment now fails to price

  1. An admin configures an openai/my-deploy (or hosted_vllm/...) deployment with base_model: claude-sonnet-4-5. The openai provider has no row for that id.
  2. A completion returns usage. _base_model_pricing_provider resolves anthropic, and selected_model becomes anthropic/claude-sonnet-4-5.
  3. completion_cost runs that name through _cost_map_model_info(candidate, "openai"). The lookup hits the claude-family-baseline rule under key openai/anthropic/claude-sonnet-4-5, so is_generalized_model_info returns True. The new ordering moves the base-model candidate behind my-deploy and openai/my-deploy.
  4. When the loop reaches the base model, idx is no longer 0. The pricing_provider = base_model_provider if ... idx == 0 branch falls back to openai, and cost_per_token raises This model isn't mapped yet. model=claude-sonnet-4-5, custom_llm_provider=openai. Before this PR, the same call billed 0.018 for 1000 input and 1000 output tokens.

The smallest fix: classify the base-model candidate under base_model_provider, or keep it first when base_model_provider is set. Alternatively, pick the pricing provider from the candidate's identity rather than its index.

Evidence

Reproducer (LITELLM_LOCAL_MODEL_COST_MAP=True): completion_cost(completion_response=ModelResponse(model="my-deploy", choices=[], usage=Usage(prompt_tokens=1000, completion_tokens=1000, total_tokens=2000)), model="openai/my-deploy", custom_llm_provider="openai", base_model="claude-sonnet-4-5")

PR head: ERR This model isn't mapped yet. model=claude-sonnet-4-5, custom_llm_provider=openai. The same error occurs with hosted_vllm.

With the pre-PR candidate list restored locally: returns 0.018000000000000002 for both providers.

Debug print at head: raw=('anthropic/claude-sonnet-4-5','my-deploy','openai/my-deploy') generalized=(True, False, False) ordered=('my-deploy','openai/my-deploy','anthropic/claude-sonnet-4-5') base_model_provider=anthropic

litellm/cost_calculator.py pricing-provider selection: base_model_provider if base_model_provider is not None and idx == 0 else custom_llm_provider

Latest summary by code-review · View this review · Reviewed 4b3ab8ede6a3

…candidate reordering

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litellm-stampbot

@kerry-berri

Copy link
Copy Markdown
Contributor

@greptileai

@greptile-apps

greptile-apps Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge with no new actionable issues found

Summary

The PR fixes cost lookup order so price-free capability rules do not hide priced model names. Priced rules and explicit pricing keep their existing behavior

It also aligns Bedrock cache pins with the request’s TTL support and repairs integration fixtures, worker setup, and expected response fields. No new actionable issues were found

  • Bedrock calls use route prices before price-free Claude rules.
  • Bedrock cache pins follow the deployment’s one-hour TTL support.
  • Isolated proxy workers can load auth modules beside their config.
  • The SCIM test interrupts a push without matching database ports.
  • Integration tests match the current MCP and Bedrock response shapes.

Reviews (5) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile

Comment thread litellm/cost_calculator.py Resolved
Comment thread litellm/cost_calculator.py Resolved
mateo-berri and others added 2 commits October 16, 2026 08:20
…onfigs

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Comment thread tests/unit/test_cost_calculator.py Resolved

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

Comment thread litellm/cost_calculator.py Resolved

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@devin-ai-integration devin-ai-integration Bot changed the title fix(cost): price exact cost-map names before capability-only Claude rules, and find the SCIM push worker on CircleCI fix(cost): price exact cost-map names before capability-only Claude rules, and fix SCIM and MCP integration tests on CircleCI Oct 16, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litellm-stampbot

mateo-berri and others added 3 commits October 16, 2026 14:10
…-worker allocator

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…r ttl its base model sends

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 2643fff. Configure here.

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litellm-stampbot

@mateo-berri

Copy link
Copy Markdown
Contributor Author

Replaced by #47037, which carries every commit here as cherry-picks on top of a stampbot-approved test-only slice

auto-merge was automatically disabled October 17, 2026 01:59

Pull request was closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:high Sensitive, broad, or high-risk change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants