Prompt

What should I use to track token usage and cost per request?

Technology / Observability2 observationsLast seen Nov 22, 2026

Latest observation

Nov 22, 2026OpenAI APIWeb search: off

A good rule of thumb:

  • Use your LLM provider’s built-in usage data for the source of truth when available.
  • Use your app logs/observability to track per-request token usage and estimated cost.

What to track per request

At minimum, log:

  • request_id
  • model
  • input_tokens
  • output_tokens
  • total_tokens
  • estimated_cost
  • latency_ms
  • user_id / tenant_id / session_id if relevant
  • timestamp

Best options

1. In-app middleware / wrapper

Best for precise per-request tracking.

Wrap every LLM call and record:

  • prompt length
  • completion length
  • usage returned by the API
  • pricing lookup to compute cost

This is the most reliable if you want request-level accounting.

2. Observability tools

Good if you want dashboards, traces, and alerting:

  • OpenTelemetry + your logging/metrics backend
  • LangSmith
  • Helicone
  • Arize Phoenix
  • W&B Weave
  • PromptLayer

These can help you inspect prompts, latency, errors, and token usage.

3. Provider dashboards

Good for billing and aggregate usage:

  • OpenAI usage dashboard
  • Anthropic usage dashboard
  • Google/Azure equivalents

These are useful for finance/billing, but usually not enough for per-request debugging.

Recommended setup

If you want something practical:

  1. Wrap every model call in middleware
  2. Log token usage and cost to your app logs
  3. Send traces to an observability tool
  4. Use provider billing dashboards for reconciliation

Simple implementation idea

Store pricing in config and compute:

cost = (input_tokens / 1_000_000) * input_rate
     + (output_tokens / 1_000_000) * output_rate

If you want, I can also give you:

  • a Python example
  • a Node.js example
  • or a database schema for tracking token usage per request.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (2 observations for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.