---
title: "Coding agent cost tracking: Claude Code, Codex, GitHub Copilot"
description: "Track AI coding agent cost across Claude Code, Codex, and GitHub Copilot in one place, per developer, team, model, and session, by routing agents through an AI gateway."
tags: [guide, agents]
---

# 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.

**Start with Langfuse** [Sign up](/cloud)

**TL;DR:** Route your coding agents through the [Langfuse AI Gateway](/docs/gateway/overview). 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](/images/docs/ai-gateway/analytics.png)

## Which agents work with the gateway [#agents]

| Agent          | Gateway setup                                                                                    |
| -------------- | ------------------------------------------------------------------------------------------------ |
| Claude Code    | [Claude Code gateway guide](/integrations/developer-tools/claude-code-gateway), API billing only |
| Codex          | [Codex gateway guide](/integrations/developer-tools/codex-gateway), API key only                 |
| GitHub Copilot | [Copilot gateway guide](/integrations/developer-tools/github-copilot-gateway), BYOK models only  |
| OpenCode       | [OpenCode gateway guide](/integrations/developer-tools/opencode-gateway)                         |
| Pi             | [Pi gateway guide](/integrations/developer-tools/pi-agent-gateway)                               |

The per-agent guides go deeper: [Claude Code](/resources/engineering/claude-code-usage-cost-tracking), [Codex](/resources/engineering/codex-usage-cost-tracking), and [GitHub Copilot](/resources/engineering/github-copilot-usage-cost-tracking).

## Why the gateway [#why-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](/resources/engineering/ai-gateway-api-keys) and [model allowlists](/resources/engineering/ai-model-allowlist).

  Some agents also have local hooks or OpenTelemetry integrations, listed in
  [tracing coding agents](/resources/engineering/coding-agent-tracing). 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 [#cost-drivers]

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 [#dashboard]

With every agent in one project, the gateway [analytics page](/docs/gateway/features/analytics) and a [custom dashboard](/docs/metrics/features/custom-dashboards) answer the questions platform teams get asked:

| Chart                   | Configuration                                  |
| ----------------------- | ---------------------------------------------- |
| Cost per agent per week | Total cost, grouped by trace name              |
| Cost per developer      | Total cost, grouped by user                    |
| Cost per team           | Total cost, grouped on the `team` key metadata |
| Most expensive sessions | Sessions table sorted by cost                  |

Attach `team` and `cost_center` as [key metadata](/docs/gateway/features/api-keys#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](/resources/engineering/finops-for-ai).

## FAQ

### Which coding agent is cheapest? [#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](/resources/engineering/claude-code-vs-codex).

### Does the gateway work with Claude or ChatGPT subscriptions? [#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? [#can-developers-opt-out]

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.

[Ask another question](/docs/ask-ai)

**Start with Langfuse** [Sign up](/cloud)

<!-- agent-instructions -->

---

## Agent Instructions

This page is part of the [Langfuse](https://langfuse.com) documentation, published as plain Markdown for AI agents. Every page is available as Markdown by appending `.md` to its URL, or by sending an `Accept: text/markdown` header. This page: `https://langfuse.com/resources/engineering/coding-agent-cost-tracking.md`.

### Querying these docs

If the answer is not on this page, query the documentation instead of guessing:

- **Semantic search** across all Langfuse docs, returning an answer with the relevant pages and excerpts. Ask a specific, self-contained question:

  ```bash
  curl -sG "https://langfuse.com/api/search-docs" --data-urlencode "query=How do I trace a LangGraph agent?"
  ```

- **Index of every page**: <https://langfuse.com/llms.txt>, with per-section indexes [llms-docs.txt](https://langfuse.com/llms-docs.txt), [llms-integrations.txt](https://langfuse.com/llms-integrations.txt), and [llms-self-hosting.txt](https://langfuse.com/llms-self-hosting.txt).

### Before writing Langfuse code

- **Install the [Langfuse Agent Skill](https://langfuse.com/docs/api-and-data-platform/features/agent-skill).** It encodes Langfuse's own best practices for instrumentation, prompt management, and evaluation, and materially improves results.
- **Read [What does a good trace look like?](https://langfuse.com/docs/observability/best-practices.md)** before instrumenting an application.
- **Verify endpoints, parameters, and response fields** against the [API reference](https://api.reference.langfuse.com) instead of inferring them from code examples.
- **Use the [Langfuse CLI](https://langfuse.com/docs/api-and-data-platform/features/cli)** (`npx @langfuse/cli api <resource> <action>`) to read or write traces, prompts, datasets, and scores from the terminal.

Found an error in these docs? Please open an issue at <https://github.com/langfuse/langfuse-docs/issues>.
