> ## Documentation Index
> Fetch the complete documentation index at: https://docs.deepinfra.com/llms.txt
> Use this file to discover all available pages before exploring further.

# HTTP/2

> api.deepinfra.com supports HTTP/2 — fewer connections and handshakes for clients that send many requests.

`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.

## Which clients use it

* **Browsers, `curl`, and Go's `net/http`** use HTTP/2 automatically. For `curl`, that needs a build with
  HTTP/2 support (`curl -V` lists `HTTP2`; most do). In Go it's the default transport; a custom `http.Transport`
  with its own TLS config needs `ForceAttemptHTTP2: 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 undici
  `Agent` with `allowH2: true` to opt in. Node 26's `fetch` is built on undici 8, which offers HTTP/2 by default.

```python Python theme={null}
# 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)
```

```javascript JavaScript theme={null}
// 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);
```

```bash cURL theme={null}
# 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"
```

## Good to know

* **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 offer `h2` in its ALPN list: offering it makes Go's `gorilla/websocket` fail with
  `websocket: protocol "h2" was given but is not supported`, usually because its `tls.Config` is shared with
  an `http.Transport`.
* **Streaming, uploads, and [request compression](https://docs.deepinfra.com/request-compression.md)** work the same over HTTP/2
  as over HTTP/1.1.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.