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 <ishaan@berri.ai>
This commit is contained in:
Cursor Agent 2026-02-02 18:23:02 +00:00
parent f9bec4b230
commit ef8699a47c

View file

@ -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:
<Tabs>
<TabItem value="python" label="Python SDK">
```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"]
```
</TabItem>
All keys created via `/key/generate` will automatically include these tags.
## Send Tags in Request
Pass tags in the request body:
<Tabs>
<TabItem value="curl" label="cURL">
```bash
@ -49,49 +40,37 @@ curl -X POST 'http://0.0.0.0:4000/chat/completions' \
}'
```
</TabItem>
<TabItem value="header" label="Header">
```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"}]
}'
```
</TabItem>
</Tabs>
## 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