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.- Python needs
openai1.17 or later. - JavaScript needs
openai5 or later, on Node.js, Bun, or Deno.
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 withContent-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.