Guide
How to improve query speed before you change the model
Problem
A user waits a long time for an answer because the bot sends a long prompt, then makes several model calls in sequence. The first visible text arrives late. A model change is not the first fix. OpenAI tells you to measure where users wait before you change the model or the prompt.
Method
OpenAI gives seven principles for latency.
- Measure time to first token, and end-to-end time from the user action to the complete result.
- Use a smaller or faster model when that model meets your quality target. Keep the fastest configuration that is good enough.
- Ask for a short answer. Request only the fields that you use. For routine work, use a lower reasoning effort if the API supports it.
- Send fewer input tokens. Keep only the context that the answer needs. Put stable instructions first so that prompt caching can reuse an exact prefix.
- Make fewer requests. Combine steps when one request has all the information that it needs.
- Run independent lookups at the same time. Do not wait for one lookup if the next lookup does not need its result.
- For interactive text, set
streamto true and show text as it arrives. The user can start to read before generation is complete. - Do not use an LLM when application code already has the answer.
On the OpenAI Responses API, max_output_tokens caps reasoning tokens and visible output tokens. A low cap can leave the response incomplete. Use the cap as a budget, and check the response status.
xAI also tells you to prefer streaming. Prompt caching can decrease the time to process a repeated prefix. OpenAI states that cached input is cheaper, and that the model can spend less time on that prefix before the response starts. OpenAI does not publish one latency percentage on that guide. Do not invent a speed gain.
Result
The first visible text can arrive sooner with streaming and a prompt-cache hit. End-to-end time can decrease when you cut tokens, merge sequential calls, and run independent work in parallel. A faster model helps after these steps, not in place of them. Measure time to first token and end-to-end time before and after each change.
Sources
- OpenAI, Latency optimization: https://developers.openai.com/api/docs/guides/latency-optimization
- OpenAI, Prompt caching: https://developers.openai.com/api/docs/guides/prompt-caching
- xAI, Best Practices Guide: https://docs.x.ai/developers/model-capabilities/text/best-practices