跳转至

MaaS_Cl_4.X

基础信息

  • 基础URL:https://genaiapi.cloudsway.net

  • API请求端点POST

  • 身份验证:通过HTTP Bearer Token方式验证,需要在请求头中携带API密钥。

参数名 类型 必填 描述
Content-Type string 固定为 application/json
Authorization string Bearer {your_api_key}

核心参数说明

参数 类型 必选 描述
model string 要使用的模型ID
messages array 对话消息列表,包含roleuserassistant)和content
max_tokens integer 生成的最大token数
system string 系统提示词,用于设定助手的行为和背景
temperature number 采样温度,范围0-1。较高的值使输出更随机,较低的值使输出更确定
top_p number 核采样参数,模型考虑具有top_p概率质量的token的结果
top_k integer 仅从每个步骤中概率最高的K个token中采样
stream boolean 是否启用流式传输,默认为false
stop_sequences array 自定义停止序列,当模型生成这些序列时停止

请求与响应示例

1. 原生请求调用方式

/claude/chat/completions

thinking模式

curl --location 'https://genaiapi.cloudsway.net/v2/ai/{YOUR_ENDPOINT}/claude/chat/completions' \
--header 'Authorization: Bearer {your_api_key}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "claude-sonnet-4@20250514",
    "max_tokens": 2048,
    "stream":false,
    "messages": [
        {
            "role": "user",
            "content": "证明勾股定理"
        }
    ],
    "thinking": { "type": "enabled", "budget_tokens": 2000 }

}'

/v1/message

Curl 请求方式
curl --request POST \
  --url https://genaiapi.cloudsway.net/{YOUR_ENDPOINT}/v1/messages \
  --header 'Authorization: Bearer {your_api_key}' \
  --header 'Content-Type: application/json' \
  --data '{
        "max_tokens": 5000,
        "stream": false,
        "system": [
                {
                        "type": "text",
                        "text": "You are an AI assistant tasked with analyzing literary works"
                }
        ],
    "messages": [
        {
            "role": "user",
            "content": "Analyze the major themes in Pride and Prejudice."
        }
    ]
}'
Python 请求示例
import anthropic

# 初始化客户端(使用你提供的配置)
client = anthropic.Anthropic(
    base_url="https://genaiapi.cloudsway.net/{YOUR_ENDPOINT}",
    api_key="{your_api_key}"
)

# 发送消息
message = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    temperature=0.7,
    system="你是一个专业的编程导师,回答问题简洁明了。",
    messages=[
        {
            "role": "user",
            "content": "解释一下async/await和Promise的区别"
        }
    ]
)

# 打印响应
print(message.content[0].text)
响应示例
{
  "id": "msg_01XyZabcDeFgHiJkLmNoPqRs",
  "type": "message",
  "role": "assistant",
  "model": "claude-3-5-sonnet-20241022",
  "content": [
    {
      "type": "text",
      "text": "async/await 是 Promise 的语法糖,主要区别在于:\n\n1. **语法简洁性**:async/await 让异步代码看起来更像同步代码,避免了 Promise 的链式调用。\n\n2. **错误处理**:async/await 可以使用 try/catch 捕获异常,而 Promise 使用 .catch()。\n\n3. **调试体验**:async/await 的调试体验更好,可以像同步代码一样设置断点。\n\n4. **本质上**:async 函数总是返回一个 Promise,await 等待 Promise 解析。\n\n示例对比:\n```javascript\n// Promise\nfetchData()\n  .then(data => process(data))\n  .then(result => console.log(result))\n  .catch(err => console.error(err));\n\n// async/await\ntry {\n  const data = await fetchData();\n  const result = await process(data);\n  console.log(result);\n} catch (err) {\n  console.error(err);\n}\n```"
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 25,
    "output_tokens": 189
  }
}

2. 兼容Openai调用方式

默认的max_tokens/max_completion_tokens是4096

开启thinking模式:

curl --location 'https://genaiapi.cloudsway.net/v1/ai/{YOUR_ENDPOINT}/chat/completions' \
--header 'Authorization: Bearer {your_api_key}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "claude-sonnet-4@20250514",
    "max_tokens": 2048,
    "stream":false,
    "messages": [
        {
            "role": "user",
            "content": "证明勾股定理"
        }
    ],
    "thinking": { "type": "enabled", "budget_tokens": 2000 }
}'

