Skip to content

feat(proxy): map baggage values to budget tags - #47358

Merged
mateo-berri merged 24 commits into
mainfrom
litellm_baggage_request_tag_mappings
Oct 20, 2026
Merged

mateo-berri merged 24 commits into
mainfrom
litellm_baggage_request_tag_mappings

Conversation

@mateo-berri

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

Copy link
Copy Markdown
Contributor

Callers that send a W3C baggage header can now drive tag spend and budgets. A rule in general_settings.request_tag_mappings maps a baggage key to a tag, by exact value or by any value under a prefix, and the proxy adds that tag to the request. Spend then tracks against the tag, budgeted or not, and an exhausted tag budget gets rejected before the provider call

This gives each entrypoint its own tag without every client setting tags by hand. Mapped tags never drive routing, policies or guardrails, since baggage comes from the client. Nothing changes until a mapping is configured, except that POST /tag/new now resets the tag spend counters, so a new budget skips earlier spend

/stupid

Original

TLDR

Problem this solves:

  • Propagated baggage values cannot select native tag budgets
  • Each entrypoint needs its own tag for spend and budgets

How it solves it:

  • Maps a baggage key to tags by exact value or any-value prefix, and exact wins
  • Adds YAML configuration and a General settings editor
  • Tags LLM API, A2A and custom pass-through POST requests, skipping token counting, model listing, request previews and MCP
  • Mapped tags drive spend and budgets, never routing, policy attachments or tag-mode guardrails
  • Rejects exhausted tag budgets before the provider call

Nothing changes until request_tag_mappings is configured, and the Severe caveats list what required and require_budgeted_tag then reject. POST /tag/new now resets every tag's spend counter, with or without mappings, so a new budget skips the spend the proxy wrote before it existed

Design decisions and their alternatives

Mapped tags never select deployments under enable_tag_filtering, an auto, complexity, adaptive or quality router strategy, a compression policy, tag-scoped policy attachments or tag-mode guardrails unless the caller also sent the tag or the key, team or project carries it, since baggage comes from the client and could otherwise steer routing, add or remove guardrails, or turn working requests into 401s. A per-rule opt-in was the alternative, left out until someone asks

With require_budgeted_tag, a failed tag budget read answers 503 instead of skipping the check. With allow_requests_on_db_unavailable on, the call goes through on the real key with the mapped tag unchecked, as other tag budget checks do during an outage, rather than taking the fallback identity that drops the key's own limits

A tag_prefix rule lets the caller choose the tag under that prefix, as the feature asks. reject_clientside_metadata_tags does not cover mapped tags because the admin configured them, and its error now says so. Client tags in the body or the x-litellm-tags header get the same answer with or without a mapped value. Refusing mappings while that flag is on, or accepting only existing tags, were the alternatives. Exact rules or require_budgeted_tag limit callers to known tags

A budget created with POST /tag/new counts spend from creation, so the counter resets and agrees with the new row across restarts. Seeding the row from the counter was the alternative, which would charge older spend to the new budget

A required rule turns off WebSocket inference, because those connections cannot carry the tag to their spend rows. Mapping the handshake through seven WebSocket endpoints that each rebuild their request was the alternative

Mappings cover every LLM API and registered pass-through POST route and skip a short list of free ones, so a required rule also applies to POSTs that may cost nothing, like file uploads. An allowlist of billed routes was the alternative, which would let a newly added billed route skip required without anyone noticing. MCP is not mapped yet, since several MCP auth paths skip the mapper and its cost rows come from rebuilt requests. Token counting, model listing and request previews cost nothing, so they are skipped. Mapped tags stay out of requester_metadata, so logging integrations still see only what the client sent. The OpenTelemetry propagator reads a bare + as a space, so a rule key with a + matches a baggage key sent with either + or %2B, and a request that sends both spellings maps nothing for that key. A value with a control character, like %00, maps no tag, and the duplicate-key check counts percent-decoded keys

When a tag maps, auth works on its own copy of the request body, and the cached body stays the client's, with the base header and key tag merges applied to it too, so pass-through forwards the client's body without mapped tags. A request that maps nothing keeps the cached body exactly as before. Normalizing metadata when the body is parsed was the alternative, which would change requests that send no baggage

Mapped tags are added after the key, team, deployment and caller tags, so a tag-mode guardrail picks the same tag with or without baggage, and spend logs list mapped tags last. Adding them when auth resolves the mapping was the alternative, which let a mapped tag win over a key or deployment tag

An invalid request_tag_mappings value written straight to the DB is ignored with an ERROR log, like an invalid user_api_key_cache_max_size, so requests are served as if it were unset until a valid value loads. Failing every mapped request was the alternative, which would block all inference over a value the settings endpoints already reject

User Flow

Before: an application's propagated entrypoint does not select its use-case budget

  1. The admin creates use-case budgets with POST https://litellm-domain/tag/new
  2. They open https://litellm-domain/ui/router-settings, General, and find no baggage mapper
  3. POST https://litellm-domain/v1/chat/completions with baggage: entrypoint=a succeeds, but its spend log has no mapped tag
  4. After exhausting that tag's budget, the same request through another proxy instance still succeeds

Before: General has no baggage mapper

After: the same propagated value selects its configured tag and budget

  1. The admin creates use-case budgets with POST https://litellm-domain/tag/new
  2. They open https://litellm-domain/ui/router-settings, General, and configure exact and any-value mappings, or use YAML
  3. The same POST returns 200, and https://litellm-domain/ui/logs shows its mapped tag and real spend
  4. After exhausting that tag's budget, the same request through another proxy instance returns 422

After: General supports exact and variable baggage mappings

Relevant issues

Replaces #46699

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

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

Last updated: b13e844b89. QA and /live-pr-risk ran on 7907353429, the last commit with a product diff

After ran at 7907353429 and Before on #46699, each on paired 2-worker proxies with real providers, through curl, the MCP SDK, WebSocket and the Admin UI. Output is below or in the gist

Case Before 9f115be88d After
Every surface, pass-through untagged tagged
Rule unmet 200 400
Spent budget, other instance 200 422
Langfuse trace tags client only plus mapped
WebSocket, valid key 101 403
Tag read error, no database 200 503
New tag, creating worker all old spend last batch only
UI rule editor no field works
Before 8dd60b2937
JSON-string and header tags default tagged
Non-object metadata, unmapped baggage 400 200
Chat litellm_metadata tag plus baggage default tagged
Reject flag, unmapped JSON-string tags 400 200
Reject flag, object tags, mapped baggage 400 400

Before 9f115be88d

Admin UI
  1. Router settings, General. There is no request_tag_mappings row, so no mapping can be added

pr46699-9f115be88d-ui_general.png

JSON-string metadata tags with x-litellm-tags, no rule

Rig: leg=u6base commit=9f115be88d instance A=http://127.0.0.1:24755 instance B=http://127.0.0.1:24199, 2 workers each, one Postgres (qa_u6base) and one Redis. Model group router-chat has two deployments, usecase-a-gpt-4o (OpenAI gpt-4o, tags [usecase:a]) and default-claude-haiku (Anthropic, tags [default]), enable_tag_filtering: true. No request_tag_mappings

  1. J1 metadata as a JSON string with tags [usecase:a], x-litellm-tags: other, no baggage, on A
