Monitor and analyze user-level LLM costs across 1600+ models using Portkey’s metadata and analytics API.
LLM runs are expensive. As your application scales, tracking costs per user, team, or workflow becomes essential to maintaining efficiency and budgeting effectively.
Traditional solutions only provide API key-level tracking, requiring complex custom systems for detailed analysis. Portkey solves this with metadata-based tracking, allowing you to monitor and allocate costs seamlessly.
Consider these scenarios:
With Portkey, you can track costs per user using two methods:
This guide walks you through both approaches.
Portkey allows you to attach metadata (key-value pairs) to each request, enabling cost breakdowns per user.
Portkey’s metadata accepts a JSON object of key:value
pair. Each metadata value should be a string (max length: 128 characters). Here’s how to implement it:
Each metadata field in your request helps categorize and track costs. You can inject these values dynamically from your application context.
Portkey’s dashboard provides a live view of costs broken down by metadata filters.
>Meta
_user = customer_12345
You can also combine filters (e.g., _user
+ env
) and adjust the time range for historical cost tracking.
This gives you an instant breakdown of LLM expenses per user or team.
For deeper integrations, the Analytics API enables real-time cost tracking inside your own application. This is useful for:
Understanding the Analytics API
The API provides comprehensive cost analytics data across any metadata dimension you’ve configured. You can query historical data, aggregate costs across different timeframes, and access detailed metrics for each metadata value. Here’s what you can access through the API:
These metrics provide insights into costs, usage patterns, and efficiency. The response includes:
Before making your first API call, you’ll need to obtain an API key from the Portkey Dashboard. This key requires analytics scope access, which you can configure in your API key settings.
Review the complete Analytics API documentation for additional endpoints and features.
The API follows RESTful principles and accepts standard HTTP requests. Here’s how to get started:
x-portkey-api-key
header.{metadataKey}
with the metadata key you want to track costs for.page_size
parameter to control the number of results per responsemetadata
fieldThat’s all you need to do the get the resonse data with the cost metric for the metadata key you are tracking.
How Developers & Teams Use This API
Once you’ve integrated metadata tagging and the Analytics API, you can:
Need enterprise-grade cost tracking? Contact Sales for custom analytics solutions.