Install the SDK
The following command installs the OpenAI Python SDK:Python client
The following Python example creates a CometAPI client and sends a chat request:Node.js client
The following Node.js example usesbaseURL with the OpenAI SDK:
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Configure the OpenAI Python and Node.js SDKs for CometAPI by setting the CometAPI API key and base URL.
pip install openai
npm install openai
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["COMETAPI_KEY"],
base_url="https://api.cometapi.com/v1",
)
completion = client.chat.completions.create(
model="your-model-id",
messages=[
{
"role": "user",
"content": "Answer in one short sentence: What is CometAPI?",
}
],
)
print(completion.choices[0].message.content)
{
"choices": [
{
"message": {
"role": "assistant",
"content": "CometAPI provides API access to models from multiple providers."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 16,
"completion_tokens": 12,
"total_tokens": 28
}
}
baseURL with the OpenAI SDK:
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.COMETAPI_KEY,
baseURL: "https://api.cometapi.com/v1",
});
const completion = await client.chat.completions.create({
model: "your-model-id",
messages: [
{
role: "user",
content: "Answer in one short sentence: What is CometAPI?",
},
],
});
console.log(completion.choices[0].message.content);
{
"id": "chatcmpl_example",
"object": "chat.completion",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "CometAPI provides API access to models from multiple providers."
}
}
]
}
| Error | Fix |
|---|---|
401 | Confirm that COMETAPI_KEY is set and that the request uses Bearer auth. |
| SDK still calls OpenAI | Set base_url in Python or baseURL in Node.js. |
| Invalid model ID | Choose a model ID from the Models page. |
Missing /v1 | Use https://api.cometapi.com/v1 for OpenAI-compatible SDKs. |