Reference
SDKs
Use official OpenAI Python and JavaScript clients with the CLSSAI base URL.
On this page
This page is for developers who prefer a maintained client library over hand-written HTTP.
CLSSAI does not require a proprietary SDK. The verified integration path uses the official OpenAI clients with a changed base URL and a CLSSAI key.
Python#
BashSyntax highlighted
pip install openaiPythonSyntax highlighted
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.clssai.com/v1",
api_key=os.environ["CLSSAI_API_KEY"],
timeout=60.0,
max_retries=2,
)
response = client.chat.completions.create(
model="openai/gpt-5.4-nano",
messages=[{"role": "user", "content": "Reply with OK."}],
)
print(response.choices[0].message.content)PythonSyntax highlighted
stream = client.chat.completions.create(
model="openai/gpt-5.4-nano",
messages=[{"role": "user", "content": "Count to three."}],
stream=True,
)
for chunk in stream:
if chunk.choices:
print(chunk.choices[0].delta.content or "", end="")
if chunk.usage:
print("\n", chunk.usage)JavaScript and TypeScript#
BashSyntax highlighted
npm install openaiJavaScriptSyntax highlighted
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.clssai.com/v1",
apiKey: process.env.CLSSAI_API_KEY,
timeout: 60_000,
maxRetries: 2,
});
const response = await client.chat.completions.create({
model: "openai/gpt-5.4-nano",
messages: [{ role: "user", content: "Reply with OK." }],
});
console.log(response.choices[0].message.content);JavaScriptSyntax highlighted
const stream = await client.chat.completions.create({
model: "openai/gpt-5.4-nano",
messages: [{ role: "user", content: "Count to three." }],
stream: true,
});
for await (const chunk of stream) {
if (chunk.choices.length > 0) process.stdout.write(chunk.choices[0].delta.content ?? "");
if (chunk.usage) console.log("\n", chunk.usage);
}Timeouts and retries#
Choose a timeout that fits the model and output size. Retry bounded connection failures before output begins. Do not automatically retry a stream after its first event, because the upstream operation may still have run.
Common mistakes#
- Python uses
base_url; JavaScript usesbaseURL. Both values include/v1. - Do not enable browser execution. Keep the key and SDK on a server; a browser call exposes the key to every visitor.
- The Anthropic SDK base URL omits
/v1because that client appends it. - Preserve complete
:freeand:batchmodel IDs. - Check
choicesbefore indexing the final streaming usage chunk. - Use
cf-rayfor inference tracing.
Need a hand?
Find answers to common questions or diagnose a failed request.
Frequently asked questions →Troubleshoot errors →