| title | HTTP/2 |
|---|---|
| description | api.deepinfra.com supports HTTP/2 — fewer connections and handshakes for clients that send many requests. |
| icon | network-wired |
api.deepinfra.com supports HTTP/2. Clients negotiate it automatically during the TLS
handshake, so there is nothing to configure on the DeepInfra side, and clients that only speak
HTTP/1.1 keep working exactly as before.
HTTP/2 runs many requests over one connection at the same time. That helps most when you send many requests in parallel or call from far away: each new connection costs a TCP and TLS handshake (a few milliseconds nearby, a few hundred from another continent), and HTTP/2 pays that once instead of per connection. It does not make an individual request faster — model time is the same either way.
- Browsers,
curl, and Go'snet/httpuse HTTP/2 automatically. Forcurl, that needs a build with HTTP/2 support (curl -VlistsHTTP2; most do). In Go it's the default transport; a customhttp.Transportwith its own TLS config needsForceAttemptHTTP2: true. - The OpenAI Python SDK (httpx) uses HTTP/1.1 unless you turn HTTP/2 on, as below.
- The OpenAI Node SDK (Node's built-in
fetch) uses HTTP/1.1 on Node 24 and older. Use an undiciAgentwithallowH2: trueto opt in. Node 26'sfetchis built on undici 8, which offers HTTP/2 by default.
# pip install "httpx[http2]"
import os
from openai import DefaultHttpxClient, OpenAI
client = OpenAI(
api_key=os.environ["DEEPINFRA_API_KEY"],
base_url="https://api.deepinfra.com/v1/openai",
http_client=DefaultHttpxClient(http2=True), # AsyncOpenAI: DefaultAsyncHttpxClient(http2=True)
)
response = client.chat.completions.create(
model="deepseek-ai/DeepSeek-V4-Flash-0731",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)// npm install openai undici (Node 20 or Node 22 before 22.19: undici@7)
// Use undici's own fetch so the Agent and fetch come from the same undici version.
import OpenAI from "openai";
import { Agent, fetch } from "undici";
const dispatcher = new Agent({ allowH2: true }); // the default from undici 8; needed on undici 7
const openai = new OpenAI({
apiKey: process.env.DEEPINFRA_API_KEY,
baseURL: "https://api.deepinfra.com/v1/openai",
fetch: (url, init) => fetch(url, { ...init, dispatcher }),
});
const response = await openai.chat.completions.create({
model: "deepseek-ai/DeepSeek-V4-Flash-0731",
messages: [{ role: "user", content: "Hello!" }],
});
console.log(response.choices[0].message.content);# prints the status and the negotiated protocol, e.g. "200 2"
curl --http2 https://api.deepinfra.com/v1/openai/models \
-H "Authorization: Bearer $DEEPINFRA_API_KEY" \
-o /dev/null -w "%{http_code} %{http_version}\n"- Up to 100 concurrent requests per connection. This is per connection, not a rate limit. Beyond it, clients either open another connection (Go's default transport) or wait for a free slot (browsers, and httpx, which also caps itself at 100).
- Realtime WebSockets (
/v1/realtime) use HTTP/1.1. Browsers and the common WebSocket libraries open a separate HTTP/1.1 connection for them automatically. If you build your own TLS config for a WebSocket client, don't offerh2in its ALPN list: offering it makes Go'sgorilla/websocketfail withwebsocket: protocol "h2" was given but is not supported, usually because itstls.Configis shared with anhttp.Transport. - Streaming, uploads, and request compression work the same over HTTP/2 as over HTTP/1.1.