Clatter LabsHelp Center

How do I use the Model API in a Jupyter notebook?

How-toUpdated
%pip install openai
import os, getpass
from openai import OpenAI

key = os.environ.get("CLATTER_API_KEY") or getpass.getpass("Clatter API key: ")
account = os.environ.get("CLATTER_ACCOUNT_ID") or input("Account ID (CL-...): ")

client = OpenAI(base_url="https://api.gateway.clatterlabs.xyz/v1", api_key=key,
                default_headers={"X-Clatter-Account": account})
client.chat.completions.create(model="supercosmos-flash",
    messages=[{"role": "user", "content": "Hello from Jupyter"}]).choices[0].message.content

getpass keeps the key out of the notebook file. Don't paste keys into cells you'll share or commit.

Good to know#

  • Every call shows in Console › Logs and Usage as Model API, with its price. See what you spent
  • Every response has an X-Request-Id; log it so a request can be found later. Why log it
  • Keep keys on your server, never in a browser or mobile app. Why

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.