关闭thinking模式

curl --location 'https://genaiapi.cloudsway.net/v1/ai/{YOUR_ENDPOINT}/chat/completions' \
--header 'Authorization: Bearer {your_api_key}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "claude-sonnet-4@20250514",
    "max_tokens": 2048,
    "stream":false,
    "messages": [
        {
            "role": "user",
            "content": "证明勾股定理"
        }
    ],
    "thinking": { "type": "disabled"}
}'

3. 多轮对话

Curl 请求示例
curl -X POST "https://genaiapi.cloudsway.net/{YOUR_ENDPOINT}/v1/messages/" \
  -H "Content-Type: application/json" \
  -H "x-api-key: {your_api_key}" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-3-5-sonnet-20241022",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": "Python中如何读取文件?"
      },
      {
        "role": "assistant",
        "content": "使用 `open()` 函数配合 `with` 语句:\n```python\nwith open('\''file.txt'\'', '\''r'\'') as f:\n    content = f.read()\n```"
      },
      {
        "role": "user",
        "content": "那如何写入文件呢?"
      }
    ]
  }'
Python 请求示例
import anthropic

# 初始化客户端
client = anthropic.Anthropic(
    base_url="https://genaiapi.cloudsway.net/{YOUR_ENDPOINT}",
    api_key="{your_api_key}"
)

# 发送包含对话历史的消息
message = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": "Python中如何读取文件?"
        },
        {
            "role": "assistant", 
            "content": "使用 `open()` 函数配合 `with` 语句:\n```python\nwith open('file.txt', 'r') as f:\n    content = f.read()\n```"
        },
        {
            "role": "user",
            "content": "那如何写入文件呢?"
        }
    ]
)

# 打印响应
print(message.content[0].text)

响应示例

{
  "id": "msg_02AbCdEfGhIjKlMnOpQrStUv",
  "type": "message",
  "role": "assistant",
  "model": "claude-3-5-sonnet-20241022",
  "content": [
    {
      "type": "text",
      "text": "写入文件同样使用 `open()` 函数,但模式不同:\n\n```python\n# 写入模式 ('w') - 覆盖原有内容\nwith open('file.txt', 'w') as f:\n    f.write('Hello, World!')\n\n# 追加模式 ('a') - 在末尾添加内容\nwith open('file.txt', 'a') as f:\n    f.write('\\nNew line')\n\n# 读写模式 ('r+') - 同时读写\nwith open('file.txt', 'r+') as f:\n    content = f.read()\n    f.write('\\nAppended')\n```\n\n注意:写入模式会创建文件(如果不存在),但会覆盖已存在的文件。"
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 78,
    "output_tokens": 145
  }
}

4. function call (tool call)

第一次请求

curl 'https://genaiapi.cloudsway.net/{YOUR_ENDPOINT}/v1/messages' \
--header 'Authorization: Bearer {YOUR_AK}' \
--header 'Content-Type: application/json' \
--data '{
    "model": "claude-opus-4-20250514",
    "max_tokens": 4000,
    "tools": [
        {
            "name": "get_weather",
            "description": "Get the current weather in a given location",
            "input_schema": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "The city and state, e.g. San Francisco, CA"
                    },
                    "unit": {
                        "type": "string",
                        "enum": [
                            "celsius",
                            "fahrenheit"
                        ],
                        "description": "The unit of temperature, either \"celsius\" or \"fahrenheit\""
                    }
                },
                "required": [
                    "location"
                ]
            }
        }
    ],
    "messages": [
        {
            "role": "user",
            "content": "What is the weather like in San Francisco?"
        }
    ],
    "thinking": {
        "type": "enabled",
        "budget_tokens": 2000
    }
}'

响应内容

