October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk8 min

How to Track Costs Across Multiple AI APIs Without a Backend

A local ledger can estimate what several AI APIs cost without a server: log each response's usage, price it from a dated table, and reconcile against provider billing reports.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

You can track what several AI APIs cost without running a server. Record the usage object each provider returns with every response, price it from a dated rate table you maintain, and treat the result as an estimate that you reconcile against each provider’s billing reports. The method has limits: a local logger only sees traffic its own client makes, it cannot guarantee invoice-level totals, and it cannot keep a secret API key safe inside a public web page or mobile app.

Where a local ledger stops

Before building anything, be clear about what the approach can and cannot do.

As an Amazon Associate I earn from qualifying purchases.

  • It sees only logged calls. Traffic from scripts, teammates’ machines, or other tools that never write to your ledger is invisible to it.
  • It estimates. Your total is a calculation from token counts and your own price table. It is not the figure on a provider invoice.
  • It cannot protect keys. A logger running on a single trusted machine is a different situation from a browser app that ships a key to every visitor.
  • It cannot enforce a budget. It can warn you after a call completes. Stopping spend requires provider-side controls.

Step 1: Capture the usage object from every response

Each provider reports token consumption inside the response, but the field names depend on the provider and on the endpoint you call. Your logger should read the usage object at the moment the call returns, before it discards anything.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

OpenAI

OpenAI’s field names differ between endpoints. Chat Completions and Responses both report input, output, and total token counts, under different names:

Endpoint Input tokens field Output tokens field Total
Chat Completions usage.prompt_tokens usage.completion_tokens Total token count is included
Responses usage.input_tokens usage.output_tokens Total token count is included

Some endpoint and model combinations also return cached-input token counts or reasoning-token counts. Store these when present. Leave them empty when absent rather than writing zero, so that you can tell “not reported” from “none used.”

Anthropic

This article does not establish Anthropic’s per-response usage field names. Read them from Anthropic’s current API reference when you write the parser. What Anthropic does document for reporting is covered in the provider section below.

Google Gemini API

This article does not list Gemini’s per-response usage field names either. Confirm them in Google’s current Gemini API reference. Whatever the names, keep the complete usage object, because Google’s cost calculation also depends on cached-token counts and cached-token storage duration, which may not be visible in a simple input and output pair.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Step 2: Define the ledger row

Write one append-only row per completed request. Never update or overwrite past rows; if a price or schema changes, add a new version rather than rewriting history. Each row should contain:

  • A local unique record ID, generated by your logger.
  • Provider name and endpoint, such as openai with responses.
  • The exact model string returned or sent, not a shortened alias.
  • A UTC timestamp.
  • An application-defined feature or user label, set before the call.
  • The provider project or key label, if it is safe to store and the provider exposes one.
  • The provider request ID, when the response includes one.
  • The complete raw usage payload.
  • Normalized fields for cross-provider totals: input, output, cached input, and total.
  • A schema version for the parser, and the price-table version used to estimate the cost.

An illustrative row, with placeholder values, looks like this:

{
  "record_id": "a1f3c9e0-example",
  "provider": "openai",
  "endpoint": "responses",
  "model": "exact-model-string-from-response",
  "timestamp_utc": "2026-10-09T14:05:12Z",
  "feature": "support-summary",
  "request_id": "value-if-returned",
  "usage_raw": { "input_tokens": 1200, "output_tokens": 350 },
  "usage_normalized": { "input": 1200, "output": 350, "cached_input": null, "total": 1550 },
  "schema_version": "openai-responses-v1",
  "price_table_version": "2026-10-01"
}

Normalize for totals, but keep the raw payload. The normalized fields make dashboards easy to build. The raw payload lets you re-derive costs if a provider changes its field names or you later discover a missed billing category.

Step 3: Keep prices in a dated, versioned table

Do not hard-code one token rate for every model and provider. Prices are set per model and per usage category, and the categories differ between providers. Keep a separate table keyed by provider, model, effective date range, and usage category.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The estimate for each row is:

estimated cost = sum of (quantity × rate per unit)

Convert units before multiplying. If a rate is quoted per million tokens, divide the token count by 1,000,000 first. The formula is a practical way to apply documented pricing dimensions. It is not a universal cost formula supplied by any provider, so check each provider’s current schedule for any category it adds.

Provider Billing dimensions to store Source of the rate
OpenAI Standard input, cached input, and output rates, which vary by model and by endpoint or tier OpenAI’s pricing page, checked on the date you apply it
Google Gemini API Input tokens, output tokens, cached-token count, and cached-token storage duration Google’s Gemini API pricing documentation, checked on the date you apply it
Anthropic Not established in this article. Use the input, output, and any other categories listed on Anthropic’s current pricing page Anthropic’s current pricing page

A worked example with illustrative rates

Suppose a model is listed at a made-up rate of 2.00 per million input tokens and 8.00 per million output tokens. A call with 1,200 input tokens and 350 output tokens costs:

  • Input: 1,200 ÷ 1,000,000 × 2.00 = 0.0024
  • Output: 350 ÷ 1,000,000 × 8.00 = 0.0028
  • Estimated total: 0.0052 in the table’s currency

