Zum Inhalt springen
PeakPrivacyDocs
AnwendenVerwaltenEinführenSicherheit & DatenschutzEntwickler

Errors and limits

The error responses of the PeakPrivacy API, timeouts, errors during a stream, and which errors are worth retrying.

Als Markdown anzeigen

The API signals errors with the HTTP status and a JSON body. Branch on the status and on machine-readable fields such as error.code, because message texts can change. Send Accept: application/json so that every error comes back as JSON. The OpenAI SDKs do this for you.

Status codes

StatusMeaningRetry?
400Invalid request, or the model rejected it. Some model rejections arrive as 500 instead, see below.No, fix the request.
401Token missing, unknown or revoked.No.
404Unknown path, or a file id you can't access.No.
405The path exists, but not for this HTTP method.No.
413Request body too large.No.
429Too many requests.Yes, with backoff.
500Unexpected error, no answer from the model in time, or a request the model rejects.Once or twice with backoff. If it repeats, check the request, see below.

400 Bad Request

Validation error. The failing fields are listed under errors. Typical causes: an unknown model, temperature outside 0 to 2, top_p outside 0 to 1, max_tokens below 1, an unsupported or oversized file, a file search without query and meta_filters.

{
  "message": "Validation error",
  "errors": { "model": ["The selected model is invalid."] }
}

Model doesn't support the endpoint

If the model's meta.capabilities marks the endpoint false, the API rejects the request before the model is called, also with "stream": true. Switch to one of the supported_endpoints or choose another model.

{
  "error": {
    "type": "invalid_request_error",
    "code": "unsupported_endpoint",
    "param": "model",
    "model": "gemma-3",
    "message": "The selected model does not support the Responses endpoint.",
    "supported_endpoints": ["/v1/ai/completions", "/v1/ai/chat/completions"]
  }
}

The model rejects the request

If the model rejects the request, for example because the prompt exceeds its context window or a tool call has no matching tool message, the body has error and trace_id. Depending on the model, error is a string or an object, and the status is 400 or 500. Check the request before you retry: shorten the input, choose a model with a larger context, or complete the tool round trip.

401, 404, 405 and 413

These bodies have a single error field:

StatusBody
401{"error": "Unauthenticated"}. See Authentication.
404{"error": "Not found"}, also for file ids of another account.
405error names the allowed methods, for example after a GET on a completions path.
413error says that the request entity is too large.

429 Too Many Requests

You exceeded a rate limit. The body is {"message": "Too Many Attempts."}. If the response has a Retry-After header, wait at least that many seconds. Otherwise back off exponentially.

500 Internal Server Error

{
  "error": "Something Went Wrong!",
  "trace_id": "5cb77078-8a1a-4b7d-9b0d-1f2d7f5e0d3a"
}

Only the completions and Responses endpoints add trace_id. Log it and retry with backoff. If the same request fails every time, the cause is usually the request. In our tests, these requests returned 500 on every attempt: a developer message on some models, a tool call without its tool message, gpt-5 with tools but without "reasoning_effort": "none", a file_uuids field, an image sent to a model without vision, and an upload with a meta[] part that isn't valid JSON. See also The model rejects the request. If the request is correct and the error persists, contact PeakPrivacy with the trace_id.

Timeouts

Without streaming, PeakPrivacy waits up to 120 seconds for the model. A longer request fails with 500. For long answers, use "stream": true, and set your own client timeout above 120 seconds.

Errors during a stream

Once a stream has started, the status is already 200. A later failure ends the stream with an error event:

event: error
data: {"error":{"message":"Something went wrong.","type":"stream_upstream_error"},"trace_id":"5cb77078-8a1a-4b7d-9b0d-1f2d7f5e0d3a"}

type names the cause, for example stream_upstream_error or stream_incomplete. Don't rely on a fixed list. The OpenAI SDKs raise an exception for this event but drop the trace_id. In Python, error.response.json() returns the full body of a failed non-streamed request. The JavaScript SDK only shows a body with a top-level error field, so log the raw response when you need the details.

A complete chat completion stream ends with data: [DONE], a complete Responses stream with a response.completed event. If a stream stops before that, with or without an error event, treat the text as incomplete and send the request again.

Retries

  • Retry 429, 500, timeouts and network errors with exponential backoff and jitter, for example after 1, 2 and 4 seconds. Stop after a few attempts. A 500 that repeats for the same request usually comes from the request, see 500.
  • Don't retry other 4xx errors without changing the request.
  • A failed file upload stores nothing, so you can send it again.
  • The OpenAI SDKs retry 429 and 5xx twice by default. Change this with max_retries (Python) or maxRetries (JavaScript).

For plain HTTP in Python:

import random
import time

import requests


def request_with_retry(method, url, attempts=4, **kwargs):
    # Pass bodies as bytes or JSON, not open files, so every attempt sends the full content.
    for attempt in range(attempts):
        try:
            response = requests.request(method, url, timeout=180, **kwargs)
        except (requests.ConnectionError, requests.Timeout):
            if attempt == attempts - 1:
                raise
        else:
            if response.status_code != 429 and response.status_code < 500:
                return response
            if attempt == attempts - 1:
                return response
            retry_after = response.headers.get("Retry-After")
            if retry_after and retry_after.isdigit():
                time.sleep(int(retry_after))
                continue
        time.sleep(2 ** attempt + random.random())

See also

Auf dieser Seite