{
    "role": "assistant",
    "usage": {
        "input_tokens": 471,
        "cache_read_input_tokens": 0,
        "output_tokens": 196,
        "cache_creation_input_tokens": 0
    },
    "stop_reason": "tool_use",
    "type": "message",3
    "content": [
        {
            "signature": "ErcBCkgIBRACGAIiQLGZAuTsAGoReXb5s//lmeAU8yxEAzyzbNCDVVL+bkCD5sefp82OhZmg8LaQrNMDDIOZwcUTKXwWGZ8W+cNZOsESDJK/giGxwNOIo2rIWxoMVsBltOlb7IYyfzNHIjAhd0Vi5lTbgppuxotqIM1nWO8kxbAwmTkPmv2C7BkM78PBC1cnNvhXTrXmmYiLTJEqHVDoJWO3Jcd8mdw8pVHIlz4k4qkJCuLv6OOUWyAbGAI=",
            "type": "thinking",
            "thinking": "The user is asking about the weather in San Francisco. I can use the `get_weather` function to provide this information.\n\nLet's check the required parameters for `get_weather`:\n1. `location` (required): The user mentioned \"San Francisco\", so I'll use \"San Francisco, CA\" as the complete location.\n2. `unit` (optional): The user didn't specify a temperature unit preference, so I'll use the default unit provided by the API.\n\nSince I have all the required parameters, I can proceed with the function call."
        },
        {
            "type": "text",
            "text": "I can check the current weather in San Francisco for you."
        },
        {
            "type": "tool_use",
            "input": {
                "location": "San Francisco, CA"
            },
            "name": "get_weather",
            "id": "toolu_vrtx_01UYzvMjCpksvN4NN5jCgsMa"
        }
    ],
    "model": "claude-3-7-sonnet-20250219",
    "id": "msg_vrtx_01PitSgaZ8apRctfAD8gvLYM"
}

替换第二次请求后

{
            "signature": "ErcBCkgIBRACGAIiQLGZAuTsAGoReXb5s//lmeAU8yxEAzyzbNCDVVL+bkCD5sefp82OhZmg8LaQrNMDDIOZwcUTKXwWGZ8W+cNZOsESDJK/giGxwNOIo2rIWxoMVsBltOlb7IYyfzNHIjAhd0Vi5lTbgppuxotqIM1nWO8kxbAwmTkPmv2C7BkM78PBC1cnNvhXTrXmmYiLTJEqHVDoJWO3Jcd8mdw8pVHIlz4k4qkJCuLv6OOUWyAbGAI=",
            "type": "thinking",
            "thinking": "The user is asking about the weather in San Francisco. I can use the `get_weather` function to provide this information.\n\nLet's check the required parameters for `get_weather`:\n1. `location` (required): The user mentioned \"San Francisco\", so I'll use \"San Francisco, CA\" as the complete location.\n2. `unit` (optional): The user didn't specify a temperature unit preference, so I'll use the default unit provided by the API.\n\nSince I have all the required parameters, I can proceed with the function call."
        },      

替换id,tool_use_id

