Practical techniques for reducing perceived and real latency in OpenDunes API integrations.
Latency has two faces: the wall-clock time until you receive the full response, and the time until your user sees the first token. These are different problems with different solutions.
The single highest-impact change is enabling streaming. Set "stream": true and render tokens as they arrive — your UI feels instant even on a 5-second full-response.
The server sends Content-Type: text/event-stream. Each data: line is a JSON delta chunk; the final line is data: [DONE]. See Streaming for full details.
Time-to-first-token varies by model size and provider. When your use case does not require a frontier model, smaller/faster models cut latency significantly and cost less DA per token.
A rough guide:
| Use case | Suggested tier |
|---|---|
| Quick classification, extraction | Small instruct models (e.g. meta-llama/llama-4-maverick) |
| General Q&A, summaries | Mid-tier (e.g. google/gemini-2.5-pro) |
| Complex reasoning, long documents | Frontier (e.g. anthropic/claude-opus-4.8) |
Browse the full catalog at /models. Sort by price or name to find faster alternatives.
Every input token adds latency. Avoid including boilerplate that the model does not need:
If you know the response will be short, set max_tokens explicitly. This prevents the model from generating a long answer when a brief one suffices, and it allows the server to allocate resources more efficiently.
Each TCP handshake adds round-trip overhead. Use persistent connections (HTTP keep-alive) or a connection pool. The OpenAI SDK handles this automatically — if you are using raw fetch or requests, configure a session/agent with keep-alive.
Not yet available. The Responses API lets you continue a conversation by ID rather than resending the full
messagesarray, cutting payload size on long threads.
Each response includes rate limit and balance headers you can use to tune request pacing:
X-RateLimit-Remaining-RPM — requests remaining in the current minute.X-RateLimit-Reset — Unix timestamp when the window resets.X-Balance-Available — remaining balance in micro-DA.Back off proactively when X-RateLimit-Remaining-RPM is low, rather than waiting for a 429.