September 2026 release is live Read More

Agent Cost & UsageConnect LiteLLM

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:

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.

Bash
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:

JSON
{
  "metadata": {
    "agent_id": "support-agent"
  }
}

Mavvrik resolves the agent ID from these supported paths, in order:

  1. metadata.requester_metadata.agent_id

  2. metadata.spend_logs_metadata.agent_id

  3. metadata.requester_metadata.spend_logs_metadata.agent_id

  4. x-litellm-agent-id request 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

JSON
{
  "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

x-litellm-session-id

Groups related calls into the same session

x-litellm-trace-id

Correlates calls belonging to one execution/run

x-litellm-tags

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

  1. Send a model request through LiteLLM.

  2. Open Home → Agentic → Cost.

  3. Confirm the LiteLLM connection shows recent activity.

  4. Verify the model and usage fields.

  5. If agent attribution is configured, confirm the request appears under the expected agent.

  6. 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 callbacks: ["otel"] and restart the proxy

Spans are created but not exported

Confirm OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf

Connection attribution is missing or incorrect

Confirm OTEL_RESOURCE_ATTRIBUTES=mvk.connection_id=...

All traffic is Unattributed

Add agent_id through a supported metadata path or x-litellm-agent-id

Sessions do not group

Supply x-litellm-session-id consistently

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_id resource 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.