Langfuse launches AI Gateway Learn more

Coding agent cost tracking: Claude Code, Codex, GitHub Copilot

Once a team uses more than one coding agent, cost lives in several places: an Anthropic org report, an OpenAI admin console, and GitHub billing. None of them shows the others, and none shows what a session did. This page explains how to bring all of them into one Langfuse project, so you can compare cost per developer, team, model, and session across agents.

TL;DR: Route your coding agents through the Langfuse AI Gateway. It works with Claude Code, Codex, the GitHub Copilot CLI and app (bring-your-own-key models), OpenCode, and Pi, and records the cost of the actual API calls. Admins set it up once: developers get a gateway key and a base URL, and every call is attributed to them automatically. Add team and cost center as key metadata, and build one dashboard across agents.

Langfuse AI Gateway analytics with total cost, requests, tokens, cost over time, and cost per user

Which agents work with the gateway

AgentGateway setup
Claude CodeClaude Code gateway guide, API billing only
CodexCodex gateway guide, API key only
GitHub CopilotCopilot gateway guide, BYOK models only
OpenCodeOpenCode gateway guide
PiPi gateway guide

The per-agent guides go deeper: Claude Code, Codex, and GitHub Copilot.

Why the gateway

  • Real cost, not an estimate. The agent calls models with your organization's provider connection, so the cost Langfuse records is the cost of the calls you pay for. Use it for chargeback and budgets.
  • Set up once for the whole team. Admins add the provider connection and the policy. Each developer only sets a base URL and their own key, and every call is attributed to them without per-machine configuration to maintain.
  • Complete coverage. The gateway key is the only way to reach the model, so developers can't skip tracking by accident.
  • Central control. Revoke one person's key, rotate provider keys without touching clients, and restrict which models can be called. See gateway API keys and model allowlists.

Some agents also have local hooks or OpenTelemetry integrations, listed in tracing coding agents. They keep the agent's own billing, estimate cost from tokens, and have to be installed and kept up to date on every developer's machine, so coverage depends on each person's setup.

What drives coding agent cost

Across agents, the same few patterns explain most of the spread between developers:

  1. Context size comes first: agents that read many files or replay long histories send far more input tokens per call.
  2. Session length compounds it, because many agents resend the conversation on every round.
  3. Model choice changes the price per token by an order of magnitude between small and large models.
  4. Cache hits reduce input cost. Generations record cached tokens separately, so you can see how much caching saves.
  5. Retries and loops add cost without progress. Failed tool calls followed by the same model call are the signature.

Each of these is visible per session in Langfuse, which is why per-session data finds savings that monthly totals miss.

One dashboard across agents

With every agent in one project, the gateway analytics page and a custom dashboard answer the questions platform teams get asked:

ChartConfiguration
Cost per agent per weekTotal cost, grouped by trace name
Cost per developerTotal cost, grouped by user
Cost per teamTotal cost, grouped on the team key metadata
Most expensive sessionsSessions table sorted by cost

Attach team and cost_center as key metadata when a developer's key is created; request headers can't override it. For cost attribution beyond coding agents, see FinOps for AI.

FAQ

Which coding agent is cheapest?

It depends on the plan, the model, and how your team works, so measure rather than compare list prices. Route every agent through the gateway into one Langfuse project and compare cost per session for similar tasks. For a direct comparison of two agents, see Claude Code vs Codex.

Does the gateway work with Claude or ChatGPT subscriptions?

No. Through the gateway, agents call models with your organization's API credentials and are billed at API rates by the provider. Developers on a subscription plan log out of it before switching. See the per-agent guides for details.

Can developers opt out of tracking?

Not through the gateway: the gateway key is the only way to reach the model, and a user key always records its owner. Remove direct provider keys so that traffic can't go around it.


Was this page helpful?