Hetzner Inference API is compatible with the OpenAI API. You can use it with cURL or with the official OpenAI SDKs for Python and JavaScript. This guide shows you how to authenticate, list the available models, and generate text with a chat model. To learn how to create embeddings, see Creating embeddings.
Base URL and authentication
Send all requests to the following base URL:
https://inference.hetzner.com/v1Authenticate every request with your Inference Token in the Authorization header:
Authorization: Bearer <your-inference-token>Storing the Inference Token in an environment variable
Do not write your Inference Token directly into your code. Store it in an environment variable or in a .env file that you do not commit to your repository. The examples in this guide read the Inference Token from the HETZNER_INFERENCE_TOKEN variable:
export HETZNER_INFERENCE_TOKEN="<your-inference-token>"Listing the available models
Use GET /models to list the models you can use with your Inference Token:
curl https://inference.hetzner.com/v1/models \
-H "Authorization: Bearer $HETZNER_INFERENCE_TOKEN"The id field of each entry contains the model name that you use in the model field of your requests. For an overview of all models and their licenses, see Models and licenses.
Sending a chat completion
Use POST /chat/completions to send a message to a model and get its answer.
cURL
curl https://inference.hetzner.com/v1/chat/completions \
-H "Authorization: Bearer $HETZNER_INFERENCE_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "zai-org/GLM-5.3-Flash",
"messages": [{"role": "user", "content": "Hello!"}]
}'Python
Install the OpenAI SDK:
pip install openaiimport os
from openai import OpenAI
client = OpenAI(
base_url="https://inference.hetzner.com/v1",
api_key=os.environ["HETZNER_INFERENCE_TOKEN"],
)
response = client.chat.completions.create(
model="zai-org/GLM-5.3-Flash",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)JavaScript
Install the OpenAI SDK:
npm install openaiimport OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://inference.hetzner.com/v1",
apiKey: process.env.HETZNER_INFERENCE_TOKEN,
});
const response = await client.chat.completions.create({
model: "zai-org/GLM-5.3-Flash",
messages: [{ role: "user", content: "Hello!" }],
});
console.log(response.choices[0].message.content);The model's answer is in the choices[0].message.content field.
Setting the reasoning level
For models with reasoning, use the reasoning_effort parameter to set how much the model reasons before it answers. To see which levels a model supports, go to Models and licenses.
curl https://inference.hetzner.com/v1/chat/completions \
-H "Authorization: Bearer $HETZNER_INFERENCE_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "zai-org/GLM-5.3-Flash",
"messages": [{"role": "user", "content": "What is 2 + 2?"}],
"reasoning_effort": "low"
}'If the model reasons, the response contains its reasoning in the reasoning field next to content. The usage.completion_tokens_details.reasoning_tokens field shows how many tokens the model used for reasoning.
Please note: Reasoning tokens are part of
completion_tokensand count towardmax_tokens. If you setmax_tokenstoo low, the model can reach the limit before it finishes its answer. If reasoning uses up the whole limit,contentis missing from the response or empty, andfinish_reasonhas the valuelength. In this case, increasemax_tokensor choose a lower reasoning level.
In the Python SDK, pass the parameter directly to client.chat.completions.create(), for example reasoning_effort="low".
Streaming responses
Set "stream": true to receive the answer in parts while the model generates it. The API sends the response as server-sent events (text/event-stream). Each event starts with data: and contains a chunk with the new text in choices[0].delta.content. If the model reasons, the reasoning arrives in choices[0].delta.reasoning.
cURL
curl -N https://inference.hetzner.com/v1/chat/completions \
-H "Authorization: Bearer $HETZNER_INFERENCE_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "zai-org/GLM-5.3-Flash",
"messages": [{"role": "user", "content": "Hello!"}],
"stream": true
}'The -N option turns off the output buffer of cURL, so that you see each chunk right away.
Python
stream = client.chat.completions.create(
model="zai-org/GLM-5.3-Flash",
messages=[{"role": "user", "content": "Hello!"}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
print()JavaScript
const stream = await client.chat.completions.create({
model: "zai-org/GLM-5.3-Flash",
messages: [{ role: "user", content: "Hello!" }],
stream: true,
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content;
if (content) process.stdout.write(content);
}