Clatter LabsHelp Center

How do I set retries and timeouts in the Python SDK?

How-toUpdated

The OpenAI client has built-in retries with backoff for rate limits and server errors. Tune them on the client or per request.

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.gateway.clatterlabs.xyz/v1",
    api_key=os.environ["CLATTER_API_KEY"],
    default_headers={"X-Clatter-Account": os.environ["CLATTER_ACCOUNT_ID"]},
    max_retries=4,
    timeout=120.0,  # seconds; Heavy can think for a while
)

# per call
client.with_options(timeout=300.0).chat.completions.create(model="supercosmos-heavy", messages=msgs)

For long Heavy answers, streaming is often better than a long timeout because tokens arrive as they're made.

The client setup above (base URL, key and the X-Clatter-Account header) is the same in every Python example; see Set up the Python SDK. Full parameter list: Create a chat completion.

Good to know#

  • New accounts get $5 of free credit; top up from $1 to $800 per purchase in Console › Billing › Credits. Billing
  • Retry only 429 and 5xx errors, with backoff; honour Retry-After when it's sent. Which errors to retry
  • Every response has an X-Request-Id; log it so a request can be found later. Why log it

Still need help?#

We usually reply within the first hour, and always within 24 hours. A full support team is with you.

Related articles

Still need help?

Tried the steps above and still stuck? Email us. We usually reply within the first hour, and always within 24 hours. A full support team is with you.

Infrastructure questions, or permanent deletion of your data
infrastructure@clatterlabs.xyz
For deleting your whole account or the data of one service.