Summary
A common enhacement to minimize latency for http calls is to make use of a keep alive connection. This prevents a lot of the back and forth chatter between the server and your client and reduces latency on subsequent calls. The further your distance to the server, the more significant the improvement. Read more about this topic by searching “keep alive connections”.How to do this
We can’t go over every possible library/language combination, so the high level recommendation is to lookup “set keep alive connection in insert lang/lib”. The some common cases:- Python requests use
session = requests.Session() - The OpenAI sdk does this by default
- JavaScript fetch set
fetch(url, {keepalive: true}) - Golang net/http does this by default
- Python
- JavaScript