Skip to content

fix(pricing): correct Bedrock Mantle gpt-oss-20b and safeguard-20b token rates - #39866

Closed
mateo-berri wants to merge 3 commits into
litellm_internal_stagingfrom
litellm_lit_6950_mantle_gpt_oss_pricing
Closed

mateo-berri wants to merge 3 commits into
litellm_internal_stagingfrom
litellm_lit_6950_mantle_gpt_oss_pricing

Conversation

@mateo-berri

@mateo-berri mateo-berri commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • bedrock_mantle/openai.gpt-oss-20b charges input at 7.5e-08/token; AWS bills 7e-08
  • bedrock_mantle/openai.gpt-oss-safeguard-20b has the same input error plus 3e-07 output; AWS bills 2e-07
  • Spend on both Mantle deployments reads 7% high on input (50% high on safeguard output)

How it solves it:

  • Sets both rows to the standard-tier Mantle SKUs in the AWS us-east-1 Bedrock offer file
  • Same values as the matching Bedrock Converse rows, which were already right
  • Pins all four commercial Mantle gpt-oss rows to the offer file in the existing Bedrock Mantle test file, whose pricing class now loads the bundled map through its own fixture instead of relying on import-time side effects

User Flow

Before: a developer routing gpt-oss-20b through Bedrock Mantle sees the gateway charge more input tokens than AWS does

  1. They send POST https://litellm-domain/v1/chat/completions with {"model": "mantle-gpt-oss-20b", "messages": [{"role": "user", "content": "Reply with the single word pong."}], "max_tokens": 32}
  2. The 200 response reports prompt_tokens: 74 and the header x-litellm-response-cost-input: 5.549999999999999e-06, but their AWS bill meters those 74 tokens at $0.00007 per 1K, so 5.18e-06
  3. They send POST https://litellm-domain/spend/calculate with {"completion_response": {"model": "bedrock_mantle/openai.gpt-oss-20b", "usage": {"prompt_tokens": 1000000, "completion_tokens": 0, "total_tokens": 1000000}}} and get back {"cost": 0.075} instead of the $0.07 AWS charges
  4. The same request against mantle-gpt-oss-safeguard-20b comes back with x-litellm-response-cost-output: 9.6e-06 for 32 completion tokens, where AWS charges $0.0002 per 1K, so 6.4e-06
  5. https://litellm-domain/ui/?page=logs shows every Mantle gpt-oss-20b request at a spend 7% above the invoice, and safeguard-20b output at 50% above it

After: the same requests are priced at the rates AWS bills

  1. They send POST https://litellm-domain/v1/chat/completions with {"model": "mantle-gpt-oss-20b", "messages": [{"role": "user", "content": "Reply with the single word pong."}], "max_tokens": 32}
  2. The 200 response reports prompt_tokens: 74 and the header x-litellm-response-cost-input: 5.18e-06, matching the AWS rate
  3. They send POST https://litellm-domain/spend/calculate with the same 1,000,000 prompt token payload and get back {"cost": 0.07}
  4. The same request against mantle-gpt-oss-safeguard-20b comes back with x-litellm-response-cost-output: 6.4e-06 for 32 completion tokens, matching the AWS rate
  5. https://litellm-domain/ui/?page=logs shows Mantle gpt-oss-20b and safeguard-20b requests at the same spend as the invoice

Relevant issues

Linear ticket

Resolves LIT-6950

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/test_litellm/<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
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays 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

Primary source: the AWS us-east-1 Bedrock offer file (publication 2026-09-01), https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonBedrock/current/us-east-1/index.csv, standard-tier Mantle SKUs per 1K tokens:

SKU rate
USE1-openai.gpt-oss-20b-mantle-input-tokens-standard $0.00007
USE1-openai.gpt-oss-20b-mantle-output-tokens-standard $0.0003
USE1-openai.gpt-oss-safeguard-20b-mantle-input-tokens-standard $0.00007
USE1-openai.gpt-oss-safeguard-20b-mantle-output-tokens-standard $0.0002

Shared setup: each side is a proxy with no database, LITELLM_LOCAL_MODEL_COST_MAP=True and AWS_BEARER_TOKEN_BEDROCK in the environment, booted with python litellm/proxy/proxy_cli.py --config config.yaml --port <port> --num_workers 2 from a checkout of that side's commit (PYTHONPATH pointed at it, litellm.__file__ checked to sit inside it). Same config on both sides:

