The short answer

For a small team, start with a request ledger and a small set of metrics. Record each logical user request separately from each outbound model call, then track four things: demand, latency, errors, and cost.

Do not buy a full analytics platform until your logs cannot answer basic questions such as:

  • How many customer requests arrived?
  • How many model calls did those requests cause?
  • Which endpoints, customers, models, or features drove the volume?
  • Which calls failed, retried, timed out, or exceeded a token budget?
  • Is traffic rising because customers are using the product more, or because an agent is looping?

That distinction matters more than a polished dashboard. Usage growth is healthy only when it represents useful customer demand.

This guide provides a practical framework for separating actual demand from retries and agent loops, selecting appropriate metrics, and determining when your logs are sufficient.

Monitoring and usage analytics answer different questions

Monitoring asks, “Is the API working for customers right now?” Usage analytics asks, “How are customers using the product, and what should we change?”

Both can start from the same measurements, but their time horizons differ. Monitoring typically operates on short windows to catch rising latency or failures. Analytics examines days and months of usage to reveal popular features, expensive workflows, and customers whose behavior may indicate a reliability problem.

For a small team, distinguish four layers:

  1. Demand: logical requests initiated by users or scheduled jobs.
  2. Upstream activity: model calls and other provider requests made to complete those requests.
  3. Service quality: latency, error rate, timeouts, and rate-limit responses.
  4. Economics and behavior: tokens, cost, retries, and repeated tool calls.

A common mistake is to use upstream request count as a proxy for customer demand. A single customer action can produce one model call, ten calls, or no model call at all. That makes provider traffic a poor standalone measure of product adoption.

The minimum metric set

A useful first dashboard needs both counts and distributions. Counters tell you how often something happened; histograms reveal whether a small number of unusually slow or large requests are distorting the average.

1. Logical request volume

Count requests entering your product boundary, before retries or internal orchestration. Break this down by API endpoint, customer or account, plan, and feature where appropriate.

Keep this count separate from model-call volume. If logical requests rise from 100 to 200 while model calls rise from 100 to 2,000, customer adoption may be healthy but an agent workflow is malfunctioning.

2. Model calls per logical request

Track the distribution, not only the average. Useful dimensions include:

  • Input and output tokens
  • Model and provider
  • Feature or workflow
  • Attempt number
  • Tool call count
  • Final status

A rising median may signal a product change. A rising p95 or p99 can reveal heavy users or agent loops that averages hide.

3. Latency distributions

Record end-to-end latency from the customer request and upstream latency separately. Track at least p50, p95, and p99 rather than relying only on a mean.

Do not combine every model call in a workflow into one undifferentiated duration. A response may feel slow because of model generation, queueing, rate-limit retries, a slow tool, or application processing. Keep the major phases distinguishable.

4. Errors by class and attempt

Count failures by useful categories rather than treating every non-2xx response alike:

  • Authentication or authorization failures
  • Invalid requests
  • Rate limits
  • Timeouts
  • Provider or upstream failures
  • Application exceptions
  • Cancelled or abandoned requests

Also count retries separately. The first attempt and the third attempt should not disappear into one aggregate error rate.

5. Token and cost usage

AI API token usage metrics should record input tokens, output tokens, cached tokens where the provider reports them, and the associated cost. Break them down by model, feature, customer, and logical request.

A total bill tells you what you paid. Usage analytics tells you which product decision created that bill. Keep both.

6. Rate-limit and saturation signals

Track upstream 429 responses, remaining or reset information when available, queue depth, and concurrency. These reveal whether a traffic increase is approaching a quota or capacity limit.

For a detailed method for planning quota across providers, see Forecasting Your API Rate-Limit Budget Across Multiple Upstreams.

The key model: one logical request can contain many provider calls

Create a request identifier at your public API boundary. Pass it through your application into every downstream provider call. Also create a separate attempt identifier for each network attempt.

A useful record has this shape:

request_id: rq_123
customer_id: customer_456
feature: document_summary
provider_call_id: pc_789
attempt: 2
model: provider/model-name
input_tokens: 4200
output_tokens: 380
status: success
retry_reason: upstream_timeout
duration_ms: 1850

