If a request to Hetzner Inference API fails, the API returns an HTTP status code and a short error text. This page explains the status codes, their most common causes, and how to fix the error.
Handling errors
The API returns error texts in two formats:
- Plain text: Errors during authentication, routing, and parsing of the request, for example
unauthorizedorroute not found. - JSON: Errors during the validation of the request and errors of the model. The OpenAI-compatible endpoints use the format
{"error": {"message": "...", ...}}. The Anthropic-compatible endpoints use the format{"type": "error", "error": {...}}.
In both cases, the OpenAI and Anthropic SDKs raise the matching exception based on the status code, for example AuthenticationError or NotFoundError. If your code parses the error text as JSON, it also needs to handle plain text.
For this reason, always use the HTTP status code to handle errors in your application. The error texts on this page help you find the cause.
Please note: The wording of the error texts can change. Do not check for a specific text in your code.
Overview
| Status code | Meaning | Retry the request? |
|---|---|---|
400 Bad Request |
The request is invalid or contains a feature that the API does not support. | No, fix the request first. |
401 Unauthorized |
The Inference Token is invalid or the model name is unknown. | No, check the Inference Token and the model name. |
404 Not Found |
The endpoint does not exist or does not match the model. | No, check the path and the model. |
413 Content Too Large |
The request is larger than 32 MiB. | No, reduce the size of the request first. |
429 Too Many Requests |
The Inference Token reached its rate limit or its consumption cap. | Yes for the rate limit, after the time in the Retry-After header. No for the consumption cap. |
504 Gateway Timeout |
The request took longer than 300 seconds. | Yes, after you shorten the request. |
500 and higher |
An error occurred on the API side. | Yes, after waiting. |
400 Bad Request
For errors in JSON format, the error message usually names the field that failed the validation in param or loc.
| Error text (example) | Cause | Solution |
|---|---|---|
inference error: BadRequest - failed to parse request body: ... |
The request body is not valid JSON. | Check the JSON for missing brackets, commas, or quotation marks. In shell scripts, check how variables are inserted. |
Unsupported Media Type: Only 'application/json' is allowed |
The Content-Type: application/json header is missing. |
Send the header. With curl -d and without this header, cURL sends the data as a form. |
must have valid messages field or Field required |
A required field is missing or has the wrong type. | Add the field from the error message. On /v1/messages, max_tokens is a required field, as in the Anthropic API. |
No user query found in messages. |
The request contains no message with the role user, or it contains a role that the API does not know. |
Send at least one message with the role user. |
max_tokens=... cannot be greater than max_model_len=... |
max_tokens is larger than the context window of the model. |
Set a lower max_tokens value. For the context windows, see Limits. |
| JSON error about allowed domains | The request contains an image as an external URL. | Download the image yourself and send it as a base64 data URL, for example data:image/png;base64,.... |
Input should be 'text', 'image', ... |
The request to /v1/messages contains a content block of the type document or file. |
Extract the text yourself and send it as a text block. |
body.tools.0.input_schema: Field required |
The request to /v1/messages contains an Anthropic server tool. |
Use your own tools with input_schema. |
does not support the background mode |
The request to /v1/responses contains "background": true. |
Remove background and send a normal request, with streaming if needed. |
does not support Matryoshka embeddings |
The request to /v1/embeddings contains dimensions for a model that does not support it. |
Remove dimensions from the request. |
To see which features and parameters the API supports, go to Compatibility with OpenAI and Anthropic.
401 Unauthorized
| Error text | Cause | Solution |
|---|---|---|
unauthorized |
The Inference Token is missing, incomplete, or invalid, or you deleted it. | Send the full Inference Token exactly in the format Authorization: Bearer <your-inference-token>, without quotation marks and without a line break at the end. A line break is easy to add by accident when you read the Inference Token from a file. |
unauthorized |
The Inference Token is in the x-api-key header, as usual for the Anthropic API. |
Send the Inference Token in the Authorization: Bearer header. In the Anthropic SDK, pass it as auth_token (Python) or authToken (TypeScript). |
inference error: Unauthorized - unauthorized |
The model field is missing, the model name is misspelled, or your Inference Token cannot use the model. |
Copy the model name exactly from GET /v1/models, for example zai-org/GLM-5.3-Flash. Model names are case-sensitive. Names from other providers such as gpt-4o do not work. |
For unknown model names, the API returns 401 on purpose and not 404. This way, nobody can find out which other models exist.
Checking the Inference Token or the model
Use GET /v1/models to find out whether the error is caused by the Inference Token or by the model name. Use the same Inference Token as in the failed request:
curl https://inference.hetzner.com/v1/models \
-H "Authorization: Bearer $HETZNER_INFERENCE_TOKEN"- The API returns a list of models: Your Inference Token works. Copy the model name from the
idfield exactly as it is into your request. - The API returns
401: Your Inference Token does not work. In Hetzner Console, check whether the Inference Token still exists. If you no longer have the Inference Token, create a new one. For instructions, see Creating an Inference Token.
404 Not Found
| Error text | Cause | Solution |
|---|---|---|
route not found |
The API does not support the endpoint. | Use one of the supported endpoints. For the list, see Compatibility with OpenAI and Anthropic. |
route not found |
The path is wrong, often because of a missing or doubled /v1. |
Check the base URL. For the OpenAI SDKs, it is https://inference.hetzner.com/v1. For the Anthropic SDK, it is https://inference.hetzner.com. |
route not found |
The HTTP method is wrong, for example GET on /v1/chat/completions. |
Send requests to /v1/chat/completions, /v1/responses, /v1/embeddings, and /v1/messages with POST. |
route not found |
The model and the endpoint do not match, for example an embedding model sent to /v1/chat/completions or a chat model sent to /v1/embeddings. |
Send embedding models to /v1/embeddings and chat models to /v1/chat/completions, /v1/responses, or /v1/messages. |
Response with id '...' not found. |
The request contains previous_response_id. The API does not store responses. |
Send the full conversation with every request. |
413 Content Too Large
A request can be up to 32 MiB in size. The API then responds with LLM request body exceeded the buffer limit, for example. This mainly affects requests with images, because images as base64 are about one third larger than the original file. Embeddings requests with a large number of texts can also exceed the limit.
Solution: Scale down the images before you send them, or split the images or texts across several requests. For details, see Limits of Hetzner Inference API.
429 Too Many Requests
| Error text | Cause | Solution |
|---|---|---|
ResourceExhausted - rate limit exceeded |
The Inference Token reached its rate limit for the model. | Wait for the number of seconds in the Retry-After header and then send the request again. |
ResourceExhausted - token limit exceeded |
The Inference Token reached its consumption cap for the calendar month. | Increase the consumption cap in Hetzner Console or wait until the next calendar month. |
With a 429, the Retry-After header contains the number of seconds until the API accepts requests again. The official OpenAI and Anthropic SDKs automatically retry requests after a 429 and take this header into account. If the Inference Token has reached its consumption cap, these retries also fail. Configure your application so that it does not retry this error endlessly. For details on all limits, see Limits of Hetzner Inference API.
500 and higher
Status codes from 500 show an error on the API side. These errors are usually temporary.
504 Gateway Timeout is an exception. On the server side, a request has 300 seconds, also with streaming. If it takes longer, the API cancels it. A simple retry will probably reach the timeout again. For this reason, shorten the request before you send it again. For example, set a lower max_tokens value, choose a lower reasoning level, or split the task into several requests. For details, see Limits of Hetzner Inference API.
For all other status codes from 500, follow these steps:
-
Retry the request Wait a moment and send the request again. Wait a little longer before each further attempt (exponential backoff). The OpenAI and Anthropic SDKs do this automatically.
-
Check the status Go to status.hetzner.com and check whether there is a known incident.
-
Contact support If the error persists, open a support request in Hetzner Console. Include the time of the request, the endpoint, the model, and the full error message.
Response without text
The API returns 200, but the response contains no text. On /v1/chat/completions, content is missing or empty, and finish_reason has the value length. On /v1/messages, stop_reason has the value max_tokens.
Cause: The model used up the max_tokens limit on reasoning before it wrote its answer. Reasoning tokens are output tokens and count toward max_tokens.
Solution: Increase max_tokens, choose a lower reasoning level, or turn off reasoning if the model supports it. To see which levels a model supports, go to Models and licenses.