model_list:
  - model_name: mantle-gpt-oss-20b
    litellm_params:
      model: bedrock_mantle/openai.gpt-oss-20b
      aws_region_name: us-east-1
  - model_name: mantle-gpt-oss-safeguard-20b
    litellm_params:
      model: bedrock_mantle/openai.gpt-oss-safeguard-20b
      aws_region_name: us-east-1
  - model_name: converse-gpt-oss-20b
    litellm_params:
      model: bedrock/converse/openai.gpt-oss-20b-1:0
      aws_region_name: us-east-1

general_settings:
  master_key: sk-lit6950

litellm_settings:
  drop_params: true

Every case sends the same prompt (Reply with the single word pong., 32 output tokens max) to the three deployments and reads the per-request cost headers next to the usage block. The converse deployment is the control: it was already priced at the offer-file rate on both sides. Real Mantle calls, real AWS spend. Mantle sometimes reports 48 of the 74 prompt tokens as cached; both sides price cached tokens at $0, so those requests show 26 x the input rate

Before (78ad88f)

POST /v1/chat/completions

  1. curl -s http://127.0.0.1:49687/v1/chat/completions -H 'Authorization: Bearer sk-lit6950' -H 'Content-Type: application/json' -d '{"model":"mantle-gpt-oss-20b","messages":[{"role":"user","content":"Reply with the single word pong."}],"max_tokens":32}' -D - | grep -iE 'x-litellm-response-cost-(input|output)|"usage"'
  2. Observed:
    HTTP/1.1 200 OK
    x-litellm-response-cost-input: 5.549999999999999e-06
    x-litellm-response-cost-output: 9.6e-06
    usage: {"completion_tokens": 32, "prompt_tokens": 74, "total_tokens": 106}
    
    74 x 7.5e-08 on input; AWS meters 74 x 7e-08 = 5.18e-06
  3. Same command with "model":"mantle-gpt-oss-safeguard-20b", observed:
    HTTP/1.1 200 OK
    x-litellm-response-cost-input: 1.95e-06
    x-litellm-response-cost-output: 9.6e-06
    usage: {"completion_tokens": 32, "prompt_tokens": 74, "total_tokens": 106, "prompt_tokens_details": {"audio_tokens": 0, "cached_tokens": 48}}
    
    26 uncached x 7.5e-08 on input (AWS: 26 x 7e-08 = 1.82e-06); output 32 x 3e-07 (AWS: 32 x 2e-07 = 6.4e-06)
  4. Same command with "model":"converse-gpt-oss-20b" (control), observed:
    HTTP/1.1 200 OK
    x-litellm-response-cost-input: 5.18e-06
    x-litellm-response-cost-output: 8.7e-06
    usage: {"completion_tokens": 29, "prompt_tokens": 74, "total_tokens": 103, ...}
    

POST /v1/responses

  1. curl -s http://127.0.0.1:49687/v1/responses -H 'Authorization: Bearer sk-lit6950' -H 'Content-Type: application/json' -d '{"model":"mantle-gpt-oss-20b","input":"Reply with the single word pong.","max_output_tokens":32}' -D - | grep -iE 'x-litellm-response-cost-(input|output)|"usage"'
  2. Observed:
    HTTP/1.1 200 OK
    x-litellm-response-cost-input: 5.549999999999999e-06
    x-litellm-response-cost-output: 9.6e-06
    usage: {"input_tokens": 74, "input_tokens_details": {"audio_tokens": null, "cached_tokens": 0, "text_tokens": null}, "output_tokens": 32, ...}
    
  3. Same command with "model":"mantle-gpt-oss-safeguard-20b", observed:
    HTTP/1.1 200 OK
    x-litellm-response-cost-input: 5.549999999999999e-06
    x-litellm-response-cost-output: 9.6e-06
    usage: {"input_tokens": 74, "input_tokens_details": null, "output_tokens": 32, "output_tokens_details": null, "total_tokens": 106, "cost": null}
    
  4. Same command with "model":"converse-gpt-oss-20b" (control), observed:
    HTTP/1.1 200 OK
    x-litellm-response-cost-input: 5.18e-06
    x-litellm-response-cost-output: 9.6e-06
    usage: {"input_tokens": 74, ..., "output_tokens": 32, ...}
    

