September 2026 release is live Read More

Agent Cost & UsageConnect Langfuse

Connect Langfuse

Use this integration when agent telemetry is already collected in Langfuse and Mavvrik should calculate agent cost from that existing data.

No Mavvrik SDK is required in the application. Mavvrik connects to the Langfuse project, discovers agent identities from configured metadata, polls supported observations, and uses model and usage data for cost reporting.

Requirements

Item

Source

Langfuse public key (pk-lf-...)

Langfuse → Settings → API Keys

Langfuse secret key (sk-lf-...)

Langfuse → Settings → API Keys

Langfuse base URL

Langfuse Cloud region URL or self-hosted HTTPS URL

Metadata field containing the agent ID

Langfuse trace/observation metadata; commonly agent_id

1. Create the Langfuse connection

In Mavvrik, go to Admin → Accounts → Agents, click + Agent, and select Langfuse.

Configure:

  • Connection ID — accept the generated value or use a stable identifier;

  • Connection Name — identify the Langfuse project;

  • Public Key;

  • Secret Key;

  • Base URL.

Mavvrik validates the credentials when the connection is saved.

If validation fails, confirm the public/secret key pair and verify that the base URL matches the Langfuse project region or self-hosted instance.

2. Configure agent identity

Add at least one Agent metadata key.

A common configuration is:

agent_id

Mavvrik checks the configured keys in order and uses the first matching value on the Langfuse trace or observation.

Matching rules:

  • the configured field name must match the metadata field exposed by Langfuse;

  • the agent value must be a string;

  • matching is exact, including case and whitespace;

  • flattened nested values must use the exact dotted key exposed by Langfuse.

Example

Python
langfuse.trace(
    name="flight-booking",
    user_id="user-123",
    session_id="session-abc",
    metadata={
        "agent_id": "booking-agent",
        "agent_name": "Flight Booking Agent",
    },
)

Configure agent_id as the Agent metadata key in Mavvrik for this example.

3. Connect discovered agents

After Mavvrik finds distinct agent IDs in Langfuse, they appear as discovered agents under the connection.

Discovery does not start data collection by itself. Connect each discovered agent that Mavvrik should collect.

4. Generate fresh activity

Mavvrik polls Langfuse every 10 minutes.

The first collection looks back 24 hours. Older history is not automatically backfilled by this integration.

Generate at least one fresh trace after the connection and agent metadata are configured.

What Mavvrik captures from Langfuse

Langfuse field

Mavvrik use

Observation model

Model identity used for normalization and pricing

Observation token usage

Input/output and other usage fields used for cost

Observation name

Step name

Observation type

Step classification where mapped

Observation latency

Duration, converted to milliseconds

Observation level

Healthy, warning, or error status

Trace userId

User attribution

Trace sessionId

Session grouping

Trace/observation metadata

Agent identity and supported metadata conventions

Mavvrik calculates cost from normalized model and usage data. The price configured inside Langfuse is not required for standard Mavvrik cost calculation.

Agent identity

JSON
{
  "agent_id": "booking-agent"
}

Optional metadata

JSON
{
  "agent_id": "booking-agent",
  "agent_name": "Flight Booking Agent",
  "user_email": "operator@example.com",
  "tool": "flight-search"
}
  • agent_name improves display naming.

  • user_email adds user attribution where appropriate.

  • tool identifies a tool on tool-call observations.

Configure user and session attribution

userId and sessionId belong on the Langfuse trace model.

Python
trace = langfuse.trace(
    name="support-session",
    user_id="user-123",
    session_id="session-456",
    metadata={"agent_id": "support-agent"},
)

Use a consistent session ID when related model operations should appear as one conversation or workflow in Mavvrik.

Data not collected by this integration

  • Prompt and response text is not required or collected for this cost integration.

  • Historical traces older than the first 24-hour collection window are not automatically backfilled.

  • Fields that Langfuse does not emit cannot be reconstructed by Mavvrik.

Verify the integration

After the next collection cycle:

  1. Open Home → Agentic → Cost and locate the connected agent.

  2. Confirm model spend appears.

  3. Open Home → Agentic → Sessions and inspect a recent trace.

  4. Verify the expected user, session, model, usage, duration, and status fields.

Troubleshoot Langfuse data

Symptom

Check

Connection is Active but no agents are discovered

Confirm an Agent metadata key is configured and present on fresh traces

Agents are discovered but no cost is collected

Connect the discovered agent to start collecting its data

Agent key does not match

Confirm the value is a string and matches case/whitespace exactly

No recent traces appear

Generate fresh traffic and wait for the next 10-minute poll

User/session is missing

Set userId and sessionId on the Langfuse trace

Model cost is missing

Confirm the observation contains model identity and token/usage fields

Verify the complete setup

  • Public key, secret key, and base URL saved successfully.
  • At least one Agent metadata key configured.
  • Fresh Langfuse traces contain the configured key as a string.
  • Discovered agents are connected in Mavvrik.
  • A collection cycle completed.
  • Cost is visible in Home → Agentic → Cost.
  • Trace detail is visible in Home → Agentic → Sessions.