Connect LiteLLM
Use this integration when applications route model calls through a LiteLLM proxy and Mavvrik should report gateway-level and per-agent model cost.
LiteLLM uses its built-in telemetry callback to send model telemetry to Mavvrik. The calling application does not require the Mavvrik SDK for this integration.
The connection ID identifies the LiteLLM gateway. The agent ID identifies the agent that made an individual request through that gateway.
1. Register the LiteLLM connection
In Mavvrik, go to Admin → Accounts → Agents, click + Agent, and select LiteLLM.
Configure:
-
Connection ID — accept the generated value or use a stable identifier;
-
Connection Name — identify the proxy deployment, for example
litellm-prod-gateway; -
Description — optional.
Continue to the Connect step and copy the endpoint, headers, tenant, API key, and connection values shown there.
2. Enable LiteLLM telemetry export
In the LiteLLM proxy config.yaml:
litellm_settings:
callbacks: ["otel"]
3. Configure the exporter
Set the values from the Mavvrik Connect step in the environment where the LiteLLM proxy runs.
OTEL_EXPORTER_OTLP_ENDPOINT=<from Mavvrik Connect>
OTEL_EXPORTER_OTLP_HEADERS=x-tenant-id=<tenant>,Authorization=Bearer <api-key>,x-mvk-connection-id=<connection-id>
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_RESOURCE_ATTRIBUTES=mvk.connection_id=<connection-id>
Required settings:
-
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf -
OTEL_RESOURCE_ATTRIBUTES=mvk.connection_id=<connection-id>
The headers authenticate and route telemetry. The resource attribute identifies the LiteLLM connection on the exported spans.
4. Restart LiteLLM
Restart the proxy after changing the callback or environment variables.
Send one known model request through the gateway after restart.
What Mavvrik captures from LiteLLM
|
Captured field |
Use |
|---|---|
|
Model and provider/backend |
Identifies the upstream model used by the proxy |
|
Input/output tokens |
Used for model cost calculation |
|
Cached/reasoning tokens |
Recorded when LiteLLM/provider telemetry includes them |
|
Latency |
Duration per model call |
|
Status/errors |
Success and error information |
|
User/session correlators |
Recorded when supplied by the request |
|
Agent ID |
Read from supported request metadata/header paths |
Mavvrik applies pricing to normalized model and usage data. The source does not need to provide the final dollar cost for supported model usage.
Attribute gateway usage to an agent
Include an agent ID on each LiteLLM request when gateway spend must be split by agent.
Example metadata:
{
"metadata": {
"agent_id": "support-agent"
}
}
Mavvrik resolves the agent ID from these supported paths, in order:
-
metadata.requester_metadata.agent_id -
metadata.spend_logs_metadata.agent_id -
metadata.requester_metadata.spend_logs_metadata.agent_id -
x-litellm-agent-idrequest header
Keep the same logical agent ID stable across requests. Use separate tags or dimensions for environment rather than changing the agent ID between staging and production.
Example request
{
"model": "gpt-4o-mini",
"messages": [
{"role": "user", "content": "Summarize this support case."}
],
"metadata": {
"agent_id": "support-agent"
}
}
If the LiteLLM deployment uses requester_metadata or spend_logs_metadata, place agent_id in one of the supported paths above.
Configure session and trace correlation
When these LiteLLM headers are supplied, Mavvrik uses them as correlators:
|
Header |
Use |
|---|---|
|
|
Groups related calls into the same session |
|
|
Correlates calls belonging to one execution/run |
|
|
Adds filtering labels |
Support-session example
x-litellm-agent-id: support-agent
x-litellm-session-id: session-456
Use the same session ID for all model calls that belong to the same conversation or workflow.
Usage without agent metadata
The LiteLLM connection can still report gateway activity when requests do not contain an agent ID. Those requests appear as Unattributed under the connection instead of being assigned to a named agent.
Verify the integration
-
Send a model request through LiteLLM.
-
Open Home → Agentic → Cost.
-
Confirm the LiteLLM connection shows recent activity.
-
Verify the model and usage fields.
-
If agent attribution is configured, confirm the request appears under the expected agent.
-
If a session ID is configured, confirm related calls appear together in Home → Agentic → Sessions.
Allow up to 10 minutes for the first processed activity to appear.
Troubleshoot LiteLLM data
|
Symptom |
Check |
|---|---|
|
Nothing appears |
Confirm |
|
Spans are created but not exported |
Confirm |
|
Connection attribution is missing or incorrect |
Confirm |
|
All traffic is Unattributed |
Add |
|
Sessions do not group |
Supply |
|
Cost is missing |
Confirm model identity and token/usage fields are present |
Verify the complete setup
- LiteLLM connection registered in Mavvrik.
callbacks: ["otel"]enabled.- Exporter variables copied from the Connect step.
- Protocol is
http/protobuf. mvk.connection_idresource attribute is present.- Proxy restarted after configuration changes.
- A known model request appears in Home → Agentic → Cost.
- Agent ID is supplied when per-agent allocation is required.
- Session ID is supplied when related calls should be grouped.