```plain text "id": "toolu_vrtx_01UYzvMjCpksvN4NN5jCgsMa"

```sql
curl 'https://genaiapi.cloudsway.net/{endpoint}/v1/messages' \
--header 'Authorization: Bearer {your_api_key}' \
--header 'Content-Type: application/json' \
--data '{
    "model": "claude-opus-4-20250514",
    "max_tokens": 4000,
    "thinking": {
        "type": "enabled",
        "budget_tokens": 2000
    },
    "tools": [
        {
            "name": "get_weather",
            "description": "Get the current weather in a given location",
            "input_schema": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "The city and state, e.g. San Francisco, CA"
                    },
                    "unit": {
                        "type": "string",
                        "enum": [
                            "celsius",
                            "fahrenheit"
                        ],
                        "description": "The unit of temperature, either \"celsius\" or \"fahrenheit\""
                    }
                },
                "required": [
                    "location"
                ]
            }
        }
    ],
    "messages": [
        {
            "role": "user",
            "content": "What is the weather like in San Francisco?"
        },
        {
            "role": "assistant",
            "content": [
               {
            "signature": "ErcBCkgIBRACGAIiQLGZAuTsAGoReXb5s//lmeAU8yxEAzyzbNCDVVL+bkCD5sefp82OhZmg8LaQrNMDDIOZwcUTKXwWGZ8W+cNZOsESDJK/giGxwNOIo2rIWxoMVsBltOlb7IYyfzNHIjAhd0Vi5lTbgppuxotqIM1nWO8kxbAwmTkPmv2C7BkM78PBC1cnNvhXTrXmmYiLTJEqHVDoJWO3Jcd8mdw8pVHIlz4k4qkJCuLv6OOUWyAbGAI=",
            "type": "thinking",
            "thinking": "The user is asking about the weather in San Francisco. I can use the `get_weather` function to provide this information.\n\nLet'\''s check the required parameters for `get_weather`:\n1. `location` (required): The user mentioned \"San Francisco\", so I'\''ll use \"San Francisco, CA\" as the complete location.\n2. `unit` (optional): The user didn'\''t specify a temperature unit preference, so I'\''ll use the default unit provided by the API.\n\nSince I have all the required parameters, I can proceed with the function call."
        },
                {
                    "type": "text",
                    "text": "I can check the current weather in San Francisco for you."
                },
                {
                    "type": "tool_use",
                    "input": {
                        "location": "San Francisco, CA"
                    },
                    "name": "get_weather",
                    "id": "toolu_vrtx_01UYzvMjCpksvN4NN5jCgsMa"
                }
            ]
        },
        {
            "role": "user",
            "content": [
                {
                    "type": "tool_result",
                    "tool_use_id": "toolu_vrtx_01UYzvMjCpksvN4NN5jCgsMa",
                    "content": "19 degrees"
                }
            ]
        }
    ]
}'

5. 视觉识别(图像输入)

请求示例

Curl 请求
curl -X POST "https://genaiapi.cloudsway.net/{endpoint}/v1/messages/" \
  -H "Content-Type: application/json" \
  -H "x-api-key: {your_api_key}" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": null,
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "image",
            "source": {
              "type": "base64",
              "media_type": "image/jpeg",
              "data": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAg..."
            }
          },
          {
            "type": "text",
            "text": "这张图片里有什么?请详细描述"
          }
        ]
      }
    ]
  }'
Python 请求
import anthropic
import base64

# 初始化客户端
client = anthropic.Anthropic(
    base_url="https://genaiapi.cloudsway.net/{endpoint}",
    api_key="{your_api_key}"
)

# 方式1:直接使用base64编码的图像数据
image_base64 = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAg..."  # 你的base64图像数据

message = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "image",
                    "source": {
                        "type": "base64",
                        "media_type": "image/jpeg",
                        "data": image_base64
                    }
                },
                {
                    "type": "text",
                    "text": "这张图片里有什么?请详细描述"
                }
            ]
        }
    ]
)

print(message.content[0].text)

响应示例

{
  "id": "msg_05StUvWxYzAbCdEfGhIjKlMn",
  "type": "message",
  "role": "assistant",
  "model": ,
  "content": [
    {
      "type": "text",
      "text": "这张图片显示的是:\n\n1. **主体**:一只橙色的猫坐在木质地板上\n2. **环境**:客厅的一角,有沙发和窗户\n3. **光线**:自然光从窗户射入,形成柔和的光影\n4. **细节**:猫的眼睛是绿色的,正在看着镜头\n5. **背景**:窗外可以看到一些绿色植物\n\n这是一张清晰的家庭宠物照片,氛围温馨自然。"
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 1567,
    "output_tokens": 95
  }
}

6. 原生请求interleaved_thinking 参数支持

用该功能后,模型会交错展示推理过程与计算步骤,而非先隐藏思考、直接给答案

  1. 该参数的核心作用是控制 “推理过程是否自然穿插在回答中”,适合需要模型 “边思考边输出” 的场景(如解题、分析类任务)。

  2. 若未指定该参数,Claude 可能默认采用更简洁的输出模式(直接给结论 + 关键步骤,而非完整交错的思考过程)。

curl --request POST \
  --url https://genaiapi.cloudsway.net/v2/ai/{endpoint}/claude/chat/completions \
  --header 'Accept: */*' \
  --header 'Accept-Encoding: gzip, deflate, br' \
  --header 'Authorization: Bearer {your_api_key}' \
  --header 'Connection: keep-alive' \
  --header 'User-Agent: PostmanRuntime-ApipostRuntime/1.1.0' \
  --header 'content-type: application/json' \
  --data '{
    "model": "claude-sonnet-4@20250514",
    "max_tokens": 2048,
    "stream":false,
    "features": {
        "interleaved_thinking": "2025-05-14"
  },
    "messages": [
        {
            "role": "user",
            "content": "证明勾股定理"
        }
    ],
    "thinking": { "type": "enabled", "budget_tokens": 2000 }

}'

