> ## 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.

# Text and chat APIs

> Choose the CometAPI text and chat API that fits your request format: Chat Completions, Responses, Anthropic Messages, or Gemini content generation.

Use CometAPI text model docs by matching your request format to the page that implements it. For OpenAI-compatible chat, start with Chat Completions or Responses; for provider-native formats, use the matching provider page.

## Choose a text and chat API

> **[Create a chat completion](https://apidoc.cometapi.com/api/text/chat.md)**
>
> Send OpenAI-compatible chat messages with a messages array.

> **[Create a model response](https://apidoc.cometapi.com/api/text/responses.md)**
>
> Use reasoning, multimodal output, and built-in tools through the Responses API.

> **[Create a Message](https://apidoc.cometapi.com/api/text/anthropic-messages.md)**
>
> Call Claude-compatible Messages workflows with provider-native fields.

> **[Generate content](https://apidoc.cometapi.com/api/text/gemini-generating-content.md)**
>
> Send Gemini native content generation requests.

## Call a text model

Use any text-capable model ID from the [Models page](https://apidoc.cometapi.com/overview/models.md) or the [model directory](https://www.cometapi.com/models/). The examples below call the OpenAI-compatible Chat Completions endpoint.

> [!NOTE]
>
> These examples use the placeholder `your-model-id`. Replace it with an available text model ID from the [Models page](https://apidoc.cometapi.com/overview/models.md) or [model directory](https://www.cometapi.com/models/) before you run the request.

```python Python theme={null}
import os
import requests

response = requests.post(
    "https://api.cometapi.com/v1/chat/completions",
    headers={
        "Authorization": "Bearer " + os.environ["COMETAPI_KEY"],
        "Content-Type": "application/json",
    },
    json={
        "model": "your-model-id",
        "messages": [
            {
                "role": "user",
                "content": "Write one sentence about CometAPI.",
            }
        ],
    },
    timeout=30,
)

response.raise_for_status()
result = response.json()
print(result["choices"][0]["message"]["content"])
```

```javascript Node.js theme={null}
const response = await fetch("https://api.cometapi.com/v1/chat/completions", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "your-model-id",
    messages: [
      {
        role: "user",
        content: "Write one sentence about CometAPI.",
      },
    ],
  }),
});

if (!response.ok) {
  throw new Error(await response.text());
}

const result = await response.json();
console.log(result.choices[0].message.content);
```

```bash cURL theme={null}
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."
      }
    ]
  }'
```

## Response example

A successful response can look like this. Field values vary by model and request:

```json theme={null}
{
  "id": "chatcmpl_example",
  "object": "chat.completion",
  "created": 1779960520,
  "model": "your-model-id",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "CometAPI lets developers route model requests through one API surface."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 14,
    "total_tokens": 26
  }
}
```

## Example model records

> [!NOTE]
>
> This example model catalog response shows the `/api/models` envelope and one text model record shape. It is not a complete model list.

```bash cURL theme={null}
curl https://api.cometapi.com/api/models
```

```json theme={null}
{
  "success": true,
  "page": 1,
  "page_size": 20,
  "total": 302,
  "data": [
    {
      "created": 1773798949,
      "id": "your-text-model-id",
      "code": "your-text-model-id",
      "provider": "ExampleProvider",
      "provider_code": "example",
      "name": "Example text model",
      "model_type": "text",
      "features": [
        "text-to-text"
      ],
      "endpoints": "{\n  \"openai-chat\": {\n    \"path\": \"/v1/chat/completions\",\n    \"method\": \"POST\"\n  }\n}",
      "pricing": {
        "currency": "USD / M Tokens",
        "input": 0.5,
        "output": 1.5,
        "per_request": null,
        "per_second": null
      }
    }
  ]
}
```

## Common errors

> **Missing or invalid API key**
>
> Send `Authorization: Bearer $COMETAPI_KEY`.

> **Wrong base URL**
>
> Use `https://api.cometapi.com/v1` for OpenAI-compatible requests.

> **Wrong model type**
>
> Choose a text-capable model from the [Models page](https://apidoc.cometapi.com/overview/models.md).

> **Provider-specific parameter error**
>
> Remove optional fields, then add the fields back one at a time.

## Error codes and retry strategy

> **400**
>
> Do not retry until the request body is fixed.

> **401**
>
> Do not retry until the API key is present and valid.

> **404**
>
> Check the base URL, path, and model ID before retrying.

> **429**
>
> Retry with exponential backoff and reduce concurrency.

> **500 or 503**
>
> Retry with backoff for transient provider or service errors.

> [!TIP]
>
> For implementation patterns, see [Error codes and retry strategy](https://apidoc.cometapi.com/guides/error-codes-and-retry-strategy.md) and [Rate limits and concurrency](https://apidoc.cometapi.com/guides/rate-limits-and-concurrency.md).

## Pricing and model directory

> **[Models page](https://apidoc.cometapi.com/overview/models.md)**
>
> Read how CometAPI exposes model IDs in the docs.

> **[Model directory](https://www.cometapi.com/models/)**
>
> Browse model availability and capabilities.

> **[Pricing](https://www.cometapi.com/pricing/)**
>
> Check pricing before you call a model.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.