For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
DiscordPlatform
DocumentationIntegrationsAPI referenceSDKsChangelog
DocumentationIntegrationsAPI referenceSDKsChangelog
  • Get started
    • Overview
    • Trace your first call
    • Run your first eval
    • Use gateway & prompts
    • Live demo
  • Features
    • Users
  • Admin
    • API keys
    • Provider keys
    • Workspaces & projects
    • Collaborate
  • Resources
      • End-to-end: from first API call to production monitoring
      • Trace a RAG pipeline
      • Monitor an AI agent in production
      • Build an eval pipeline from production logs
      • A/B test prompts in production
      • Migrate from OpenAI to multi-model
      • Track cost per feature
      • GEPA: self-improving prompt optimization
      • How to structure LLM output with Anthropic models
      • Filters in Jinja templates
      • Trace CLI coding agents
      • Use Respan AI gateway as a proxy for coding agents
  • Security & Support
    • Support
    • Status
LogoLogo
DiscordPlatform
On this page
  • Overview
  • Tag requests with metadata
  • Recommended metadata schema
  • Create a helper function
  • Analyze costs on the dashboard
  • Set user budgets
  • Next steps
ResourcesCookbooks

Track cost per feature

Use metadata and customer identifiers to build per-feature and per-user cost breakdowns.

Was this page helpful?
Previous

GEPA: self-improving prompt optimization

A Generate-Evaluate-Promote-Analyze loop for systematically improving prompts with data.

Next
Built with
Set up Respan
  1. Sign up — Create an account at platform.respan.ai
  2. Create an API key — Generate one on the API keys page
  3. Add credits or a provider key — Add credits on the Credits page or connect your own provider key on the Integrations page

Overview

“How much does our summarization feature cost?” “Which users are the most expensive?” These questions are hard to answer when all your LLM calls look the same in billing.

This cookbook shows how to tag requests with metadata so you can break down costs by feature, user, team, or any dimension you care about.

Tag requests with metadata

Add metadata and customer_identifier to every LLM call:

1from openai import OpenAI
2
3client = OpenAI(
4 base_url="https://api.respan.ai/api/",
5 api_key="YOUR_RESPAN_API_KEY",
6)
7
8response = client.chat.completions.create(
9 model="gpt-4o-mini",
10 messages=[{"role": "user", "content": "Summarize this document..."}],
11 extra_body={
12 "customer_identifier": "user_456",
13 "metadata": {
14 "feature": "summarization",
15 "team": "content",
16 "environment": "production",
17 },
18 },
19)

Recommended metadata schema

Be consistent across your codebase. Here’s a practical schema:

KeyPurposeExamples
featureWhich product feature made the call"summarization", "chat", "search"
teamWhich team owns this feature"content", "support", "product"
environmentDeployment environment"production", "staging"
versionFeature or prompt version"v2", "2024-01"

Create a helper function

Centralize your metadata tagging so it’s consistent:

1from openai import OpenAI
2
3client = OpenAI(
4 base_url="https://api.respan.ai/api/",
5 api_key="YOUR_RESPAN_API_KEY",
6)
7
8def llm_call(messages, model="gpt-4o-mini", feature="unknown", customer_id=None, **kwargs):
9 """Wrapper that ensures every call is tagged."""
10 extra_body = {
11 "metadata": {
12 "feature": feature,
13 "environment": "production",
14 },
15 }
16 if customer_id:
17 extra_body["customer_identifier"] = customer_id
18
19 return client.chat.completions.create(
20 model=model,
21 messages=messages,
22 extra_body=extra_body,
23 **kwargs,
24 )
25
26# Usage
27response = llm_call(
28 messages=[{"role": "user", "content": "Summarize..."}],
29 feature="summarization",
30 customer_id="user_456",
31)

Analyze costs on the dashboard

Once your requests are tagged, go to the Dashboard:

  1. Cost by feature: Filter by metadata.feature to see cost per feature over time
  2. Cost by user: Go to Users to see total cost per customer
  3. Cost by model: Use model breakdown to see which models drive the most spend
  4. Custom views: Create saved views with preset filters for recurring cost analysis

Set user budgets

For per-user cost control, set budgets on individual customers:

1import requests
2
3requests.post(
4 "https://api.respan.ai/api/users/create/",
5 headers={"Authorization": "Bearer YOUR_RESPAN_API_KEY"},
6 json={
7 "customer_identifier": "user_456",
8 "period_budget": 10.00, # $10 per period
9 "budget_duration": "monthly", # Reset monthly
10 },
11)

When a user exceeds their budget, Respan blocks further requests and returns a 429 status. See User budgets for details.

Next steps

Customer identifier

Track users, set budgets and rate limits

Dashboard

Monitor metrics and trends