$ curl -s -D headers.txt -o resp.json -w 'HTTP %{http_code}\n' -X POST "http://127.0.0.1:24755/chat/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "x-litellm-tags: other" -H "Content-Type: application/json" -d '{"model": "router-chat", "metadata": "{\"tags\": [\"usecase:a\"]}", "messages": [{"role": "user", "content": "hello"}]}' && grep -i '^x-litellm-model-id' headers.txt | tr -d '\r'; jq -c '.error // {id, model, content: .choices[0].message.content}' resp.json
HTTP 200
x-litellm-model-id: usecase-a-gpt-4o
{"id":"chatcmpl-Ea86RzoW3xCZpQ3o1IL8SSruJvwKG","model":"router-chat","content":"Hello! How can I assist you today?"}
  1. J9 Spend logs for this rig (time, request id, deployment, status, tags as JSON), instance A
(waiting 30 s for spend logs)
$ curl -s "http://127.0.0.1:24755/spend/logs/v2?start_date=2026-10-16%2000:00:00&end_date=2026-10-20%2000:00:00&page_size=100" -H "Authorization: Bearer $LITELLM_MASTER_KEY" | jq -r '[.data[] | select(.startTime >= "2026-10-17T23:27:42")] | {data: .} | .data | sort_by(.startTime)[] | [.startTime[11:19], .request_id, .model_id, .status, ((.request_tags // []) | map(select(startswith("User-Agent") | not)) | tojson)] | @tsv'
23:27:43	chatcmpl-Ea86RzoW3xCZpQ3o1IL8SSruJvwKG	usecase-a-gpt-4o	success	["usecase:a","other"]
23:27:44	chatcmpl-Ea86S8gibdXQBVvaWQLdqPY96jrFo	usecase-a-gpt-4o	success	["usecase:a","other"]
23:27:45	chatcmpl-Ea86TElGYdlru9tzwP3fwAoyk6t5k	usecase-a-gpt-4o	success	["usecase:a"]
23:27:46	chatcmpl-Ea86UxUj5uHY0o03FvOdRpXTaUoNd	usecase-a-gpt-4o	success	["usecase:a"]
23:27:46	chatcmpl-Ea86VLtHVsjSEszwlveITahpeEOws	usecase-a-gpt-4o	success	["usecase:a"]
23:27:47	chatcmpl-Ea86Vhw6loG2gsvlDJ9JbdJ13UZpk	usecase-a-gpt-4o	success	["usecase:a"]
23:27:48	resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGVyOm9wZW5haTttb2RlbF9pZDp1c2VjYXNlLWEtZ3B0LTRvO3Jlc3BvbnNlX2lkOnJlc3BfMDRiMzUxOGNkMTA0ZWQ3MjAwNmFkNDA0NzQ3ZDI4ODdkMjgzMjBiZjA3ZDYzYmU2M2E=	usecase-a-gpt-4o	success	["usecase:a"]
23:27:49	resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGVyOm9wZW5haTttb2RlbF9pZDp1c2VjYXNlLWEtZ3B0LTRvO3Jlc3BvbnNlX2lkOnJlc3BfMDUwMDgzNDZhOTc5MDZlMDAwNmFkNDA0NzU3MmFjODdkMmJhMTA5ODNjNjY4YWRkNjM=	usecase-a-gpt-4o	success	["usecase:a"]
23:27:50	msg_011Cg8gBVCavcL2ZSWyP5Cxx	default-claude-haiku	success	["default"]
Controls for the last group

Every control for the last table group (no rule, the optional rule config, which this base ignores, and the reject flag) ran at this base in this round, through the same rigs and steps as the other two legs. Commands and raw output are in the gist, whole

Every other case

Every case in the first table rows ran at this base in earlier rounds with the same clients, steps and setup, so it stands. Commands and raw output are in the gist

The Before legs at eec15b37fd and 8dd60b2937 are in the gist

After 7907353429

JSON-string metadata tags with x-litellm-tags, no rule

Rig: leg=u6tip26 commit=7907353429 instance A=http://127.0.0.1:45345 instance B=http://127.0.0.1:52655, 2 workers each, one Postgres (u6tip26_head) and one Redis. Model group router-chat has two deployments, usecase-a-gpt-4o (OpenAI gpt-4o, tags [usecase:a]) and default-claude-haiku (Anthropic, tags [default]), enable_tag_filtering: true. No request_tag_mappings

  1. J1 metadata as a JSON string with tags [usecase:a], x-litellm-tags: other, no baggage, on A
$ curl -s -D headers.txt -o resp.json -w 'HTTP %{http_code}\n' -X POST "http://127.0.0.1:45345/chat/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "x-litellm-tags: other" -H "Content-Type: application/json" -d '{"model": "router-chat", "metadata": "{\"tags\": [\"usecase:a\"]}", "messages": [{"role": "user", "content": "hello"}]}' && grep -i '^x-litellm-model-id' headers.txt | tr -d '\r'; jq -c '.error // {id, model, content: .choices[0].message.content}' resp.json
HTTP 200
x-litellm-model-id: usecase-a-gpt-4o
{"id":"chatcmpl-EawdYLw5L54dLRxfxpdD0USHue7eu","model":"router-chat","content":"Hello! How can I assist you today?"}
  1. J2 the same plus baggage entrypoint=a, which nothing maps here, on B
$ curl -s -D headers.txt -o resp.json -w 'HTTP %{http_code}\n' -X POST "http://127.0.0.1:52655/chat/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "x-litellm-tags: other" -H "baggage: entrypoint=a" -H "Content-Type: application/json" -d '{"model": "router-chat", "metadata": "{\"tags\": [\"usecase:a\"]}", "messages": [{"role": "user", "content": "hello"}]}' && grep -i '^x-litellm-model-id' headers.txt | tr -d '\r'; jq -c '.error // {id, model, content: .choices[0].message.content}' resp.json
HTTP 200
x-litellm-model-id: usecase-a-gpt-4o
{"id":"chatcmpl-EawdZFBbRDnfm64BKRtAgv6iHoJMW","model":"router-chat","content":"Hello! How can I assist you today?"}
  1. J9 Spend logs for this rig (time, request id, deployment, status, tags as JSON), instance A
(waiting 30 s for spend logs)
$ curl -s "http://127.0.0.1:45345/spend/logs/v2?start_date=2026-10-18%2000:00:00&end_date=2026-10-22%2000:00:00&page_size=100" -H "Authorization: Bearer $LITELLM_MASTER_KEY" | jq -r '[.data[] | select(.startTime >= "2026-10-20T05:25:10")] | {data: .} | .data | sort_by(.startTime)[] | [.startTime[11:19], .request_id, .model_id, .status, ((.request_tags // []) | map(select(startswith("User-Agent") | not)) | tojson)] | @tsv'
05:25:16	chatcmpl-EawdYLw5L54dLRxfxpdD0USHue7eu	usecase-a-gpt-4o	success	["usecase:a","other"]
05:25:17	chatcmpl-EawdZFBbRDnfm64BKRtAgv6iHoJMW	usecase-a-gpt-4o	success	["usecase:a","other"]
05:25:18	chatcmpl-Eawdb3y6A5qC03Q7edwAF2E9i7tje	usecase-a-gpt-4o	success	["usecase:a"]
05:25:20	chatcmpl-Eawdc1Pl3j0RnB8sZyuJ91drXenmO	usecase-a-gpt-4o	success	["usecase:a"]
05:25:21	chatcmpl-EawddzjvpEVqBR4KXV2xNtZrjhqQ9	usecase-a-gpt-4o	success	["usecase:a"]
05:25:22	chatcmpl-EawdfworoIjKLbCAuabnbppoIiUMI	usecase-a-gpt-4o	success	["usecase:a"]
05:25:24	resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGVyOm9wZW5haTttb2RlbF9pZDp1c2VjYXNlLWEtZ3B0LTRvO3Jlc3BvbnNlX2lkOnJlc3BfMGRiZjYzZmY3NmQ0YjI5ZjAwNmFkNmZiNDRhMTVjODdkMTlmMzdkNzI4Zjg3MzczOWI=	usecase-a-gpt-4o	success	["usecase:a"]
05:25:26	resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGVyOm9wZW5haTttb2RlbF9pZDp1c2VjYXNlLWEtZ3B0LTRvO3Jlc3BvbnNlX2lkOnJlc3BfMGIyY2FkMjVmYzgxM2MzNzAwNmFkNmZiNDY4ZGJjODdkMTlhZjgxMWU1ZjYxN2JlZmM=	usecase-a-gpt-4o	success	["usecase:a"]
05:25:28	msg_011CgCw56LzvfHzdTgz1BrfP	default-claude-haiku	success	["default"]
JSON-string tags with mapped baggage, and string or list metadata, optional rule

