From ef8699a47c724eef4eb361560186354aa56124d1 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 2 Feb 2026 18:23:02 +0000 Subject: [PATCH] Simplify request tags doc for AI Gateway usage - Focus on config.yaml setup with default_key_generate_params - Show both request body and header methods for sending tags - Remove SDK examples, keep concise cURL examples - Streamline for quick reference Co-authored-by: ishaan --- docs/my-website/docs/proxy/request_tags.md | 83 ++++++++-------------- 1 file changed, 31 insertions(+), 52 deletions(-) diff --git a/docs/my-website/docs/proxy/request_tags.md b/docs/my-website/docs/proxy/request_tags.md index 6b75a03b44e..e54b2c5fa49 100644 --- a/docs/my-website/docs/proxy/request_tags.md +++ b/docs/my-website/docs/proxy/request_tags.md @@ -5,35 +5,26 @@ import TabItem from '@theme/TabItem'; Add tags to your LLM requests to track spend by environment, AWS account, team, or any custom label. -Tags appear in the `request_tags` field of LiteLLM spend logs, making it easy to filter and analyze costs. +Tags appear in the `request_tags` field of LiteLLM spend logs. -## Quick Start +## Set Default Tags in Config -Add tags via the `metadata.tags` field in your request: +Set default tags for all API keys generated through the proxy: - - - -```python -from openai import OpenAI - -client = OpenAI( - api_key="sk-1234", - base_url="http://0.0.0.0:4000" -) - -response = client.chat.completions.create( - model="gpt-4", - messages=[{"role": "user", "content": "Hello"}], - extra_body={ - "metadata": { - "tags": ["AWS_IAM_PROD", "us-east-1"] - } - } -) +```yaml title="config.yaml" +litellm_settings: + default_key_generate_params: + metadata: + tags: ["AWS_IAM_PROD", "us-east-1"] ``` - +All keys created via `/key/generate` will automatically include these tags. + +## Send Tags in Request + +Pass tags in the request body: + + ```bash @@ -49,49 +40,37 @@ curl -X POST 'http://0.0.0.0:4000/chat/completions' \ }' ``` + + + +```bash +curl -X POST 'http://0.0.0.0:4000/chat/completions' \ + -H 'Authorization: Bearer sk-1234' \ + -H 'Content-Type: application/json' \ + -H 'x-litellm-tags: AWS_IAM_PROD,us-east-1' \ + -d '{ + "model": "gpt-4", + "messages": [{"role": "user", "content": "Hello"}] + }' +``` + ## Where Tags Appear -Tags are stored in the `LiteLLM_SpendLogs` table under `request_tags`: +Tags are stored in `LiteLLM_SpendLogs` under `request_tags`: ```json { "request_id": "chatcmpl-abc123", "request_tags": ["AWS_IAM_PROD", "us-east-1"], "spend": 0.002, - "model": "gpt-4", - ... + "model": "gpt-4" } ``` -## Common Use Cases - -| Tag Example | Purpose | -|-------------|---------| -| `AWS_IAM_PROD` | Track requests from production AWS account | -| `AWS_IAM_DEV` | Track requests from development AWS account | -| `team-backend` | Attribute costs to backend team | -| `project-chatbot` | Track spend for a specific project | - -## Set Default Tags on API Keys - -Set tags at the API key level so all requests automatically inherit them: - -```bash -curl -X POST 'http://0.0.0.0:4000/key/generate' \ - -H 'Authorization: Bearer sk-1234' \ - -H 'Content-Type: application/json' \ - -d '{ - "metadata": { - "tags": ["AWS_IAM_PROD", "team-backend"] - } - }' -``` - ## Related - [Spend Tracking Overview](cost_tracking.md) - [Tag Budgets](tag_budgets.md) - Set budget limits per tag -- [Tag Routing](tag_routing.md) - Route requests based on tags