Clatter LabsHelp Center

How should I store my key and Account ID for Python?

How-toUpdated

Put both values in environment variables and read them at start-up. Don't hard-code them or commit them.

# shell / .env (keep .env out of git)
# export CLATTER_API_KEY="clsk_..."
# export CLATTER_ACCOUNT_ID="CL-XXXXXXXX"

import os
key = os.environ.get("CLATTER_API_KEY")
account = os.environ.get("CLATTER_ACCOUNT_ID")
if not key or not key.startswith("clsk_"):
    raise SystemExit("CLATTER_API_KEY is missing or not a clsk_ key")
if not account or not account.upper().startswith("CL-"):
    raise SystemExit("CLATTER_ACCOUNT_ID is missing")

Failing fast on start-up turns a confusing 401 invalid_api_key or 401 missing_account_id later into a clear message now. In production, use your platform's secret manager.

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#

  • 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
  • Base URL: https://api.gateway.clatterlabs.xyz/v1, with Authorization: Bearer clsk_... and X-Clatter-Account: CL-... on every call. Quick reference

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.