Per-Model Latency and Token Usage Report from Request Logs

Last updated: November 29, 2026

Quick Overview

Using an inference request log table, compute for each model and day the request count, total billed tokens, median and p95 time to first token, and the share of requests that errored.

Together AI
Data Manipulation (SQL/Python)
Data Engineer
Together AI
November 29, 2026
Data Engineer
Technical Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Using an inference request log table, compute for each model and day the request count, total billed tokens, median and p95 time to first token, and the share of requests that errored.

Together AI serves many open models on shared infrastructure, and model owners and the inference team watch daily dashboards of latency and usage per model. This SQL screen checks percentile functions, conditional aggregation, and care about which rows belong in which metric (errors should count in error rate but not distort latency).

What the Interviewer Expects
  • Groups by model and calendar day correctly
  • Uses percentile_cont or an equivalent for median and p95
  • Excludes failed requests from latency percentiles but includes them in the error rate
  • Computes billed tokens as prompt plus completion
  • Avoids integer division in the error share
Key Topics to Cover
SQL aggregation
percentiles
conditional aggregation
latency metrics
usage reporting
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you compute p95 if your warehouse has no exact percentile function on billions of rows?
  • How would you report inter-token latency instead of time to first token?
  • How would you break this down for dedicated endpoints versus serverless traffic?
  • What index or partitioning would make this query cheap to run hourly?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

Assume requests(request_id, api_key, model, created_at, status, prompt_tokens, completion_tokens, ttft_ms) with status in ('ok','error') and ttft_ms null when the request failed before the first...

Approach

One pass grouped by model and DATE(created_at). Use COUNT(*) for volume, SUM with a CASE for billed tokens and errors, and ordered-set aggregates with a FILTER clause so percentiles only s...


Submit Your Answer
Markdown supported

Related Questions