Skip to main content

A2A Agent Cost Tracking

LiteLLM supports adding custom cost tracking for A2A agents. You can configure:

  • Flat cost per query - A fixed cost charged for each agent request
  • Cost by input/output tokens - Variable cost based on token usage

This allows you to track and attribute costs for agent usage across your organization, making it easy to see how much each team or project is spending on agent calls.

Quick Start​

1. Navigate to Agents​

From the sidebar, click on "Agents" to open the agent management page.

Navigate to Agents

2. Create a New Agent​

Click "+ Add New Agent" to open the creation form. You'll need to provide a few basic details:

  • Agent Name - A unique identifier for your agent (used in API calls)
  • Display Name - A human-readable name shown in the UI

Enter Agent Name

Enter Display Name

3. Configure Cost Settings​

Scroll down and click on "Cost Configuration" to expand the cost settings panel. This is where you define how much to charge for agent usage.

Click Cost Configuration

4. Set Cost Per Query​

Enter the cost per query amount (in dollars). For example, entering 0.05 means each request to this agent will be charged $0.05.

Set Cost Per Query

Enter Cost Amount

5. Create the Agent​

Once you've configured everything, click "Create Agent" to save. Your agent is now ready to use with cost tracking enabled.

Create Agent

Testing Cost Tracking​

Let's verify that cost tracking is working by sending a test request through the Playground.

1. Go to Playground​

Click "Playground" in the sidebar to open the interactive testing interface.

Go to Playground

2. Select A2A Endpoint​

By default, the Playground uses the chat completions endpoint. To test your agent, click "Endpoint Type" and select /v1/a2a/message/send from the dropdown.

Select Endpoint Type

Select A2A Endpoint

3. Select Your Agent​

Now pick the agent you just created from the agent dropdown. You should see it listed by its display name.

Select Agent

4. Send a Test Message​

Type a message and hit send. You can use the suggested prompts or write your own.

Send Message

Once the agent responds, the request is logged with the cost you configured.

Agent Response

Viewing Cost in Logs​

Now let's confirm the cost was actually tracked.

1. Navigate to Logs​

Click "Logs" in the sidebar to see all recent requests.

Go to Logs

2. View Cost Attribution​

Find your agent request in the list. You'll see the cost column showing the amount you configured. This cost is now attributed to the API key that made the request, so you can track spend per team or project.

View Cost in Logs

View Spend in Usage Page​

Navigate to the Agent Usage tab in the Admin UI to view agent-level spend analytics:

1. Access Agent Usage​

Go to the Usage page in the Admin UI (PROXY_BASE_URL/ui/?login=success&page=new_usage) and click on the Agent Usage tab.

2. View Agent Analytics​

The Agent Usage dashboard provides:

  • Total spend per agent: View aggregated spend across all agents
  • Daily spend trends: See how agent spend changes over time
  • Model usage breakdown: Understand which models each agent uses
  • Activity metrics: Track requests, tokens, and success rates per agent

3. Filter by Agent​

Use the agent filter dropdown to view spend for specific agents:

  • Select one or more agent IDs from the dropdown
  • View filtered analytics, spend logs, and activity metrics
  • Compare spend across different agents

Cost Configuration Options​

You can mix and match these options depending on your pricing model:

FieldDescription
Cost Per Query ($)Fixed cost charged for each agent request
Input Cost Per Token ($)Cost per input token processed
Output Cost Per Token ($)Cost per output token generated

For most use cases, a flat cost per query is simplest. Use token-based pricing if your agent costs vary significantly based on input/output length.