Rig: leg=r6tip26 commit=7907353429 instance A=http://127.0.0.1:59993 instance B=http://127.0.0.1:43823, 2 workers each, one Postgres (r6tip26_head) and one Redis. Model group router-chat has two deployments, usecase-a-gpt-4o (OpenAI gpt-4o, tags [usecase:a]) and default-claude-haiku (Anthropic, tags [default]), enable_tag_filtering: true. One optional rule maps baggage entrypoint to usecase:

  1. J1 metadata as a JSON string with tags [usecase:a], x-litellm-tags: other, no baggage, on A
$ curl -s -D headers.txt -o resp.json -w 'HTTP %{http_code}\n' -X POST "http://127.0.0.1:59993/chat/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "x-litellm-tags: other" -H "Content-Type: application/json" -d '{"model": "router-chat", "metadata": "{\"tags\": [\"usecase:a\"]}", "messages": [{"role": "user", "content": "hello"}]}' && grep -i '^x-litellm-model-id' headers.txt | tr -d '\r'; jq -c '.error // {id, model, content: .choices[0].message.content}' resp.json
HTTP 200
x-litellm-model-id: usecase-a-gpt-4o
{"id":"chatcmpl-EavqwVGLD7fiB65885cCQxTpWBMAf","model":"router-chat","content":"Hello! How can I assist you today?"}
  1. J3 the same plus baggage entrypoint=a, which maps usecase:a, on A
$ curl -s -D headers.txt -o resp.json -w 'HTTP %{http_code}\n' -X POST "http://127.0.0.1:59993/chat/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "x-litellm-tags: other" -H "baggage: entrypoint=a" -H "Content-Type: application/json" -d '{"model": "router-chat", "metadata": "{\"tags\": [\"usecase:a\"]}", "messages": [{"role": "user", "content": "hello"}]}' && grep -i '^x-litellm-model-id' headers.txt | tr -d '\r'; jq -c '.error // {id, model, content: .choices[0].message.content}' resp.json
HTTP 200
x-litellm-model-id: usecase-a-gpt-4o
{"id":"chatcmpl-Eavqz1vj0iswR8GFVNRDQQSAqtYej","model":"router-chat","content":"Hello! How can I assist you today?"}
  1. J4 the same plus baggage entrypoint=b, which maps usecase:b, on B
$ curl -s -D headers.txt -o resp.json -w 'HTTP %{http_code}\n' -X POST "http://127.0.0.1:43823/chat/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "x-litellm-tags: other" -H "baggage: entrypoint=b" -H "Content-Type: application/json" -d '{"model": "router-chat", "metadata": "{\"tags\": [\"usecase:a\"]}", "messages": [{"role": "user", "content": "hello"}]}' && grep -i '^x-litellm-model-id' headers.txt | tr -d '\r'; jq -c '.error // {id, model, content: .choices[0].message.content}' resp.json
HTTP 200
x-litellm-model-id: usecase-a-gpt-4o
{"id":"chatcmpl-Eavr0gROD4ToSIEsVN9ONaZ3AyAfX","model":"router-chat","content":"Hello! How can I assist you today?"}
  1. N1 metadata as the plain string "run-123", x-litellm-tags: usecase:a, baggage region=sg, on A
$ curl -s -D headers.txt -o resp.json -w 'HTTP %{http_code}\n' -X POST "http://127.0.0.1:59993/chat/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "x-litellm-tags: usecase:a" -H "baggage: region=sg" -H "Content-Type: application/json" -d '{"model": "router-chat", "metadata": "run-123", "messages": [{"role": "user", "content": "hello"}]}' && grep -i '^x-litellm-model-id' headers.txt | tr -d '\r'; jq -c '.error // {id, model, content: .choices[0].message.content}' resp.json
HTTP 200
x-litellm-model-id: usecase-a-gpt-4o
{"id":"chatcmpl-Eavr2EIjdNxQmUrolh1G5oAaWbTax","model":"router-chat","content":"Hello! How can I assist you today?"}
  1. N3 metadata as the list ["x"], x-litellm-tags: usecase:a, baggage region=sg, on A
$ curl -s -D headers.txt -o resp.json -w 'HTTP %{http_code}\n' -X POST "http://127.0.0.1:59993/chat/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "x-litellm-tags: usecase:a" -H "baggage: region=sg" -H "Content-Type: application/json" -d '{"model": "router-chat", "metadata": ["x"], "messages": [{"role": "user", "content": "hello"}]}' && grep -i '^x-litellm-model-id' headers.txt | tr -d '\r'; jq -c '.error // {id, model, content: .choices[0].message.content}' resp.json
HTTP 200
x-litellm-model-id: usecase-a-gpt-4o
{"id":"chatcmpl-Eavr4xnK09SvMedkicHGFRcsxpEcZ","model":"router-chat","content":"Hello! How can I assist you today?"}
  1. J9 Spend logs for this rig (time, request id, deployment, status, tags as JSON), instance A
