Simple client throttling (Python)
Useasyncio.Semaphore to control concurrency:
Exponential backoff
Token-bucket rate limiting
aiolimiter implements a client-side token bucket in Python:
Use the response headers
Every response carries remaining-quota headers, enabling adaptive throttling:Batching tips
- Merge short requests: concatenate several independent prompts into one large request (use a system prompt to delimit tasks).
- Embed many texts at once:
inputaccepts an array, up to ~2048 items per call. - Rerank many documents at once:
documentscan hold tens to hundreds at a time. - Streaming + early stop: if the answer length is controllable, have the model output a JSON header first and use a stop sequence to end early on the client.
Increase your quota
If the strategies above still can’t meet your needs, consider:- Top up to raise your account level for higher quotas.
- Apply for a dedicated quota and isolated channel via enterprise sales.
Monitoring
- Console → Usage statistics: watch daily peak RPM / TPM.
- Client logs: print the
Retry-Afterandx-ratelimit-*headers to locate the rate-limit bottleneck. - Integrate Prometheus / Grafana for your own monitoring: report spend / tokens / latency for each call.