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

# Claude API quickstart: Send Messages requests with CometAPI

> Call Claude models through CometAPI's Anthropic-compatible Messages API with curl, Python, and Node.js.

## What you will build

You will send one request to `POST /v1/messages`, print the Claude response text, and keep the code ready for Anthropic SDK or direct HTTP usage.

## Prerequisites

* A CometAPI API key stored in `COMETAPI_KEY`
* A Claude model ID from the [Models page](/overview/models)
* `curl`, Python 3.10+, or Node.js 18+

## API key, base URL, authentication

Use the Anthropic-compatible Messages endpoint through CometAPI:

```text theme={null}
https://api.cometapi.com/v1/messages
```

Authenticate direct HTTP requests with `x-api-key` and the Anthropic API version header:

```text theme={null}
x-api-key: $COMETAPI_KEY
anthropic-version: 2023-06-01
```

## Code examples

Use the tabs below for copyable examples in cURL, Python, and Node.js.

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.cometapi.com/v1/messages \
    -H "Content-Type: application/json" \
    -H "x-api-key: $COMETAPI_KEY" \
    -H "anthropic-version: 2023-06-01" \
    -d '{
      "model": "your-claude-model-id",
      "max_tokens": 256,
      "messages": [
        {
          "role": "user",
          "content": "Reply with one short sentence."
        }
      ]
    }'
  ```

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

  client = anthropic.Anthropic(
      api_key=os.environ["COMETAPI_KEY"],
      base_url="https://api.cometapi.com",
  )

  message = client.messages.create(
      model="your-claude-model-id",
      max_tokens=256,
      messages=[
          {
              "role": "user",
              "content": "Reply with one short sentence.",
          }
      ],
  )

  print(message.content[0].text)
  ```

  ```javascript Node.js theme={null}
  import Anthropic from "@anthropic-ai/sdk";

  const client = new Anthropic({
    apiKey: process.env.COMETAPI_KEY,
    baseURL: "https://api.cometapi.com",
  });

  const message = await client.messages.create({
    model: "your-claude-model-id",
    max_tokens: 256,
    messages: [
      {
        role: "user",
        content: "Reply with one short sentence.",
      },
    ],
  });

  console.log(message.content[0].text);
  ```
</CodeGroup>

## Flow explanation

Claude Messages requests are synchronous by default. The API returns a message object in one HTTP response, and your application reads the first text content block.

Use this route when you need Claude-specific request shapes such as Anthropic message arrays, extended thinking, prompt caching, or tool use. If your application already uses the official Anthropic SDK, set the SDK base URL to `https://api.cometapi.com` and keep the Messages API request shape.

## Common parameters

| Parameter    | Use                                                                   |
| ------------ | --------------------------------------------------------------------- |
| `model`      | A Claude model ID available to your account.                          |
| `max_tokens` | Maximum response token budget for the Messages API response.          |
| `messages`   | Anthropic message array with `user` and `assistant` roles.            |
| `stream`     | Streams incremental message events when set to `true`.                |
| `thinking`   | Enables Claude extended thinking when the selected model supports it. |

## Troubleshooting / FAQ

<AccordionGroup>
  <Accordion title="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.
  </Accordion>

  <Accordion title="The SDK still calls Anthropic directly">
    Confirm that the SDK client sets `base_url` in Python or `baseURL` in Node.js to `https://api.cometapi.com`.
  </Accordion>

  <Accordion title="Which model should I use">
    Use a Claude model ID available to your account. This quickstart does not hardcode a Claude model because availability changes by account and model family.
  </Accordion>
</AccordionGroup>

## Next steps

* Use the [Anthropic Messages API reference](/api/text/anthropic-messages) for full request and response fields.
* Check model availability in [Models](/overview/models).
* Configure local coding sessions with the [Claude Code integration guide](/integrations/claude-code).
* Review retry behavior in [Error codes and retry strategy](/guides/error-codes-and-retry-strategy).
