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

<CardGroup cols={2}>
  <Card title="Create a chat completion" icon="message" href="/api/text/chat">
    Send OpenAI-compatible chat messages with a messages array.
  </Card>

  <Card title="Create a model response" icon="sparkles" href="/api/text/responses">
    Use reasoning, multimodal output, and built-in tools through the Responses API.
  </Card>

  <Card title="Create a Message" icon="message" href="/api/text/anthropic-messages">
    Call Claude-compatible Messages workflows with provider-native fields.
  </Card>

  <Card title="Generate content" icon="sparkles" href="/api/text/gemini-generating-content">
    Send Gemini native content generation requests.
  </Card>
</CardGroup>

## Call a text model

Use any text-capable model ID from the [Models page](/overview/models) 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](/overview/models) or [model directory](https://www.cometapi.com/models/) before you run the request.
</Note>

<CodeGroup>
  ```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."
        }
      ]
    }'
  ```
</CodeGroup>

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

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

```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

<AccordionGroup>
  <Accordion title="Missing or invalid API key">
    Send `Authorization: Bearer $COMETAPI_KEY`.
  </Accordion>

  <Accordion title="Wrong base URL">
    Use `https://api.cometapi.com/v1` for OpenAI-compatible requests.
  </Accordion>

  <Accordion title="Wrong model type">
    Choose a text-capable model from the [Models page](/overview/models).
  </Accordion>

  <Accordion title="Provider-specific parameter error">
    Remove optional fields, then add the fields back one at a time.
  </Accordion>
</AccordionGroup>

## Error codes and retry strategy

<AccordionGroup>
  <Accordion title="400">
    Do not retry until the request body is fixed.
  </Accordion>

  <Accordion title="401">
    Do not retry until the API key is present and valid.
  </Accordion>

  <Accordion title="404">
    Check the base URL, path, and model ID before retrying.
  </Accordion>

  <Accordion title="429">
    Retry with exponential backoff and reduce concurrency.
  </Accordion>

  <Accordion title="500 or 503">
    Retry with backoff for transient provider or service errors.
  </Accordion>
</AccordionGroup>

<Tip>
  For implementation patterns, see [Error codes and retry strategy](/guides/error-codes-and-retry-strategy) and [Rate limits and concurrency](/guides/rate-limits-and-concurrency).
</Tip>

## Pricing and model directory

<CardGroup cols={3}>
  <Card title="Models page" icon="list" href="/overview/models">
    Read how CometAPI exposes model IDs in the docs.
  </Card>

  <Card title="Model directory" icon="puzzle-piece" href="https://www.cometapi.com/models/">
    Browse model availability and capabilities.
  </Card>

  <Card title="Pricing" icon="tag" href="https://www.cometapi.com/pricing/">
    Check pricing before you call a model.
  </Card>
</CardGroup>
