1
Streaming
interactive · perceived speed
Example: the agent-assist chat that drafts a reply while the support agent watches.
- Send tokens as they are generated over SSE or WebSockets. The full answer still takes seconds, but the user starts reading in under one.
- Measure time to first token (TTFT) and tokens per second, not total latency.
- Handle cancellation: when the user hits stop or closes the tab, abort the model call so you stop paying for tokens no one will read.
- Run output guardrails on chunks or sentences, and have a way to retract text that fails a check.
"For chat I stream, because what users feel is time to first token. A 12-second answer that starts in 600 ms feels fast."
streaming JSON that code has to parse. Partial JSON is not valid JSON. Stream to people, not to parsers.
2
Sync request/response
short · needed before the next step
Example: classify each incoming ticket's intent and extract the order ID as JSON, then route it.
- Short, structured output that code consumes whole. Nothing useful to show halfway.
- Use small, fast models and keep outputs short: output tokens are the slow part.
- Set a timeout and a retry budget, and have a fallback (a rule, a default queue) when the call fails.
- Validate against a schema before the next step uses it.
"Intent classification sits in the request path, so it's a sync call to a small model with a 3-second timeout and a default route if it fails."
a sync call with no timeout. One slow provider response holds a thread and can cascade through the workflow.
3
Async job
seconds to hours
Example: "Summarise this customer's last 200 tickets into an account report." An agent reads, calls tools and writes for several minutes.
- Accept the job, return a job ID at once, and do the work in a worker that reads from a queue.
- Give a status API and a webhook or push notification when it's done.
- Checkpoint long work, so a crashed worker resumes from step 7 instead of step 1.
- Show progress: "Reading 200 tickets… Grouping issues… Writing summary".
"Anything that can run past the gateway timeout becomes a job: 202 with a job ID, a queue, workers with checkpoints, then a status endpoint and a webhook."
holding an HTTP connection open for minutes. It works in dev, then dies at the load balancer in production.
4
Batch
hours acceptable
Example: every night, tag all of the day's tickets by topic and sentiment for the analytics dashboard. Or backfill embeddings for the whole knowledge base.
- Use the provider's batch API: upload a file of requests, collect results within a window (often 24 h), usually at about 50% off.
- Batch traffic doesn't use your real-time rate limits, so it doesn't compete with live users.
- Self-hosted: run on spare or spot GPUs with big batch sizes, optimising for throughput, not latency.
- Make each item retryable on its own, and keep a record of which IDs are done.
10M items × 500 tokens = 5B tokens · at $1 per 1M ≈ $5,000 live, ≈ $2,500 batch (illustrative)
"If no one is waiting, I use the batch API. It's about half the price and stays out of my live rate limits."
looping over 10 million items with the real-time API. You hit rate limits, pay full price and slow down live traffic.