Skip to main content
This page is a CometAPI OpenAI-compatible API quickstart. It helps you reuse the Chat Completions request shape, OpenAI SDKs, and a CometAPI base URL. It is not an OpenAI account setup guide or an OpenAI-only model page.

What you will build

You will send one text request to CometAPI’s OpenAI-compatible POST /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:
https://api.cometapi.com/v1
Authenticate direct HTTP requests with a Bearer token:
Authorization: Bearer $COMETAPI_KEY

Code examples

Use the tabs below to send the same Chat Completions request with cURL, Python, and Node.js.
curl https://api.cometapi.com/v1/chat/completions \
  -H "Authorization: Bearer $COMETAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "your-model-id",
    "messages": [
      {
        "role": "user",
        "content": "Write one sentence about CometAPI."
      }
    ]
  }'

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 reads choices[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

ParameterUse
modelThe CometAPI model ID for a text-capable model.
messagesThe conversation array. Start with one user message for a minimal request.
temperatureControls randomness. Lower values make output more deterministic.
max_completion_tokensCaps generated output for model families that use completion-token budgets.
streamStreams incremental response chunks when set to true.
response_formatRequests JSON output when the selected model supports it.

Troubleshooting and FAQ

No. This is CometAPI’s OpenAI-compatible API route. You use a CometAPI API key, the CometAPI base URL, and a CometAPI model ID.
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.
Use a CometAPI model ID that supports text or chat requests. Check the Models page before retrying.
Confirm the client sets base_url in Python or baseURL in Node.js to https://api.cometapi.com/v1.

Next steps