(waiting 30 s for spend logs)
$ curl -s "http://127.0.0.1:59993/spend/logs/v2?start_date=2026-10-18%2000:00:00&end_date=2026-10-22%2000:00:00&page_size=100" -H "Authorization: Bearer $LITELLM_MASTER_KEY" | jq -r '[.data[] | select(.startTime >= "2026-10-20T04:34:55")] | {data: .} | .data | sort_by(.startTime)[] | [.startTime[11:19], .request_id, .model_id, .status, ((.request_tags // []) | map(select(startswith("User-Agent") | not)) | tojson)] | @tsv'
04:35:01	chatcmpl-EavqwVGLD7fiB65885cCQxTpWBMAf	usecase-a-gpt-4o	success	["usecase:a","other"]
04:35:03	chatcmpl-EavqyPBfbD8keoQMsuqI26RjOypdX	usecase-a-gpt-4o	success	["usecase:a","other"]
04:35:05	chatcmpl-Eavqz1vj0iswR8GFVNRDQQSAqtYej	usecase-a-gpt-4o	success	["usecase:a","other"]
04:35:06	chatcmpl-Eavr0gROD4ToSIEsVN9ONaZ3AyAfX	usecase-a-gpt-4o	success	["usecase:a","other","usecase:b"]
04:35:07	chatcmpl-Eavr2EIjdNxQmUrolh1G5oAaWbTax	usecase-a-gpt-4o	success	["usecase:a"]
04:35:09	chatcmpl-Eavr3dhbSqHrhdK22n3fh2WU6uMmp	usecase-a-gpt-4o	success	["usecase:a"]
04:35:10	chatcmpl-Eavr4xnK09SvMedkicHGFRcsxpEcZ	usecase-a-gpt-4o	success	["usecase:a"]
04:35:12	chatcmpl-Eavr6gXKi6lLBZlMxEJSpHdrI77aV	usecase-a-gpt-4o	success	["usecase:a"]
04:35:13	resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGVyOm9wZW5haTttb2RlbF9pZDp1c2VjYXNlLWEtZ3B0LTRvO3Jlc3BvbnNlX2lkOnJlc3BfMDBhMDQ3OGM2YTY5MjJiYTAwNmFkNmVmODIwM2I4ODdkMWI0ZTlkYTk0OWJmYjM2ODg=	usecase-a-gpt-4o	success	["usecase:a"]
04:35:16	resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGVyOm9wZW5haTttb2RlbF9pZDp1c2VjYXNlLWEtZ3B0LTRvO3Jlc3BvbnNlX2lkOnJlc3BfMDQ2NmJmZjc0NjJjYzZkYTAwNmFkNmVmODRjOGNjODdkMWE4YjMyODI0NzRmYjhiZTY=	usecase-a-gpt-4o	success	["usecase:a"]
04:35:18	msg_011CgCsFDDop1wG2Un2vT3GU	default-claude-haiku	success	["default","usecase:a"]
litellm_metadata tags plus baggage on Chat Completions, Responses and Messages

Rig: leg=r6tip26 commit=7907353429 instance A=http://127.0.0.1:59993 instance B=http://127.0.0.1:43823, 2 workers each, one Postgres (r6tip26_head) and one Redis. Model group router-chat has two deployments, usecase-a-gpt-4o (OpenAI gpt-4o, tags [usecase:a]) and default-claude-haiku (Anthropic, tags [default]), enable_tag_filtering: true. One optional rule maps baggage entrypoint to usecase:

  1. L1 Chat Completions with litellm_metadata.tags [usecase:a] plus baggage entrypoint=a, on A
$ curl -s -D headers.txt -o resp.json -w 'HTTP %{http_code}\n' -X POST "http://127.0.0.1:59993/chat/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "baggage: entrypoint=a" -H "Content-Type: application/json" -d '{"model": "router-chat", "litellm_metadata": {"tags": ["usecase:a"]}, "messages": [{"role": "user", "content": "hello"}]}' && grep -i '^x-litellm-model-id' headers.txt | tr -d '\r'; jq -c '.error // {id, model, content: .choices[0].message.content}' resp.json
HTTP 200
x-litellm-model-id: usecase-a-gpt-4o
{"id":"chatcmpl-EavrjJScC0U3TdJxWuYk53C7rgVmN","model":"router-chat","content":"Hello! How can I assist you today?"}
  1. L2 Chat Completions with litellm_metadata.tags [usecase:a] and no baggage, on B
$ curl -s -D headers.txt -o resp.json -w 'HTTP %{http_code}\n' -X POST "http://127.0.0.1:43823/chat/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model": "router-chat", "litellm_metadata": {"tags": ["usecase:a"]}, "messages": [{"role": "user", "content": "hello"}]}' && grep -i '^x-litellm-model-id' headers.txt | tr -d '\r'; jq -c '.error // {id, model, content: .choices[0].message.content}' resp.json
HTTP 200
x-litellm-model-id: usecase-a-gpt-4o
{"id":"chatcmpl-EavrktyU1Q8egLupRvdm00mtmx1ne","model":"router-chat","content":"Hello! How can I assist you today?"}
  1. L3 Responses with litellm_metadata.tags [usecase:a] plus baggage entrypoint=a, on B
$ curl -s -D headers.txt -o resp.json -w 'HTTP %{http_code}\n' -X POST "http://127.0.0.1:43823/v1/responses" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "baggage: entrypoint=a" -H "Content-Type: application/json" -d '{"model": "router-chat", "litellm_metadata": {"tags": ["usecase:a"]}, "input": "hello"}' && grep -i '^x-litellm-model-id' headers.txt | tr -d '\r'; jq -c '.error // {id, model, status, text: .output[-1].content[0].text}' resp.json
HTTP 200
x-litellm-model-id: usecase-a-gpt-4o
{"id":"resp_BLkWw7yzeDviFmsgBwxHgBJXB8oDEJFm8Nycf_0Csq10q9qbza8t8c7GhFnpS7a7xQ0fnUDUB5CQDn78GhUcCZTl1XiRbNBpU0bF1D4adPi12HChwB_HyUO-yKXSO5e68dQu92woojOvAuF4HNUOP_sR7CX_EaMJ5jEq3IU3Py1IAf4deU5iesXCLgVeHFuMQcJctzVu2jSYpDopuA8pYU4xBaUtV7-NAxGCn1mg9aL835QEkHfViUzLqiqMFw0yiQOSTiALBQo-Q7O7z06qfXFfN2_FlDyIa4T2nMA31yaFCGNrDuYy_WqQ5CjT6Ya7lwspGtyw5eP8dmm0hxZVFgLlWcS7FeCwhbI7vB3hhZWV7OpdQD21Hudo0QLjsomL1pM=","model":"router-chat","status":"completed","text":"Hello! How can I assist you today?"}
  1. L4 Responses with litellm_metadata.tags [usecase:a] and no baggage, on A
$ curl -s -D headers.txt -o resp.json -w 'HTTP %{http_code}\n' -X POST "http://127.0.0.1:59993/v1/responses" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model": "router-chat", "litellm_metadata": {"tags": ["usecase:a"]}, "input": "hello"}' && grep -i '^x-litellm-model-id' headers.txt | tr -d '\r'; jq -c '.error // {id, model, status, text: .output[-1].content[0].text}' resp.json
HTTP 200
x-litellm-model-id: usecase-a-gpt-4o
{"id":"resp_U4hHo7qoFh9OeEr8EqUt1xDlsD0-B_R9QrrlH0uojPr09wUN1i4q2XJT2Lzdlwr2aJOOR26lj-_pHEkSmaxHZT8j7tqe1q2TCNIZOzMQ_jYaAZ40QvLjuvuZ3rKU8Iz_clSW2FsfNQIflu1zeVBJ8hr556b5tgiZscS1EgjVcawdYWsw0nLaD-QZs1FtAi25vB0DyHOqXmi5IRYr8CYVWV8fGUIwbmkcwwyPpU05UFA6DB8AW0yTo3IRx62Rza20mI8PPLBs0LtGhhdwnUPN5WDwPRlmXdvfbJGmWyonW_LT27RPuMEKZM-Tsln6rsp4jzKTS6ZJasiAqHmEUxLovOaKTy-yndwKlLVheACKXq1fGFoTWi-XaQkwXsGmUzpafw0=","model":"router-chat","status":"completed","text":"Hello! How can I assist you today?"}
  1. L5 Messages with litellm_metadata.tags [usecase:a] plus baggage entrypoint=a, streaming, on B
