Skip to main content

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
  • curl, Python 3.10+, or Node.js 18+

API key, base URL, authentication

Use the Anthropic-compatible Messages endpoint through CometAPI:
https://api.cometapi.com/v1/messages
Authenticate direct HTTP requests with x-api-key and the Anthropic API version header:
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.
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."
      }
    ]
  }'

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

ParameterUse
modelA Claude model ID available to your account.
max_tokensMaximum response token budget for the Messages API response.
messagesAnthropic message array with user and assistant roles.
streamStreams incremental message events when set to true.
thinkingEnables Claude extended thinking when the selected model supports it.

Troubleshooting / FAQ

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.
Confirm that the SDK client sets base_url in Python or baseURL in Node.js to https://api.cometapi.com.
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.

Next steps