caft/docs
Dashboard

SDK examples

Call caft with the OpenAI SDKs.

Set CAFT_API_KEY on the server. Never ship the key to a browser or commit it. To go through a router instead, see Routers.

Python
import os
from openai import OpenAI

client = OpenAI(base_url="https://api.caft.dev/v1", api_key=os.environ["CAFT_API_KEY"])

stream = client.chat.completions.create(
    model="glm-5.3-flash",
    messages=[{"role": "user", "content": "Hello"}],
    max_tokens=64,
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")
TypeScript
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://api.caft.dev/v1", apiKey: process.env.CAFT_API_KEY });

const stream = await client.chat.completions.create({
  model: "glm-5.3-flash",
  messages: [{ role: "user", content: "Hello" }],
  max_tokens: 64,
  stream: true,
});
for await (const chunk of stream) process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
cURL
curl https://api.caft.dev/v1/chat/completions \
  --header "Authorization: Bearer $CAFT_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
  "model": "glm-5.3-flash",
  "messages": [{ "role": "user", "content": "Hello" }],
  "max_tokens": 64,
  "stream": true
}'

HTTP 401 means the key is missing or wrong; see Troubleshooting.