The rates here are illustrative, not published prices. Replace them with the figures from the provider’s current schedule, and record the effective date of each figure.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Step 4: Label totals as estimates and reconcile them

Show every total with its basis: the price-table version, its effective date, and the date you last reconciled that provider’s invoice or cost report. A total without those labels is hard to trust a month later.

Expect gaps between your ledger and the bill. Two providers have documented reasons:

  • OpenAI says its granular Usage API may not perfectly reconcile with Costs data, and it points users to the Costs endpoint and Costs dashboard for invoice reconciliation. Treat Usage-derived figures as operational data and Costs as the financial record.
  • Google says Cloud Billing cost detail is typically available within a day, but it can sometimes take more than 24 hours. A reconciliation run on the morning after a busy day may simply be early.

Reconciliation routine

  1. Pick a closed period, such as a full calendar month in UTC, and total your ledger per provider for that period.
  2. Pull the provider’s cost figure for the same period: OpenAI Costs data in the dashboard or API, or Cloud Billing cost detail for Gemini.
  3. Compare totals per provider and per model. Record the difference and the date of the check.
  4. If the gap is large, work through the causes below before changing your prices.

When the numbers disagree

  • Missing rows. Another client, script, or failed-then-retried call is not in the ledger. Compare request counts against the provider’s usage view.
  • Missing rate categories. A cached-input or storage-duration charge has no rate in your table, so the estimate omits it.
  • Stale prices. The provider changed rates and your table still reflects the old version.
  • Timing. Billing data for the last day or so has not finished posting.

Step 5: Attribute cost to features and users

To get cost per feature or per customer, decide the label before the call and write it to the ledger row with the response. Setting it after the fact, by matching timestamps, is fragile.

Provider consoles offer their own filters, but they are not uniform:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • OpenAI Usage Dashboard can show current and past billing periods, filter by project, and filter by user for specified capabilities, with usage shown at one-minute intervals. Dashboard data is in UTC. The dashboard does not combine data across separate organizations; for combined analysis, OpenAI points to the Usage API.
  • Anthropic Claude Console usage reports can be filtered by workspace, model, month or day, and API key. They show input and output token totals, rate-limited requests, and tokens-per-minute charts, and they can be exported as CSV. Anthropic says the Usage and Cost reports are visible to the Developer, Billing, and Admin roles.
  • Google Gemini usage can be monitored in AI Studio, and costs are viewed in Cloud Billing. API keys inherit the billing and caps of their project rather than having their own billing settings, so per-key cost is not a built-in breakdown.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Keys: never ship them in a public client

A local ledger running on your own computer is one threat model. A web page or mobile app that calls a provider directly with an embedded key is another, and it is not safe. Google’s guidance is direct: “Never expose keys client-side in production: Do not hardcode API keys directly in web or mobile apps. Keys compiled in client-side code can be extracted by users. To secure client-side apps, run a backend proxy server to make the actual API calls.”

OpenAI gives similar guidance, advising against exposing keys in code or public repositories and recommending secure key storage. If your tracker runs in a browser with a key in it, anyone who loads the page can extract that key and spend against your account. In that case, the honest answer to “track costs without a backend” is that you need at least a minimal proxy to hold the key, and that is outside this article’s scope.

Spend guardrails are separate from the ledger

Provider controls can stop or warn about spend. Your ledger cannot. Use them alongside it, and do not describe your local alert as a cap.

  • OpenAI spend alerts notify you when spend reaches a threshold. Hard spend limits can stop affected requests, but enforcement is not instantaneous, and recorded spend may slightly exceed the configured amount while the limit status propagates.
  • Google Gemini offers account- and project-level caps. The project spend cap is marked experimental in Google’s billing documentation. Google notes about ten minutes of possible processing latency, so spend can overshoot the cap during that window.

A local alert that fires when your ledger total passes a threshold tells you something is happening. It does not stop anything, and it can be late if a call is logged after it is made.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choosing an approach

Approach Strength Limitation What to compare
Local logger and dated price table Combines providers and adds your own feature or user labels without running a server Records only the traffic your client observes. Rate changes and special categories can make estimates diverge from invoices Capture completeness, attribution fields, how often you update prices, storage and privacy
Provider dashboards and exports Provider-side usage visibility, filters, and cost reporting for each account Data stays split across provider accounts, and filters differ by provider Reconciliation quality, reporting delay, export formats, project, key, and user filters
Dedicated multi-provider reporting service A possible next step if local files and separate dashboards stop meeting your reporting needs Adds another service, account, and data-handling relationship. This article does not evaluate specific products Provider coverage, invoice reconciliation, attribution, access controls, and data export

For most individual developers and small teams, the local ledger plus each provider’s own billing reports is enough to see where money goes. Add a reporting service only if you need one view across many accounts that you cannot maintain yourself.

Storage, privacy, and exports

  • Do not log prompts or completions unless you have a specific need. Token counts, model names, timestamps, and labels answer the cost question without storing user content.
  • Export regularly. Write a CSV or JSON snapshot of the ledger for backup and for reconciliation. Keep copies outside the machine that generated them.
  • Version the price table. Keep it in version control, with a date on each entry, so you can recompute any past estimate.

“

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.