Metadata
Add custom context to your AI requests for better observability and analytics
This feature is available on all Portkey plans.
What is Metadata?
Metadata in Portkey allows you to attach custom contextual information to your AI requests. Think of it as tagging your requests with important business context that helps you:
- Track usage across different users, environments, or features
- Filter logs to isolate specific request types
- Analyze patterns in how your AI is being used
- Audit activities for compliance and security
Quick Implementation
Common Use Cases
User Analytics
Track which users are using AI features by adding the _user
identifier in metadata
Cost Attribution
Attribute AI costs to teams, features or products by adding identifiers in metadata
Environment Tracking
Differentiate between dev/staging/prod usage with the environment
metadata key
Feature Usage
See which product features are using AI most heavily with feature identifiers
Metadata Keys and Values
- You can send any number of metadata keys with each request
- All values must be strings with a maximum length of 128 characters
- Keys can be any string, but some have special meaning (like
_user
)
Special Metadata Keys
Key | Purpose | Notes |
---|---|---|
_user | User tracking | Powers user-level analytics in the Portkey dashboard |
About the _user
key: If you pass a user
field in your OpenAI request body, we’ll automatically copy it to the _user
metadata key. If both exist, the explicit _user
metadata value takes precedence.
Where to See Your Metadata
Analytics Dashboard
Analytics dashboard has a dedicated Tab to view aggregate stats on all your metadat keys:
Request Logs
You can also apply any metadata filters to the logs or analytics and filter data by any metadata key you’ve used:
Enterprise Features
For enterprise users, Portkey offers advanced metadata governance and lets you define metadata at multiple levels:
- Request level - Applied to a single request
- API key level - Applied to all requests using that key
- Workspace level - Applied to all requests in a workspace
Enforcing Required Metadata
Define mandatory metadata fields that must be included with all requests
When the same key appears at multiple levels, the precedence order is:
- Request metadata (highest priority)
- API key metadata
- Workspace metadata (lowest priority)
Best Practices
-
Use consistent keys across your organization
-
Create naming conventions for metadata keys
-
Consider adding these common fields:
_user
: Who initiated this requestenvironment
: Which environment (dev/staging/prod)feature
orcomponent
: Which part of your productversion
: API or app versionsession_id
: To group related requestsrequest_id
: Your internal tracking ID
-
For proper tracking, always include the
_user
field when the request is on behalf of an end-user
Was this page helpful?