$ curl -s -N -D headers.txt -X POST "http://127.0.0.1:43823/v1/messages" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "baggage: entrypoint=a" -H "Content-Type: application/json" -d '{"model": "router-chat", "max_tokens": 40, "stream": true, "litellm_metadata": {"tags": ["usecase:a"]}, "messages": [{"role": "user", "content": "hello"}]}' | grep -c '^data:'; grep -i '^HTTP/\|^x-litellm-model-id' headers.txt | tr -d '\r'
14
HTTP/1.1 200 OK
x-litellm-model-id: usecase-a-gpt-4o
  1. L9 Spend logs for this rig (time, request id, deployment, status, tags as JSON), instance A
(waiting 30 s for spend logs)
$ curl -s "http://127.0.0.1:59993/spend/logs/v2?start_date=2026-10-18%2000:00:00&end_date=2026-10-22%2000:00:00&page_size=100" -H "Authorization: Bearer $LITELLM_MASTER_KEY" | jq -r '[.data[] | select(.startTime >= "2026-10-20T04:35:45")] | {data: .} | .data | sort_by(.startTime)[] | [.startTime[11:19], .request_id, .model_id, .status, ((.request_tags // []) | map(select(startswith("User-Agent") | not)) | tojson)] | @tsv'
04:35:50	chatcmpl-EavrjJScC0U3TdJxWuYk53C7rgVmN	usecase-a-gpt-4o	success	["usecase:a"]
04:35:52	chatcmpl-EavrktyU1Q8egLupRvdm00mtmx1ne	usecase-a-gpt-4o	success	["usecase:a"]
04:35:53	resp_BLkWw7yzeDviFmsgBwxHgBJXB8oDEJFm8Nycf_0Csq10q9qbza8t8c7GhFnpS7a7xQ0fnUDUB5CQDn78GhUcCZTl1XiRbNBpU0bF1D4adPi12HChwB_HyUO-yKXSO5e68dQu92woojOvAuF4HNUOP_sR7CX_EaMJ5jEq3IU3Py1IAf4deU5iesXCLgVeHFuMQcJctzVu2jSYpDopuA8pYU4xBaUtV7-NAxGCn1mg9aL835QEkHfViUzLqiqMFw0yiQOSTiALBQo-Q7O7z06qfXFfN2_FlDyIa4T2nMA31yaFCGNrDuYy_WqQ5CjT6Ya7lwspGtyw5eP8dmm0hxZVFgLlWcS7FeCwhbI7vB3hhZWV7OpdQD21Hudo0QLjsomL1pM=	usecase-a-gpt-4o	success	["usecase:a"]
04:35:55	resp_U4hHo7qoFh9OeEr8EqUt1xDlsD0-B_R9QrrlH0uojPr09wUN1i4q2XJT2Lzdlwr2aJOOR26lj-_pHEkSmaxHZT8j7tqe1q2TCNIZOzMQ_jYaAZ40QvLjuvuZ3rKU8Iz_clSW2FsfNQIflu1zeVBJ8hr556b5tgiZscS1EgjVcawdYWsw0nLaD-QZs1FtAi25vB0DyHOqXmi5IRYr8CYVWV8fGUIwbmkcwwyPpU05UFA6DB8AW0yTo3IRx62Rza20mI8PPLBs0LtGhhdwnUPN5WDwPRlmXdvfbJGmWyonW_LT27RPuMEKZM-Tsln6rsp4jzKTS6ZJasiAqHmEUxLovOaKTy-yndwKlLVheACKXq1fGFoTWi-XaQkwXsGmUzpafw0=	usecase-a-gpt-4o	success	["usecase:a"]
04:35:57	msg_3eeb2f17-70b2-41a0-94ec-103ac6af1a9c	usecase-a-gpt-4o	success	["usecase:a"]
Client tags rejected, one optional rule

Rig: leg=j6tip26 commit=7907353429 instance A=http://127.0.0.1:55403 instance B=http://127.0.0.1:43329, 2 workers each, one Postgres (j6tip26_head) and one Redis. Model group router-chat has two deployments, usecase-a-gpt-4o (OpenAI gpt-4o, tags [usecase:a]) and default-claude-haiku (Anthropic, tags [default]), enable_tag_filtering: true, reject_clientside_metadata_tags: true. One optional rule maps baggage entrypoint to usecase:

  1. K1 metadata as a JSON string with tags [usecase:a], baggage region=sg, which nothing maps, on A
$ curl -s -D headers.txt -o resp.json -w 'HTTP %{http_code}\n' -X POST "http://127.0.0.1:55403/chat/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "baggage: region=sg" -H "Content-Type: application/json" -d '{"model": "router-chat", "metadata": "{\"tags\": [\"usecase:a\"]}", "messages": [{"role": "user", "content": "hello"}]}' && grep -i '^x-litellm-model-id' headers.txt | tr -d '\r'; jq -c '.error // {id, model, content: .choices[0].message.content}' resp.json
HTTP 200
x-litellm-model-id: default-claude-haiku
{"id":"chatcmpl-a1818ed1-747a-43ab-a7bb-b30ed5cc6f12","model":"router-chat","content":"Hello! How can I help you today?"}
  1. K2 metadata as a JSON string with tags [usecase:a], no baggage, on B
$ curl -s -D headers.txt -o resp.json -w 'HTTP %{http_code}\n' -X POST "http://127.0.0.1:43329/chat/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model": "router-chat", "metadata": "{\"tags\": [\"usecase:a\"]}", "messages": [{"role": "user", "content": "hello"}]}' && grep -i '^x-litellm-model-id' headers.txt | tr -d '\r'; jq -c '.error // {id, model, content: .choices[0].message.content}' resp.json
HTTP 200
x-litellm-model-id: default-claude-haiku
{"id":"chatcmpl-a147d625-fe45-4454-a549-3fd528b4d6da","model":"router-chat","content":"Hello! How can I help you today?"}
  1. K3 metadata as a JSON string with tags [usecase:a], baggage entrypoint=a, on A
$ curl -s -D headers.txt -o resp.json -w 'HTTP %{http_code}\n' -X POST "http://127.0.0.1:55403/chat/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "baggage: entrypoint=a" -H "Content-Type: application/json" -d '{"model": "router-chat", "metadata": "{\"tags\": [\"usecase:a\"]}", "messages": [{"role": "user", "content": "hello"}]}' && grep -i '^x-litellm-model-id' headers.txt | tr -d '\r'; jq -c '.error // {id, model, content: .choices[0].message.content}' resp.json
HTTP 200
x-litellm-model-id: default-claude-haiku
{"id":"chatcmpl-d614872b-4793-4e85-aee5-2135b168c419","model":"router-chat","content":"Hello! How can I help you today?"}
  1. K4 metadata object with tags [usecase:a], no baggage, on B
$ curl -s -D headers.txt -o resp.json -w 'HTTP %{http_code}\n' -X POST "http://127.0.0.1:43329/chat/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model": "router-chat", "metadata": {"tags": ["usecase:a"]}, "messages": [{"role": "user", "content": "hello"}]}' && grep -i '^x-litellm-model-id' headers.txt | tr -d '\r'; jq -c '.error // {id, model, content: .choices[0].message.content}' resp.json
HTTP 400
{"message":"Client-side 'metadata.tags' not allowed in request. 'reject_clientside_metadata_tags'=True. Tags can only be set via key or team metadata, or by configured request_tag_mappings.","type":"bad_request_error","param":"metadata.tags","code":"400"}
  1. K5 metadata object with tags [usecase:a], baggage entrypoint=a, on A