This may look like log data, and that is fine. The objective is to establish a reliable event model before choosing a metrics backend.

Do not label an internal or upstream request as the same logical request merely because it shares an HTTP handler. Retries, parallel subtasks, and agent tool loops need separate attempt or call identities.

Separating customer demand from retries

A retry usually creates another provider call with the same logical objective. Classify it as an attempt, not a new request.

For each logical request, calculate:

attempts = number of provider calls made for that logical request

Then segment model-call volume into:

  • First-attempt calls
  • Retry calls
  • Calls generated by parallel tools or subtasks
  • Additional calls caused by an agent continuation loop

A simple warning signal is the proportion of provider calls that are retries. If 30% of calls are retries, a dashboard may still show healthy request volume while customers are experiencing degraded latency and your costs are rising.

Do not infer retries from identical prompts alone. Two genuine customer actions can produce identical prompts. Use the request ID, attempt metadata, and error context to establish the relationship.

Detecting agent loops without guessing

An agent loop usually appears as repeated tool or model calls attached to one logical request. The exact pattern depends on your architecture, but common indicators include:

  • The number of calls per request grows sharply.
  • The same tool is called repeatedly with similar arguments.
  • A run continues without meaningful state change.
  • Token consumption rises while completed tasks or successful outcomes do not.
  • A run reaches a step, time, or token ceiling that is usually far above normal behavior.

Track these metrics:

  • Calls per logical request
  • Steps per agent run
  • Repeated tool calls within a run
  • Consecutive failures of the same operation
  • Run duration
  • Tokens consumed per completed outcome

Then set guardrails based on your product’s normal workflows rather than an invented universal threshold. A research assistant that legitimately uses many steps should not be judged like a one-shot summarization endpoint.

If you already run agent workloads, the MCP Server Timeouts and Retries guide covers how timeout and retry policy affects duplicate work and incident amplification.

A practical request-to-metric model

OpenTelemetry is useful here because it provides a vendor-neutral way to instrument metrics, logs, and traces. Counters fit cumulative events such as requests, provider calls, retries, and errors. Histograms fit latency, token volume, payload size, and call counts per logical request. Up-down counters or gauges represent changing values such as active requests or queue depth.

The instrumentation should attach bounded, useful dimensions. A provider call might be labeled by:

service.name
http.route
server.status_code
ai.provider
ai.model
ai.operation.name
retry.attempt
feature
customer.plan

Avoid unbounded dimensions in metric labels. User IDs, prompt text, request IDs, and full error messages create high-cardinality metric series. Put those in logs or traces, where event context belongs, and link back from a dashboard sample.

The same division of labor applies beyond OpenTelemetry:

Signal Best for Example
Metrics Trends, alerts, distributions p95 latency, error rate, tokens per request
Logs Individual events and investigation provider error details, retry reason, request identifiers
Traces One request across components application call, model call, and tool call sequence

Metrics should reveal that something is wrong. Logs and traces should help explain why.

When simple logs are enough

Logs are sufficient while your product has modest traffic, a small number of endpoints and workflows, and no proven need for percentile dashboards or alerts. A structured log line with the fields above can support weekly usage reviews and most incident investigations.

Move beyond logs when at least one of these becomes true:

  • You cannot answer which feature or customer causes usage growth without running ad hoc queries.
  • Alerts require aggregation across many instances.
  • You need p95 or p99 latency rather than individual timings.
  • Usage and errors must be segmented by model, route, customer tier, or attempt.
  • Multiple upstream providers need comparable measurements.
  • Support needs usage evidence without access to raw logs.
  • You need retained trend data to forecast quota or spend.

Even then, do not assume you need a complete observability platform. OpenTelemetry-compatible collection and a lightweight metrics backend may cover your immediate needs. A collector can receive and process telemetry, then export it to systems such as Prometheus or Grafana. The important architectural decision is instrumenting a stable event model first; the export destination can change later.

A seven-day adoption plan

Day 1: Define the request boundary

Write down what counts as one logical customer request. Identify where retries, parallel jobs, and agent steps begin. Create request_id, provider_call_id, and attempt fields.