返回结果

{"role":"assistant","usage":{"input_tokens":43,"cache_read_input_tokens":0,"output_tokens":1128,"cache_creation_input_tokens":0},"stop_reason":"end_turn","type":"message","content":[{"signature":"ErYECkgIBxABGAIqQH3o8Vn/NKBG3vnFCY5mV1t5zHhr23lB3euRIPestKEpNpjE4c6BOeDfs4TShHKwurO1D0F2GRUp6zAVT+so1rASDGQeHiO5pKPrY5P7QhoMPcrxCvMYagRAC02TIjCfSi1QgHYuD05wGfkTHU2jdt5ivRh3Sc956z1o+5/Z8aueNwAjRACIVQ/43VejUf4qmwNDcY3uvPucc3C7q5V6lm7+LkrAY3PVMpPwmBIpCPBx/S13ugu3XFNTs6YCL6d70zwnN1a6kBpKxS62EiElpWcaFbAep8Jppf8n+hXt49bk/QCCfxCG4W9T5tg/LVLINCJLULA+pLhSVsEDOYbqUVi8cYj7N/QKZxRGb0f3TWm0kThCBOoUByl6ih52Ur4XfFh409Iajmn5pGMXK7rkgm/MOZrGYZPi4WQoySYEpjga9vAI5nESGwZUzGtaA8RxXmCJnvuMaBS/cUeXcF+elP5UpYHqZGc++UKhMLtY3SU3Ouk/sLbhVmAIxSHnp21oFOfhpaYBUFJ6GL5+9zseKOYpcnTxdSZzEhNgDDhyUgXVEY0TxFOJqhHURVlqBfqfwGaoHelXt1vBUQ79yOm8yc48uaYtpaUtiT2fZexLCHOSs2JiMC7TQjRo2QcVQbxldempBjo84eztsAy8KgPE98Q5lwkp2emjJwjVq7cYDtfodr27XcDVUqf8z3mHhg1rQ0VbO2jRNG7rfSUMk3DNZcWCjzUrBTlgmy7nQcAYAQ==","type":"thinking","thinking":"用户要求证明勾股定理。勾股定理是一个非常经典的几何定理,有很多种证明方法。我可以提供几种不同的证明方法,包括几何证明和代数证明。让我选择几个最经典和直观的证明方法。\n\n勾股定理:在直角三角形中,直角边的平方和等于斜边的平方。即:a² + b² = c²,其中a、b是直角边,c是斜边。"},{"type":"text","text":"我来为您提供几种经典的勾股定理证明方法:\n\n## 勾股定理表述\n**在直角三角形中,两直角边的平方和等于斜边的平方**\n即:a² + b² = c²(其中a、b为直角边,c为斜边)\n\n## 证明方法一:面积法(最直观)\n\n构造一个边长为(a+b)的正方形:\n\n```\n┌─────────────────┐\n│        │        │\n│   c    │   c    │ b\n│     ╱  │  ╲     │\n├────╱───┼───╲────┤\n│  ╱  a  │ a  ╲  │\n│╱       │     ╲ │ a  \n├────────┼────────┤\n│   c    │   c    │\n│     ╱  │  ╲     │ b\n└─────────────────┘\n```\n\n**计算总面积的两种方法:**\n- 方法1:大正方形面积 = (a+b)²\n- 方法2:4个直角三角形 + 中间小正方形 = 4×(½ab) + c² = 2ab + c²\n\n**因此:**(a+b)² = 2ab + c²\n\n展开:a² + 2ab + b² = 2ab + c²\n\n**得到:a² + b² = c²** ✓\n\n## 证明方法二:相似三角形法\n\n在直角三角形ABC中(∠C = 90°),作高CD到斜边AB:\n\n```\n    C\n    │╲\n    │ ╲\n    │  ╲\n    │   ╲\n  a │    ╲ b\n    │     ╲\n    │      ╲\n    D──────╲\n    └───────╲\n  A     c     B\n```\n\n**由相似三角形性质:**\n- △ACD ∽ △ABC ∽ △CBD\n\n**得到比例关系:**\n- AC²/AB = AD/AC,即 b²/c = AD/b\n- BC²/AB = BD/BC,即 a²/c = BD/a\n\n**因此:**\n- AD = b²/c\n- BD = a²/c\n\n**由于 AD + BD = AB = c:**\nb²/c + a²/c = c\n\n**整理得:**(a² + b²)/c = c\n\n**因此:a² + b² = c²** ✓\n\n## 证明方法三:代数法(坐标几何)\n\n建立坐标系,设直角三角形三个顶点为:\n- A(0, 0)\n- B(a, 0)  \n- C(0, b)\n\n**计算各边长:**\n- |AB| = a\n- |AC| = b  \n- |BC| = √[(a-0)² + (0-b)²] = √(a² + b²)\n\n**根据距离公式,斜边BC的长度为:**\nc = √(a² + b²)\n\n**因此:c² = a² + b²** ✓\n\n## 应用示例\n\n**例:**直角三角形两直角边分别为3和4,求斜边长。\n\n**解:**根据勾股定理\nc² = 3² + 4² = 9 + 16 = 25\nc = 5\n\n这就是著名的\"3-4-5\"直角三角形!\n\n勾股定理不仅是几何学的基础定理,在物理学、工程学等领域也有广泛应用。"}],"model":"MaaS_Sonnet_4","id":"msg_bdrk_01X9RbtVdwyWMr6gJ4wgmwrm"}