$ curl -s -D headers.txt -o resp.json -w 'HTTP %{http_code}\n' -X POST "http://127.0.0.1:55403/chat/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "baggage: entrypoint=a" -H "Content-Type: application/json" -d '{"model": "router-chat", "metadata": {"tags": ["usecase:a"]}, "messages": [{"role": "user", "content": "hello"}]}' && grep -i '^x-litellm-model-id' headers.txt | tr -d '\r'; jq -c '.error // {id, model, content: .choices[0].message.content}' resp.json
HTTP 400
{"message":"Client-side 'metadata.tags' not allowed in request. 'reject_clientside_metadata_tags'=True. Tags can only be set via key or team metadata, or by configured request_tag_mappings.","type":"bad_request_error","param":"metadata.tags","code":"400"}
  1. K9 Spend logs for this rig (time, request id, deployment, status, tags as JSON), instance A
(waiting 30 s for spend logs)
$ curl -s "http://127.0.0.1:55403/spend/logs/v2?start_date=2026-10-18%2000:00:00&end_date=2026-10-22%2000:00:00&page_size=100" -H "Authorization: Bearer $LITELLM_MASTER_KEY" | jq -r '[.data[] | select(.startTime >= "2026-10-20T04:41:29")] | {data: .} | .data | sort_by(.startTime)[] | [.startTime[11:19], .request_id, .model_id, .status, ((.request_tags // []) | map(select(startswith("User-Agent") | not)) | tojson)] | @tsv'
04:41:35	chatcmpl-a1818ed1-747a-43ab-a7bb-b30ed5cc6f12	default-claude-haiku	success	["default"]
04:41:37	chatcmpl-a147d625-fe45-4454-a549-3fd528b4d6da	default-claude-haiku	success	["default"]
04:41:38	chatcmpl-d614872b-4793-4e85-aee5-2135b168c419	default-claude-haiku	success	["default","usecase:a"]
04:41:40	a3b23750-c14e-4129-9cd2-48f5fde91c4a		failure	["usecase:a"]
04:41:40	46ad9631-ec92-4719-9a1c-bd0abf01ec76		failure	["usecase:a"]
04:41:41	chatcmpl-0199dbd5-0af8-4a1d-a0dd-04eb048eb870	default-claude-haiku	success	["default","usecase:a"]
Every case of these rigs, and the configs

The number 42 and no-baggage string cases (N2, N4), the /v1/messages cases (M1 to M3) and the configs are in the gist, whole

Admin UI
  1. Router settings, General, two exact mappings for entrypoint=support_bot. Update is disabled and the second row says why

pr47358-7907353429-ui_dup_exact.png

  1. Two any-value mappings for entrypoint, prefixes usecase: and team:. Update is disabled again

pr47358-7907353429-ui_dup_any.png

  1. A fresh Add mapping with nothing filled in. Update is disabled

pr47358-7907353429-ui_add_empty.png

  1. Any value and key entrypoint, no prefix. Update stays disabled

pr47358-7907353429-ui_add_noprefix.png

  1. Prefix usecase: and both switches on. Update is enabled

pr47358-7907353429-ui_add_ready.png

  1. Update, then a page reload. The rule shows In DB

pr47358-7907353429-ui_add.png

  1. Delete the rule, Update, reload

pr47358-7907353429-ui_delete.png

  1. Rig 1, the YAML rules show read-only with an In Config badge

pr47358-7907353429-ui_general.png

The browser driver output for each step is in the gist

Every other case

Every other case from the earlier rounds ran again at this tip, with the same clients and steps, and is in the gist, whole, because it passes the body size cap. The routing file has the complexity routers, tag routing, tag policy, control characters, client tags rejected with and without a rule and the outage flag. The core file has every surface, the spent budget across instances, spend logs, the late budget cases T1 to T9, WebSocket and no database. The Admin UI file has the rule cases, skipped routes, A2A, request previews and the settings read after a save. The new cases file has guardrail modes, plus-sign keys and string, empty, false and mixed metadata.tags next to a spent mapped budget, on this tip and on main 0675c22d56

Each case matches the earlier After output, or differs in one of four ways. The deployment tag now comes before the mapped tag, with the same tags. Spend counters are double the spend rows, as on main since #47192. Spend still in the database write batch when POST /tag/new runs reaches the new budget (T3, T4, T7, T8), and a settings read right after a save mixes old and new values (Z2) until each worker's 30 s reload

Observations
  • A tag-attached policy stops that tag's routing. Pre-existing
  • At eec15b37fd, %00 logged tag usecase:, row kept. Fixed at tip
  • Off-model calls answer 403, not 401, on both commits. Unchanged
  • Unbudgeted mapped tags pass in a flagged outage. Caused here
  • Without Redis, reset skips other workers, unchanged from base
  • Other workers enforce a new tag after about 60 s. Pre-existing
  • Valid-key WebSocket 403 has an empty body. Caused here
  • Logged headers still carry the raw baggage. Pre-existing
  • A2A rows log 0.0 spend, streams none. Pre-existing
  • Request preview answers 200 carrying an error. Pre-existing
  • Other workers show old settings until reload. Pre-existing
  • Rejected pass-through rows log call type acompletion. Caused here
  • Required rules turn unknown A2A agent 404 into 400. Caused here
  • The reject flag silently drops JSON-string metadata tags. Pre-existing
  • 8dd60b2937 misrouted only Chat Completions litellm_metadata tags. Fixed at tip
  • Batched spend at create reaches a new budget. Narrower than main
  • Falsy-tag 400 rows carry the mapped tag at 0 spend. Caused here
Audit round 2, at a0da37a

Base 0675c22d56 and head a0da37a085 each ran on their own 2-worker proxy with their own Postgres, Redis and scripted upstream, in one remote_rig.py round. The head runs used tree b0d4c12ba2, which is 98cc33e plus this round's C18 test, and the same tree as a0da37a085. Base ran once and head ran twice with seed 5113701 and order seed 5113702, in CircleCI's accounting group setup (2 workers, each owned proxy on its own private database). Every cell matches its spend rows, callback payloads, guardrail calls and upstream records by a per-request uuid marker. Base had 20 reds and 21 passes, all as expected, and both head runs collected and passed the same 41 cells

