Lesson 2 of 4 Observability for Generative AI

Performance Metrics for Generative AI

This lesson explains the parts of generative AI latency, how throughput is limited, which metrics Azure Monitor provides, and why percentiles are used.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe time to first token and generation time.
  • Explain throughput limits and 429 responses.
  • Identify the deployment metrics in Azure Monitor.
  • Explain why targets use P95 and P99.

The parts of latency

A generative response is produced token by token, so its latency has several parts. The model first processes the prompt, then emits the first token, then generates the rest at a roughly steady rate. In a RAG application or agent, retrieval and tool calls add time before or between model calls.

ComponentDriven byReduced by
Time to first token (TTFT)Prompt length, model size, loadShorter prompts, prompt caching, smaller models, provisioned capacity
Generation timeNumber of output tokens, tokens per secondShorter outputs, maximum token limits, faster models
Reasoning timeReasoning effort of reasoning modelsLower reasoning effort, non-reasoning models for simple tasks
Retrieval and toolsSearch queries, reranking, API callsFewer steps, parallel calls, caching

Streaming returns tokens as they are generated, so users see the answer start after the time to first token rather than after the full response. It improves perceived latency without changing total latency.

Throughput and limits

Throughput is how much work a deployment handles: requests per minute and tokens per minute. Standard deployments are limited by their tokens per minute (TPM) and requests per minute (RPM) quotas; provisioned deployments are limited by their PTUs. Exceeding the limit returns HTTP 429, which clients should handle by honouring retry-after with exponential backoff, not by retrying immediately.

A rising 429 rate means demand has reached capacity. The options are more quota, another deployment or region behind a gateway, provisioned throughput, spillover from provisioned to standard, reducing tokens per request, or moving work that can wait to batch deployments.

Metrics in Azure Monitor

The Foundry resource publishes metrics per deployment in Azure Monitor, which can be charted, split by deployment and model, and used in alert rules. The most useful families are listed below.

  • Requests: counts of calls, splittable by status code to show errors and throttling.
  • Latency: time to response and time between tokens, which separate prompt processing from generation speed.
  • Tokens: prompt (input) tokens and generated (output) tokens processed per deployment.
  • Provisioned-managed utilization V2: the share of PTU capacity in use, for provisioned deployments.

Application-side traces add end-to-end timing, including retrieval and tool calls, which platform metrics cannot see, and allow latency to be broken down by feature, user group or prompt version.

Measuring with percentiles

Generative latency has a long tail: most requests are quick, a few are very slow, for example because they produce long answers or hit a busy period. An average hides the tail, so service targets are stated as percentiles: P50 (the median), P95 and P99.

Average latency
Example1.8 s
ShowsA blend of fast and slow requests
UseRough capacity trends
Choose when Trend dashboards
Percentile latency
ExampleP50 1.2 s, P95 6.5 s, P99 14 s
ShowsWhat most users and the slowest users experience
UseService targets and alerting
Choose when Targets, alerts and user experience
dependencies
| where timestamp > ago(1d) and name startswith "chat"
| summarize p50 = percentile(duration, 50), p95 = percentile(duration, 95), p99 = percentile(duration, 99)
    by bin(timestamp, 1h)
| render timechart
Worked example

Slow answers at peak

An assistant on a Global Standard deployment meets its P95 latency target of 5 seconds most of the day, but at the daily peak P95 rises to 12 seconds and the 429 rate rises to 6 percent. Traces show that retrieval takes 300 ms throughout, and that responses average 600 output tokens although the product team considers 200 enough.

Two causes combine. The deployment reaches its capacity at peak, so requests are throttled and retried; and responses are three times longer than needed, which lengthens generation time and consumes capacity. Limit output length with the prompt and max_tokens, stream responses, and add capacity for the peak, for example more quota or a provisioned deployment with spillover, then confirm the effect on P95 and the 429 rate.

Optimizing retrieval would save little, because it takes 300 ms. Retrying 429s immediately would increase load at the worst moment. Reporting average latency would make the peak look acceptable.

Check yourself

Why does streaming improve perceived latency without reducing total generation time?

Show answer

Streaming returns tokens as they are generated, so users see the answer after the time to first token, instead of waiting for the full response.

Exam Tips

Remember for the exam

  • Latency = time to first token + generation time (+ reasoning, retrieval and tools); streaming improves perceived latency.
  • TPM and RPM quotas or PTUs limit throughput; 429s mean capacity is exhausted.
  • Azure Monitor metrics cover requests, latency, tokens and PTU utilization per deployment.
  • State targets as P95 and P99, not averages.