Skip to main content
DeepInfra accepts gzip-compressed request bodies. For large payloads — long chat histories, big embeddings batches, sizable inputs — compressing the request shrinks the bytes you upload (JSON and text typically compress 4–8×), which lowers your egress and can speed up requests over slower or metered connections. To use it, gzip the request body and set the Content-Encoding: gzip header. It works on every HTTP API endpoint (chat completions, embeddings, files, and the rest), including requests whose response streams back — the request body is a single upload regardless of how the response is returned.

With the OpenAI SDK

The OpenAI SDKs don’t compress requests on their own, but a small hook gzips every JSON request body they send. Responses, retries, and streaming are unaffected.
Both hooks leave file uploads as they are.
  • Python needs openai 1.17 or later.
  • JavaScript needs openai 5 or later, on Node.js, Bun, or Deno.
With AsyncOpenAI, wrap the Python hook in an async def and pass it to DefaultAsyncHttpxClient:

Without an SDK

Gzip the JSON body yourself and send it with Content-Encoding: gzip:

When it helps

The savings grow with the size of the request: long conversations, large embeddings batches, and big inputs upload a fraction of the bytes. For a tiny body like a one-word prompt, gzip adds a few bytes, which is harmless, so the hooks above simply compress everything.
gzip only. Content-Encoding: gzip is the only supported request compression. Other codings (deflate, br, zstd) are not decompressed — a body compressed with those will fail to parse. Use gzip.