# Contract Node id Base Head x2
C1 Tags reach spend, chat test_mapped_baggage_tags_reach_spend_and_callbacks_but_not_requester_metadata[chat] red pass
C1 Tags reach spend, chat litellm_metadata ...[chat_litellm_metadata] red pass
C1 Tags reach spend, messages ...[messages] red pass
C1 Tags reach spend, responses ...[responses] red pass
C1b JSON-string metadata gains only mapped tags test_json_string_metadata_gains_exactly_the_mapped_tags red pass
C2 A2A row has tags test_a2a_spend_row_carries_the_mapped_tags red pass
C3 Spent budget 422s first test_spent_mapped_tag_budget_rejects_the_next_request_before_the_provider red pass
C4 Required rule 400s first test_required_mapping_rejects_a_request_without_its_baggage_value_before_the_provider red pass
C5 Unbudgeted tag 400, then 200 test_require_budgeted_tag_rejects_an_unbudgeted_mapped_tag_until_the_tag_has_a_budget red pass
C6 Failed read, flag off, 503 test_budgeted_mapping_on_a_failed_tag_read[outage_flag_off] red pass
C6 Failed read, flag on, 200 ...[outage_flag_on] red pass
C7 Baggage never routes test_mapped_tags_never_select_a_tag_routed_deployment[baggage_only] pass pass
C7 Header tag still routes ...[caller_tag] pass pass
C7 JSON-string tag with header routes ...[metadata_json_tag_with_header] pass pass
C7 litellm_metadata tag routes ...[litellm_metadata_tag] pass pass
C8 No policy from baggage test_mapped_tags_never_trigger_a_tag_scoped_policy_attachment pass pass
C9 WebSocket gets 403 test_required_mapping_refuses_websocket_inference_before_the_upstream red pass
C10 token_counter skipped test_required_mapping_skips_unbilled_routes[token_counter] pass pass
C10 count_tokens skipped ...[messages_count_tokens] pass pass
C11 Pass-through row has tags test_custom_passthrough_spend_row_carries_the_mapped_tags red pass
C12 Baggage alone allowed test_reject_clientside_metadata_tags_with_baggage[baggage_only] red pass
C12 Header tag still 400 ...[header_tag] pass pass
C12 Body tag still 400 ...[body_tag] pass pass
C12 JSON-string tag, mapped ...[metadata_json_tag] red pass
C12 JSON-string tag, unmapped ...[metadata_json_tag_unmapped_baggage] pass pass
C12 litellm_metadata tag allowed ...[litellm_metadata_tag] red pass
C13 /tag/new resets spend test_tag_budget_enforcement.py::test_tag_new_counts_spend_from_creation_not_before red pass
C14 + key, plus on wire test_plus_sign_rule_key_matches_either_wire_spelling_but_not_both[plus] red pass
C14 + key, %2B on wire ...[percent_encoded] red pass
C14 + key, both spellings ...[both_spellings] red pass
C15 Tagged deployment keeps guardrail test_serving_deployment_tag_selects_its_guardrail_mode_when_baggage_maps_the_same_tag[tagged_deployment] pass pass
C15 Baggage alone adds no guardrail ...[untagged_deployment] pass pass
C16 Non-object metadata, unmapped test_malformed_metadata_keeps_its_status_under_baggage[unmapped_baggage-non_object] pass pass
C16 Same, with header tag ...[header_tag_unmapped_baggage-non_object] pass pass
C16 Non-object metadata, mapped ...[mapped_baggage-non_object] pass pass, fixed in 5281d71
C16 Same, with header tag ...[header_tag_mapped_baggage-non_object] pass pass, fixed in 5281d71
C17 Team tag's guardrail mode stays first test_baggage_mapping_a_deployment_tag_keeps_the_team_tag_guardrail_mode_first pass pass, fixed in 5281d71
C18 String metadata.tags, unmapped test_malformed_metadata_keeps_its_status_under_baggage[unmapped_baggage-string_tags] pass pass
C18 Same, with header tag ...[header_tag_unmapped_baggage-string_tags] pass pass
C18 String metadata.tags, mapped ...[mapped_baggage-string_tags] pass pass, fixed in 98cc33e
C18 Same, with header tag ...[header_tag_mapped_baggage-string_tags] pass pass

The cells are in tests/integration/spend/test_baggage_tag_mappings.py unless the row names another file. This round found three behavior changes, and each one has its fix commit in the table. At f734e9e, a chat body with metadata: "run-123" got 400 "Invalid type for 'metadata'" and no provider call with baggage that mapped a tag, while the same body without baggage (and base) got 200. Baggage that mapped the serving deployment's tag also put it ahead of a team tag, so the deployment tag's guardrail mode won and the team's post_call guardrail did not run (C17 red at f734e9e with no guardrail call, base pass). At 5281d71, a body with metadata: {"tags": "run-123"} got 400 "'str' object has no attribute 'copy'" without baggage and 200 with mapped baggage, since the string tag was dropped (C18 red at 5281d71 on the no-header mapped cell only). 98cc33e leaves a non-list metadata.tags as sent, so both requests now get the same 400 as base

The controls ran once on head. 45 of 51 passed, covering the tag budget, rpm, tpm, update, delete and info cells in spend/test_tag_budget_enforcement.py, the tag cells in spend/test_passthrough_request_tags.py, the count_tokens cells in spend/test_cache_and_quota.py, routing/test_team_tag_routing.py, the tag-scope cells of management/test_policy_attachment_runtime.py, and the JSON-string and form metadata cells of the chat, text completion and audio transcription wire tests. 5 skip themselves on bug markers already on main. The one red control, test_repeated_count_tokens_on_budgeted_key_does_not_reserve_budget_or_block_later_completion (0.12 against 0.06), is inherited. Main's CircleCI has it red with the same figures at the merge base and on every run since #47192, apart from one green run, so it is a Low caveat. The 11 mapped unit files passed at 98cc33e, 3855 tests, including the invalid DB request_tag_mappings reload and the one-pass deployment tag merge. test_router.py ran on Python 3.12, because 4 of its auto-router tests need semantic-router, which does not install on 3.14. There are no live rows because a header-to-tag mapping inside the proxy has no vendor contract to check. JSON-string metadata without an x-litellm-tags header loses its own tags on base and head alike, so those cells compare against the same body sent without baggage instead of pinning that existing bug

Round 2 passed with its tests in a0da37a085.

Type

🆕 New Feature

Caveats (if any)

Severe

  • A required rule returns 403 on every WebSocket inference route, for every valid key
    • Realtime, Responses WebSocket, Live and pass-through WebSocket apps need a separate proxy or no required rule
  • A required rule returns 400 on every LLM API POST without baggage, file uploads and the Admin UI playground included
  • Mapped tags skip reject_clientside_metadata_tags, so the caller picks the budget
    • Any key can send another use case's value and charge or exhaust that budget, and a tag_prefix rule reaches every tag under the prefix
  • require_budgeted_tag answers 503 when tag budgets cannot be read and allow_requests_on_db_unavailable is off, while other tag budget checks fail open

Low

  • POST /tag/new resets every tag's counter, without Redis only on its worker, and spend still in the database write batch reaches the new budget
  • /queue/chat/completions, MCP, batch and background /v1/responses spend carry no mapped tag, all but MCP gaps older than this PR
  • A2A calls log 0.0 spend as on main, and a required rule turns an unknown agent's 404 into 400
  • Mapper rejections on pass-through routes log as acompletion, like other auth failures there on main
  • Without require_budgeted_tag, a tag_prefix rule accepts unlimited new tags, and an outage with allow_requests_on_db_unavailable passes unbudgeted mapped tags
  • Baggage values are percent-decoded as OpenTelemetry does, so + reads as a space
  • Spend counters count each success twice, as on main since fix(logging): deliver completed batch success callbacks consistently #47192, which fix(logging,decisions): bill each request once and price returned decision models only when they carry rates #47047 fixes
  • Under reject_clientside_metadata_tags, the 400 for falsy client tags plus baggage logs the mapped tag at 0 spend
  • caller_tags now also lists body metadata.tags, which can hold key tags, but only the mapping filter reads it
  • Mapper rejections and an invalid DB request_tag_mappings value log at ERROR, the latter on every reload, and other workers keep old mappings until a reload
  • Pip installs need opentelemetry-api, which Docker ships
  • Docs come in a separate litellm-docs 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
  • 7907353 passes /live-pr-risk
Bugbot summary

