Documentation Index
Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
Use this file to discover all available pages before exploring further.
Use the OpenAI SDK with CometAPI by changing two client settings: the API key and the base URL. Keep your existing OpenAI-compatible request code, then replace the model ID with an available CometAPI model ID.
Install the SDK
The following command installs the OpenAI Python SDK:
The following command installs the OpenAI Node.js SDK:
Python client
The following Python example creates a CometAPI client and sends a chat request:
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)
The response object contains the assistant message:
{
"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
}
}
Node.js client
The following Node.js example uses 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);
The response shape is the same OpenAI-compatible chat completion shape:
{
"id": "chatcmpl_example",
"object": "chat.completion",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "CometAPI provides API access to models from multiple providers."
}
}
]
}
Common errors
| 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. |
Last updated: May 27, 2026