Skip to main content

Connect agent and application telemetry

Telemetry adds usage detail from the tools making model requests. It can show which developer used a coding agent or which customer, agent, and feature an application request belongs to.

Choose a source

Go to Integrations > Add integration and choose a source from Telemetry.

IntegrationSetup
Claude Code OpenTelemetryAdd the generated environment variables to Claude Code's settings or the settings your organization manages.
Codex OpenTelemetryMerge the generated exporter configuration into ~/.codex/config.toml.
OpenTelemetryChoose the Format your application sends: OpenTelemetry GenAI for standard metrics, or Your application for single requests with business details.

The two OpenTelemetry formats share one catalog card. Choose the format before creating the integration so its setup instructions match your exporter.

Configure and verify

  1. Name and create the integration.
  2. Copy the connection token shown on the result screen. It is shown only once. You can create a replacement from the integration's settings.
  3. Open Show setup instructions. Use the endpoint and configuration generated for your connection.
  4. Merge the configuration into the existing client settings, preserving any other settings. Keep connection tokens out of source control.
  5. Restart the client or deploy the updated application, then generate some usage.
  6. Check whether the integration has received data. Open Explore, select the source, and choose Notional to view usage costs.

The setup dialog also provides a prompt for your coding agent. It leaves a token placeholder for you to replace yourself.

Claude Code

The generated configuration turns on telemetry and sends metrics over OTLP, the OpenTelemetry protocol. It includes session and account IDs so Infracost AI can tell who the usage belongs to. Add it through Claude Code's environment settings. Restart Claude Code before checking the connection.

Existing OpenTelemetry instrumentation

Choose OpenTelemetry, then select OpenTelemetry GenAI under Format if your application already sends the standard gen_ai.client.token.usage metric. For example, it might use OpenLLMetry, OpenLIT, or vLLM.

Set the metrics endpoint and authorization header using the values from the setup dialog. Export using delta temporality. This sends only the usage since the last export. Cumulative data points are dropped so running totals are not counted more than once. If the exporter cannot send deltas, put an OpenTelemetry collector with a cumulativetodelta processor in front of it.

Your application

Choose OpenTelemetry, then select Your application under Format to report each model request with business details. The exporter sends one record per request. Add the customer, agent, feature, and unit of work using details your application already has. You can also add your own attribution keys, such as environment or prompt version, to group and filter spend.

For example, a support application can label requests with the customer being helped and the ticket-summary feature. You can then filter or group the spending by Customer and Feature in Explore. Your application must supply these details. They cannot be worked out from a provider's combined bill.

Follow the exporter installation instructions in the connection's setup dialog. For this source, you must add tracking to your application and set the endpoint and token, for example:

import Anthropic from '@anthropic-ai/sdk';
import InfracostAI from '@infracost/ai';

const infracost = new InfracostAI();

// Apply attributes to every request from this client
const client = new Anthropic({
middleware: [infracost.anthropicMiddleware({
attribution: {
feature: 'ticket-summary',
product: 'helpdesk',
team: 'customer-success',
environment: 'production',
},
})],
});

If your application already emits OpenTelemetry GenAI inference spans, you can send them to the traces endpoint with the same connection token instead. Use either traces or the exporter for each model call, so its usage is counted once.

Troubleshooting

No data after configuration

Confirm that the client was restarted and has generated new model usage. Check that it can reach the endpoint from the setup dialog, that the token is active, and that the exporter sends the authorization header.

Metrics arrive, but usage is missing

For metric sources, check that the client sends a supported metric, such as the Claude Code metrics or gen_ai.client.token.usage, with delta temporality. Cumulative data points are dropped. In Explore, select Notional and a date range that includes the new usage.

Developer or application details are missing

Check which attributes the client sends. Billing totals and combined token metrics do not always include developer or business details. Add details your application owns, such as customer and feature, when you add tracking to the request.