[!NOTE]
High Risk
Changes proxy auth, tag budgets, and spend attribution from client-controlled baggage, with fail-closed DB checks and WebSocket denial when mappings are required—misconfiguration or mapping abuse can block traffic or charge wrong tag budgets.

Overview
Adds configurable W3C baggage → request tag mapping so propagated context can drive tag spend and budgets without clients setting metadata.tags. Admins define general_settings.request_tag_mappings (YAML + Router Settings UI): exact value → tag, or any value under a tag_prefix, with optional required and require_budgeted_tag.

Pre-auth resolution on billed LLM API, A2A, and registered pass-through POSTs parses baggage, merges mapped tags into auth metadata (separate from the cached client body for pass-through), and enforces tag budgets—including 503 when budgeted-tag DB lookup fails unless allow_requests_on_db_unavailable is on. Mapped tags are stamped in _baggage_mapped_tags / BaggageMappedTagsStamp and stripped from routing, policy matching, and most guardrail mode logic unless the caller, key/team/project, or serving deployment already carries that tag.

Related behavior changes: reject_clientside_metadata_tags still blocks client tags but allows admin-mapped tags; required mappings block WebSocket inference; POST /tag/new invalidates tag spend counters so new budgets ignore prior spend; unbilled routes centralized in RouteChecks.is_unbilled_route; enterprise tag-mode guardrails use the same baggage filter.

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

…hem out of tag routing

Mapped tags now apply only to billed LLM API routes, skipping token counting,
model listing, MCP and A2A. They classify spend and budgets but never select
deployments unless a key, team or client set the same tag. WebSocket inference
returns 403 only while a required rule exists. A tag created with /tag/new resets
its spend counter so its budget counts from creation. The General settings editor
keeps a new mapping unsaved until every required field is filled in.
# Conflicts:
#	litellm/proxy/litellm_pre_call_utils.py
… tag lookup errors, map custom pass-through routes, check the key before the WebSocket 403
…olicy and guardrail matching, honor allow_requests_on_db_unavailable, reject control characters in baggage values
Adds integration cells for request_tag_mappings across chat, messages,
responses, A2A and custom pass-through spend, required and budgeted
rules, the WebSocket refusal, unbilled routes, reject_clientside_metadata_tags,
tag routing and policy isolation, a dropped tag read with and without
allow_requests_on_db_unavailable, and the /tag/new spend counter reset
…t JSON-string metadata tags, count litellm_metadata caller tags

Requests with no mapped baggage now reuse the cached body exactly as before, so header and key tag merges still normalize metadata for routing. The client body copy is made only when a tag maps, and the base merges are mirrored onto it. A request that maps nothing no longer gets a 400 for non-object metadata. caller_tags now counts tags sent in both metadata and litellm_metadata. Optional mappings no longer reject JSON-string metadata tags under reject_clientside_metadata_tags.
# Conflicts:
#	litellm/constants.py
…outing strategies

Auto, complexity, adaptive and quality router selection, the consumed-tags stamp and compression policy lookup now read request tags without baggage-mapped tags, unless the caller sent the tag or the key, team or project carries it, matching deployment tag filtering.
…appings_mat1059

# Conflicts:
#	litellm/proxy/proxy_server.py
#	tests/unit/proxy/pass_through_endpoints/test_llm_passthrough_endpoints.py
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litellm-stampbot

@kerry-berri

kerry-berri commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

litellm-stampbot: risk low

Approved at 96b971b.

Rules (stampbot/risk_rules.yml):

  • low: no rule flagged it

Cursor Bugbot: Low Risk at 96b971b. Standalone parser and types with no request-path integration yet; behavior change only arrives when wiring lands. Bugbot run requested, finished in 8 min.
Bugbot Low is low, Medium and High are high. The judge model was not called.

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

@kerry-berri

Copy link
Copy Markdown
Contributor

bugbot run

@codspeed

codspeed Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 32 untouched benchmarks


Comparing litellm_baggage_request_tag_mappings (b13e844) with main (270d108)

Open in CodSpeed

@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.

@kerry-berri kerry-berri added the risk:low Small, isolated, low-risk change label Oct 19, 2026

@kerry-berri kerry-berri 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.

Low risk by rule and by judgement at 96b971b

@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.89157% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/proxy/litellm_pre_call_utils.py 97.41% 3 Missing ⚠️
litellm/router_strategy/tag_based_routing.py 93.87% 3 Missing ⚠️
litellm/proxy/auth/auth_checks.py 96.42% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@mateo-berri mateo-berri changed the title feat(proxy): parse baggage headers into request tag mappings feat(proxy): map baggage values to budget tags Oct 19, 2026
@veria-ai

veria-ai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 4 · PR risk: 0/10

@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.

…client tags as sent under mapped baggage

Merge serving deployment tags into the request tags in one pass, so a large client tag list no longer blocks the event loop. Leave a non-list metadata.tags untouched when baggage maps a tag, so the request gets the same answer as without baggage. Add the C17 integration cell for the team tag's guardrail mode under a mapped deployment tag.
@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@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.

Comment thread litellm/proxy/litellm_pre_call_utils.py Resolved
… or holds non-strings

Mapped baggage tags are applied again after the header and key tag merges, so
a header or key tag that replaces a string metadata.tags no longer hides the
mapped tag from the tag budget check. An empty or false metadata.tags is read
like a missing one, and a tags list with non-string items is kept as sent with
the mapped tags added after it, instead of failing auth with a 401
# Conflicts:
#	litellm/proxy/litellm_pre_call_utils.py
@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.

if _has_required_baggage_tag_mapping():
raise HTTPException(
403, "Required baggage tag mappings need HTTP inference, WebSocket inference is disabled"
)

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.

WebSocket refusal leaks auth reservations

Medium Severity

The required-mapping WebSocket denial runs only after user_api_key_auth finishes, so budget reservations and admission counters minted for that handshake are never released by a later spend callback. Valid-key realtime, Responses, and Live upgrades then leave those holds in place until TTL expiry.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7907353. Configure here.

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.

Not a leak. Auth stamps the reservation on the shared socket state, and BudgetReservationReleaseMiddleware releases it when the denied socket closes

@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 guide

@litereview

litereview Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

⚠️ guide

Open preview

Scope: full · Full PR review.

Review incomplete.

The review could not complete.

Couldn’t complete

  • Codex exited without submitting a review (exit 0).
  • Review harness exit code: 0.

View review · Reviewed b13e844b8981

# Conflicts:
#	tests/unit/router_strategy/test_router_tag_routing.py
@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!

1 issue from previous review remains unresolved.

Fix All in Cursor

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit b13e844. Configure here.

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview guide

@mateo-berri
mateo-berri merged commit dfac770 into main Oct 20, 2026
115 checks passed
@mateo-berri
mateo-berri deleted the litellm_baggage_request_tag_mappings branch October 20, 2026 09:09
@norkelbyte norkelbyte mentioned this pull request Oct 28, 2026
4 of 6 tasks
@mateo-berri

Copy link
Copy Markdown
Contributor Author

The post-merge audit of this change is in #48784. Every behavior it checked holds at the merge commit, and it adds two integration tests

mateo-berri added a commit that referenced this pull request Oct 28, 2026
* test(proxy): audit #47358

Add integration cells for pass-through bodies and settings-endpoint mappings across workers

* test(proxy): wait for every worker to hold the saved mapping before probing

* test(proxy): compare passthrough bodies to the client body and probe each worker on its own connection

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:low Small, isolated, low-risk change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants