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

# Opprett en melding

> Kall Claude via CometAPI Messages-endepunktet med tekst- og bildeinndata, adaptiv tenkning, Prompt-caching, Streaming og verktøy.

Bruk `POST /v1/messages` til å sende Claude-forespørsler i Anthropic Messages-formatet.
Eksemplene konfigurerer den offisielle Anthropic SDK-en med CometAPI-base-URL-en og
leser API-nøkkelen din fra `$COMETAPI_KEY`.

<Tip>
  For feltdefinisjoner og modellspesifikke alternativer kan du se den offisielle
  [Messages API-referansen](https://platform.claude.com/docs/en/api/messages/create).
  For OpenAI-kompatible forespørsler, se [Chat Completions](/api/text/chat).
</Tip>

<Note>
  Autentiser med `x-api-key` eller `Authorization: Bearer`. Anthropic SDK-en bruker
  `x-api-key`. HTTP-eksemplene inkluderer `anthropic-version: 2023-06-01`.
</Note>

## Hurtigstart

Eksemplene nedenfor ber om tre søkespørringer. Angi `$COMETAPI_KEY` før
du kjører dem. Installer `anthropic` for Python eller `@anthropic-ai/sdk` for JavaScript:

<CodeGroup>
  ```bash Shell 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": "claude-opus-5",
    "max_tokens": 1000,
    "messages": [
      {
        "role": "user",
        "content": "Suggest three search queries about renewable energy storage."
      }
    ]
  }'
  ```

  ```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-opus-5",
      max_tokens=1000,
      messages=[
          {
              "role": "user",
              "content": "Suggest three search queries about renewable energy storage.",
          },
      ],
  )

  for block in message.content:
      if block.type == "text":
          print(block.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-opus-5",
    "max_tokens": 1000,
    "messages": [
      {
        "role": "user",
        "content": "Suggest three search queries about renewable energy storage."
      }
    ]
  });

  for (const block of message.content) {
    if (block.type === "text") console.log(block.text);
  }
  ```
</CodeGroup>

Svaret inneholder en `content`-array. Les blokker der `type` er `text`;
blokker for tenkning og verktøy kan vises før teksten.

## Kontroller adaptiv tenkning

Sett `thinking.type` til `adaptive`, og velg en `output_config.effort`-verdi.
Følgende eksempel bruker `xhigh` og leser den fullførte meldingen fra en strøm:

```python theme={null}
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-opus-5",
    max_tokens=4096,
    messages=[
        {
            "role": "user",
            "content": "A shop sells notebooks for $7 each. Buying three earns a $4 discount. A customer pays $20 for three notebooks. Calculate the total and the change, and explain your steps.",
        },
    ],
    thinking={
        "type": "adaptive",
    },
    output_config={
        "effort": "xhigh",
    },
) as stream:
    message = stream.get_final_message()

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

Tenkning bidrar til utdata-grensen for `max_tokens`. La det være plass til det endelige
svaret samt tenkning. Et svar kan inneholde tekst uten en synlig
tenkningsblokk. Behold eventuelle returnerte tenkningsblokker uendret i samtale
historikken.

Se
[Thinking](https://platform.claude.com/docs/en/build-with-claude/extended-thinking).
Eksemplene utelater `temperature`, `top_p` og `top_k`; se dokumentasjonen for den valgte
modellens parametere før du legger til samplingkontroller.

## Mellomlagre Prompt-er

Plasser et cache-breakpoint på referansemateriale som du gjenbruker mellom forespørsler.
Lagre referansematerialet ditt i en UTF-8-`reference.txt`-fil før du kjører dette
eksempelet. Bruk et prefiks som oppfyller den valgte modellens
[minste mellomlagringsbare lengde](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#cache-limitations):

```python theme={null}
import os
from pathlib import Path
import anthropic

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

reference = Path("reference.txt").read_text(encoding="utf-8")

with client.messages.stream(
    model="claude-sonnet-5",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": "How long can customers return damaged books, and what must they provide?",
        },
    ],
    system=[
        {
            "type": "text",
            "text": reference,
            "cache_control": {
                "type": "ephemeral",
            },
        },
    ],
) as stream:
    message = stream.get_final_message()

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

