What Metrics measures
Every AI feature in your product, measured four ways, and all of it on the LLM page beside the calls your own instrumentation reports.
| Way | What you set up | What you see |
|---|---|---|
| Chat turns in the browser | Nothing. The snippet does it | Time to first token, how long each answer took, stopped answers, regenerations, thumbs up and down and copies |
| Gateway | One base URL in your AI client | Every model call with its model, tokens, cost, latency and errors, by person, session and feature |
| Provider usage | Your provider's admin key | What OpenAI or Anthropic say your organization used and spent, by model and day, including calls nothing else saw |
| Coding agents | Three environment variables | Every model call Claude Code, Codex or Gemini CLI makes, by session, with its cost |
No prompt and no answer is ever recorded by any of the four. Only counts, times, names and money.
Chat turns in the browser
When your page streams an answer from its own server, the snippet times it.
A turn is a POST from the page to its own site whose answer streams (text/event-stream, newline delimited JSON, or the AI SDK's stream). The snippet reads a copy of the answer, so your page is untouched, and sends $ai_turn with the endpoint's path, the status, first_token_ms, duration_ms, bytes and pieces, stopped when the page cancelled it and regenerated when it followed a regenerate button.
Once a page has streamed a turn, the buttons beside answers are read by their label, title, test id or text. A thumbs up or down sends $ai_feedback with rating, a copy button $ai_copy and a regenerate or retry button $ai_regenerate, each with the turn it follows.
When your server answers with the call's trace in a traceresponse header (the gateway gives you one to pass on), every turn and rating carries its trace_id, so a thumbs down on the page opens the very model calls behind that answer.
Your AI endpoint is on another site? Name it with signals: { ai_paths: ['/v1/chat'] } in the snippet's options. Turn chat turns off for a site under Setup, What the site captures, AI chat turns.
Gateway
Point your AI client's base URL at Mode. Every call goes to your provider exactly as before, and Mode records it.
- Open Metrics, then Setup, and under Keys make a secret key with the ingest scope
- Set your client's base URL to the address of your provider below
- Send the key as the
x-mode-keyheader, or put it in the address where a client can set only the URL
| Provider | Base URL |
|---|---|
| OpenAI | https://app.gotmode.com/v1/metrics/ai/openai/v1 |
| Anthropic | https://app.gotmode.com/v1/metrics/ai/anthropic |
| Google (OpenAI compatible) | https://app.gotmode.com/v1/metrics/ai/google/v1beta/openai |
| Mistral, Groq, DeepSeek, xAI, Together, Fireworks, OpenRouter, Perplexity, Cerebras | https://app.gotmode.com/v1/metrics/ai/<provider> followed by the provider's own path, such as /v1 |
from openai import OpenAI client = OpenAI( base_url="https://app.gotmode.com/v1/metrics/ai/openai/v1", default_headers={"x-mode-key": "YOUR_SECRET_KEY"}, )
Your provider key goes to your provider and is never kept by Mode. Answers stream back piece by piece as they arrive. Name who and what a call is for with three optional headers, x-mode-distinct-id (the person), x-mode-session-id (the conversation) and x-mode-feature (the product feature), and send a traceparent to put the call in your own trace. Every answer carries traceresponse, the trace the call was recorded in.
A streamed chat completion reports its tokens only when asked. The gateway asks for them and keeps that extra last piece from your client unless your client asked too, so your code sees exactly what it saw before.
Provider usage and cost
Connect your provider's admin key and Mode reads what your whole organization used and spent, by model and day.
Connect it under Metrics, Systems, as OpenAI usage or Anthropic usage, with an admin key (OpenAI's organization admin key, Anthropic's admin key). Mode reads the last 30 days first and then each finished day, tokens by kind with cached reads and writes apart, requests, and cost by line item. It shows on the LLM page as Provider usage, and agents read it with ai_provider_usage. Comparing it with the calls Mode saw itself finds spend no instrumentation covers.
Coding agents
Claude Code, Codex and Gemini CLI report every model call over OpenTelemetry. Send it to Mode and each call shows on the LLM page with its session and cost.
Use your project's collection address, shown on the Setup page, and a secret key with the ingest scope.
# Claude Code export CLAUDE_CODE_ENABLE_TELEMETRY=1 export OTEL_LOGS_EXPORTER=otlp export OTEL_EXPORTER_OTLP_PROTOCOL=http/json export OTEL_EXPORTER_OTLP_ENDPOINT=https://YOUR_COLLECTION_HOST export OTEL_EXPORTER_OTLP_HEADERS="x-mode-key=YOUR_SECRET_KEY" # Gemini CLI export GEMINI_TELEMETRY_ENABLED=true export GEMINI_TELEMETRY_TARGET=local export GEMINI_TELEMETRY_OTLP_PROTOCOL=http export GEMINI_TELEMETRY_OTLP_ENDPOINT=https://YOUR_COLLECTION_HOST export OTEL_EXPORTER_OTLP_HEADERS="x-mode-key=YOUR_SECRET_KEY"
Codex reads its exporter from ~/.codex/config.toml.
[otel]
exporter = { otlp-http = { endpoint = "https://YOUR_COLLECTION_HOST/v1/logs", protocol = "json", headers = { "x-mode-key" = "YOUR_SECRET_KEY" } } }Each agent's session is one trace, so the LLM page lists it under Sessions with its calls, tokens and cost. The records themselves are kept in Logs as they came. Claude Code states each call's cost and Mode keeps it, the others are priced from Mode's price table.
Sessions
Calls that share a session id are one conversation.
The LLM page lists sessions newest first with their person, feature, models, calls, tokens, cost and errors. A session id comes from the gateway's x-mode-session-id, from session.id or mode.session_id on any OpenTelemetry span, and from a coding agent's own session. Agents read them with list_llm_sessions, and one session's calls with list_llm_calls and session.