Prompt

I'm building an LLM product and need prompt analytics tied to cost and latency

Artificial Intelligence / MLOps2 observationsLast seen Nov 22, 2026

Latest observation

Nov 22, 2026OpenAI APIWeb search: off

Absolutely — for an LLM product, prompt analytics should connect what was sent to the model with what it cost, how long it took, and ideally what happened downstream.

Here’s a practical framework you can implement.

1) Core metrics to track per request

Cost

Track at least:

  • input_tokens
  • output_tokens
  • total_tokens
  • model_name
  • provider
  • unit pricing at the time of request
  • estimated_cost
  • actual_cost if available from provider billing

Latency

Track:

  • request_start_ts
  • first_token_latency_ms if streaming
  • end_to_end_latency_ms
  • queue_time_ms if you have internal routing
  • provider_latency_ms if exposed
  • retry_count
  • timeout_flag

Prompt analytics

Store:

  • prompt_template_id
  • prompt_version
  • system_prompt_hash
  • user_prompt_hash
  • tool_calls_count
  • retrieval_docs_count
  • context_window_usage_pct
  • prompt_length_chars/tokens
  • structured fields extracted from the request

Quality / outcome

If possible:

  • success/failure
  • user_rating
  • task_completion_flag
  • regeneration_count
  • fallback_used
  • error_type
  • hallucination / policy / refusal labels

2) Minimum event schema

A good request-level schema:

{
  "request_id": "uuid",
  "timestamp": "2026-11-22T12:34:56Z",
  "user_id": "hashed-or-internal-id",
  "session_id": "uuid",
  "app_id": "my-product",
  "environment": "prod",

  "provider": "openai",
  "model": "gpt-4.1-mini",
  "prompt_template_id": "support_reply_v3",
  "prompt_version": "3.2.1",

  "input_tokens": 1200,
  "output_tokens": 220,
  "total_tokens": 1420,
  "estimated_cost_usd": 0.0048,

  "request_start_ts": 1730000000.123,
  "first_token_latency_ms": 480,
  "end_to_end_latency_ms": 1530,
  "retry_count": 0,
  "timeout": false,

  "tool_calls_count": 1,
  "retrieval_docs_count": 4,
  "context_window_usage_pct": 62,

  "status": "success",
  "error_type": null
}

3) Useful derived metrics

Once you collect raw events, derive:

Efficiency

  • cost per successful task
  • latency per successful task
  • tokens per successful task
  • output tokens per input token
  • cost per 1k tokens
  • latency per 1k tokens

Quality-adjusted economics

  • cost per accepted response
  • cost per resolved ticket
  • cost per conversion
  • cost per high-rated response

Prompt optimization signals

  • Which prompt versions have:
    • highest cost
    • highest latency
    • lowest success rate
    • most retries
    • highest output token inflation

4) Analytics slices that are especially useful

Break down by:

  • prompt_template_id
  • prompt_version
  • model
  • tenant/customer
  • user cohort
  • task type
  • channel (chat, email, API, agent)
  • language
  • region
  • tooling path (RAG/no RAG, tools used, function calling)
  • request size buckets
  • time of day

This helps answer:

  • “Which prompt versions are expensive?”
  • “Which tasks are slow?”
  • “Does adding retrieval reduce cost or increase latency?”
  • “Which model is cheapest for acceptable quality?”

5) How to tie prompt text to analytics safely

Don’t log raw prompts everywhere by default. Instead:

  • Store prompt hashes for deduping and grouping
  • Store template IDs + version
  • Redact or tokenize sensitive user content
  • Optionally keep raw prompts in a restricted audit store

A common pattern:

  • hot analytics table: metadata only
  • secure archive: raw prompt/response with redaction controls

6) Dashboards worth building

Executive dashboard

  • total requests
  • total spend
  • average latency
  • success rate
  • spend by model
  • latency by model

Prompt dashboard

  • spend by prompt template/version
  • latency by prompt template/version
  • token distribution
  • regression detection after prompt changes

Debug dashboard

  • request trace
  • prompt input/output
  • tool calls
  • retrieval chunks
  • retries/errors
  • timing breakdown

7) Implementation tips

Instrument at the wrapper layer

Wrap every model call so you capture:

  • prompt metadata
  • token counts
  • timing
  • provider response
  • retries/errors

Use trace IDs

Propagate:

  • request_id
  • session_id
  • trace_id across your app and model calls so you can join analytics later.

Store timestamps in a standard way

Use epoch ms or RFC3339 UTC.

Capture token counts from provider if possible

Provider-reported token usage is better than estimates.


8) Example table design

llm_requests

  • request_id
  • timestamp
  • user_id
  • session_id
  • app_id
  • prompt_template_id
  • prompt_version
  • model
  • provider
  • input_tokens
  • output_tokens
  • total_tokens
  • estimated_cost_usd
  • first_token_latency_ms
  • end_to_end_latency_ms
  • retry_count
  • status
  • error_type

llm_request_events

For more detailed traces:

  • request_id
  • event_type
  • event_ts
  • payload_json

Examples: prompt_rendered, model_called, first_token_received, tool_called, response_postprocessed.


9) If you want to optimize cost and latency automatically

You can add:

  • model routing based on prompt/task difficulty
  • prompt length budgets
  • dynamic truncation/summarization
  • response length caps
  • cache for repeated prompts
  • fallback to cheaper models
  • A/B testing on prompt versions

If you want, I can help with any of these next:

  1. a production-ready analytics schema
  2. a Postgres / BigQuery table design
  3. a LangChain / OpenAI / Anthropic instrumentation example
  4. a dashboard spec for cost + latency + prompt versions

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.