POST /v1/messages

  1. curl -s http://127.0.0.1:49687/v1/messages -H 'Authorization: Bearer sk-lit6950' -H 'Content-Type: application/json' -d '{"model":"mantle-gpt-oss-20b","max_tokens":32,"messages":[{"role":"user","content":"Reply with the single word pong."}]}' -D - | grep -iE 'x-litellm-response-cost-(input|output)|"usage"'
  2. Observed:
    HTTP/1.1 200 OK
    x-litellm-response-cost-input: 5.549999999999999e-06
    x-litellm-response-cost-output: 7.8e-06
    usage: {"input_tokens": 74, "output_tokens": 26}
    
  3. Same command with "model":"mantle-gpt-oss-safeguard-20b", observed:
    HTTP/1.1 200 OK
    x-litellm-response-cost-input: 1.95e-06
    x-litellm-response-cost-output: 9.6e-06
    usage: {"input_tokens": 26, "output_tokens": 32, "cache_read_input_tokens": 48}
    
  4. Same command with "model":"converse-gpt-oss-20b" (control), observed:
    HTTP/1.1 200 OK
    x-litellm-response-cost-input: 5.18e-06
    x-litellm-response-cost-output: 9.6e-06
    usage: {"input_tokens": 74, "output_tokens": 32}
    

POST /spend/calculate at 1,000,000 tokens

  1. curl -s http://127.0.0.1:49687/spend/calculate -H 'Authorization: Bearer sk-lit6950' -H 'Content-Type: application/json' -d '{"completion_response":{"model":"bedrock_mantle/openai.gpt-oss-20b","usage":{"prompt_tokens":1000000,"completion_tokens":0,"total_tokens":1000000}}}'
  2. Observed: {"cost":0.075} (AWS: $0.07)
  3. Same with "prompt_tokens":0,"completion_tokens":1000000, observed: {"cost":0.3}
  4. Same two calls with "model":"bedrock_mantle/openai.gpt-oss-safeguard-20b", observed: {"cost":0.075} for prompt (AWS: $0.07) and {"cost":0.3} for completion (AWS: $0.20)
  5. Same two calls with "model":"bedrock/converse/openai.gpt-oss-20b-1:0" (control), observed: {"cost":0.07} and {"cost":0.3}

After (5cc06c3)

