MaaS_Cl_Opus_5.5
Claude Opus 5.5
在消息中定义工具(beta)
借助 inline-tools-2026-09-15 beta 标头,对话过程中系统消息内的 tool_addition 块可携带完整工具定义而非引用,因此你无需编辑 tools 即可在对话过程中添加工具、更改其架构,或将服务器工具迁移至更新版本,同时不会丢失提示词缓存。该功能适用于所有支持对话中途工具变更的模型,包括 Claude Opus 5.5。
例如,要在对话过程中定义自定义工具:
curl --location --request POST 'https://genaiapi.cloudsway.net/{ENDPOINT}/v1/messages' \
--header 'Authorization: Bearer {Your AK}' \
--header 'Content-Type: application/json' \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: inline-tools-2026-09-15" \
-d '{
"model": "claude-opus-5-5",
"max_tokens": 1024,
"tools": [
{
"name": "get_weather",
"description": "Get the current weather for a location.",
"input_schema": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City name"}
},
"required": ["location"]
}
}
],
"messages": [
{
"role": "user",
"content": "How many orders shipped yesterday?"
},
{
"role": "system",
"content": [
{
"type": "tool_addition",
"tool": {
"type": "tool_definition",
"definition": {
"name": "db_query",
"description": "Run a read-only SQL query against the analytics database.",
"input_schema": {
"type": "object",
"properties": {"sql": {"type": "string"}},
"required": ["sql"]
}
}
}
}
]
}
]
}'
按需压缩(beta)
借助compact-2026-09-04 beta 标头,发送顶级压缩参数的请求会返回一个经过签名的压缩块,用于汇总整个会话,之后你可以先发送该压缩块,替代被汇总的消息。该功能适用于所有支持压缩的模型,包括 Claude Opus 5.5。你可以自行决定何时进行压缩,请求可在后台运行,且你保留的轮次中的思维块在替换后仍可保持有效(需满足压缩与保留思维中规定的条件),这一点对 Claude Opus 5.5 而言十分重要,因为其思维块与会话绑定。
# max_tokens caps the whole call, including any thinking, so allow several thousand tokens.
curl --location --request POST 'https://genaiapi.cloudsway.net/{ENDPOINT}/v1/messages' \
--header 'Authorization: Bearer {Your AK}' \
--header 'Content-Type: application/json' \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: compact-2026-09-04" \
-d '{
"model": "claude-opus-5-5",
"max_tokens": 4096,
"messages": [
{"role": "user", "content": "I am building a recipe app. Help me name the main entities in the data model."},
{"role": "assistant", "content": "Start with Recipe, Ingredient, and Step. Add a RecipeIngredient entry that holds the quantity and unit for each ingredient in a recipe."},
{"role": "user", "content": "Good. Now suggest field names for Recipe."}
],
"compaction": {"type": "summarize"}
}'
返回示例:
{
"id": "msg_013Zva2CMHLNnXjNJJKqJ2EF",
"type": "message",
"role": "assistant",
"model": "claude-opus-5-5",
"content": [
{
"type": "compaction",
"content": "Summary of the conversation: the user is designing the data model for a recipe app. The entities agreed so far are Recipe, Ingredient, Step, and RecipeIngredient, which holds the quantity and unit. The user then asked for field names for Recipe.",
"signature": "EuYBCkQY..."
}
],
"stop_reason": "compaction",
"usage": {
"input_tokens": 0,
"output_tokens": 0,
"iterations": [{ "type": "compaction", "input_tokens": 144, "output_tokens": 276 }]
}
}