> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qwencloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Anthropic Messages API

> Call Qwen models using Anthropic SDKs

## FAQ

**After configuring Claude Desktop or Claude Code, the connection test fails with `Model discovery — Gateway /v1/models returned HTTP 404`, or the request URL contains `/v1/v1/models`. How do I fix it?**

The model discovery feature of clients such as Claude Desktop and Claude Code automatically appends `/v1/models` to the configured base URL. Check the following two points:

- **Do not end the base URL with `/v1/`**: it should end at `/apps/anthropic` (for example, for Singapore use `https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic`). If you mistakenly enter `.../apps/anthropic/v1/`, the client appends `/v1/models` and produces the duplicated path `/v1/v1/models`, which returns HTTP 404.

- **Add models manually to skip discovery**: the Anthropic-compatible endpoint provides only the Messages API (`/v1/messages`) and does not provide a model list endpoint (`/v1/models`), so the model discovery request returns 404 as well. Manually add models (for example, `qwen3.7-plus`) under Models in the client to skip automatic discovery.

## OpenAPI

````yaml post /apps/anthropic/v1/messages
openapi: 3.1.0
info:
  title: Anthropic compatible Messages API
  description: |-
    Call Qwen models through the Anthropic-compatible Messages API. Supports thinking, tool use, web search, streaming, image/video understanding, and context caching.

    Authentication: pass your API key via the `x-api-key` header or the `Authorization: Bearer` header.
  version: 1.0.0
servers:
  - url: https://{region}.maas.qwencloudapi.com
    description: Region. Use an API key from the same region.
    variables:
      region:
        default: ap-southeast-1
        enum:
          - ap-southeast-1
          - cn-beijing
          - eu-central-1
          - cn-hongkong
          - ap-northeast-1
          - us-east-1
security:
  - ApiKeyAuth: []
paths:
  /apps/anthropic/v1/messages:
    post:
      operationId: anthropicMessages
      summary: Create a message
      description: Send messages to a Qwen model via the Anthropic-compatible interface and receive generated replies. Supports multi-turn conversation, streaming, thinking, tool use, image/video understanding, and context caching.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/AnthropicMessagesRequest"
            example:
              model: qwen3.7-plus
              max_tokens: 1024
              system: You are a helpful assistant
              messages:
                - role: user
                  content: Who are you?
      responses:
        "200":
          description: Successful response
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AnthropicMessage"
              example:
                id: msg_e2898f19-fc0e-4cb3-bd9b-5b7dc4ea3bc9
                type: message
                role: assistant
                model: qwen3.7-plus
                content:
                  - type: thinking
                    thinking: Let me analyze this question...
                    signature: ""
                  - type: text
                    text: Hello! I am Qwen...
                stop_reason: end_turn
                stop_sequence: null
                usage:
                  input_tokens: 22
                  output_tokens: 223
                  cache_creation_input_tokens: 0
                  cache_read_input_tokens: 0
            text/event-stream:
              schema:
                $ref: "#/components/schemas/AnthropicStreamEvent"
              example:
                type: content_block_delta
                index: 1
                delta:
                  type: text_delta
                  text: Artificial intelligence (AI) is a major branch of computer science...
        "400":
          description: Invalid request parameters
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AnthropicErrorResponse"
              example:
                type: error
                error:
                  type: invalid_request_error
                  message: "max_tokens: Field required"
        "401":
          description: Authentication failed
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AnthropicErrorResponse"
              example:
                type: error
                error:
                  type: authentication_error
                  message: invalid x-api-key
        "429":
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AnthropicErrorResponse"
              example:
                type: error
                error:
                  type: rate_limit_error
                  message: Rate limit exceeded
      x-codeSamples:
        - lang: python
          label: Basic call
          source: |-
            import anthropic
            import os

            client = anthropic.Anthropic(
                api_key=os.getenv("DASHSCOPE_API_KEY"),
                # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
                # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
                base_url="https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic",
            )

            message = client.messages.create(
                model="qwen3.7-plus",
                max_tokens=1024,
                system="You are a helpful assistant",
                messages=[
                    {
                        "role": "user",
                        "content": "Who are you?"
                    }
                ],
                thinking={"type": "disabled"},
            )

            print(message.content[0].text)
        - lang: javascript
          label: Basic call
          source: |-
            import Anthropic from "@anthropic-ai/sdk";

            const anthropic = new Anthropic({
              apiKey: process.env.DASHSCOPE_API_KEY,
              // Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
              // API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
              baseURL: "https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic",
            });

            async function main() {
              const message = await anthropic.messages.create({
                model: "qwen3.7-plus",
                max_tokens: 1024,
                system: "You are a helpful assistant",
                messages: [{
                  role: "user",
                  content: "Who are you?"
                }],
                thinking: { type: "disabled" },
              });

              console.log(message.content[0].text);
            }

            main().catch(console.error);
        - lang: curl
          label: Basic call
          source: |-
            # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
            # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
            curl -X POST "https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic/v1/messages" \
              -H "Content-Type: application/json" \
              -H "x-api-key: $DASHSCOPE_API_KEY" \
              -d '{
                "model": "qwen3.7-plus",
                "max_tokens": 1024,
                "system": "You are a helpful assistant",
                "messages": [
                    {
                        "role": "user",
                        "content": "Who are you?"
                    }
                ],
                "thinking": {"type": "disabled"}
            }'
        - lang: python
          label: Streaming
          source: |-
            import anthropic
            import os

            client = anthropic.Anthropic(
                api_key=os.getenv("DASHSCOPE_API_KEY"),
                # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
                # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
                base_url="https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic",
            )

            stream = client.messages.create(
                model="qwen3.7-plus",
                max_tokens=1024,
                stream=True,
                messages=[
                    {
                        "role": "user",
                        "content": "Give a brief introduction to artificial intelligence."
                    }
                ],
                thinking={"type": "disabled"},
            )

            for chunk in stream:
                if chunk.type == "content_block_delta":
                    if hasattr(chunk.delta, 'text'):
                        print(chunk.delta.text, end="", flush=True)
        - lang: javascript
          label: Streaming
          source: |-
            import Anthropic from "@anthropic-ai/sdk";

            async function main() {
              const anthropic = new Anthropic({
                apiKey: process.env.DASHSCOPE_API_KEY,
                // Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
                // API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
                baseURL: "https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic",
              });

              const stream = await anthropic.messages.create({
                model: "qwen3.7-plus",
                max_tokens: 1024,
                stream: true,
                messages: [{
                  role: "user",
                  content: "Give a brief introduction to artificial intelligence."
                }],
                thinking: { type: "disabled" },
              });

              for await (const chunk of stream) {
                if (chunk.type === "content_block_delta" && 'text' in chunk.delta) {
                  process.stdout.write(chunk.delta.text);
                }
              }
            }

            main().catch(console.error);
        - lang: curl
          label: Streaming
          source: |-
            # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
            # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
            curl -X POST "https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic/v1/messages" \
              -H "Content-Type: application/json" \
              -H "x-api-key: $DASHSCOPE_API_KEY" \
              --no-buffer \
              -d '{
                "model": "qwen3.7-plus",
                "max_tokens": 1024,
                "stream": true,
                "messages": [
                    {
                        "role": "user",
                        "content": "Give a brief introduction to artificial intelligence."
                    }
                ],
                "thinking": {"type": "disabled"}
            }'
        - lang: python
          label: Thinking
          source: |-
            import anthropic
            import os

            client = anthropic.Anthropic(
                api_key=os.getenv("DASHSCOPE_API_KEY"),
                # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
                # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
                base_url="https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic",
            )

            stream = client.messages.create(
                model="qwen3.7-plus",
                max_tokens=2048,
                stream=True,
                thinking={
                    "type": "enabled",
                    "budget_tokens": 1024
                },
                messages=[
                    {
                        "role": "user",
                        "content": "Analyze the future prospects of quantum computing."
                    }
                ]
            )

            for chunk in stream:
                if chunk.type == "content_block_delta":
                    if hasattr(chunk.delta, 'thinking'):
                        print(chunk.delta.thinking, end="", flush=True)
                    elif hasattr(chunk.delta, 'text'):
                        print(chunk.delta.text, end="", flush=True)
        - lang: javascript
          label: Thinking
          source: |-
            import Anthropic from "@anthropic-ai/sdk";

            async function main() {
              const anthropic = new Anthropic({
                apiKey: process.env.DASHSCOPE_API_KEY,
                // Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
                // API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
                baseURL: "https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic",
              });

              const stream = await anthropic.messages.create({
                model: "qwen3.7-plus",
                max_tokens: 2048,
                stream: true,
                thinking: { type: "enabled", budget_tokens: 1024 },
                messages: [{
                  role: "user",
                  content: "Analyze the future prospects of quantum computing."
                }]
              });

              for await (const chunk of stream) {
                if (chunk.type === "content_block_delta") {
                  if ('thinking' in chunk.delta) {
                    process.stdout.write(chunk.delta.thinking);
                  } else if ('text' in chunk.delta) {
                    process.stdout.write(chunk.delta.text);
                  }
                }
              }
            }

            main().catch(console.error);
        - lang: curl
          label: Thinking
          source: |-
            # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
            # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
            curl -X POST "https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic/v1/messages" \
              -H "Content-Type: application/json" \
              -H "x-api-key: $DASHSCOPE_API_KEY" \
              -d '{
                "model": "qwen3.7-plus",
                "max_tokens": 2048,
                "stream": true,
                "thinking": {
                    "type": "enabled",
                    "budget_tokens": 1024
                },
                "messages": [
                    {
                        "role": "user",
                        "content": "Analyze the future prospects of quantum computing."
                    }
                ]
            }'
        - lang: python
          label: Image input
          source: |-
            import anthropic
            import os

            client = anthropic.Anthropic(
                api_key=os.getenv("DASHSCOPE_API_KEY"),
                # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
                # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
                base_url="https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic",
            )

            stream = client.messages.create(
                model="qwen3.7-plus",
                max_tokens=1024,
                stream=True,
                messages=[
                    {
                        "role": "user",
                        "content": [
                            {
                                "type": "image",
                                "source": {
                                    "type": "url",
                                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250414/mqqmiy/animal_01.jpg",
                                },
                            },
                            {
                                "type": "text",
                                "text": "Describe the content of this image."
                            },
                        ],
                    }
                ],
                thinking={"type": "disabled"},
            )

            for chunk in stream:
                if chunk.type == "content_block_delta":
                    if hasattr(chunk.delta, 'text'):
                        print(chunk.delta.text, end="", flush=True)
        - lang: javascript
          label: Image input
          source: |-
            import Anthropic from "@anthropic-ai/sdk";

            async function main() {
              const anthropic = new Anthropic({
                apiKey: process.env.DASHSCOPE_API_KEY,
                // Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
                // API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
                baseURL: "https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic",
              });

              const stream = await anthropic.messages.create({
                model: "qwen3.7-plus",
                max_tokens: 1024,
                stream: true,
                messages: [{
                  role: "user",
                  content: [
                    {
                      type: "image",
                      source: {
                        type: "url",
                        url: "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250414/mqqmiy/animal_01.jpg",
                      },
                    },
                    { type: "text", text: "Describe the content of this image." },
                  ],
                }],
                thinking: { type: "disabled" },
              });

              for await (const chunk of stream) {
                if (chunk.type === "content_block_delta" && 'text' in chunk.delta) {
                  process.stdout.write(chunk.delta.text);
                }
              }
            }

            main().catch(console.error);
        - lang: curl
          label: Image input
          source: |-
            # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
            # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
            curl -X POST "https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic/v1/messages" \
              -H "Content-Type: application/json" \
              -H "x-api-key: $DASHSCOPE_API_KEY" \
              -d '{
                "model": "qwen3.7-plus",
                "max_tokens": 1024,
                "stream": true,
                "messages": [
                    {
                        "role": "user",
                        "content": [
                            {
                                "type": "image",
                                "source": {
                                    "type": "url",
                                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250414/mqqmiy/animal_01.jpg"
                                }
                            },
                            {
                                "type": "text",
                                "text": "Describe the content of this image."
                            }
                        ]
                    }
                ],
                "thinking": {"type": "disabled"}
            }'
        - lang: python
          label: Video input
          source: |-
            import anthropic
            import os

            client = anthropic.Anthropic(
                api_key=os.getenv("DASHSCOPE_API_KEY"),
                # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
                # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
                base_url="https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic",
            )

            stream = client.messages.create(
                model="qwen3.7-plus",
                max_tokens=1024,
                stream=True,
                messages=[
                    {
                        "role": "user",
                        "content": [
                            {
                                "type": "video",
                                "source": {
                                    "type": "url",
                                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251208/zpupby/3e81ef38-98f0-4d55-bbb6-259334ca18d0.mp4",
                                },
                            },
                            {
                                "type": "text",
                                "text": "Describe the content of this video."
                            },
                        ],
                    }
                ],
                thinking={"type": "disabled"},
            )

            for chunk in stream:
                if chunk.type == "content_block_delta":
                    if hasattr(chunk.delta, 'text'):
                        print(chunk.delta.text, end="", flush=True)
        - lang: javascript
          label: Video input
          source: |-
            import Anthropic from "@anthropic-ai/sdk";

            async function main() {
              const anthropic = new Anthropic({
                apiKey: process.env.DASHSCOPE_API_KEY,
                // Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
                // API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
                baseURL: "https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic",
              });

              const stream = await anthropic.messages.create({
                model: "qwen3.7-plus",
                max_tokens: 1024,
                stream: true,
                messages: [{
                  role: "user",
                  content: [
                    {
                      type: "video",
                      source: {
                        type: "url",
                        url: "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251208/zpupby/3e81ef38-98f0-4d55-bbb6-259334ca18d0.mp4",
                      },
                    },
                    { type: "text", text: "Describe the content of this video." },
                  ],
                }],
                thinking: { type: "disabled" },
              });

              for await (const chunk of stream) {
                if (chunk.type === "content_block_delta" && 'text' in chunk.delta) {
                  process.stdout.write(chunk.delta.text);
                }
              }
            }

            main().catch(console.error);
        - lang: curl
          label: Video input
          source: |-
            # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
            # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
            curl -X POST "https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic/v1/messages" \
              -H "Content-Type: application/json" \
              -H "x-api-key: $DASHSCOPE_API_KEY" \
              -d '{
                "model": "qwen3.7-plus",
                "max_tokens": 1024,
                "stream": true,
                "messages": [
                    {
                        "role": "user",
                        "content": [
                            {
                                "type": "video",
                                "source": {
                                    "type": "url",
                                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251208/zpupby/3e81ef38-98f0-4d55-bbb6-259334ca18d0.mp4"
                                }
                            },
                            {
                                "type": "text",
                                "text": "Describe the content of this video."
                            }
                        ]
                    }
                ],
                "thinking": {"type": "disabled"}
            }'
        - lang: python
          label: Function Call
          source: |-
            import anthropic
            import os

            client = anthropic.Anthropic(
                api_key=os.getenv("DASHSCOPE_API_KEY"),
                # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
                # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
                base_url="https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic",
            )

            tools = [
                {
                    "name": "get_weather",
                    "description": "Get weather information for a specified city",
                    "input_schema": {
                        "type": "object",
                        "properties": {
                            "city": {
                                "type": "string",
                                "description": "City name"
                            }
                        },
                        "required": ["city"]
                    }
                }
            ]

            message = client.messages.create(
                model="qwen3.7-plus",
                max_tokens=1024,
                tools=tools,
                messages=[
                    {
                        "role": "user",
                        "content": "What's the weather like in Hangzhou today?"
                    }
                ]
            )

            print(message.content)
        - lang: javascript
          label: Function Call
          source: |-
            import Anthropic from "@anthropic-ai/sdk";

            async function main() {
              const anthropic = new Anthropic({
                apiKey: process.env.DASHSCOPE_API_KEY,
                // Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
                // API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
                baseURL: "https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic",
              });

              const message = await anthropic.messages.create({
                model: "qwen3.7-plus",
                max_tokens: 1024,
                tools: [
                  {
                    name: "get_weather",
                    description: "Get weather information for a specified city",
                    input_schema: {
                      type: "object",
                      properties: {
                        city: { type: "string", description: "City name" }
                      },
                      required: ["city"],
                    },
                  },
                ],
                messages: [{
                  role: "user",
                  content: "What's the weather like in Hangzhou today?"
                }],
              });

              console.log(JSON.stringify(message.content, null, 2));
            }

            main().catch(console.error);
        - lang: curl
          label: Function Call
          source: |-
            # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
            # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
            curl -X POST "https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic/v1/messages" \
              -H "Content-Type: application/json" \
              -H "x-api-key: $DASHSCOPE_API_KEY" \
              -d '{
                "model": "qwen3.7-plus",
                "max_tokens": 1024,
                "tools": [
                    {
                        "name": "get_weather",
                        "description": "Get weather information for a specified city",
                        "input_schema": {
                            "type": "object",
                            "properties": {
                                "city": {
                                    "type": "string",
                                    "description": "City name"
                                }
                            },
                            "required": ["city"]
                        }
                    }
                ],
                "messages": [
                    {
                        "role": "user",
                        "content": "What's the weather like in Hangzhou today?"
                    }
                ]
            }'
        - lang: python
          label: Web Search
          source: |-
            import anthropic
            import os

            client = anthropic.Anthropic(
                api_key=os.getenv("DASHSCOPE_API_KEY"),
                # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
                # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
                base_url="https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic",
            )

            message = client.messages.create(
                model="qwen3.8-max",
                max_tokens=2048,
                # Pass the client identifier, otherwise web search does not take effect
                system=[{"type": "text", "text": "x-anthropic-billing-header: cc_entrypoint=cli;"}],
                messages=[{"role": "user", "content": "What is the weather in Hangzhou tomorrow?"}],
                tools=[
                    {
                        "type": "web_search_20250305",
                        "name": "web_search",
                        "max_uses": 8
                    }
                ],
                thinking={"type": "disabled"},
            )

            for block in message.content:
                print(f"[{block.type}]")
                if block.type == "server_tool_use":
                    print(f"  name: {block.name}, queries: {block.input.get('queries')}")
                elif block.type == "web_search_tool_result":
                    for result in block.content:
                        print(f"  {result.title} - {result.url}")
                elif block.type == "text":
                    print(block.text)

            print(f"Search requests: {message.usage.server_tool_use.web_search_requests}")
        - lang: javascript
          label: Web Search
          source: |-
            import Anthropic from "@anthropic-ai/sdk";

            async function main() {
              const anthropic = new Anthropic({
                apiKey: process.env.DASHSCOPE_API_KEY,
                // Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
                // API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
                baseURL: "https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic",
              });

              const message = await anthropic.messages.create({
                model: "qwen3.8-max",
                max_tokens: 2048,
                // Pass the client identifier, otherwise web search does not take effect
                system: [{ type: "text", text: "x-anthropic-billing-header: cc_entrypoint=cli;" }],
                messages: [{ role: "user", content: "What is the weather in Hangzhou tomorrow?" }],
                tools: [
                  {
                    type: "web_search_20250305",
                    name: "web_search",
                    max_uses: 8,
                  },
                ],
                thinking: { type: "disabled" },
              });

              for (const block of message.content) {
                console.log(`[${block.type}]`);
                if (block.type === "server_tool_use") {
                  console.log(`  name: ${block.name}, queries: ${block.input?.queries}`);
                } else if (block.type === "web_search_tool_result") {
                  for (const result of block.content) {
                    console.log(`  ${result.title} - ${result.url}`);
                  }
                } else if (block.type === "text") {
                  console.log(block.text);
                }
              }

              console.log(`Search requests: ${message.usage.server_tool_use?.web_search_requests}`);
            }

            main().catch(console.error);
        - lang: curl
          label: Web Search
          source: |-
            # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
            # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
            curl -X POST "https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic/v1/messages" \
              -H "Content-Type: application/json" \
              -H "x-api-key: $DASHSCOPE_API_KEY" \
              -d '{
                "model": "qwen3.8-max",
                "max_tokens": 2048,
                "system": [{"type": "text", "text": "x-anthropic-billing-header: cc_entrypoint=cli;"}],
                "messages": [{"role": "user", "content": "What is the weather in Hangzhou tomorrow?"}],
                "tools": [{"type": "web_search_20250305", "name": "web_search", "max_uses": 8}],
                "thinking": {"type": "disabled"}
            }'
        - lang: python
          label: Context caching
          source: |-
            import anthropic
            import os

            client = anthropic.Anthropic(
                api_key=os.getenv("DASHSCOPE_API_KEY"),
                # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
                # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
                base_url="https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic",
            )

            # Simulate code repository content, must reach minimum cacheable length (1024 tokens)
            long_text_content = "<Your Code Here>" * 400

            def get_completion(user_input):
                response = client.messages.create(
                    # Choose a model that supports explicit caching
                    model="qwen3.7-plus",
                    max_tokens=1024,
                    system=[
                        {
                            "type": "text",
                            "text": long_text_content,
                            # Adding cache_control to a text block marks a cache breakpoint; can also be placed on content blocks in the messages array
                            "cache_control": {"type": "ephemeral"},
                        }
                    ],
                    messages=[
                        {"role": "user", "content": user_input},
                    ],
                )
                return response

            # First request: create cache
            first = get_completion("What does this code do")
            print(f"Cache creation tokens:{first.usage.cache_creation_input_tokens}")
            print(f"Cache read tokens:{first.usage.cache_read_input_tokens}")
            print("=" * 20)
            # Second request: same long content, different question -> cache hit
            second = get_completion("How can this code be optimized")
            print(f"Cache creation tokens:{second.usage.cache_creation_input_tokens}")
            print(f"Cache read tokens:{second.usage.cache_read_input_tokens}")
        - lang: javascript
          label: Context caching
          source: |-
            import Anthropic from "@anthropic-ai/sdk";

            const client = new Anthropic({
              apiKey: process.env.DASHSCOPE_API_KEY,
              // Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
              // API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
              baseURL: "https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic",
            });

            // Simulate code repository content, must reach minimum cacheable length (1024 tokens)
            const longTextContent = "<Your Code Here>".repeat(400);

            async function getCompletion(userInput) {
              return client.messages.create({
                // Choose a model that supports explicit caching
                model: "qwen3.7-plus",
                max_tokens: 1024,
                system: [
                  {
                    type: "text",
                    text: longTextContent,
                    // Adding cache_control to a text block marks a cache breakpoint; can also be placed on content blocks in the messages array
                    cache_control: { type: "ephemeral" },
                  },
                ],
                messages: [{ role: "user", content: userInput }],
              });
            }

            // First request: create cache
            const first = await getCompletion("What does this code do");
            console.log(`Cache creation tokens:${first.usage.cache_creation_input_tokens}`);
            console.log(`Cache read tokens:${first.usage.cache_read_input_tokens}`);
            console.log("=".repeat(20));
            // Second request: same long content, different question -> cache hit
            const second = await getCompletion("How can this code be optimized");
            console.log(`Cache creation tokens:${second.usage.cache_creation_input_tokens}`);
            console.log(`Cache read tokens:${second.usage.cache_read_input_tokens}`);
        - lang: curl
          label: Context caching
          source: |-
            # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
            # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
            curl -X POST "https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic/v1/messages" \
              -H "Content-Type: application/json" \
              -H "x-api-key: $DASHSCOPE_API_KEY" \
              -d '{
                "model": "qwen3.7-plus",
                "max_tokens": 1024,
                "system": [
                  {
                    "type": "text",
                    "text": "<Place cacheable content here with at least 1024 tokens>",
                    "cache_control": {"type": "ephemeral"}
                  }
                ],
                "messages": [
                  {"role": "user", "content": "What does this code do"}
                ]
            }'
        - lang: python
          label: Structured outputs
          source: |-
            import anthropic
            import os

            client = anthropic.Anthropic(
              api_key=os.getenv("DASHSCOPE_API_KEY"),
              # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
              # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
              base_url="https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic",
            )

            message = client.messages.create(
              model="deepseek-v4-pro",
              max_tokens=1024,
              messages=[
                {
                  "role": "user",
                  "content": "Extract key info from this email: John Smith (john@example.com) is interested in the Enterprise plan and wants to schedule a demo for next Tuesday at 2pm."
                }
              ],
              extra_body={
                "output_config": {
                  "format": {
                    "type": "json_schema",
                    "schema": {
                      "type": "object",
                      "properties": {
                        "name": {"type": "string"},
                        "email": {"type": "string"},
                        "plan_interest": {"type": "string"},
                        "demo_requested": {"type": "boolean"}
                      },
                      "required": ["name", "email", "plan_interest", "demo_requested"],
                      "additionalProperties": False
                    }
                  }
                }
              },
            )
            # deepseek-v4-pro returns a thinking block; find the text content block
            text_block = next(block for block in message.content if block.type == "text")
            print(text_block.text)
        - lang: javascript
          label: Structured outputs
          source: |-
            import Anthropic from "@anthropic-ai/sdk";

            const anthropic = new Anthropic({
              apiKey: process.env.DASHSCOPE_API_KEY,
              // Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
              // API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
              baseURL: "https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic",
            });

            async function main() {
              // output_config is a platform extension parameter, pass via body
              const message = await (anthropic.messages.create as Function)({
                model: "deepseek-v4-pro",
                max_tokens: 1024,
                messages: [{
                  role: "user",
                  content: "Extract key info from this email: John Smith (john@example.com) is interested in the Enterprise plan and wants to schedule a demo for next Tuesday at 2pm."
                }],
                output_config: {
                  format: {
                    type: "json_schema",
                    schema: {
                      type: "object",
                      properties: {
                        name: { type: "string" },
                        email: { type: "string" },
                        plan_interest: { type: "string" },
                        demo_requested: { type: "boolean" }
                      },
                      required: ["name", "email", "plan_interest", "demo_requested"],
                      additionalProperties: false
                    }
                  }
                }
              });

              // deepseek-v4-pro returns a thinking block; find the text content block
              const textBlock = message.content.find(
                (block: { type: string }) => block.type === "text"
              );
              console.log(textBlock?.text);
            }

            main().catch(console.error);
        - lang: curl
          label: Structured outputs
          source: |-
            # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
            # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
            curl -X POST "https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic/v1/messages" \
              -H "Content-Type: application/json" \
              -H "x-api-key: $DASHSCOPE_API_KEY" \
              -d '{
                "model": "deepseek-v4-pro",
                "max_tokens": 1024,
                "messages": [
                    {
                        "role": "user",
                        "content": "Extract key info from this email: John Smith (john@example.com) is interested in the Enterprise plan and wants to schedule a demo for next Tuesday at 2pm."
                    }
                ],
                "output_config": {
                    "format": {
                        "type": "json_schema",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "name": {"type": "string"},
                                "email": {"type": "string"},
                                "plan_interest": {"type": "string"},
                                "demo_requested": {"type": "boolean"}
                            },
                            "required": ["name", "email", "plan_interest", "demo_requested"],
                            "additionalProperties": false
                        }
                    }
                }
            }'
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: "QwenCloud API key passed via `x-api-key` header. `Authorization: Bearer` header is also supported."
  schemas:
    AnthropicMessagesRequest:
      type: object
      required:
        - model
        - max_tokens
        - messages
      properties:
        model:
          type: string
          description: |-
            Model name. Supported models:

            **Qwen Max**: qwen3.8-max, qwen3.8-max-0902, qwen3.7-max, qwen3.7-max-2026-06-08, qwen3.7-max-2026-05-20

            **Qwen Plus**: qwen3.7-plus, qwen3.7-plus-2026-05-26, qwen3.6-plus, qwen3.6-plus-2026-04-02, qwen3.5-plus, qwen3.5-plus-2026-04-20, qwen3.5-plus-2026-02-15, qwen-plus, qwen-plus-latest

            **Qwen Flash**: qwen3.8-flash, qwen3.7-flash, qwen3.7-flash-2026-07-15, qwen3.6-flash, qwen3.6-flash-2026-04-16, qwen3.5-flash, qwen3.5-flash-2026-02-23, qwen-flash, qwen-flash-2025-07-28

            **Qwen Coder**: qwen3.7-plus, qwen3-coder-flash

            **Qwen VL**: qwen3-vl-plus

            **Qwen Open-source**: qwen3.6-27b, qwen3.5-397b-a17b, qwen3.5-122b-a10b, qwen3.5-27b, qwen3.5-35b-a3b, qwen3.8-2.4t-a95b, qwen3.8-27b

            **Third-party models**: deepseek-v4.1-flash, deepseek-v4.1-flash-1017, deepseek-v4-pro-0813, deepseek-v4-pro, deepseek-v4-flash-0731, kimi-k3, kimi-k2.7-code, kimi-k2.5, glm-5.3, glm-5.2, glm-5.1, glm-5, MiniMax-M2.5

            Model availability varies by region; see [Regions and endpoints](/developer-guides/getting-started/regions) before selecting a model and endpoint. glm-5 and MiniMax-M2.5 are available only in China North 2 (Beijing). Use the `cn-beijing` endpoint to call them.
        max_tokens:
          type: integer
          description: |-
            deepseek-v4.1-flash, deepseek-v4.1-flash-1017, deepseek-v4-pro-0813, deepseek-v4-pro, deepseek-v4-flash-0731, qwen3.8-max, qwen3.8-flash: `max_tokens` is the maximum total token count for both the reply content and the chain-of-thought content. Generation stops early when the model output exceeds this value, and `stop_reason` is `max_tokens`. `max_tokens` limits the combined length of the reply content and the thinking process. When extended thinking is enabled, `max_tokens` must be greater than `thinking.budget_tokens`.

            glm-5.3: `max_tokens` is the maximum total token count for both the reply content and the chain-of-thought content. Generation stops early when the model output exceeds this value, and `stop_reason` is `max_tokens`. glm-5.3 ignores the `thinking.budget_tokens` parameter.

            glm-5.2: When the `thinking.budget_tokens` parameter is not passed, `max_tokens` is the maximum total token count for both the reply content and the chain-of-thought content. Generation stops early when the model output exceeds this value, and `stop_reason` is `max_tokens`. When the `thinking.budget_tokens` parameter is passed, `max_tokens` is only the maximum number of tokens for the reply content, and the thinking tokens are controlled separately by `thinking.budget_tokens`.

            Other models: Maximum number of tokens for the reply content. If the generated content exceeds this value, generation stops early and `stop_reason` is `max_tokens`. `max_tokens` does not limit the length of the thinking process. When extended thinking is enabled, the thinking tokens are controlled separately by `thinking.budget_tokens`.
        system:
          oneOf:
            - type: string
            - type: array
              items:
                type: object
                required:
                  - type
                  - text
                properties:
                  type:
                    type: string
                    enum:
                      - text
                    description: Always `text`.
                  text:
                    type: string
                    description: System prompt text.
                  cache_control:
                    type: object
                    description: Mark an explicit cache breakpoint on this content block.
                    properties:
                      type:
                        type: string
                        enum:
                          - ephemeral
                        description: Always `ephemeral`.
          description: System prompt to set the model's role or behavior. Passed as a top-level parameter; the `messages` array does not accept the `system` role. A string is equivalent to a single `type="text"` content block. To use context caching, pass an array of content blocks with `cache_control`.
        messages:
          type: array
          description: The message array, arranged in conversational order.
          items:
            type: object
            required:
              - role
              - content
            properties:
              role:
                type: string
                enum:
                  - user
                  - assistant
                  - system
                description: Message role.
              content:
                oneOf:
                  - type: string
                  - type: array
                    description: Structured content array supporting text, image, video, tool_use, and tool_result types.
                    items:
                      type: object
                      required:
                        - type
                      properties:
                        type:
                          type: string
                          enum:
                            - text
                            - image
                            - video
                            - tool_use
                            - tool_result
                          description: Content block type.
                        text:
                          type: string
                          description: Text content when `type` is `text`.
                        source:
                          type: object
                          description: Data source when `type` is `image` or `video`.
                          properties:
                            type:
                              type: string
                              enum:
                                - url
                                - base64
                              description: "Value: `url` (public URL) or `base64` (Base64 encoded)."
                            url:
                              type: string
                              description: Public URL. Required when `type` is `url`.
                            media_type:
                              type: string
                              description: MIME type, e.g. `image/jpeg`, `video/mp4`. Required when `type` is `base64`.
                            data:
                              type: string
                              description: Base64 encoded data. Required when `type` is `base64`.
                        id:
                          type: string
                          description: Unique identifier for the tool call when `type` is `tool_use`.
                        name:
                          type: string
                          description: Name of the tool being called when `type` is `tool_use`.
                        input:
                          type: object
                          description: Tool call input parameters when `type` is `tool_use`.
                        tool_use_id:
                          type: string
                          description: The `tool_use` id this result corresponds to when `type` is `tool_result`.
                        cache_control:
                          type: object
                          description: Mark an explicit cache breakpoint on this content block.
                          properties:
                            type:
                              type: string
                              enum:
                                - ephemeral
                description: Message content. Can be a plain text string or a structured content array.
        stream:
          type: boolean
          default: false
          description: Enable streaming output. Default is `false`.
        temperature:
          type: number
          description: |-
            Controls diversity of generated text, range [0, 2). Higher values produce more random output. This range differs from Anthropic's native [0.0, 1.0] — verify this parameter when migrating from Anthropic.

            **qwen3.8-max**: Defaults to 0.6 in thinking mode. Values below 0.6 are automatically adjusted to 0.6.
        top_p:
          type: number
          description: Probability threshold for nucleus sampling. Both `temperature` and `top_p` control diversity — set only one at a time.
        top_k:
          type: integer
          description: Size of the sampling candidate set during generation.
        stop_sequences:
          type: array
          items:
            type: string
          description: Text sequences that stop generation. The model stops before outputting the sequence. After a match, the `stop_reason` in the response is `stop_sequence`, and the matched sequence is returned in the response's `stop_sequence` field.
        thinking:
          type: object
          description: Extended thinking configuration. When enabled, the model reasons before responding, and the response includes `thinking`-type content blocks. Not all models support thinking mode.
          properties:
            type:
              type: string
              enum:
                - enabled
                - disabled
              description: |-
                `enabled` (enable thinking) or `disabled` (disable thinking).

                When this parameter is omitted, whether the model thinks is determined by its default behavior: qwen3.8-max, qwen3.8-flash, the deepseek-v4 series, and the glm series think by default; kimi-k2.7-code and MiniMax-M2.5 support thinking mode only and cannot disable it.
            budget_tokens:
              type: integer
              deprecated: true
              description: "**To be deprecated.** For new integrations, use `output_config.effort`. Maximum tokens for the thinking process. Does not overlap with `max_tokens`: this parameter limits thinking; `max_tokens` limits the final reply. Takes effect when `type` is `enabled`."
        tools:
          type: array
          description: Tool definition array. Supports custom tools (function calling), the server-side web search tool, and the web scraping tool.
          items:
            oneOf:
              - type: object
                required:
                  - name
                  - input_schema
                description: Custom tool (function calling).
                properties:
                  name:
                    type: string
                    description: Tool name.
                  description:
                    type: string
                    description: Description of the tool's function.
                  input_schema:
                    type: object
                    description: JSON Schema definition of the tool's input parameters.
              - type: object
                required:
                  - type
                  - name
                description: "Server-side web search tool. Declare it in `tools` to enable; no client-side retrieval is needed. When calling the API directly with the Anthropic SDK or over HTTP, you must pass the client identifier `x-anthropic-billing-header: cc_entrypoint=cli;` in `system`; otherwise web search does not take effect. `deepseek-v4.1-flash-1017` also supports the `web_fetch` tool. For Anthropic-compatible request requirements and examples, see [Web scraping](/developer-guides/tool-calling/web-scraping)."
                properties:
                  type:
                    type: string
                    description: Tool type, such as `web_search_20250305` with a date suffix. The date suffix does not need to be fixed; keep it consistent with the value sent by the client.
                  name:
                    type: string
                    enum:
                      - web_search
                    description: Fixed to `web_search`.
                  max_uses:
                    type: integer
                    description: Maximum number of searches per request.
        tool_choice:
          type: object
          description: 'Tool choice strategy. `{"type": "auto"}`: model decides whether to call tools (default). `{"type": "any"}`: force calling any tool. `{"type": "none"}`: disable tool calling. `{"type": "tool", "name": "tool_name"}`: force calling a specific tool.'
          properties:
            type:
              type: string
              enum:
                - auto
                - any
                - none
                - tool
              description: Strategy type.
            name:
              type: string
              description: When `type` is `tool`, specifies the name of the tool to call.
        output_config:
          type: object
          properties:
            effort:
              type: string
              enum:
                - low
                - medium
                - high
                - xhigh
                - max
              description: |-
                Controls the inference intensity of models. The valid values and default values vary by model.

                - **glm-5.3**: Default value: `max`. Valid values: `low`, `high`, and `max`. Passing any other value returns an error.
                - **glm-5.2, deepseek-v4-pro, and deepseek-v4-flash-0731 (supplied by Alibaba Cloud)**: Default value: `max`. Valid values: `high` and `max`. `low` and `medium` are mapped to `high`, and `xhigh` is mapped to `max`.
                - **qwen3.8-max and qwen3.8-flash**: Default value: `xhigh`. Valid values: `xhigh`, `medium`, and `low`. `max` and `high` are mapped to `xhigh`.
            format:
              type: object
              description: |-
                Structured output configuration. When enabled, the model returns a JSON string. Behavior varies by model:

                `deepseek-v4.1-flash` and `deepseek-v4.1-flash-1017` do not support this parameter and return a 400 error if it is specified.

                - **Strict structured outputs**: Available for qwen3.8, qwen3.7, deepseek (excluding `deepseek-v4.1-flash`, `deepseek-v4.1-flash-1017`, `deepseek-v4-flash-0731`, and `deepseek-v4-pro-0813`), and glm series models. The model strictly follows the provided JSON Schema, guaranteeing the same field types and hierarchy.
                - **Regular structured outputs**: For all other models, schema field constraints are not enforced — the API automatically falls back to a plain JSON mode (only guaranteeing that the output is a valid JSON string). In this fallback mode, the request must satisfy both of the following: (1) the `output_config` parameter is explicitly provided; (2) the `system` or `messages` content contains the keyword "JSON" (case-insensitive). If the keyword "JSON" is missing, the API throws: `'messages' must contain the word 'json' in some form`.
              required:
                - type
                - schema
              properties:
                type:
                  type: string
                  enum:
                    - json_schema
                  description: "Fixed value: `json_schema`."
                schema:
                  type: object
                  description: JSON Schema object that follows the standard JSON Schema specification. Should include `type` (data type), `properties` (field definitions), `required` (array of required field names), and `additionalProperties` (must be set to `false`).
    AnthropicMessage:
      type: object
      description: Non-streaming response message object.
      properties:
        id:
          type: string
          description: Unique message identifier.
        type:
          type: string
          enum:
            - message
          description: Always `message`.
        role:
          type: string
          enum:
            - assistant
          description: Always `assistant`.
        model:
          type: string
          description: The model used for generation.
        content:
          type: array
          description: Content array. Element types can be `text`, `thinking` (returned when thinking is enabled), `tool_use` (tool call), `server_tool_use` (server-side tool call), or `web_search_tool_result` (web search results).
          items:
            type: object
            properties:
              type:
                type: string
                enum:
                  - text
                  - thinking
                  - tool_use
                  - server_tool_use
                  - web_search_tool_result
                description: Content block type.
              text:
                type: string
                description: Model-generated text reply when `type` is `text`.
              thinking:
                type: string
                description: The model's reasoning before the final response.
              signature:
                type: string
                description: Signature when `type` is `thinking`. Currently always an empty string.
              id:
                type: string
                description: Unique identifier for the tool call when `type` is `tool_use`.
              name:
                type: string
                description: Name of the tool being called when `type` is `tool_use`.
              input:
                type: object
                description: Tool call input when `type` is `tool_use`; for `server_tool_use`, the retrieval input generated by the model, including the `queries` array.
              tool_use_id:
                type: string
                description: For `web_search_tool_result`, the `id` of the corresponding `server_tool_use`.
              content:
                type: array
                description: For `web_search_tool_result`, the array of search results. Each element is a `web_search_result` object.
                items:
                  type: object
                  properties:
                    type:
                      type: string
                      enum:
                        - web_search_result
                      description: Always `web_search_result`.
                    title:
                      type: string
                      description: Page title.
                    url:
                      type: string
                      description: Page URL.
                    encrypted_content:
                      type: string
                      description: Encrypted page content.
                    page_age:
                      type:
                        - string
                        - "null"
                      description: Page age. Can be `null`.
              caller:
                type: object
                description: Caller information. A `type` of `direct` means the call was initiated directly by the model. (Optional)
        stop_reason:
          type: string
          enum:
            - end_turn
            - max_tokens
            - tool_use
          description: "Stop reason: `end_turn` (normal completion), `max_tokens` (token limit reached), `tool_use` (tool call)."
        stop_sequence:
          type:
            - string
            - "null"
          description: Always `null`.
        usage:
          $ref: "#/components/schemas/AnthropicUsage"
    AnthropicStreamEvent:
      type: object
      description: "Streaming response event. Events are sent in order: `message_start` → `content_block_start` → `content_block_delta` (repeated) → `content_block_stop` → `message_delta` → `message_stop`, with `ping` keepalive events interspersed."
      properties:
        type:
          type: string
          enum:
            - message_start
            - content_block_start
            - content_block_delta
            - content_block_stop
            - message_delta
            - message_stop
            - ping
          description: "Event type. `message_start`: first event in the stream, marks message start with the initial message object. `content_block_start`: sent at the beginning of each content block, marks the index and type. `content_block_delta`: incremental update containing text, thinking, or signature fragments. `content_block_start` may also carry `server_tool_use` or `web_search_tool_result` blocks for web search. `content_block_stop`: marks content block end. `message_delta`: second-to-last event with `stop_reason` and final `usage`. `message_stop`: last event. `ping`: keepalive heartbeat."
        index:
          type: integer
          description: Content block index (present in `content_block_start`, `content_block_delta`, `content_block_stop` events).
        message:
          type: object
          description: Initial message object in the `message_start` event, with an empty `content` array.
        content_block:
          type: object
          description: Initial content block object in the `content_block_start` event. `type` can be `text`, `thinking`, `tool_use`, `server_tool_use`, or `web_search_tool_result`.
        delta:
          type: object
          description: Delta object in `content_block_delta` events, or stop info in `message_delta` events.
        usage:
          $ref: "#/components/schemas/AnthropicUsage"
    AnthropicUsage:
      type: object
      description: Token usage statistics. In streaming, the `usage` in the `message_start` event only contains `input_tokens` and `output_tokens`; the full fields (including `cache_creation_input_tokens`, `cache_read_input_tokens`, and `server_tool_use`) appear in the `message_delta` event.
      properties:
        input_tokens:
          type: integer
          description: Number of input tokens.
        output_tokens:
          type: integer
          description: Number of output tokens.
        cache_creation_input_tokens:
          type: integer
          description: Number of input tokens consumed for cache creation.
        cache_read_input_tokens:
          type: integer
          description: Number of input tokens consumed by cache reads.
        server_tool_use:
          type: object
          description: Server-side tool usage. Returned only when server-side tools such as web search are used in the request. (Optional)
          properties:
            web_search_requests:
              type: integer
              description: Number of web searches.
    AnthropicErrorResponse:
      type: object
      description: Error response.
      properties:
        type:
          type: string
          enum:
            - error
          description: Always `error`.
        error:
          type: object
          properties:
            type:
              type: string
              description: Error type, e.g. `invalid_request_error`, `authentication_error`, `rate_limit_error`.
            message:
              type: string
              description: Error details.
````