7. 兼容openAI非流包含思考的tool调用

第一次请求

{
    "model": "claude-opus-4-20250514",
    "max_tokens": 4000,
    "stream": false,
    "thinking": {
        "type": "enabled",
        "budget_tokens": 2000
    },
    "messages": [
        {
            "role": "user",
            "content": "What is the weather like in San Francisco?"
        }
    ],
    "tools": [
        {
            "function": {
                "name": "get_weather",
                "description": "Get the current weather in a given location",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "location": {
                            "type": "string",
                            "description": "The city and state, e.g. San Francisco, CA"
                        },
                        "unit": {
                            "type": "string",
                            "enum": [
                                "celsius",
                                "fahrenheit"
                            ],
                            "description": "The unit of temperature, either \"celsius\" or \"fahrenheit\""
                        }
                    },
                    "required": [
                        "location"
                    ]
                }
            }
        }
    ]
}

第一次请求返回内容

{
    "id": "msg_bdrk_01FUe2hFxT5tVJbDP3Enh5vT",
    "choices": [
        {
            "index": 0,
            "logprobs": null,
            "message": {
                "role": "assistant",
                "content": null,
                "refusal": null,
                "annotations": null,
                "images": null,
                "reasoning_content": "The user is asking about the weather in San Francisco. I have access to a get_weather function that can help me answer this question. \n\nLet me check the required parameters:\n- location: required - The user specified \"San Francisco\" which I should interpret as \"San Francisco, CA\"\n- unit: optional - The user didn't specify a unit, so I can proceed without it (it will likely default to something)\n\nI have all the required information to make this function call.",
                "function_call": null,
                "tool_calls": [
                    {
                        "id": "toolu_bdrk_01TZ4CVdLzN1qHvL4gKxYRen",
                        "type": "function",
                        "function": {
                            "arguments": "{\"location\": \"San Francisco, CA\"}",
                            "name": "get_weather"
                        },
                        "custom": null
                    }
                ],
                "reasoning_details": [
                    {
                        "type": "thinking",
                        "text": "The user is asking about the weather in San Francisco. I have access to a get_weather function that can help me answer this question. \n\nLet me check the required parameters:\n- location: required - The user specified \"San Francisco\" which I should interpret as \"San Francisco, CA\"\n- unit: optional - The user didn't specify a unit, so I can proceed without it (it will likely default to something)\n\nI have all the required information to make this function call.",
                        "signature": "EvgECkgICBABGAIqQPmd1CzClo8o0+SHD4xw2fZXfPisXbrTiHaStvkliW8P8yT0M3YH1YusAKjPjVlzbpt1nngKXTk2SVTp8gsKzdwSDCLw4L/Hw4g1h9SAhBoMqwdY/izYIujWf/LsIjDU9rUyztXUjrcJI84al3QKOZOCd/Fcx81nlNv++4vAjCGxdMgpfZ/j35SeXojXMIAq3QPvrwoF9NwsVZyI2dS4RsCpNN1qlNlIv1rTGCeIQOxTb4x4jdM73f7ALcowxZEYryoU4+bTtq8qkiXluDOzwqdVuUspiHwmQV3jnDt3ADaYVXiCHpmvuZONqLnlnJK96mGY1iJaQ2J+osBAEDRKj6qC7Fv4mJfKp910aq1+XOVGNGYY4SoOTaNqlQn3Kk8OfhGWkVjSXlfGuKQQ+ESj4vZdOWJT6FC7aqjgXxDamsG008Xx5VAGicZ+4zH+t+AsszMhefBDY0ssgeOfy21jrKMLggzm2wFAVhB7WXhW09BC648U3NfKYyY5Vyje8DnBviCsOwg1w2GXHKKD3hTjTvdKAA7JfLnBuBLzuZkW/6EFF2r6437ZvFjIxqrSsPJDLmkbujTHPYhO+rk30FTwnjGMpkZsQ1dLwbDHYy+QmP2afc3F8K/26sE+t7QFMbqqZR20ubINFY8VO91ojkNQVCz3wwoQk90sHOBphDwKOXPR/TKQyLWbq/TPevtKgEBq7gThoRlhAh/AO5BI022l1UT9ds02AVr6KtOC5bBSqIqUbrkLHMQoUUIIjNe0rryEfgdLswoCjbyngEdoCG7p2YMRmTPzaJu2c3aeXKUUV5XE7TdaehkcVJLwxDGGDGMYAQ=="
                    }
                ]
            },
            "finish_reason": "tool_calls",
            "native_finish_reason": "tool_use"
        }
    ],
    "created": 1760448766,
    "model": "MaaS_Cl_sonnet_4.5_20250929",
    "object": "chat.completion",
    "system_fingerprint": null,
    "service_tier": null,
    "usage": {
        "prompt_tokens": 654,
        "completion_tokens": 167,
        "total_tokens": 821,
        "completion_tokens_details": null,
        "prompt_tokens_details": {
            "audio_tokens": 0,
            "cached_tokens": 0
        },
        "cache_creation_input_tokens": 0,
        "cache_creation": null,
        "gemini_cache_tokens_details": null
    }
}

