Skip to main content
Track, measure, and allocate your API usage across apps, projects, and customers. App Attribution lets you tag every API call with metadata so you can see exactly where your budget is going.

What’s in It for You

  • Clear usage insights — See how each app, project, or customer uses your API
  • Cost allocation — No more guesswork when dividing bills
  • Budget controls — Set spending limits per tag and get alerts
  • Data-driven decisions — Spot trends and optimize your spend

How It Works

AnyAPI uses tags and metadata to attribute API requests. Pass them in the metadata field of your request body, and every request gets tracked and grouped accordingly.

Tagging Your Requests

Using Tags

Tags are labels you attach to requests to track spending by category. Pass them as an array in the metadata field:
curl -X POST "https://api.anyapi.ai/v1/chat/completions" \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-5",
    "messages": [
      {"role": "user", "content": "Hello, how can you help me?"}
    ],
    "metadata": {
      "tags": ["app:customer-support-bot", "env:production", "team:support"]
    }
  }'

Using Custom Metadata

For richer tracking, pass spend_logs_metadata with custom key-value pairs that get logged to spend records:
Python
response = requests.post(
    "https://api.anyapi.ai/v1/chat/completions",
    headers={
        "Authorization": "Bearer your_api_key",
        "Content-Type": "application/json"
    },
    json={
        "model": "anthropic/claude-sonnet-4",
        "messages": [
            {"role": "user", "content": "Analyze this quarterly data..."}
        ],
        "metadata": {
            "tags": ["app:bi-tool", "env:production"],
            "spend_logs_metadata": {
                "project": "q4-sales-analysis",
                "department": "marketing",
                "version": "1.5.2"
            }
        }
    }
)

Tracking End Users

Use the user parameter to track spend per end user:
Python
response = requests.post(
    "https://api.anyapi.ai/v1/chat/completions",
    headers={
        "Authorization": "Bearer your_api_key",
        "Content-Type": "application/json"
    },
    json={
        "model": "openai/gpt-5",
        "messages": [
            {"role": "user", "content": "How do I reset my password?"}
        ],
        "user": "customer_54321",
        "metadata": {
            "tags": ["app:support-bot"]
        }
    }
)

Using Headers

You can also pass tags and metadata via HTTP headers:
Python
headers = {
    "Authorization": "Bearer your_api_key",
    "Content-Type": "application/json",
    "x-litellm-tags": "app:my-chatbot,env:production",
    "x-litellm-spend-logs-metadata": '{"project": "q4-analysis", "version": "2.0"}'
}

Tag Budgets

Set spending limits per tag to control costs. When a tag exceeds its budget, requests with that tag are blocked.

Create a Tag Budget

curl -X POST "https://api.anyapi.ai/tag/new" \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "app:customer-support-bot",
    "max_budget": 100.0,
    "budget_duration": "30d"
  }'
ParameterTypeDescription
namestringUnique tag identifier
max_budgetnumberSpending limit in USD
budget_durationstringReset frequency: "1d", "7d", "30d", etc.

Check Tag Info

curl -X GET "https://api.anyapi.ai/tag/info?names=app:customer-support-bot" \
  -H "Authorization: Bearer your_api_key"

Update a Tag Budget

curl -X POST "https://api.anyapi.ai/tag/update" \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "app:customer-support-bot",
    "max_budget": 200.0
  }'

Delete a Tag

curl -X POST "https://api.anyapi.ai/tag/delete" \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "app:customer-support-bot"
  }'

Tagging Strategies

By Application

Python
metadata = {
    "tags": ["app:customer-support-bot"]
}

By Environment

Python
metadata = {
    "tags": ["app:my-chatbot", "env:production"]
}

Multi-Tenant SaaS

Python
metadata = {
    "tags": ["app:saas-platform", "tenant:company-abc"],
    "spend_logs_metadata": {
        "tier": "enterprise"
    }
}

By Team and Project

Python
metadata = {
    "tags": ["team:marketing", "project:q4-campaign"]
}

Best Practices

Smart Tag Names

  • Be descriptive: Use app:customer-chat-prod not app1
  • Stay consistent: Pick a naming convention and stick to it (e.g., key:value format)
  • Include environment: Separate env:prod, env:staging, env:dev

Cost Management

  • Set tag budgets: Start conservative, adjust as needed
  • Use budget durations: Monthly (30d) resets for predictable billing
  • Tag everything: Untagged requests are harder to attribute later

Security

  • Hash user IDs: Protect customer privacy when using the user parameter
  • No secrets in metadata: Attribution data is logged in spend records

Start with a simple tag on your next request, then gradually add more as your needs grow. Your future self (and your finance team) will thank you.