February 8, 20268 min read

AI Cost Tracking Without Code Changes

Most AI cost tools require proxies or SDKs. Here is why the billing-API approach gives you the same cost visibility with zero code changes, zero latency impact, and zero maintenance.

AI Cost Tracking Without Code Changes

You want to know how much you spend on AI. You should not need to change your production code to find out. Yet most AI cost tracking tools require exactly that - routing your API traffic through a proxy or instrumenting every LLM call with an SDK.

Both approaches work. Both give you data. But both come with integration overhead, latency trade-offs, and ongoing maintenance that has nothing to do with your actual goal: understanding where the money goes.

There is a simpler way. Read cost data directly from provider billing APIs. No code changes, no network hops, no risk to your production system.

The three approaches to AI cost tracking

Every AI cost tracking tool on the market uses one of three fundamental approaches:

  1. Proxy-based. Route your API traffic through a middleman that logs requests and calculates costs. Examples: Helicone, Portkey.
  2. SDK-based. Wrap your LLM calls with SDK decorators that capture token usage and trace execution. Examples: Langfuse, LangSmith.
  3. Billing-API-based. Read cost data directly from provider billing endpoints. No interaction with your API traffic at all. This is what Grafient does.

Each approach involves different trade-offs. The right choice depends on what you're actually trying to accomplish.

The proxy approach

Proxy-based tools like Helicone work by intercepting your API traffic. Instead of calling api.openai.com directly, you point your requests to oai.helicone.ai, which forwards them to OpenAI, logs the request and response, and returns the result.

What you get:

  • Request-level data - every prompt, completion, and token count logged individually.
  • Response caching - identical prompts can return cached results, saving money.
  • Custom headers for tagging and segmenting costs by feature, team, or environment.

What it costs you:

  • Latency. Every API call now includes an extra network hop. For real-time applications, even 50–100ms of added latency is noticeable. For high-throughput pipelines, it compounds.
  • Single point of failure. If the proxy goes down, your application's AI features break. Your uptime now depends on a third party's uptime.
  • Code changes and deployment. You need to update base URLs, add authentication headers, and deploy. For a single service this is straightforward. For a microservices architecture with multiple AI touchpoints, it's a project.
  • Incomplete coverage. The proxy only tracks traffic that routes through it. Usage from Cursor, Claude Code, direct dashboard queries, and other tools outside your codebase is invisible.
  • Privacy considerations. Every prompt and completion passes through a third-party server. For teams handling sensitive data, this can be a compliance blocker.

The proxy approach is powerful when you need request-level debugging. But if your primary goal is cost tracking, the overhead is disproportionate to the value.

The SDK approach

SDK-based tools like Langfuse work by wrapping your LLM calls with their library's decorators or wrappers. You import their SDK, annotate your functions, and the tool captures detailed execution traces.

What you get:

  • Deep tracing with execution trees - you can see exactly how a multi-step agent workflow unfolds.
  • Prompt versioning and management built into the tracing pipeline.
  • Token-level tracking tied to specific code paths, making it easy to attribute costs to features.

What it costs you:

  • Instrumentation effort. You need to wrap every LLM call in your codebase. For a mature application with dozens of call sites across multiple services, this is hours of work - plus code review, testing, and deployment.
  • Maintenance burden. SDKs release updates, introduce breaking changes, and occasionally conflict with other dependencies. You're adding a new dependency to your critical path.
  • Incomplete coverage. If a developer adds a new LLM call and forgets to instrument it, that usage is invisible. Coverage depends on discipline, which means it degrades over time.
  • No visibility into external tools. Like the proxy approach, SDKs only track what runs through your code. Cursor usage, Claude Code sessions, and direct API calls from teammates don't show up.
  • Estimated costs. SDK-based tools typically calculate costs from token counts using published pricing tables. This is an estimate, not your actual bill. Discounts, committed-use agreements, and pricing changes can make these estimates diverge from reality.

The SDK approach is the right choice when you need deep tracing for debugging agent workflows or managing prompts at scale. For cost tracking alone, it's overengineered.

The billing API approach

The third approach skips your API traffic entirely. Instead of intercepting requests or instrumenting code, it reads cost data directly from each provider's billing and usage endpoints.

This is what Grafient does. You generate an API key from your provider's dashboard, paste it into Grafient, and your cost data starts flowing - historical data included.

What you get:

  • Zero code changes. Nothing in your codebase changes. No new dependencies, no deployment, no code review.
  • Zero latency impact. Grafient never touches your API traffic. Your requests go directly from your application to the provider, exactly as before.
  • Billing-accurate data. The data comes from the same source as your invoice. There's no estimation from token counts - you see what the provider actually charges you.
  • Complete coverage. Every dollar spent through your account is captured, regardless of where the usage originated. API calls from your production app, experiments from a Jupyter notebook, usage from Cursor or Claude Code, manual queries from the provider's playground - it all shows up.
  • Works with any workflow. Direct API calls, LangChain, LlamaIndex, Vercel AI SDK, custom agent frameworks - it doesn't matter. If it hits your provider account, Grafient tracks the cost.

What you don't get:

  • No request-level logging. You see daily aggregates by model, not individual requests. If you need to debug why a specific API call returned a bad response, this isn't the tool for that.
  • Granularity depends on the provider. Some providers expose detailed per-model breakdowns. Others provide less granular data. You're limited by what the billing API returns.

The trade-off is clear. If your goal is cost management - knowing how much you spend, where the money goes, and whether it's trending in the right direction - the billing API approach gives you everything you need without any of the integration overhead.

When each approach makes sense

These approaches are not mutually exclusive. You can use Grafient for cost tracking alongside Helicone for request logging, or alongside Langfuse for agent tracing. But most teams don't need all three.

Your goalBest approach
Cost management and budgetingBilling API
Request-level debugging and loggingProxy
Deep tracing and prompt managementSDK
All of the aboveBilling API + proxy or SDK

The key insight: most teams that just want to know "how much am I spending" do not need the complexity of a proxy or SDK. They need a dashboard that reads their billing data and presents it clearly. Everything else is optional.

If you later decide you need request-level logging for a specific service, you can add a proxy for that service without ripping out your cost tracking. Start simple, add complexity only when the use case demands it.

How it works in practice

Here's a concrete example with Anthropic, start to finish.

Step 1: Go to your Anthropic Console. Navigate to Settings, then API Keys. Generate a new Admin API key with billing read access.

Step 2: Open Grafient. Go to Integrations, select Anthropic, and paste your API key.

Step 3: Historical cost data loads immediately. You see a daily cost chart, per-model breakdowns (how much you spent on Claude 4 Sonnet vs. Claude 3.5 Haiku), token usage by type (input, output, cache read, cache write), and cache efficiency metrics.

Total time: under two minutes. No deployment, no code review, no pull request, no risk to your production system. If you decide Grafient isn't for you, remove the integration - nothing in your codebase was ever touched.

This same process works for every supported provider. Generate a key, paste it in, see your data. The integration surface is deliberately minimal because it reduces your risk to zero.

The bottom line

AI cost tracking should not require architectural decisions. You should not need to evaluate proxy reliability, audit SDK coverage, or worry about added latency - just to answer the question "how much am I spending on AI?"

Grafient connects to nine AI providers - Anthropic, OpenAI, OpenRouter, Cursor, xAI, ElevenLabs, Google AI, Bedrock, and Vercel - via their billing APIs. One dashboard, zero code changes, billing-accurate data from day one.

Get started for free and connect your first provider in under two minutes.

Start tracking your AI costs

Free plan. No credit card. Set up in under two minutes.