第二次请求

{
    "model": "claude-opus-4-20250514",
    "max_tokens": 4000,
    "stream": false,
    "thinking": {
        "type": "enabled",
        "budget_tokens": 2000
    },
    "messages": [
        {
            "role": "user",
            "content": "What is the weather like in San Francisco?"
        },
        {
            "role": "assistant",
            "content": null,
            "reasoning_content": "The user is asking about the weather in San Francisco. I have access to a get_weather function that can help me answer this question. \n\nLet me check the required parameters:\n- location: required - The user specified \"San Francisco\" which I should interpret as \"San Francisco, CA\"\n- unit: optional - The user didn't specify a unit, so I can proceed without it (it will likely default to something)\n\nI have all the required information to make this function call.",
            "function_call": null,
            "tool_calls": [
                {
                    "id": "toolu_bdrk_01TZ4CVdLzN1qHvL4gKxYRen",
                    "type": "function",
                    "function": {
                        "arguments": "{\"location\": \"San Francisco, CA\"}",
                        "name": "get_weather"
                    },
                    "custom": null
                }
            ],
            "reasoning_details": [
                {
                    "type": "thinking",
                    "text": "The user is asking about the weather in San Francisco. I have access to a get_weather function that can help me answer this question. \n\nLet me check the required parameters:\n- location: required - The user specified \"San Francisco\" which I should interpret as \"San Francisco, CA\"\n- unit: optional - The user didn't specify a unit, so I can proceed without it (it will likely default to something)\n\nI have all the required information to make this function call.",
                    "signature": "EvgECkgICBABGAIqQPmd1CzClo8o0+SHD4xw2fZXfPisXbrTiHaStvkliW8P8yT0M3YH1YusAKjPjVlzbpt1nngKXTk2SVTp8gsKzdwSDCLw4L/Hw4g1h9SAhBoMqwdY/izYIujWf/LsIjDU9rUyztXUjrcJI84al3QKOZOCd/Fcx81nlNv++4vAjCGxdMgpfZ/j35SeXojXMIAq3QPvrwoF9NwsVZyI2dS4RsCpNN1qlNlIv1rTGCeIQOxTb4x4jdM73f7ALcowxZEYryoU4+bTtq8qkiXluDOzwqdVuUspiHwmQV3jnDt3ADaYVXiCHpmvuZONqLnlnJK96mGY1iJaQ2J+osBAEDRKj6qC7Fv4mJfKp910aq1+XOVGNGYY4SoOTaNqlQn3Kk8OfhGWkVjSXlfGuKQQ+ESj4vZdOWJT6FC7aqjgXxDamsG008Xx5VAGicZ+4zH+t+AsszMhefBDY0ssgeOfy21jrKMLggzm2wFAVhB7WXhW09BC648U3NfKYyY5Vyje8DnBviCsOwg1w2GXHKKD3hTjTvdKAA7JfLnBuBLzuZkW/6EFF2r6437ZvFjIxqrSsPJDLmkbujTHPYhO+rk30FTwnjGMpkZsQ1dLwbDHYy+QmP2afc3F8K/26sE+t7QFMbqqZR20ubINFY8VO91ojkNQVCz3wwoQk90sHOBphDwKOXPR/TKQyLWbq/TPevtKgEBq7gThoRlhAh/AO5BI022l1UT9ds02AVr6KtOC5bBSqIqUbrkLHMQoUUIIjNe0rryEfgdLswoCjbyngEdoCG7p2YMRmTPzaJu2c3aeXKUUV5XE7TdaehkcVJLwxDGGDGMYAQ=="
                }
            ]
        },
        {
            "role": "tool",
            "content": "28 degrees",
            "tool_call_id": "toolu_bdrk_01TZ4CVdLzN1qHvL4gKxYRen"
        }
    ],
    "tools": [
        {
            "function": {
                "name": "get_weather",
                "description": "Get the current weather in a given location",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "location": {
                            "type": "string",
                            "description": "The city and state, e.g. San Francisco, CA"
                        },
                        "unit": {
                            "type": "string",
                            "enum": [
                                "celsius",
                                "fahrenheit"
                            ],
                            "description": "The unit of temperature, either \"celsius\" or \"fahrenheit\""
                        }
                    },
                    "required": [
                        "location"
                    ]
                }
            }
        }
    ]
}

8. SDK调用 (Thinking 不支持SDK仅支持原生)

import anthropic

client = anthropic.Anthropic(base_url="https://genaiapi.cloudsway.net/xxx",
                             api_key="xxx")

message = client.beta.messages.create(
    model="xxx",
    max_tokens=4096,
    system="你是一个专家",
    messages=[{"role": "user", "content": "给我一个三百字的作文"}],
    stream=True,
    thinking={
        "type": "enabled",
        "budget_tokens": 4000
    }

)

for chunk in message:
    print(chunk)