Day 2: Instrument the four baseline signals

Add request count, provider-call count, latency, and error class. Record input and output tokens at the same time, even if the first dashboard does not display them.

Day 3: Add retry and loop indicators

Annotate every retry with its reason. Track calls per logical request and repeated tool calls per agent run. Preserve the original logical request identifier.

Day 4: Build one operational view

Display logical requests, provider calls, success rate, p50/p95/p99 latency, retries, and tokens. Segment by endpoint, model, feature, and customer tier.

Day 5: Build one usage view

Compare the same dimensions over days and weeks. Include cost per logical request and cost per successful outcome. Identify features that consume disproportionate tokens or calls.

Day 6: Define alerts and budgets

Create a small number of actionable alerts, such as sustained upstream error-rate changes, rising p95 latency, and abnormal retry share. Add token or step budgets where runaway behavior has a clear operational cost.

Day 7: Review what the team actually used

If nobody queries a metric, does not act on an alert, or cannot explain a customer’s usage during support, remove or redesign it. Instrumentation is useful only when it changes a decision or shortens an investigation.

Metric-card template

Use a consistent card for every important metric:

Name:
Question it answers:
Source event:
Dimensions:
Aggregation window:
Owner:
Alert threshold and rationale:
How it influences a product or reliability decision:

This template prevents a dashboard from becoming a collection of attractive but unusable numbers.

Common mistakes

Counting provider calls as customer requests

This inflates apparent demand whenever an agent uses more tools or a request retries.

Using averages for latency and token usage

A few huge requests can hide the customer experience of the typical request. Use distributions and segment them.

Recording only final status

A call that failed twice and then succeeded should not look identical to a first-attempt success. You lose retry rate, added latency, and cost.

Attaching prompts to metric labels

Prompt text, request IDs, and user identifiers are high-cardinality data. Keep them in logs or traces and use bounded dimensions for metrics.

Building analytics before deciding the questions

Start with the decisions you need to make: protect uptime, understand feature usage, control spend, and catch runaway agents. The metrics follow those decisions.

Treating a vendor dashboard as product analytics

Provider dashboards tell you about provider consumption. Your own telemetry must connect that consumption to customer demand, workflow outcomes, and revenue-relevant features.

Frequently asked questions

Do I need tracing if I already have logs?

Not immediately. Logs can solve the early-stage questions above. Add tracing when you need to follow a single request through your application, model provider, and tools, especially during complex agent failures. Metrics can use exemplars to link an unusual aggregate sample to a trace, but that capability does not remove the need for a deliberate correlation strategy.

Should token usage be a metric or a log field?

Use both for different purposes. Record tokens as metric observations for aggregation by model, feature, and customer. Preserve tokens on individual request events for investigation and billing reconciliation. Do not expect every backend to support the same histogram or log-query behavior.

How do I compare API usage across customers?\n

Start with logical requests per active customer, then add provider calls and tokens per logical request. Ratios expose customers whose workflows are disproportionately expensive or retry-heavy. Keep the view private and avoid publishing individual customer values without appropriate controls.

When is an API analytics tool worth its overhead?

Add one when your questions have become recurring, manual, and expensive to answer with logs. The business case is usually better incident response, faster product prioritization, earlier detection of runaway agents, or more accurate spend attribution—not merely having a prettier dashboard.

The founder’s decision

For a founder, API usage analytics is not an infrastructure ornament. It is a control system for three business risks:

  1. Customers cannot reliably use the product you are selling.
  2. Engineering cannot distinguish healthy demand from runaway orchestration.
  3. You cannot explain or forecast the infrastructure cost of delivering value.

Start with structured request logs, a stable identifier model, and five durable measurements: logical requests, provider calls, latency distributions, classified errors, and token usage. Add retries and agent-loop indicators before adopting elaborate analytics infrastructure.

Once manual analysis becomes repetitive, instrument those events with OpenTelemetry or an equivalent standard. Let metrics expose trends, logs preserve individual evidence, and traces explain multi-step paths. That sequence gives a small team more operational leverage without buying complexity before it has a job.

Sources