Skip to content

Track AI and coding spend

Goal: know what your AI usage costs, who and what drives it, and get warned before it spikes. Time: about 5 minutes per source.

Spend comes from two kinds of sources. Pick the ones you use:

Source How it connects Endpoint type
Coding tools: Claude Code, Codex CLI, Antigravity A hook installed on each developer's machine, one command Claude Code & Codex CLI
Your own AI apps and agents The Anosys SDK, one line at startup OpenTelemetry / AI Agents
%%{init: {"flowchart": {"curve": "linear"}}}%%
graph LR
    subgraph Developer machines
      A["Claude Code"]
      B["Codex CLI"]
      C["Antigravity"]
    end
    subgraph Your services
      D["OpenAI / Anthropic /<br/>Claude Agent SDK apps"]
    end
    A --> E["Coding tools endpoint"]
    B --> E
    C --> E
    D --> F["AI apps endpoint"]
    E --> G["Spend dashboards<br/>and cost alerts"]
    F --> G

Coding tools

Step 1. Create one endpoint for your team

Create an endpoint of type Claude Code & Codex CLI and copy its API key (Collecting → Integration Options → API → Create New API Key). The whole team can share one endpoint; each session records the developer and project.

Step 2. Install the hook on each machine

pip install anosys-claude-code
anosys-claude-code install --api-key "YOUR_KEY"

Or with Node.js: npx -y anosys-sdk-claude-code install --api-key "YOUR_KEY". Full guide: Claude Code.

pip install anosys-codex
anosys-codex install --api-key "YOUR_KEY"

Or with Node.js: npx -y anosys-sdk-codex install --api-key "YOUR_KEY". Then approve the hook once inside Codex (/hooks). Full guide: Codex CLI.

pip install anosys-antigravity
anosys-antigravity install --api-key "YOUR_KEY"

Full guide: Antigravity.

Add --redaction to any installer to send usage and cost without prompt or code content.

Result: finish one session or turn in the tool. The endpoint's activity graph shows calls within seconds.

What you can see

Claude Code Codex CLI Antigravity
Input, output and cache tokens ✓ ✓ (plus reasoning tokens) Not reported by the tool
Estimated cost (USD) ✓ ✓ Not available
Per developer and project ✓ ✓ ✓
Git branch and pull request ✓ — —
Tool calls, commands, files changed ✓ ✓ ✓
Subagents ✓ — —
Session and turn duration ✓ ✓ ✓

Antigravity doesn't report tokens

Google Antigravity doesn't expose token counts to hooks, so Anosys tracks its activity (model steps, tool calls, duration) but not its cost.

Costs are estimates calculated from the model name and token counts using public list prices. They don't include discounts or credits on your provider invoice.

Your own AI apps

Add the Anosys SDK for your framework (see Debug AI agents). Token counts and model names are captured on every call. To attribute spend, pass who and what each call is for through get_user_context, for example the user, team or feature:

AnosysAnthropicLogger(get_user_context=lambda: {"session_id": current_user_id()})

Build the spend views

  1. Create a dashboard and add, for each endpoint:
    • cost over time (Advanced Time Series),
    • cost by developer or user (Bar Chart),
    • cost by model (Pie Chart or Table),
    • top sessions by cost (Table), with a Trace Timeline to open one.
  2. Ask the AI Assistant questions such as "Which projects drove Claude Code spend this week?"

Get warned before it spikes

In Data Processing → Alert Builder, create a trigger on the cost field (for example daily cost per developer above a limit) and send it to Slack, email or a webhook. See Monitor agents in production.

Next steps