print(message.usage.model_dump_json())
```

Kjør forespørselen på nytt med samme modell, referansetekst og tenkningsinnstillinger.
Undersøk brukstellerne for å avgjøre om forespørselen gjenbrukte et prefiks:

* `cache_creation_input_tokens` teller tokens som skrives til cachen.
* `cache_read_input_tokens` teller tokens som leses fra cachen.
* `input_tokens` teller inndata som behandles utenfor disse cache-tellerne.

Ved gjentatte forespørsler rapporterer `cache_read_input_tokens` hvor mange input tokens
som ble lest fra cachen. OpenAPI- **Prompt Cache**
-eksempelet inneholder en komplett fiktiv referanse som du kan lagre som
`reference.txt` for å prøve eksempelet.

## Strøm svar

Angi `stream: true` for Server-Sent Events. SDK-en eksponerer tekstfragmenter etter hvert som de
ankommer:

```python theme={null}
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-opus-5",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": "Write a two-line poem about a comet.",
        },
    ],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
```

En meldingsstrøm inneholder `message_start`, innholdsblokkhendelser, `message_delta`,
og `message_stop`. Innholdsblokker kan inneholde tekst, tenkning eller verktøyaktivitet.
For en tekstblokk inneholder `content_block_delta` en `text_delta`. Les endelige bruksdata
og stoppårsaken fra `message_delta`.

## Kontroller innsats

Angi `output_config.effort` for å styre mengden resonnering. Dette eksemplet bruker
`low` for en kort forklaring og venter på den fullførte strømmede meldingen:

```python theme={null}
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-opus-5",
    max_tokens=1000,
    messages=[
        {
            "role": "user",
            "content": "Summarize the benefit of automated tests in one sentence.",
        },
    ],
    output_config={
        "effort": "low",
    },
) as stream:
    message = stream.get_final_message()

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

