The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
docs: add JWT-to-Virtual-Key mapping documentation
Harshit28j63459d677724
diff --git a/docs/my-website/docs/proxy/token_auth.md b/docs/my-website/docs/proxy/token_auth.mdindex e8634f0faf5..7364ae0fb56 100644--- a/docs/my-website/docs/proxy/token_auth.md+++ b/docs/my-website/docs/proxy/token_auth.md@@ -1054,6 +1054,95 @@ curl -X GET 'http://0.0.0.0:4000/user/info?user_id=user-123' \-H 'Authorization: Bearer <PROXY_MASTER_KEY>'```+## [BETA] JWT-to-Virtual-Key Mapping++Map JWT identities to LiteLLM virtual keys so that JWT-authenticated users get per-user budgets, rate limits, model access controls, and spend tracking.++When a JWT comes in, LiteLLM looks up a configured claim (e.g. `email`, `sub`) in a mapping table. If a mapping exists, the request is treated as if it arrived with the corresponding virtual key — all virtual key features apply.++### Setup++Add `virtual_key_claim_field` to your JWT auth config:++```yaml+general_settings:+ enable_jwt_auth: True+ litellm_jwtauth:+ virtual_key_claim_field: "email" # JWT claim to look up (supports dot notation)+ virtual_key_mapping_cache_ttl: 300 # Cache TTL in seconds (default: 300)+```++### Managing Mappings++All endpoints require admin auth (`Authorization: Bearer <master_key>`).++**Create a mapping** — link a JWT claim value to an existing virtual key:++```bash+curl -X POST http://localhost:4000/jwt/key/mapping/new \+ -H "Authorization: Bearer sk-1234" \+ -H "Content-Type: application/json" \+ -d '{+ "jwt_claim_name": "email",+ "jwt_claim_value": "[email protected]",+ "key": "sk-virtual-key-from-key-generate"+ }'+```++**List mappings** (paginated):++```bash+curl http://localhost:4000/jwt/key/mapping/list?page=1&size=50 \+ -H "Authorization: Bearer sk-1234"+```++**Get a specific mapping:**++```bash+curl "http://localhost:4000/jwt/key/mapping/info?id=<mapping-id>" \+ -H "Authorization: Bearer sk-1234"+```++**Update a mapping:**++```bash+curl -X POST http://localhost:4000/jwt/key/mapping/update \+ -H "Authorization: Bearer sk-1234" \+ -H "Content-Type: application/json" \+ -d '{+ "id": "<mapping-id>",+ "description": "Updated description",+ "is_active": true+ }'+```++**Delete a mapping:**++```bash+curl -X POST http://localhost:4000/jwt/key/mapping/delete \+ -H "Authorization: Bearer sk-1234" \+ -H "Content-Type: application/json" \+ -d '{"id": "<mapping-id>"}'+```++### How It Works++1. A request arrives with a JWT bearer token+2. LiteLLM validates the JWT signature+3. Extracts the configured claim (e.g. `email` → `[email protected]`)+4. Looks up the claim value in the `LiteLLM_JWTKeyMapping` table+5. If a mapping exists, the request proceeds as if the mapped virtual key was used — budgets, rate limits, model access, and spend tracking all apply+6. If no mapping exists, falls back to standard JWT auth (team-level controls)++### Error Codes++| Code | Meaning |+|------|---------|+| 409 | Duplicate mapping — a mapping for that claim name + value already exists |+| 400 | The provided key does not match an existing virtual key |+| 404 | Mapping not found (for update/delete/info) |+| 403 | Non-admin user attempted a mapping operation |+## All JWT Params[**See Code**](https://github.com/BerriAI/litellm/blob/b204f0c01c703317d812a1553363ab0cb989d5b6/litellm/proxy/_types.py#L95)