Tip 6e0ebd2 adds one test-only commit on top of 5cc06c3 (the pricing tests load the bundled map through the file's fixture and the offer-file checks move into the mapped test file), which cannot change what the proxy returns, so the run below stands

POST /v1/chat/completions

  1. curl -s http://127.0.0.1:23294/v1/chat/completions -H 'Authorization: Bearer sk-lit6950' -H 'Content-Type: application/json' -d '{"model":"mantle-gpt-oss-20b","messages":[{"role":"user","content":"Reply with the single word pong."}],"max_tokens":32}' -D - | grep -iE 'x-litellm-response-cost-(input|output)|"usage"'
  2. Observed:
    HTTP/1.1 200 OK
    x-litellm-response-cost-input: 5.18e-06
    x-litellm-response-cost-output: 8.1e-06
    usage: {"completion_tokens": 27, "prompt_tokens": 74, "total_tokens": 101}
    
    74 x 7e-08 on input, 27 x 3e-07 on output, both at the offer-file rate
  3. Same command with "model":"mantle-gpt-oss-safeguard-20b", observed:
    HTTP/1.1 200 OK
    x-litellm-response-cost-input: 5.18e-06
    x-litellm-response-cost-output: 6.4e-06
    usage: {"completion_tokens": 32, "prompt_tokens": 74, "total_tokens": 106}
    
    Output is now 32 x 2e-07
  4. Same command with "model":"converse-gpt-oss-20b" (control), observed:
    HTTP/1.1 200 OK
    x-litellm-response-cost-input: 5.18e-06
    x-litellm-response-cost-output: 9.6e-06
    usage: {"completion_tokens": 32, "prompt_tokens": 74, "total_tokens": 106, ...}
    

POST /v1/responses

  1. curl -s http://127.0.0.1:23294/v1/responses -H 'Authorization: Bearer sk-lit6950' -H 'Content-Type: application/json' -d '{"model":"mantle-gpt-oss-20b","input":"Reply with the single word pong.","max_output_tokens":32}' -D - | grep -iE 'x-litellm-response-cost-(input|output)|"usage"'
  2. Observed:
    HTTP/1.1 200 OK
    x-litellm-response-cost-input: 1.8200000000000002e-06
    x-litellm-response-cost-output: 9.6e-06
    usage: {"input_tokens": 74, "input_tokens_details": {"audio_tokens": null, "cached_tokens": 48, "text_tokens": null}, "output_tokens": 32, ...}
    
    26 uncached x 7e-08 on input
  3. Same command with "model":"mantle-gpt-oss-safeguard-20b", observed:
    HTTP/1.1 200 OK
    x-litellm-response-cost-input: 1.8200000000000002e-06
    x-litellm-response-cost-output: 6.2e-06
    usage: {"input_tokens": 74, "input_tokens_details": {"audio_tokens": 0, "cached_tokens": 48, "text_tokens": null}, "output_tokens": 31, ...}
    
    31 x 2e-07 on output
  4. Same command with "model":"converse-gpt-oss-20b" (control), observed:
    HTTP/1.1 200 OK
    x-litellm-response-cost-input: 5.18e-06
    x-litellm-response-cost-output: 9.6e-06
    usage: {"input_tokens": 74, ..., "output_tokens": 32, ...}
    

POST /v1/messages

  1. curl -s http://127.0.0.1:23294/v1/messages -H 'Authorization: Bearer sk-lit6950' -H 'Content-Type: application/json' -d '{"model":"mantle-gpt-oss-20b","max_tokens":32,"messages":[{"role":"user","content":"Reply with the single word pong."}]}' -D - | grep -iE 'x-litellm-response-cost-(input|output)|"usage"'
  2. Observed:
    HTTP/1.1 200 OK
    x-litellm-response-cost-input: 5.18e-06
    x-litellm-response-cost-output: 9.6e-06
    usage: {"input_tokens": 74, "output_tokens": 32}
    
  3. Same command with "model":"mantle-gpt-oss-safeguard-20b", observed:
    HTTP/1.1 200 OK
    x-litellm-response-cost-input: 1.8200000000000002e-06
    x-litellm-response-cost-output: 6.4e-06
    usage: {"input_tokens": 26, "output_tokens": 32, "cache_read_input_tokens": 48}
    
  4. Same command with "model":"converse-gpt-oss-20b" (control), observed:
    HTTP/1.1 200 OK
    x-litellm-response-cost-input: 5.18e-06
    x-litellm-response-cost-output: 9.6e-06
    usage: {"input_tokens": 74, "output_tokens": 32}
    

POST /spend/calculate at 1,000,000 tokens

  1. curl -s http://127.0.0.1:23294/spend/calculate -H 'Authorization: Bearer sk-lit6950' -H 'Content-Type: application/json' -d '{"completion_response":{"model":"bedrock_mantle/openai.gpt-oss-20b","usage":{"prompt_tokens":1000000,"completion_tokens":0,"total_tokens":1000000}}}'
  2. Observed: {"cost":0.07}
  3. Same with "prompt_tokens":0,"completion_tokens":1000000, observed: {"cost":0.3}
  4. Same two calls with "model":"bedrock_mantle/openai.gpt-oss-safeguard-20b", observed: {"cost":0.07} for prompt and {"cost":0.19999999999999998} for completion
  5. Same two calls with "model":"bedrock/converse/openai.gpt-oss-20b-1:0" (control), observed: {"cost":0.07} and {"cost":0.3}

Observations from the run:

  • Mantle intermittently reports 48 cached prompt tokens; both sides price them $0
  • The offer file lists no Mantle cache-read SKU; this PR leaves that alone
  • Which requests get the cache hit varies, so input totals differ between runs
  • safeguard-20b on /v1/responses returned input_tokens_details: null once; pre-existing, unrelated

Type

🐛 Bug Fix

Caveats (if any)

Medium

  • Mantle gpt-oss outside us-east-1 and us-west-2 still bills at the us-east-1 rates
    • AWS prices the same Mantle SKUs higher in eu-west-1 (8e-08 in, 3.5e-07 out), eu-central-1 (9e-08, 4e-07), ap-northeast-1 (8e-08, 3.6e-07), and GovCloud (8.4e-08, 3.6e-07), and the map has no bedrock_mantle/<region>/openai.gpt-oss-* rows (nor EU or AP Converse rows), so the region lookup falls back to the base row: up to 22% under-charge on input and 25% on output for EU deployments. Pre-existing, outside this base-rate fix; PR feat(pricing): add GovCloud pricing for every live but unpriced Bedrock model #39764 adds the GovCloud Mantle rows; the rest is LIT-7046. Workaround: input_cost_per_token and output_cost_per_token on the deployment
  • Cache-hit prompt tokens on Mantle gpt-oss are billed at $0
    • The rows carry no cache_read_input_token_cost, so the cost calculator multiplies cache-hit tokens by 0: the after run above charged 26 of 74 prompt tokens on a request that reported 48 cached. The offer files carry no gpt-oss cache-read SKU in any region or tier, so what AWS bills for those tokens is unverified and most likely the full input rate. Pre-existing and left alone here rather than guessing a rate; LIT-7047 verifies it against Cost Explorer and sets it. Workaround: cache_read_input_token_cost on the deployment

Low

  • The after leg ran at 5cc06c3, one commit behind tip 6e0ebd2, which touches only the two test files, so the proxy output cannot differ (see the note under the After heading)
  • service_tier flex and priority requests (and batch) are priced at the standard rate: the offer file lists flex, priority, and batch SKUs for these models but the Mantle rows carry no per-tier fields, which predates this PR and is folded into LIT-7047
  • Spend already written to the logs keeps the old rate (the wrong rates shipped with the Mantle provider in 1.82.x), since migrations never rewrite rows, and a proxy without LITELLM_LOCAL_MODEL_COST_MAP picks the fix up only once the JSON on main carries it
  • The Logs page was not exercised with a DB; the spend it shows is the same computed cost the response headers and /spend/calculate return above

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

  • 6e0ebd2 passes /live-pr-risk

@mateo-berri
mateo-berri requested a review from a team September 5, 2026 05:33
@codspeed

codspeed Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_lit_6950_mantle_gpt_oss_pricing (6e0ebd2) with litellm_internal_staging (aea5358)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

Corrects Bedrock Mantle token pricing to match AWS’s standard-tier rates and strengthens regression coverage.

  • Lowers input pricing for openai.gpt-oss-20b and openai.gpt-oss-safeguard-20b from 7.5e-08 to 7e-08 per token.
  • Lowers safeguard-20b output pricing from 3e-07 to 2e-07 per token.
  • Keeps the primary and backup price maps synchronized.
  • Moves offer-file and Converse-equivalence checks into the existing Bedrock Mantle transformation test module.

Confidence Score: 5/5

The PR appears safe to merge; the corrected rates are synchronized and covered by valid local regression tests.

Both previous findings are resolved: the stale pricing assertion now expects the corrected rate, and the pricing regression coverage was moved into the required existing Bedrock Mantle test module. No new actionable failures remain.

Important Files Changed

Filename Overview
model_prices_and_context_window.json Updates the primary Mantle pricing rows to the stated AWS input and safeguard output rates.
litellm/model_prices_and_context_window_backup.json Mirrors the corrected rates in the packaged backup cost map.
tests/test_litellm/llms/bedrock_mantle/test_bedrock_mantle_transformation.py Updates the stale expectation and adds local, parametrized coverage for both price maps and matching Converse rows.

Reviews (3): Last reviewed commit: "test(bedrock_mantle): consolidate the pr..." | Re-trigger Greptile

},
"bedrock_mantle/openai.gpt-oss-20b": {
"input_cost_per_token": 7.5e-08,
"input_cost_per_token": 7e-08,

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.

P1 Stale pricing test expectation

The rate is now 7e-08, but the existing Mantle pricing test expects 7.5e-8, causing that test to fail

Knowledge Base Used: Spend, budgets, and rate limits

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 5cc06c3: the assertion now pins 7e-8, matching the offer file and the rate this PR sets.

@codecov

codecov Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

…st file

TestBedrockMantlePricing set LITELLM_LOCAL_MODEL_COST_MAP after import and
never reloaded litellm.model_cost, so it only passed by side effect of the
module-level map and failed against the network map once the rate changed.
It now uses the file's local_cost_map fixture, which reloads the bundled map,
clears the get_model_info cache, and restores everything afterwards.

The offer-file and Converse-parity checks move from a sibling top-level file
into this mapped test file, per the repository test layout rule.
@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.

✅ 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 6e0ebd2. Configure here.

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Absorbed into the rolling registry PR #31884 along with the test expectation update. Closing this one to keep a single registry PR.

auto-merge was automatically disabled September 5, 2026 13:32

Pull request was closed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant