---
title: Send AI gateway and router traffic to Agent Analytics
description: "Capture agent traffic that passes through OpenRouter, LiteLLM, Requesty, Fireworks AI, or Strands in Agent Analytics, by wrapping the client with the AI SDK or exporting the gateway's OpenTelemetry spans."
product: general
lang: en
token_estimate: 1865
---
# Send AI gateway and router traffic to Agent Analytics

> For AI agents: a documentation index is available at [/docs/llms.txt](/docs/llms.txt). Append `.md` to any page URL for markdown, or send `Accept: text/markdown`.

Traffic that passes through an AI gateway or inference router can reach Agent Analytics three ways: wrap the client with the AI SDK, have the gateway export OpenTelemetry GenAI spans, or send `[Agent]` events through the HTTP API for conversations you already store. Wrapping the client is the complete path. It captures turns, tool calls, user feedback, experiment context, and the gateway's request ID.

## Set up with your AI coding agent (recommended)

Paste this prompt into your AI coding agent, such as Cursor, Claude Code, Windsurf, GitHub Copilot, or Codex. The agent installs the AI SDK, reads its bundled instructions, finds every model call, and instruments it.

#### Node

```text
Instrument this app with Amplitude Agent Analytics using the Node SDK. Our model calls go through an AI gateway or inference router.

Also fetch https://raw.githubusercontent.com/amplitude/Amplitude-AI-Node/main/docs/integrations/routers.md
and follow it for the base URL, the gateway tag, and routed-model pricing.

Install the SDK:

npm install @amplitude/ai @amplitude/analytics-node

Then follow `node_modules/@amplitude/ai/amplitude-ai.md`.
```

#### Python

```text
Instrument this app with Amplitude Agent Analytics using the Python SDK. Our model calls go through an AI gateway or inference router.

Also fetch https://raw.githubusercontent.com/amplitude/Amplitude-AI-Node/main/docs/integrations/routers.md
and follow it for the base URL, the gateway tag, and routed-model pricing.

Install the SDK:

python3 -m pip install amplitude-ai

Then run `amplitude-ai --print-guide` and follow the printed instrumentation guide.
```

Review the changes it proposes, then verify with the steps in [Get started](#get-started).

## What this means for you

Every path needs the same three facts on every request: who the user is, which conversation the request belongs to, and which agent made it. The gateway knows the model, tokens, and latency, but not your user or conversation, so your application supplies them.

## Wrap the client

Point the AI SDK's wrapped OpenAI client at the gateway's OpenAI-compatible URL, tag the agent with the gateway name, and run each request inside an agent session. The wrapped client tracks each new user message for you, so don't also track it by hand.

#### Node

```typescript
import { AmplitudeAI, OpenAI } from "@amplitude/ai";

const ai = new AmplitudeAI({ apiKey: process.env.AMPLITUDE_AI_API_KEY! });
const client = new OpenAI({
  amplitude: ai,
  apiKey: process.env.OPENROUTER_API_KEY,
  baseUrl: "https://openrouter.ai/api/v1",
});
const agent = ai.agent("support-bot", {
  context: { ingestion_path: "gateway", gateway: "openrouter" },
});

export async function handleChat(userId: string, sessionId: string, messages: { role: "user"; content: string }[]) {
  return agent.session({ userId, sessionId }).run(async () => {
    const response = await client.chat.completions.create({ model: "openai/gpt-4o-mini", messages });
    return response.choices[0]?.message.content;
  });
}
```

#### Python

```python
import os

from amplitude_ai import AmplitudeAI, wrap
from openai import OpenAI

ai = AmplitudeAI(api_key=os.environ["AMPLITUDE_AI_API_KEY"])
client = wrap(
    OpenAI(api_key=os.environ["OPENROUTER_API_KEY"], base_url="https://openrouter.ai/api/v1"),
    amplitude=ai,
)
agent = ai.agent("support-bot", context={"ingestion_path": "gateway", "gateway": "openrouter"})

def handle_chat(user_id: str, session_id: str, messages: list):
    with agent.session(user_id=user_id, session_id=session_id):
        response = client.chat.completions.create(model="openai/gpt-4o-mini", messages=messages)
        return response.choices[0].message.content
```

Use the base URL and tag for your gateway:

| Gateway | Base URL | `gateway` tag | OpenTelemetry export |
| --- | --- | --- | --- |
| OpenRouter | `https://openrouter.ai/api/v1` | `openrouter` | Partial |
| LiteLLM | Your proxy, for example `http://localhost:4000/v1` | `litellm` | Partial |
| Requesty | `https://router.requesty.ai/v1` | `requesty` | None, so wrap the client |
| Fireworks AI | `https://api.fireworks.ai/inference/v1` | `fireworks` | Fireworks-managed. Refer to [Fireworks AI](#fireworks-ai). |

The `ingestion_path` and `gateway` values land in `[Agent] Context`, so you can separate gateway traffic from direct provider calls in charts.

## Cost

The AI SDK prices each response at the public rate of the model the gateway selected. Pass the routed model name, such as `openai/gpt-4o-mini`, when you choose it. A gateway alias such as `openrouter/auto` has no price, so the response has no `[Agent] Cost USD` rather than `$0`. If you know the billed amount, pass `totalCostUsd` (Node) or `total_cost_usd` (Python).

## Export gateway traces

OpenRouter and LiteLLM can export OpenTelemetry spans to Amplitude's OTLP endpoint, but neither carries all three identity facts, so wrapping the client is the complete path for both.

- **OpenRouter**: Broadcast sends the user and session to Amplitude, but has no field for the agent ID, so the agent is the exporter's service name. Generations arrive as `[Agent] Span` events with model, tokens, and cost, not as `[Agent] AI Response` events, unless your own OpenTelemetry Collector sets `gen_ai.operation.name` first. Match your Amplitude privacy mode to OpenRouter's Privacy Mode.
- **LiteLLM**: The proxy's spans have no conversation ID, so every request becomes its own one-turn session. To include message text, set `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_ONLY` on the proxy.
- **Strands and other agent frameworks**: Frameworks that emit GenAI spans export them with the AI SDK's `AmplitudeAgentExporter` or `enableOtel()`. Cost needs the model and input and output tokens on each span.

For endpoints and attribute mapping, refer to [Send OpenTelemetry traces to Agent Analytics](https://amplitude.com/docs/amplitude-ai/agent-analytics/instrument-opentelemetry).

## Fireworks AI

Fireworks AI traffic reaches Agent Analytics two ways: through the AI SDK wrapping Fireworks' OpenAI-compatible client, or through OTLP traces that Fireworks exports. Both produce the same `[Agent]` events.

- **Wrap the client**: Use the base URL `https://api.fireworks.ai/inference/v1` with the steps in [Wrap the client](#wrap-the-client). The SDK captures the Router request ID as `[Agent] Provider Request ID`. It doesn't send Fireworks' `x-multi-turn-session-id` header automatically.
- **Fireworks-managed OTLP**: When Fireworks exports traces, send them to the US or EU OTLP endpoint with your Amplitude project API key. Refer to [Configure your exporter](https://amplitude.com/docs/amplitude-ai/agent-analytics/instrument-opentelemetry#configure-your-exporter). Amplitude doesn't require an enablement request. Fireworks must persist the `user`, a conversation or session ID, and `gen_ai.response.id` through every Router route.

## Get started

Follow the [AI gateways and routers guide](https://github.com/amplitude/Amplitude-AI-Node/blob/main/docs/integrations/routers.md). To verify, send a multi-request conversation and confirm it appears as one session, with `[Agent] Provider Request ID` on each AI Response.

Guide last verified on October 6, 2026.