Bruk den offisielle
[referansen for innsats](https://platform.claude.com/docs/en/build-with-claude/effort)
for å velge et innsatsnivå. Angi `max_tokens` separat for å begrense utdataenes lengde.

## Bruk serververktøy

Serververktøy kjøres under API-forespørselen og returnerer resultatblokker sammen med
Claudes svar.

<Tabs>
  <Tab title="Web Fetch">
    Hent en artikkel og be Claude bruke det hentede dokumentet i svaret sitt.
    Dette eksemplet streamer svaret og undersøker både den endelige teksten og
    `web_fetch_tool_result` blokken:

    ```python theme={null}
    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=2048,
        messages=[
            {
                "role": "user",
                "content": "Fetch https://arxiv.org/abs/1512.03385 and state the paper title and the proposed learning framework in two sentences.",
            },
        ],
        tools=[
            {
                "type": "web_fetch_20250910",
                "name": "web_fetch",
                "max_uses": 3,
            },
        ],
    ) as stream:
        message = stream.get_final_message()

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

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

    Svaret kombinerer en `server_tool_use`-blokk med en `web_fetch_tool_result`
    som inneholder det hentede dokumentet eller en verktøyfeil.
  </Tab>

  <Tab title="Web Search">
    Søk etter en offisiell lanseringsdato og be Claude oppgi kilden sin.
    Dette eksemplet streamer svaret, samler inn den endelige meldingen og skriver ut de
    returnerte søkekildene:

    ```python theme={null}
    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=4096,
        messages=[
            {
                "role": "user",
                "content": "Search the web for the official Python 3.14 release date. Answer with the date and cite a source.",
            },
        ],
        tools=[
            {
                "type": "web_search_20250305",
                "name": "web_search",
                "max_uses": 3,
            },
        ],
    ) as stream:
        message = stream.get_final_message()

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

    for block in message.content:
        if block.type == "web_search_tool_result":
            if isinstance(block.content, list):
                for result in block.content:
                    if result.type == "web_search_result":
                        print(result.title, result.url)
    ```

    Svaret kombinerer en `server_tool_use`-blokk med en `web_search_tool_result`
    som inneholder kilder. Les kildetitlene og URL-ene fra denne resultatblokken.
  </Tab>
</Tabs>

## Returner resultater fra klientverktøy

For et klientverktøy returnerer Claude en `tool_use`-blokk. Kjør applikasjonsfunksjonen
og send resultatet i en `tool_result`-blokk med den samsvarende `tool_use_id`.
Behold alt assistentinnholdet mellom de to forespørslene.

Dette eksemplet oppgir et fiktivt bestillingsresultat og ber Claude bruke dette resultatet:

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

client = anthropic.Anthropic(
    base_url="https://api.cometapi.com",
    api_key=os.environ["COMETAPI_KEY"],
)
tools = [{
    "name": "get_order_status",
    "description": "Look up the status of a demonstration order.",
    "input_schema": {
        "type": "object",
        "properties": {
            "order_id": {
                "type": "string",
                "description": "The order reference.",
            },
        },
        "required": ["order_id"],
    },
}]
messages = [{
    "role": "user",
    "content": "Check the status of demo-order-42 using the order tool.",
}]

with client.messages.stream(
    model="claude-opus-5",
    max_tokens=1000,
    messages=messages,
    tools=tools,
) as stream:
    message = stream.get_final_message()

tool_call = next(b for b in message.content if b.type == "tool_use")
messages.append({
    "role": "assistant",
    "content": [block.model_dump() for block in message.content],
})
messages.append({
    "role": "user",
    "content": [{
        "type": "tool_result",
        "tool_use_id": tool_call.id,
        "content": json.dumps({
            "status": "ready_for_pickup",
            "pickup_code": "COMET42",
        }),
    }],
})

with client.messages.stream(
    model="claude-opus-5",
    max_tokens=1000,
    messages=messages,
    tools=tools,
) as stream:
    follow_up = stream.get_final_message()

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

## Svareksempel

En forespørsel uten strømming returnerer et meldingsobjekt. Følgende eksempel viser dets
tekst- og bruksfelt med en illustrativ meldingsidentifikator:

```json theme={null}
{
  "id": "msg_example",
  "type": "message",
  "role": "assistant",
  "model": "claude-opus-5",
  "content": [
    {
      "type": "text",
      "text": "Here are three search queries covering different angles of the topic:\n\n1. **\"grid-scale battery storage cost trends 2024 2025\"**\n — Targets economics and recent price data for lithium-ion and other utility-scale systems.\n\n2. **\"long-duration energy storage technologies comparison flow battery vs compressed air vs thermal\"**\n — Surfaces technical comparisons of options for storage beyond the 4–8 hour range, where lithium-ion becomes less cost-effective.\n\n3. **\"green hydrogen seasonal storage feasibility round-trip efficiency\"**\n — Digs into the viability of hydrogen for multi-week or seasonal balancing, including its efficiency penalties.\n\n**A few tips for refining these:**\n- Add `site:.gov` or `site:.edu` to prioritize research and agency reports (e.g., NREL, IEA, DOE).\n- Append a region like `Europe`, `India`, or `California` if you need location-specific policy or deployment data.\n- Try `filetype:pdf` to pull up technical white papers and government studies directly.\n\nWant me to tailor these toward a specific use case — academic research, investment analysis, or policy work?"
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 23,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0,
    "cache_creation": {
      "ephemeral_5m_input_tokens": 0,
      "ephemeral_1h_input_tokens": 0
    },
    "output_tokens": 437,
    "output_tokens_details": {
      "thinking_tokens": 50
    }
  }
}
```

Stoppårsaken beskriver neste handling. `end_turn` fullfører svaret,
`max_tokens` betyr at utdataene nådde grensen, og `tool_use` ber om et klientverktøy
resultat. For en serververktøyrunde som returnerer `pause_turn`, fortsett med det
returnerte assistentinnholdet uendret.


## 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 Claude requests in the Anthropic Messages format. The examples
        cover text and image input, conversation history, adaptive thinking,
        client tools, prompt caching, streaming, and server tools.
      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 feature identifiers required by a specific beta API
            feature. Omit this header for the examples on this page.
          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-opus-5
                  default: claude-opus-5
                messages:
                  type: array
                  description: >-
                    Conversation history. Use user and assistant messages with
                    text strings or content-block arrays. Return complete
                    assistant content blocks when continuing a tool call.
                  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
                                    - thinking
                                    - redacted_thinking
                                    - tool_use
                                    - tool_result
                                    - server_tool_use
                                    - web_fetch_tool_result
                                    - web_search_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 URL for the image or
                                        document.
                                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
                                      enum:
                                        - 5m
                                        - 1h
                                      description: >-
                                        Cache lifetime. Use 5m for five minutes
                                        or 1h for one hour. The default is 5m.
                                id:
                                  type: string
                                  description: >-
                                    The ID from a returned tool_use block.
                                    Preserve this value in assistant history.
                                name:
                                  type: string
                                  description: The function name in a tool_use block.
                                input:
                                  type: object
                                  description: Function arguments in a tool_use block.
                                tool_use_id:
                                  type: string
                                  description: >-
                                    The ID of the tool_use block answered by
                                    this tool_result.
                                content:
                                  description: >-
                                    Tool result content: a string, an array of
                                    content blocks, or a server-tool result or
                                    error object.
                                  oneOf:
                                    - type: string
                                    - type: array
                                      items:
                                        type: object
                                    - type: object
                                is_error:
                                  type: boolean
                                  description: >-
                                    Set true when a client tool_result reports a
                                    failed tool execution.
                                thinking:
                                  type: string
                                  description: >-
                                    Thinking content returned in an assistant
                                    block. Preserve it unchanged in conversation
                                    history.
                                signature:
                                  type: string
                                  description: >-
                                    Thinking signature returned by the API.
                                    Preserve it unchanged with its thinking
                                    block.
                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`.
                              ttl:
                                type: string
                                enum:
                                  - 5m
                                  - 1h
                                description: >-
                                  Cache lifetime. Use 5m for five minutes or 1h
                                  for one hour. The default is 5m.
                            description: >-
                              Marks this system block as a prompt-cache
                              breakpoint.
                temperature:
                  type: number
                  description: Sampling temperature. The examples omit sampling overrides.
                  minimum: 0
                  maximum: 1
                top_p:
                  type: number
                  description: >-
                    Nucleus sampling threshold. The examples omit sampling
                    overrides.
                  minimum: 0
                  maximum: 1
                top_k:
                  type: integer
                  description: >-
                    Limits sampling to the k most likely tokens. The examples
                    omit sampling overrides.
                  minimum: 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: >-
                    Thinking configuration. The adaptive example uses type
                    adaptive and sets output_config.effort separately.
                  properties:
                    type:
                      type: string
                      description: >-
                        Thinking mode. Use adaptive for the example on this
                        page. Other values depend on the selected model.
                      enum:
                        - adaptive
                        - disabled
                        - enabled
                    budget_tokens:
                      type: integer
                      description: >-
                        Token budget for models that support manual thinking
                        with type enabled. Omit this field when using type
                        adaptive.
                      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: >-
                    Client tools define a name and input_schema. Server tools
                    use a versioned type and name, such as the web_fetch and
                    web_search examples on this page.
                  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: >-
                          Versioned server tool type. The basic examples use
                          web_fetch_20250910 and web_search_20250305.
                      max_uses:
                        type: integer
                        description: Maximum uses of this server tool within one 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 reasoning effort and structured output.
                  properties:
                    effort:
                      type: string
                      description: >-
                        Reasoning effort. The examples use low for a brief
                        answer and xhigh with adaptive thinking.
                      enum:
                        - low
                        - medium
                        - high
                        - xhigh
                        - max
                      example: medium
                    format:
                      type: object
                      description: >-
                        Structured output configuration for supported models.
                        See the [structured outputs
                        documentation](https://platform.claude.com/docs/en/build-with-claude/structured-outputs)
                        for schema requirements.
                      required:
                        - type
                        - schema
                      properties:
                        type:
                          type: string
                          enum:
                            - json_schema
                          description: >-
                            Set json_schema to request output matching the
                            supplied schema.
                        schema:
                          type: object
                          description: JSON Schema that describes the requested 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-opus-5
                  max_tokens: 1000
                  messages:
                    - role: user
                      content: >-
                        Suggest three search queries about renewable energy
                        storage.
              Image Input:
                summary: Image Input
                value:
                  model: claude-opus-5
                  max_tokens: 1000
                  messages:
                    - role: user
                      content:
                        - type: image
                          source:
                            type: url
                            url: https://picsum.photos/seed/comet/800/600.jpg
                        - type: text
                          text: Describe the visible scene in one sentence.
                  stream: true
              Prompt Cache:
                summary: With prompt caching
                value:
                  model: claude-sonnet-5
                  max_tokens: 1024
                  messages:
                    - role: user
                      content: >-
                        How long can customers return damaged books, and what
                        must they provide?
                  system:
                    - type: text
                      text: >-
                        Comet Books sample reference. The following policies
                        describe a fictional bookstore.


                        Section 1: Damaged books may be returned within 30 days.
                        A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 2: Damaged books may be returned within 30 days.
                        A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 3: Damaged books may be returned within 30 days.
                        A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 4: Damaged books may be returned within 30 days.
                        A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 5: Damaged books may be returned within 30 days.
                        A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 6: Damaged books may be returned within 30 days.
                        A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 7: Damaged books may be returned within 30 days.
                        A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 8: Damaged books may be returned within 30 days.
                        A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 9: Damaged books may be returned within 30 days.
                        A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 10: Damaged books may be returned within 30
                        days. A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 11: Damaged books may be returned within 30
                        days. A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 12: Damaged books may be returned within 30
                        days. A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 13: Damaged books may be returned within 30
                        days. A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 14: Damaged books may be returned within 30
                        days. A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 15: Damaged books may be returned within 30
                        days. A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 16: Damaged books may be returned within 30
                        days. A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 17: Damaged books may be returned within 30
                        days. A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 18: Damaged books may be returned within 30
                        days. A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 19: Damaged books may be returned within 30
                        days. A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 20: Damaged books may be returned within 30
                        days. A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 21: Damaged books may be returned within 30
                        days. A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 22: Damaged books may be returned within 30
                        days. A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 23: Damaged books may be returned within 30
                        days. A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 24: Damaged books may be returned within 30
                        days. A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 25: Damaged books may be returned within 30
                        days. A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 26: Damaged books may be returned within 30
                        days. A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 27: Damaged books may be returned within 30
                        days. A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.

                        Section 28: Damaged books may be returned within 30
                        days. A receipt is required. Unopened stationery may be
                        exchanged within 14 days. Digital downloads are final.
                        Staff record the order reference and explain the return
                        steps clearly.
                      cache_control:
                        type: ephemeral
                  stream: true
                description: >-
                  The code samples read this reference material from a local
                  UTF-8 reference.txt file. Keep the cached prefix unchanged
                  when repeating the request.
              Streaming:
                summary: Streaming response
                value:
                  model: claude-opus-5
                  max_tokens: 1024
                  messages:
                    - role: user
                      content: Write a two-line poem about a comet.
                  stream: true
              Web Fetch:
                summary: With web fetch tool
                value:
                  model: claude-sonnet-5
                  max_tokens: 2048
                  messages:
                    - role: user
                      content: >-
                        Fetch https://arxiv.org/abs/1512.03385 and state the
                        paper title and the proposed learning framework in two
                        sentences.
                  tools:
                    - type: web_fetch_20250910
                      name: web_fetch
                      max_uses: 3
                  stream: true
              Adaptive Thinking:
                summary: With adaptive thinking and effort
                value:
                  model: claude-opus-5
                  max_tokens: 4096
                  messages:
                    - role: user
                      content: >-
                        A shop sells notebooks for $7 each. Buying three earns a
                        $4 discount. A customer pays $20 for three notebooks.
                        Calculate the total and the change, and explain your
                        steps.
                  thinking:
                    type: adaptive
                  output_config:
                    effort: xhigh
                  stream: true
              Effort control:
                summary: Stream a concise response with low effort
                value:
                  model: claude-opus-5
                  max_tokens: 1000
                  messages:
                    - role: user
                      content: >-
                        Summarize the benefit of automated tests in one
                        sentence.
                  output_config:
                    effort: low
                  stream: true
              Web Search:
                summary: Web Search
                value:
                  model: claude-sonnet-5
                  max_tokens: 4096
                  messages:
                    - role: user
                      content: >-
                        Search the web for the official Python 3.14 release
                        date. Answer with the date and cite a source.
                  tools:
                    - type: web_search_20250305
                      name: web_search
                      max_uses: 3
                  stream: true
      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: Message identifier returned by the API.
                  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: >-
                            Content block type, such as text, thinking,
                            tool_use, server_tool_use, web_fetch_tool_result, or
                            web_search_tool_result.
                        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).
                        tool_use_id:
                          type: string
                          description: The server tool call answered by this result block.
                        content:
                          description: >-
                            Server tool results or an error object. Inspect the
                            block type before reading its fields.
                          oneOf:
                            - type: object
                            - type: array
                              items:
                                type: object
                        citations:
                          type: array
                          description: >-
                            Source citations attached to a text block when
                            returned.
                          items:
                            type: object
                  model:
                    type: string
                    description: Model ID reported by the response.
                  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: >-
                          Uncached input tokens processed for the request. Cache
                          creation and cache reads have separate counters.
                      output_tokens:
                        type: integer
                        description: >-
                          Total output tokens, including thinking when the model
                          uses thinking.
                      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.
                      server_tool_use:
                        type: object
                        description: Server tool request counts when server tools are used.
                        properties:
                          web_fetch_requests:
                            type: integer
                            description: Number of web fetch requests.
                          web_search_requests:
                            type: integer
                            description: Number of web search requests.
                example:
                  id: msg_example
                  type: message
                  role: assistant
                  model: claude-opus-5
                  content:
                    - type: text
                      text: >-
                        Here are three search queries covering different angles
                        of the topic:


                        1. **"grid-scale battery storage cost trends 2024
                        2025"**
                         — Targets economics and recent price data for lithium-ion and other utility-scale systems.

                        2. **"long-duration energy storage technologies
                        comparison flow battery vs compressed air vs thermal"**
                         — Surfaces technical comparisons of options for storage beyond the 4–8 hour range, where lithium-ion becomes less cost-effective.

                        3. **"green hydrogen seasonal storage feasibility
                        round-trip efficiency"**
                         — Digs into the viability of hydrogen for multi-week or seasonal balancing, including its efficiency penalties.

                        **A few tips for refining these:**

                        - Add `site:.gov` or `site:.edu` to prioritize research
                        and agency reports (e.g., NREL, IEA, DOE).

                        - Append a region like `Europe`, `India`, or
                        `California` if you need location-specific policy or
                        deployment data.

                        - Try `filetype:pdf` to pull up technical white papers
                        and government studies directly.


                        Want me to tailor these toward a specific use case —
                        academic research, investment analysis, or policy work?
                  stop_reason: end_turn
                  stop_sequence: null
                  usage:
                    input_tokens: 23
                    cache_creation_input_tokens: 0
                    cache_read_input_tokens: 0
                    cache_creation:
                      ephemeral_5m_input_tokens: 0
                      ephemeral_1h_input_tokens: 0
                    output_tokens: 437
                    output_tokens_details:
                      thinking_tokens: 50
              example:
                id: msg_example
                type: message
                role: assistant
                model: claude-opus-5
                content:
                  - type: text
                    text: >-
                      Here are three search queries covering different angles of
                      the topic:


                      1. **"grid-scale battery storage cost trends 2024 2025"**
                       — Targets economics and recent price data for lithium-ion and other utility-scale systems.

                      2. **"long-duration energy storage technologies comparison
                      flow battery vs compressed air vs thermal"**
                       — Surfaces technical comparisons of options for storage beyond the 4–8 hour range, where lithium-ion becomes less cost-effective.

                      3. **"green hydrogen seasonal storage feasibility
                      round-trip efficiency"**
                       — Digs into the viability of hydrogen for multi-week or seasonal balancing, including its efficiency penalties.

                      **A few tips for refining these:**

                      - Add `site:.gov` or `site:.edu` to prioritize research
                      and agency reports (e.g., NREL, IEA, DOE).

                      - Append a region like `Europe`, `India`, or `California`
                      if you need location-specific policy or deployment data.

                      - Try `filetype:pdf` to pull up technical white papers and
                      government studies directly.


                      Want me to tailor these toward a specific use case —
                      academic research, investment analysis, or policy work?
                stop_reason: end_turn
                stop_sequence: null
                usage:
                  input_tokens: 23
                  cache_creation_input_tokens: 0
                  cache_read_input_tokens: 0
                  cache_creation:
                    ephemeral_5m_input_tokens: 0
                    ephemeral_1h_input_tokens: 0
                  output_tokens: 437
                  output_tokens_details:
                    thinking_tokens: 50
            text/event-stream:
              schema:
                type: string
                description: >-
                  Anthropic SSE events. A completed message ends with
                  message_stop; text_delta events contain text fragments.
      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-opus-5",
                max_tokens=1000,
                messages=[
                    {
                        "role": "user",
                        "content": "Suggest three search queries about renewable energy storage.",
                    },
                ],
            )

            for block in message.content:
                if block.type == "text":
                    print(block.text)
        - lang: Python
          label: Prompt Cache
          source: |
            import os
            from pathlib import Path
            import anthropic

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

            reference = Path("reference.txt").read_text(encoding="utf-8")

            with client.messages.stream(
                model="claude-sonnet-5",
                max_tokens=1024,
                messages=[
                    {
                        "role": "user",
                        "content": "How long can customers return damaged books, and what must they provide?",
                    },
                ],
                system=[
                    {
                        "type": "text",
                        "text": reference,
                        "cache_control": {
                            "type": "ephemeral",
                        },
                    },
                ],
            ) as stream:
                message = stream.get_final_message()

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

            print(message.usage.model_dump_json())
        - 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"],
            )

            with client.messages.stream(
                model="claude-opus-5",
                max_tokens=4096,
                messages=[
                    {
                        "role": "user",
                        "content": "A shop sells notebooks for $7 each. Buying three earns a $4 discount. A customer pays $20 for three notebooks. Calculate the total and the change, and explain your steps.",
                    },
                ],
                thinking={
                    "type": "adaptive",
                },
                output_config={
                    "effort": "xhigh",
                },
            ) as stream:
                message = stream.get_final_message()

            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"],
            )

            with client.messages.stream(
                model="claude-opus-5",
                max_tokens=1000,
                messages=[
                    {
                        "role": "user",
                        "content": "Summarize the benefit of automated tests in one sentence.",
                    },
                ],
                output_config={
                    "effort": "low",
                },
            ) as stream:
                message = stream.get_final_message()

            for block in message.content:
                if block.type == "text":
                    print(block.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-opus-5",
                max_tokens=1024,
                messages=[
                    {
                        "role": "user",
                        "content": "Write a two-line poem about a comet.",
                    },
                ],
            ) as stream:
                for text in stream.text_stream:
                    print(text, end="", flush=True)
        - 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"],
            )

            with client.messages.stream(
                model="claude-sonnet-5",
                max_tokens=2048,
                messages=[
                    {
                        "role": "user",
                        "content": "Fetch https://arxiv.org/abs/1512.03385 and state the paper title and the proposed learning framework in two sentences.",
                    },
                ],
                tools=[
                    {
                        "type": "web_fetch_20250910",
                        "name": "web_fetch",
                        "max_uses": 3,
                    },
                ],
            ) as stream:
                message = stream.get_final_message()

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

            for block in message.content:
                if block.type == "web_fetch_tool_result":
                    print(block.model_dump_json())
        - 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"],
            )

            with client.messages.stream(
                model="claude-opus-5",
                max_tokens=1000,
                messages=[
                    {
                        "role": "user",
                        "content": [
                            {
                                "type": "image",
                                "source": {
                                    "type": "url",
                                    "url": "https://picsum.photos/seed/comet/800/600.jpg",
                                },
                            },
                            {
                                "type": "text",
                                "text": "Describe the visible scene in one sentence.",
                            },
                        ],
                    },
                ],
            ) as stream:
                message = stream.get_final_message()

            for block in message.content:
                if block.type == "text":
                    print(block.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-opus-5",
              "max_tokens": 1000,
              "messages": [
                {
                  "role": "user",
                  "content": "Suggest three search queries about renewable energy storage."
                }
              ]
            });

            for (const block of message.content) {
              if (block.type === "text") console.log(block.text);
            }
        - lang: JavaScript
          label: Prompt Cache
          source: |
            import Anthropic from "@anthropic-ai/sdk";
            import fs from "node:fs";

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

            const reference = fs.readFileSync("reference.txt", "utf8");

            const stream = client.messages.stream({
              "model": "claude-sonnet-5",
              "max_tokens": 1024,
              "messages": [
                {
                  "role": "user",
                  "content": "How long can customers return damaged books, and what must they provide?"
                }
              ],
              "system": [
                {
                  "type": "text",
                  "text": reference,
                  "cache_control": {
                    "type": "ephemeral"
                  }
                }
              ]
            });
            const message = await stream.finalMessage();

            for (const block of message.content) {
              if (block.type === "text") console.log(block.text);
            }

            console.log(message.usage);
        - 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 stream = client.messages.stream({
              "model": "claude-opus-5",
              "max_tokens": 4096,
              "messages": [
                {
                  "role": "user",
                  "content": "A shop sells notebooks for $7 each. Buying three earns a $4 discount. A customer pays $20 for three notebooks. Calculate the total and the change, and explain your steps."
                }
              ],
              "thinking": {
                "type": "adaptive"
              },
              "output_config": {
                "effort": "xhigh"
              }
            });
            const message = await stream.finalMessage();

            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 stream = client.messages.stream({
              "model": "claude-opus-5",
              "max_tokens": 1000,
              "messages": [
                {
                  "role": "user",
                  "content": "Summarize the benefit of automated tests in one sentence."
                }
              ],
              "output_config": {
                "effort": "low"
              }
            });
            const message = await stream.finalMessage();

            for (const block of message.content) {
              if (block.type === "text") console.log(block.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 = client.messages.stream({
              "model": "claude-opus-5",
              "max_tokens": 1024,
              "messages": [
                {
                  "role": "user",
                  "content": "Write a two-line poem about a comet."
                }
              ]
            });
            stream.on("text", (text) => process.stdout.write(text));
            await stream.finalMessage();
        - 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 stream = client.messages.stream({
              "model": "claude-sonnet-5",
              "max_tokens": 2048,
              "messages": [
                {
                  "role": "user",
                  "content": "Fetch https://arxiv.org/abs/1512.03385 and state the paper title and the proposed learning framework in two sentences."
                }
              ],
              "tools": [
                {
                  "type": "web_fetch_20250910",
                  "name": "web_fetch",
                  "max_uses": 3
                }
              ]
            });
            const message = await stream.finalMessage();

            for (const block of message.content) {
              if (block.type === "text") console.log(block.text);
            }

            for (const block of message.content) {
              if (block.type === "web_fetch_tool_result") console.log(block);
            }
        - 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 stream = client.messages.stream({
              "model": "claude-opus-5",
              "max_tokens": 1000,
              "messages": [
                {
                  "role": "user",
                  "content": [
                    {
                      "type": "image",
                      "source": {
                        "type": "url",
                        "url": "https://picsum.photos/seed/comet/800/600.jpg"
                      }
                    },
                    {
                      "type": "text",
                      "text": "Describe the visible scene in one sentence."
                    }
                  ]
                }
              ]
            });
            const message = await stream.finalMessage();

            for (const block of message.content) {
              if (block.type === "text") console.log(block.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-opus-5",
              "max_tokens": 1000,
              "messages": [
                {
                  "role": "user",
                  "content": "Suggest three search queries about renewable energy storage."
                }
              ]
            }'
        - lang: Shell
          label: Prompt Cache
          source: |
            request_body=$(jq -n --rawfile reference reference.txt '
            {
              "model": "claude-sonnet-5",
              "max_tokens": 1024,
              "messages": [
                {
                  "role": "user",
                  "content": "How long can customers return damaged books, and what must they provide?"
                }
              ],
              "system": [
                {
                  "type": "text",
                  "text": $reference,
                  "cache_control": {
                    "type": "ephemeral"
                  }
                }
              ],
              "stream": true
            }
            ')

            curl "https://api.cometapi.com/v1/messages" \
              -H "Content-Type: application/json" \
              -H "x-api-key: $COMETAPI_KEY" \
              -H "anthropic-version: 2023-06-01" \
              --no-buffer \
              --data-binary "$request_body"
        - 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" \
              --no-buffer \
              -d '{
              "model": "claude-opus-5",
              "max_tokens": 4096,
              "messages": [
                {
                  "role": "user",
                  "content": "A shop sells notebooks for $7 each. Buying three earns a $4 discount. A customer pays $20 for three notebooks. Calculate the total and the change, and explain your steps."
                }
              ],
              "thinking": {
                "type": "adaptive"
              },
              "output_config": {
                "effort": "xhigh"
              },
              "stream": true
            }'
        - 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" \
              --no-buffer \
              -d '{
              "model": "claude-opus-5",
              "max_tokens": 1000,
              "messages": [
                {
                  "role": "user",
                  "content": "Summarize the benefit of automated tests in one sentence."
                }
              ],
              "output_config": {
                "effort": "low"
              },
              "stream": true
            }'
        - 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" \
              --no-buffer \
              -d '{
              "model": "claude-opus-5",
              "max_tokens": 1024,
              "messages": [
                {
                  "role": "user",
                  "content": "Write a two-line poem about a comet."
                }
              ],
              "stream": true
            }'
        - 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" \
              --no-buffer \
              -d '{
              "model": "claude-sonnet-5",
              "max_tokens": 2048,
              "messages": [
                {
                  "role": "user",
                  "content": "Fetch https://arxiv.org/abs/1512.03385 and state the paper title and the proposed learning framework in two sentences."
                }
              ],
              "tools": [
                {
                  "type": "web_fetch_20250910",
                  "name": "web_fetch",
                  "max_uses": 3
                }
              ],
              "stream": true
            }'
        - 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" \
              --no-buffer \
              -d '{
              "model": "claude-opus-5",
              "max_tokens": 1000,
              "messages": [
                {
                  "role": "user",
                  "content": [
                    {
                      "type": "image",
                      "source": {
                        "type": "url",
                        "url": "https://picsum.photos/seed/comet/800/600.jpg"
                      }
                    },
                    {
                      "type": "text",
                      "text": "Describe the visible scene in one sentence."
                    }
                  ]
                }
              ],
              "stream": true
            }'
        - lang: Python
          label: Web Search
          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=4096,
                messages=[
                    {
                        "role": "user",
                        "content": "Search the web for the official Python 3.14 release date. Answer with the date and cite a source.",
                    },
                ],
                tools=[
                    {
                        "type": "web_search_20250305",
                        "name": "web_search",
                        "max_uses": 3,
                    },
                ],
            ) as stream:
                message = stream.get_final_message()

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

            for block in message.content:
                if block.type == "web_search_tool_result":
                    if isinstance(block.content, list):
                        for result in block.content:
                            if result.type == "web_search_result":
                                print(result.title, result.url)
        - lang: JavaScript
          label: Web Search
          source: |
            import Anthropic from "@anthropic-ai/sdk";

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

            const stream = client.messages.stream({
              "model": "claude-sonnet-5",
              "max_tokens": 4096,
              "messages": [
                {
                  "role": "user",
                  "content": "Search the web for the official Python 3.14 release date. Answer with the date and cite a source."
                }
              ],
              "tools": [
                {
                  "type": "web_search_20250305",
                  "name": "web_search",
                  "max_uses": 3
                }
              ]
            });
            const message = await stream.finalMessage();

            for (const block of message.content) {
              if (block.type === "text") console.log(block.text);
              if (block.type === "web_search_tool_result" && Array.isArray(block.content)) {
                for (const result of block.content) {
                  if (result.type === "web_search_result") console.log(result.title, result.url);
                }
              }
            }
        - lang: Shell
          label: Web Search
          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" \
              --no-buffer \
              -d '{
              "model": "claude-sonnet-5",
              "max_tokens": 4096,
              "messages": [
                {
                  "role": "user",
                  "content": "Search the web for the official Python 3.14 release date. Answer with the date and cite a source."
                }
              ],
              "tools": [
                {
                  "type": "web_search_20250305",
                  "name": "web_search",
                  "max_uses": 3
                }
              ],
              "stream": true
            }'
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.

````