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

# 메시지 생성

> CometAPI를 통해 Anthropic 메시지 API를 사용하여 adaptive thinking, 프롬프트 캐싱, 도구 사용, 웹 검색, 스트리밍, effort control과 함께 Claude 모델을 호출합니다.

CometAPI는 Anthropic 메시지 API를 네이티브로 지원하여 Anthropic 전용 기능과 함께 Claude 모델에 직접 액세스할 수 있게 해줍니다. adaptive thinking, 프롬프트 캐싱, effort control과 같은 Claude 기능에는 이 엔드포인트를 사용하세요.

<Tip>
  전체 파라미터 목록, 응답 스키마, Claude 전용 동작에 대한 권위 있는 기준으로 공식 [Anthropic Messages API reference](https://platform.claude.com/docs/en/api/messages)를 사용하세요. 이 CometAPI 페이지는 해당 요청 형태를 CometAPI를 통해 어떻게 보내는지 설명합니다.
</Tip>

<Warning>
  Claude 기능이 발전함에 따라 Anthropic 요청 파라미터와 응답 필드가 변경될 수 있습니다. 최신 전체 파라미터 목록과 provider별 동작은 [Anthropic Messages API 문서](https://platform.claude.com/docs/en/api/messages)에서 확인하세요.
</Warning>

<Warning>
  많은 최신 Claude 모델은 Messages API에서 기본값이 아닌 `temperature`, `top_p`, `top_k` 값을 거부합니다. 선택한 모델에서 지원이 확인된 경우가 아니라면 이러한 샘플링 필드는 생략하세요. 모델이 unsupported 또는 deprecated-parameter 오류를 반환하면 요청에서 해당 필드를 제거하세요.
</Warning>

<Note>
  인증에는 `x-api-key`와 `Authorization: Bearer` 헤더를 모두 지원합니다. 공식 Anthropic SDK는 기본적으로 `x-api-key`를 사용합니다.
</Note>

## 빠른 시작

CometAPI와 함께 공식 Anthropic SDK를 사용하려면 base URL을 설정하세요:

<CodeGroup>
  ```python Python theme={null}
  import os
  import anthropic

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

  message = client.messages.create(
      model="claude-sonnet-5",
      max_tokens=1024,
      messages=[{"role": "user", "content": "Hello!"}],
  )
  print(message.content[0].text)
  ```

  ```javascript JavaScript 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: "claude-sonnet-5",
      max_tokens: 1024,
      messages: [{ role: "user", content: "Hello!" }],
  });
  console.log(message.content[0].text);
  ```
</CodeGroup>

## adaptive thinking 제어

`output_config.effort`와 함께 adaptive thinking을 사용하면 Claude가 응답에 얼마나 많은 작업을 적용할지 제어할 수 있습니다. 최신 Claude 모델은 레거시 수동 thinking 형식인 `thinking={"type": "enabled", "budget_tokens": ...}`를 거부합니다.

```python theme={null}
message = client.messages.create(
    model="claude-sonnet-5",
    max_tokens=4096,
    thinking={"type": "adaptive"},
    output_config={"effort": "xhigh"},
    messages=[
        {
            "role": "user",
            "content": "Analyze the trade-offs between a monolithic architecture and microservices for a small engineering team.",
        }
    ],
)

for block in message.content:
    if block.type == "text":
        print(block.text)
```

<Warning>
  Thinking 토큰(Token)은 `max_tokens` 제한에 포함됩니다. 더 높은 effort 수준을 사용할 때는 thinking과 최종 답변 모두를 위해 `max_tokens`를 충분히 높게 설정하세요.
</Warning>

***

## 프롬프트 캐시

후속 요청의 지연 시간과 비용을 줄이기 위해, 큰 system 프롬프트 또는 대화 접두사를 캐시하세요. 캐시해야 하는 content 블록에 `cache_control`을 추가합니다:

```python theme={null}
message = client.messages.create(
    model="claude-sonnet-5",
    max_tokens=1024,
    system=[
        {
            "type": "text",
            "text": "You are an expert code reviewer. [Long detailed instructions...]",
            "cache_control": {"type": "ephemeral"},
        }
    ],
    messages=[{"role": "user", "content": "Review this code..."}],
)
```

캐시 사용량은 응답의 `usage` 필드에 보고됩니다:

* `cache_creation_input_tokens` — 캐시에 기록된 토큰(Token) 수(더 높은 요금으로 청구)
* `cache_read_input_tokens` — 캐시에서 읽은 토큰(Token) 수(할인된 요금으로 청구)

<Info>
  프롬프트 캐싱을 사용하려면 캐시된 content 블록에 최소 **1,024 tokens**가 필요합니다. 이보다 짧은 content는 캐시되지 않습니다.
</Info>

***

## 응답 스트리밍

Server-Sent Events (SSE)를 사용해 응답을 스트리밍하려면 `stream: true`로 설정하세요. 이벤트는 다음 순서로 도착합니다:

1. `message_start` — 메시지 메타데이터와 초기 usage를 포함
2. `content_block_start` — 각 content 블록의 시작을 표시
3. `content_block_delta` — 점진적으로 전달되는 텍스트 청크(`text_delta`)
4. `content_block_stop` — 각 content 블록의 끝을 표시
5. `message_delta` — 최종 `stop_reason` 및 전체 `usage`
6. `message_stop` — 스트림의 끝을 알림

```python theme={null}
with client.messages.stream(
    model="claude-sonnet-5",
    max_tokens=256,
    messages=[{"role": "user", "content": "Hello"}],
) as stream:
    for text in stream.text_stream:
        print(text, end="")
```

***

## 노력 수준 제어

Claude가 응답을 생성할 때 얼마나 많은 노력을 들일지 제어하려면 `output_config.effort`를 사용하세요:

```python theme={null}
message = client.messages.create(
    model="claude-sonnet-5",
    max_tokens=4096,
    messages=[
        {"role": "user", "content": "Summarize this briefly."}
    ],
    output_config={"effort": "low"},  # "low", "medium", "high", "xhigh", or "max"
)
```

***

## 서버 도구 사용

Claude는 Anthropic의 인프라에서 실행되는 서버 측 도구를 지원합니다:

<Tabs>
  <Tab title="Web Fetch">
    URL의 콘텐츠를 가져와 분석합니다:

    ```python theme={null}
    message = client.messages.create(
        model="claude-sonnet-5",
        max_tokens=1024,
        messages=[
            {"role": "user", "content": "Analyze the content at https://arxiv.org/abs/1512.03385"}
        ],
        tools=[
            {"type": "web_fetch_20250910", "name": "web_fetch", "max_uses": 5}
        ],
    )
    ```
  </Tab>

  <Tab title="Web Search">
    실시간 정보를 위해 웹을 검색합니다:

    ```python theme={null}
    message = client.messages.create(
        model="claude-sonnet-5",
        max_tokens=1024,
        messages=[
            {"role": "user", "content": "What are the latest developments in AI?"}
        ],
        tools=[
            {"type": "web_search_20250305", "name": "web_search", "max_uses": 5}
        ],
    )
    ```
  </Tab>
</Tabs>

***

## 응답 예시

CometAPI의 Anthropic 엔드포인트에서 반환되는 일반적인 응답 예시입니다:

```json theme={null}
{
  "id": "msg_bdrk_01UjHdmSztrL7QYYm7CKBDFB",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "Hello!"
    }
  ],
  "model": "claude-sonnet-5",
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 19,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0,
    "cache_creation": {
      "ephemeral_5m_input_tokens": 0,
      "ephemeral_1h_input_tokens": 0
    },
    "output_tokens": 4
  }
}
```

***

## OpenAI 호환 엔드포인트와 비교

| 기능        | Anthropic 메시지 (`/v1/messages`)                            | OpenAI 호환 (`/v1/chat/completions`) |
| --------- | --------------------------------------------------------- | ---------------------------------- |
| 적응형 사고    | `thinking`과 `type: "adaptive"`, `output_config.effort` 사용 | 지원되지 않음                            |
| 프롬프트 캐싱   | content 블록의 `cache_control`                               | 지원되지 않음                            |
| effort 제어 | `output_config.effort`                                    | 지원되지 않음                            |
| 웹 가져오기/검색 | 서버 도구(`web_fetch`, `web_search`)                          | 지원되지 않음                            |
| 인증 헤더     | `x-api-key` 또는 `Bearer`                                   | `Bearer`만 지원                       |
| 응답 형식     | Anthropic 형식(`content` 블록)                                | OpenAI 형식(`choices`, `message`)    |
| 모델        | Claude 전용                                                 | 멀티 프로바이더(GPT, Claude, Gemini 등)    |


## OpenAPI

````yaml api/openapi/text/post-anthropic-messages.openapi.json POST /v1/messages
openapi: 3.1.0
info:
  title: Anthropic Messages API
  version: 1.0.0
servers:
  - url: https://api.cometapi.com
security:
  - apiKeyAuth: []
paths:
  /v1/messages:
    post:
      summary: Anthropic Messages
      description: >-
        Send structured messages to Claude models using the Anthropic native API
        format. Supports text and multimodal inputs, multi-turn conversations,
        adaptive thinking, tool use, prompt caching, streaming, and web search.
        Use this endpoint when you need Claude-specific features like adaptive
        thinking or prompt caching that are not available through the
        OpenAI-compatible endpoint.
      operationId: anthropic_messages
      parameters:
        - name: anthropic-version
          in: header
          required: false
          description: The Anthropic API version to use. Defaults to `2023-06-01`.
          schema:
            type: string
            default: '2023-06-01'
            example: '2023-06-01'
        - name: anthropic-beta
          in: header
          required: false
          description: >-
            Comma-separated list of beta features to enable. Examples:
            `max-tokens-3-5-sonnet-2024-07-15`, `pdfs-2024-09-25`,
            `output-128k-2025-02-19`.
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - messages
                - max_tokens
              properties:
                model:
                  type: string
                  description: >-
                    The Claude model to use. See the [Models
                    page](/overview/models) for available Claude model IDs.
                  example: claude-sonnet-5
                messages:
                  type: array
                  description: >-
                    The conversation messages. Must alternate between `user` and
                    `assistant` roles. Each message's `content` can be a string
                    or an array of content blocks (text, image, document,
                    tool_use, tool_result). There is a limit of 100,000 messages
                    per request.
                  items:
                    type: object
                    required:
                      - role
                      - content
                    properties:
                      role:
                        type: string
                        description: The role of the message author.
                        enum:
                          - user
                          - assistant
                      content:
                        description: >-
                          The message content. Either a plain string or an array
                          of content blocks for multimodal input.
                        oneOf:
                          - type: string
                          - type: array
                            items:
                              type: object
                              properties:
                                type:
                                  type: string
                                  description: The content block type.
                                  enum:
                                    - text
                                    - image
                                    - document
                                    - tool_use
                                    - tool_result
                                text:
                                  type: string
                                  description: Text content (for `text` type blocks).
                                source:
                                  type: object
                                  description: >-
                                    Source data for `image` or `document`
                                    blocks.
                                  properties:
                                    type:
                                      type: string
                                      enum:
                                        - base64
                                        - url
                                      description: >-
                                        Image source type: `url` for a public
                                        image URL, or `base64` for inline data.
                                    media_type:
                                      type: string
                                      description: >-
                                        Image MIME type for base64 sources, such
                                        as `image/jpeg` or `image/png`.
                                    data:
                                      type: string
                                      description: >-
                                        Base64-encoded image bytes when `type`
                                        is `base64`.
                                    url:
                                      type: string
                                      description: >-
                                        Public HTTPS image URL when `type` is
                                        `url`. The provider must be able to
                                        download it.
                                cache_control:
                                  type: object
                                  description: >-
                                    Cache control for prompt caching. Set
                                    `{"type": "ephemeral"}` to cache this
                                    content block.
                                  properties:
                                    type:
                                      type: string
                                      enum:
                                        - ephemeral
                                      description: Cache control type. Use `ephemeral`.
                                    ttl:
                                      type: string
                                      description: >-
                                        Cache TTL. Options: `ephemeral_5m` (5
                                        min), `ephemeral_1h` (1 hour).
                max_tokens:
                  type: integer
                  description: >-
                    The maximum number of tokens to generate. The model may stop
                    before reaching this limit. When using `thinking`, the
                    thinking tokens count towards this limit.
                  minimum: 1
                  example: 1024
                system:
                  description: >-
                    System prompt providing context and instructions to Claude.
                    Can be a plain string or an array of content blocks (useful
                    for prompt caching).
                  oneOf:
                    - type: string
                    - type: array
                      items:
                        type: object
                        properties:
                          type:
                            type: string
                            enum:
                              - text
                            description: Content block type, `text`.
                          text:
                            type: string
                            description: System prompt text for this block.
                          cache_control:
                            type: object
                            properties:
                              type:
                                type: string
                                enum:
                                  - ephemeral
                                description: Cache control type. Use `ephemeral`.
                            description: >-
                              Marks this system block as a prompt-cache
                              breakpoint.
                temperature:
                  type: number
                  description: >-
                    Model-dependent sampling control. Many newer Claude models
                    reject non-default `temperature` values on the Messages API.
                    Omit this field unless you have verified that the selected
                    model accepts it; if the model returns an unsupported or
                    deprecated-parameter error, remove the field instead of
                    substituting another sampling value.
                  minimum: 0
                  maximum: 1
                  default: 1
                  example: 1
                top_p:
                  type: number
                  description: >-
                    Model-dependent nucleus sampling control. Many newer Claude
                    models reject non-default `top_p` values on the Messages
                    API. Omit this field unless you have verified support for
                    the selected model. Do not set `temperature` and `top_p`
                    together.
                  minimum: 0
                  maximum: 1
                  example: 1
                top_k:
                  type: integer
                  description: >-
                    Model-dependent top-k sampling control. Many newer Claude
                    models reject non-default `top_k` values on the Messages
                    API. Omit this field unless you have verified support for
                    the selected model.
                  minimum: 0
                  example: 0
                stream:
                  type: boolean
                  description: >-
                    If `true`, stream the response incrementally using
                    Server-Sent Events (SSE). Events include `message_start`,
                    `content_block_start`, `content_block_delta`,
                    `content_block_stop`, `message_delta`, and `message_stop`.
                  default: false
                stop_sequences:
                  type: array
                  description: >-
                    Custom strings that cause the model to stop generating when
                    encountered. The stop sequence is not included in the
                    response.
                  items:
                    type: string
                thinking:
                  type: object
                  description: >-
                    Controls Claude thinking when the selected model supports a
                    configurable thinking mode. For newer adaptive-thinking
                    models, use `{"type":"adaptive"}` with
                    `output_config.effort`, or omit `thinking` when adaptive
                    thinking is already the model default. Manual
                    `{"type":"enabled","budget_tokens":...}` is supported only
                    by older models and is rejected by newer Claude models.
                  properties:
                    type:
                      type: string
                      description: >-
                        Thinking mode. `adaptive` lets the model decide when and
                        how much to think. `disabled` turns thinking off only on
                        models that support disabling it. `enabled` is the
                        legacy manual-budget mode and is rejected by newer
                        Claude models.
                      enum:
                        - adaptive
                        - disabled
                        - enabled
                    budget_tokens:
                      type: integer
                      description: >-
                        Legacy manual-thinking token budget. Minimum: 1,024 when
                        accepted. These tokens count toward `max_tokens`. Do not
                        send this field to newer adaptive-thinking models that
                        reject manual thinking budgets.
                      minimum: 1024
                    display:
                      type: string
                      description: >-
                        Controls visible thinking blocks on models that support
                        display selection. `summarized` returns a readable
                        thinking summary; `omitted` returns an empty thinking
                        field with continuity metadata where applicable.
                      enum:
                        - summarized
                        - omitted
                tools:
                  type: array
                  description: >-
                    Tools the model may use. Supports client-defined functions,
                    web search (`web_search_20250305`), web fetch
                    (`web_fetch_20250910`), code execution
                    (`code_execution_20250522`), and more.
                  items:
                    type: object
                    properties:
                      name:
                        type: string
                        description: >-
                          Tool name. The model repeats it in `tool_use` blocks
                          when it calls the tool.
                      description:
                        type: string
                        description: A description of what the tool does.
                      input_schema:
                        type: object
                        description: JSON Schema defining the tool's input parameters.
                      type:
                        type: string
                        description: >-
                          The tool type. Required for server tools (e.g.,
                          `web_search_20250305`, `web_fetch_20250910`,
                          `code_execution_20250522`).
                      max_uses:
                        type: integer
                        description: >-
                          Maximum number of times this tool can be used in a
                          single request.
                tool_choice:
                  type: object
                  description: Controls how the model uses tools.
                  properties:
                    type:
                      type: string
                      description: >-
                        The tool choice mode: `auto` (model decides), `any`
                        (must use a tool), `tool` (must use a specific tool), or
                        `none` (no tools).
                      enum:
                        - auto
                        - any
                        - tool
                        - none
                    name:
                      type: string
                      description: >-
                        The specific tool name to use. Required when `type` is
                        `tool`.
                    disable_parallel_tool_use:
                      type: boolean
                      description: >-
                        If `true`, prevent the model from calling multiple tools
                        in parallel.
                metadata:
                  type: object
                  description: Request metadata for tracking and analytics.
                  properties:
                    user_id:
                      type: string
                      description: >-
                        An external identifier for the user making the request.
                        Used for abuse detection.
                output_config:
                  type: object
                  description: >-
                    Configuration for response effort and output format. Field
                    support depends on the selected Claude model.
                  properties:
                    effort:
                      type: string
                      description: >-
                        Controls how much effort Claude applies to the response.
                        `high` is the default for newer effort-capable models.
                        Use `low` or `medium` for lower latency and cost,
                        `xhigh` for advanced coding or agentic work when
                        supported, and `max` only for the hardest tasks with a
                        large `max_tokens` value.
                      enum:
                        - low
                        - medium
                        - high
                        - xhigh
                        - max
                      example: medium
                    format:
                      type: object
                      description: >-
                        Structured output configuration. Use
                        `{"type":"json","schema":{...}}` to ask for JSON that
                        matches your schema when the selected model supports
                        structured output.
                service_tier:
                  type: string
                  description: >-
                    The service tier to use. `auto` tries priority capacity
                    first, `standard_only` uses only standard capacity.
                  enum:
                    - auto
                    - standard_only
            examples:
              Default:
                summary: Basic message
                value:
                  model: claude-sonnet-5
                  max_tokens: 1024
                  system: You are a helpful assistant.
                  messages:
                    - role: user
                      content: Hello, world
              Image Input:
                summary: Image Input
                value:
                  model: claude-sonnet-5
                  max_tokens: 1024
                  messages:
                    - role: user
                      content:
                        - type: image
                          source:
                            type: url
                            url: https://picsum.photos/seed/comet/800/600.jpg
                        - type: text
                          text: Describe this image in one sentence.
              Prompt Cache:
                summary: With prompt caching
                value:
                  model: claude-sonnet-5
                  max_tokens: 1024
                  system:
                    - type: text
                      text: >-
                        You are an expert code reviewer. Analyze code for
                        correctness, performance, security, and maintainability.
                        Follow SOLID principles and provide actionable
                        suggestions. [Long system prompt content that exceeds
                        1024 tokens to enable caching...]
                      cache_control:
                        type: ephemeral
                  messages:
                    - role: user
                      content: |-
                        Please review this Python code:

                        def calculate_order_total(items):
                            total = 0
                            for item in items:
                                total += item['price'] * item['quantity']
                            return total
              Streaming:
                summary: Streaming response
                value:
                  model: claude-sonnet-5
                  max_tokens: 256
                  stream: true
                  messages:
                    - role: user
                      content: Hello
              Web Fetch:
                summary: With web fetch tool
                value:
                  model: claude-sonnet-5
                  max_tokens: 1024
                  messages:
                    - role: user
                      content: >-
                        Please analyze the content at
                        https://arxiv.org/abs/1512.03385
                  tools:
                    - type: web_fetch_20250910
                      name: web_fetch
                      max_uses: 5
              Adaptive Thinking:
                summary: With adaptive thinking and effort
                value:
                  model: claude-sonnet-5
                  max_tokens: 4096
                  thinking:
                    type: adaptive
                  output_config:
                    effort: xhigh
                  messages:
                    - role: user
                      content: >-
                        Analyze the trade-offs between a monolithic architecture
                        and microservices for a small engineering team.
      responses:
        '200':
          description: >-
            Successful response. When `stream` is `true`, the response is a
            stream of SSE events.
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    description: >-
                      Unique identifier for this message (e.g.,
                      `msg_01XFDUDYJgAACzvnptvVoYEL`).
                  type:
                    type: string
                    description: Always `message`.
                    enum:
                      - message
                  role:
                    type: string
                    description: Always `assistant`.
                    enum:
                      - assistant
                  content:
                    type: array
                    description: >-
                      The response content blocks. May include `text`,
                      `thinking`, `tool_use`, and other block types.
                    items:
                      type: object
                      properties:
                        type:
                          type: string
                          description: The content block type.
                          enum:
                            - text
                            - thinking
                            - tool_use
                        text:
                          type: string
                          description: The generated text (for `text` blocks).
                        thinking:
                          type: string
                          description: >-
                            Thinking text or summary for `thinking` blocks when
                            the selected model returns visible thinking content.
                        signature:
                          type: string
                          description: Cryptographic signature for the thinking block.
                        id:
                          type: string
                          description: Tool use ID (for `tool_use` blocks).
                        name:
                          type: string
                          description: Tool name (for `tool_use` blocks).
                        input:
                          type: object
                          description: Tool input arguments (for `tool_use` blocks).
                  model:
                    type: string
                    description: >-
                      The specific model version that generated this response,
                      such as `claude-sonnet-5`.
                  stop_reason:
                    type: string
                    description: >-
                      Why the model stopped generating. `refusal` can be
                      returned as a successful HTTP response when the model
                      declines a request.
                    enum:
                      - end_turn
                      - max_tokens
                      - stop_sequence
                      - tool_use
                      - pause_turn
                      - refusal
                  stop_sequence:
                    type:
                      - string
                      - 'null'
                    description: >-
                      The stop sequence that caused the model to stop, if
                      applicable.
                  usage:
                    type: object
                    description: Token usage statistics.
                    properties:
                      input_tokens:
                        type: integer
                        description: >-
                          Number of input tokens (prompt + conversation
                          history).
                      output_tokens:
                        type: integer
                        description: Number of output tokens generated.
                      cache_creation_input_tokens:
                        type: integer
                        description: >-
                          Number of input tokens used to create the prompt
                          cache.
                      cache_read_input_tokens:
                        type: integer
                        description: Number of input tokens read from the prompt cache.
                      cache_creation:
                        type: object
                        description: Detailed cache creation token breakdown by TTL tier.
                        properties:
                          ephemeral_5m_input_tokens:
                            type: integer
                            description: Tokens written to 5-minute ephemeral cache.
                          ephemeral_1h_input_tokens:
                            type: integer
                            description: Tokens written to 1-hour ephemeral cache.
                      output_tokens_details:
                        type: object
                        description: >-
                          Detailed output token breakdown when returned by the
                          selected model.
                        properties:
                          thinking_tokens:
                            type: integer
                            description: >-
                              Number of output tokens used for model thinking
                              when reported.
      x-codeSamples:
        - lang: Python
          label: Basic
          source: |
            import os
            import anthropic

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

            message = client.messages.create(
                model="claude-sonnet-5",
                max_tokens=1024,
                system="You are a helpful assistant.",
                messages=[
                    {"role": "user", "content": "Hello, world"}
                ],
            )

            print(message.content[0].text)
        - lang: Python
          label: Prompt Cache
          source: |
            import os
            import anthropic

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

            message = client.messages.create(
                model="claude-sonnet-5",
                max_tokens=1024,
                system=[
                    {
                        "type": "text",
                        "text": "You are an expert code reviewer. Analyze code, identify issues, "
                                "and suggest improvements following SOLID principles...",
                        "cache_control": {"type": "ephemeral"},
                    }
                ],
                messages=[
                    {
                        "role": "user",
                        "content": "Please review this Python code:\n\n"
                                   "def calculate_order_total(items):\n"
                                   "    total = 0\n"
                                   "    for item in items:\n"
                                   "        total += item['price'] * item['quantity']\n"
                                   "    return total",
                    }
                ],
            )

            print(message.content[0].text)
        - lang: Python
          label: Adaptive thinking
          source: |
            import os
            import anthropic

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

            message = client.messages.create(
                model="claude-sonnet-5",
                max_tokens=4096,
                thinking={"type": "adaptive"},
                output_config={"effort": "xhigh"},
                messages=[
                    {
                        "role": "user",
                        "content": "Analyze the trade-offs between a monolithic architecture and microservices for a small engineering team.",
                    }
                ],
            )

            for block in message.content:
                if block.type == "text":
                    print(block.text)
        - lang: Python
          label: Effort control
          source: |
            import os
            import anthropic

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

            message = client.messages.create(
                model="claude-sonnet-5",
                max_tokens=2048,
                messages=[
                    {
                        "role": "user",
                        "content": "Summarize the key risks in moving a billing service to microservices.",
                    }
                ],
                output_config={"effort": "low"},
            )

            print(message.content[0].text)
        - lang: Python
          label: Streaming
          source: |
            import os
            import anthropic

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

            with client.messages.stream(
                model="claude-sonnet-5",
                max_tokens=256,
                messages=[
                    {"role": "user", "content": "Hello"}
                ],
            ) as stream:
                for text in stream.text_stream:
                    print(text, end="")
        - lang: Python
          label: Web Fetch
          source: |
            import os
            import anthropic

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

            message = client.messages.create(
                model="claude-sonnet-5",
                max_tokens=1024,
                messages=[
                    {
                        "role": "user",
                        "content": "Please analyze the content at https://arxiv.org/abs/1512.03385",
                    }
                ],
                tools=[
                    {
                        "type": "web_fetch_20250910",
                        "name": "web_fetch",
                        "max_uses": 5,
                    }
                ],
            )

            print(message.content)
        - lang: Python
          label: Image Input
          source: |
            import os
            import anthropic

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

            message = client.messages.create(
                model="claude-sonnet-5",
                max_tokens=1024,
                messages=[
                    {
                        "role": "user",
                        "content": [
                            {
                                "type": "image",
                                "source": {
                                    "type": "url",
                                    "url": "https://picsum.photos/seed/comet/800/600.jpg",
                                },
                            },
                            {"type": "text", "text": "Describe this image in one sentence."},
                        ],
                    }
                ],
            )

            print(message.content[0].text)
        - lang: JavaScript
          label: Basic
          source: |
            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: "claude-sonnet-5",
                max_tokens: 1024,
                system: "You are a helpful assistant.",
                messages: [
                    { role: "user", content: "Hello, world" },
                ],
            });

            console.log(message.content[0].text);
        - lang: JavaScript
          label: Adaptive thinking
          source: |
            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: "claude-sonnet-5",
                max_tokens: 4096,
                thinking: { type: "adaptive" },
                output_config: { effort: "xhigh" },
                messages: [
                    {
                        role: "user",
                        content: "Analyze the trade-offs between a monolithic architecture and microservices for a small engineering team.",
                    },
                ],
            });

            for (const block of message.content) {
                if (block.type === "text") {
                    console.log(block.text);
                }
            }
        - lang: JavaScript
          label: Effort control
          source: |
            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: "claude-sonnet-5",
                max_tokens: 2048,
                messages: [
                    {
                        role: "user",
                        content: "Summarize the key risks in moving a billing service to microservices.",
                    },
                ],
                output_config: { effort: "low" },
            });

            console.log(message.content[0].text);
        - lang: JavaScript
          label: Streaming
          source: |
            import Anthropic from "@anthropic-ai/sdk";

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

            const stream = await client.messages.create({
                model: "claude-sonnet-5",
                max_tokens: 256,
                messages: [
                    { role: "user", content: "Hello" },
                ],
                stream: true,
            });

            for await (const event of stream) {
                if (event.type === "content_block_delta" && event.delta.type === "text_delta") {
                    process.stdout.write(event.delta.text);
                }
            }
        - lang: JavaScript
          label: Web Fetch
          source: |
            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: "claude-sonnet-5",
                max_tokens: 1024,
                messages: [
                    {
                        role: "user",
                        content: "Please analyze the content at https://arxiv.org/abs/1512.03385",
                    },
                ],
                tools: [
                    {
                        type: "web_fetch_20250910",
                        name: "web_fetch",
                        max_uses: 5,
                    },
                ],
            });

            console.log(message.content);
        - lang: JavaScript
          label: Image Input
          source: |
            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: "claude-sonnet-5",
                max_tokens: 1024,
                messages: [
                    {
                        role: "user",
                        content: [
                            {
                                type: "image",
                                source: { type: "url", url: "https://picsum.photos/seed/comet/800/600.jpg" },
                            },
                            { type: "text", text: "Describe this image in one sentence." },
                        ],
                    },
                ],
            });

            console.log(message.content[0].text);
        - lang: JavaScript
          label: Prompt Cache
          source: |
            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: "claude-sonnet-5",
                max_tokens: 1024,
                system: [
                    {
                        type: "text",
                        text: "You are an expert code reviewer. Analyze code, identify issues, and suggest improvements following SOLID principles...",
                        cache_control: { type: "ephemeral" },
                    },
                ],
                messages: [
                    {
                        role: "user",
                        content: "Please review this Python code:\n\ndef calculate_order_total(items):\n    total = 0\n    for item in items:\n        total += item['price'] * item['quantity']\n    return total",
                    },
                ],
            });

            console.log(message.content[0].text);
        - lang: Shell
          label: Basic
          source: |
            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": "claude-sonnet-5",
                "max_tokens": 1024,
                "system": "You are a helpful assistant.",
                "messages": [
                  {"role": "user", "content": "Hello, world"}
                ]
              }'
        - lang: Shell
          label: Adaptive thinking
          source: |
            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": "claude-sonnet-5",
                "max_tokens": 4096,
                "thinking": {"type": "adaptive"},
                "output_config": {"effort": "xhigh"},
                "messages": [
                  {"role": "user", "content": "Analyze the trade-offs between a monolithic architecture and microservices for a small engineering team."}
                ]
              }'
        - lang: Shell
          label: Effort control
          source: |
            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": "claude-sonnet-5",
                "max_tokens": 2048,
                "messages": [
                  {"role": "user", "content": "Summarize the key risks in moving a billing service to microservices."}
                ],
                "output_config": {"effort": "low"}
              }'
        - lang: Shell
          label: Streaming
          source: |
            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": "claude-sonnet-5",
                "max_tokens": 256,
                "stream": true,
                "messages": [
                  {"role": "user", "content": "Hello"}
                ]
              }'
        - lang: Shell
          label: Prompt Cache
          source: |
            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": "claude-sonnet-5",
                "max_tokens": 1024,
                "system": [
                  {
                    "type": "text",
                    "text": "You are an expert code reviewer...",
                    "cache_control": {"type": "ephemeral"}
                  }
                ],
                "messages": [
                  {"role": "user", "content": "Please review this code..."}
                ]
              }'
        - lang: Shell
          label: Web Fetch
          source: |
            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": "claude-sonnet-5",
                "max_tokens": 1024,
                "messages": [
                  {"role": "user", "content": "Please analyze the content at https://arxiv.org/abs/1512.03385"}
                ],
                "tools": [
                  {"type": "web_fetch_20250910", "name": "web_fetch", "max_uses": 5}
                ]
              }'
        - lang: Shell
          label: Image Input
          source: |
            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": "claude-sonnet-5",
                "max_tokens": 1024,
                "messages": [
                  {
                    "role": "user",
                    "content": [
                      {"type": "image", "source": {"type": "url", "url": "https://picsum.photos/seed/comet/800/600.jpg"}},
                      {"type": "text", "text": "Describe this image in one sentence."}
                    ]
                  }
                ]
              }'
components:
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Your CometAPI key passed via the `x-api-key` header. `Authorization:
        Bearer $COMETAPI_KEY` is also supported.

````