What you will build
You will send one text request to CometAPI’s OpenAI-compatiblePOST /v1/chat/completions route, print the assistant message, and keep the request shape ready for apps that already use OpenAI SDKs.
When to use this page
Use this quickstart when one of these matches your project:- You already use OpenAI SDKs or Chat Completions request shapes.
- You want to switch the base URL to CometAPI.
- You want to call a CometAPI model ID through an OpenAI API-compatible route.
Prerequisites
- A CometAPI API key stored in
COMETAPI_KEY - A text model ID from the Models page
curl, Python 3.10+, or Node.js 18+
API key, base URL, authentication
Use the CometAPI base URL with OpenAI-compatible clients:Code examples
Use the tabs below to send the same Chat Completions request with cURL, Python, and Node.js.Flow explanation
OpenAI-compatible means your application keeps the Chat Completions endpoint, request body, and SDK method names while changing the base URL and model ID to CometAPI values. The route is synchronous by default. The API returns the completed response object in one HTTP response, and your application readschoices[0].message.content.
For incremental output, set stream to true. The response becomes Server-Sent Events and ends with data: [DONE]. Use streaming for chat interfaces and long responses. Keep the synchronous form for background jobs and simple tests.
Common parameters
| Parameter | Use |
|---|---|
model | The CometAPI model ID for a text-capable model. |
messages | The conversation array. Start with one user message for a minimal request. |
temperature | Controls randomness. Lower values make output more deterministic. |
max_completion_tokens | Caps generated output for model families that use completion-token budgets. |
stream | Streams incremental response chunks when set to true. |
response_format | Requests JSON output when the selected model supports it. |
Troubleshooting and FAQ
Is this the OpenAI API?
Is this the OpenAI API?
No. This is CometAPI’s OpenAI-compatible API route. You use a CometAPI API key, the CometAPI base URL, and a CometAPI model ID.
The request returns 401
The request returns 401
Confirm that
COMETAPI_KEY is set in the same shell or runtime that sends the request. Do not paste a real key into source files.The model is not found
The model is not found
Use a CometAPI model ID that supports text or chat requests. Check the Models page before retrying.
The SDK still calls OpenAI
The SDK still calls OpenAI
Confirm the client sets
base_url in Python or baseURL in Node.js to https://api.cometapi.com/v1.Next steps
- Read the Chat Completions API reference.
- Configure SDK clients in Use CometAPI with OpenAI SDKs.
- List available models with List available CometAPI models.
- Add retry and rate-limit handling with Error codes and retry strategy.