Clatter LabsHelp Center

How do I set up the OpenAI Python SDK for the Model API?

How-toUpdated

Install the official OpenAI package and create a client with the Clatter Labs base URL, your clsk_ key and your Account ID as a default header.

# pip install openai
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"]},
)

resp = client.chat.completions.create(
    model="supercosmos-flash",
    messages=[{"role": "user", "content": "Write a haiku about the sea."}],
)
print(resp.choices[0].message.content)

Create the key in Console › API keys with the Model API preset; it's shown once. Your Account ID (like CL-7K2M9QXA) is in Console › Settings.

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#

  • Every response has an X-Request-Id; log it so a request can be found later. Why log it
  • If calls fail unexpectedly, check status.clatterlabs.com before debugging further.
  • Each key has its own limit: 10, 30 (default), 60 or 120 requests per minute. Rate limits

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.