import os
import anthropic
client = anthropic.Anthropic(
base_url="https://api.cometapi.com",
api_key=os.environ["COMETAPI_KEY"],
)
message = client.messages.create(
model="claude-opus-5",
max_tokens=1000,
messages=[
{
"role": "user",
"content": "Suggest three search queries about renewable energy storage.",
},
],
)
for block in message.content:
if block.type == "text":
print(block.text)
{ "id": "msg_example", "type": "message", "role": "assistant", "model": "claude-opus-5", "content": [ { "type": "text", "text": "Here are three search queries covering different angles of the topic:\n\n1. **\"grid-scale battery storage cost trends 2024 2025\"**\n — Targets economics and recent price data for lithium-ion and other utility-scale systems.\n\n2. **\"long-duration energy storage technologies comparison flow battery vs compressed air vs thermal\"**\n — Surfaces technical comparisons of options for storage beyond the 4–8 hour range, where lithium-ion becomes less cost-effective.\n\n3. **\"green hydrogen seasonal storage feasibility round-trip efficiency\"**\n — Digs into the viability of hydrogen for multi-week or seasonal balancing, including its efficiency penalties.\n\n**A few tips for refining these:**\n- Add `site:.gov` or `site:.edu` to prioritize research and agency reports (e.g., NREL, IEA, DOE).\n- Append a region like `Europe`, `India`, or `California` if you need location-specific policy or deployment data.\n- Try `filetype:pdf` to pull up technical white papers and government studies directly.\n\nWant me to tailor these toward a specific use case — academic research, investment analysis, or policy work?" } ], "stop_reason": "end_turn", "stop_sequence": null, "usage": { "input_tokens": 23, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 0, "cache_creation": { "ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0 }, "output_tokens": 437, "output_tokens_details": { "thinking_tokens": 50 } }}
使用 POST /v1/messages 以 Anthropic 消息格式发送 Claude 请求。
这些示例使用 CometAPI 基础 URL 配置官方 Anthropic SDK,并
从 $COMETAPI_KEY 读取您的 API 密钥。
import osimport anthropicclient = anthropic.Anthropic( base_url="https://api.cometapi.com", api_key=os.environ["COMETAPI_KEY"],)with client.messages.stream( model="claude-opus-5", max_tokens=4096, messages=[ { "role": "user", "content": "A shop sells notebooks for $7 each. Buying three earns a $4 discount. A customer pays $20 for three notebooks. Calculate the total and the change, and explain your steps.", }, ], thinking={ "type": "adaptive", }, output_config={ "effort": "xhigh", },) as stream: message = stream.get_final_message()for block in message.content: if block.type == "text": print(block.text)
import osimport anthropicclient = anthropic.Anthropic( base_url="https://api.cometapi.com", api_key=os.environ["COMETAPI_KEY"],)with client.messages.stream( model="claude-opus-5", max_tokens=1024, messages=[ { "role": "user", "content": "Write a two-line poem about a comet.", }, ],) as stream: for text in stream.text_stream: print(text, end="", flush=True)
获取一篇论文,并要求 Claude 在回答中使用检索到的文档。
此示例以流式方式返回响应,并检查最终文本和
web_fetch_tool_result 块:
import osimport anthropicclient = anthropic.Anthropic( base_url="https://api.cometapi.com", api_key=os.environ["COMETAPI_KEY"],)with client.messages.stream( model="claude-sonnet-5", max_tokens=2048, messages=[ { "role": "user", "content": "Fetch https://arxiv.org/abs/1512.03385 and state the paper title and the proposed learning framework in two sentences.", }, ], tools=[ { "type": "web_fetch_20250910", "name": "web_fetch", "max_uses": 3, }, ],) as stream: message = stream.get_final_message()for block in message.content: if block.type == "text": print(block.text)for block in message.content: if block.type == "web_fetch_tool_result": print(block.model_dump_json())
搜索正式发布日期,并要求 Claude 引用其来源。
此示例以流式方式返回响应,收集最终消息,并打印
返回的搜索来源:
import osimport anthropicclient = anthropic.Anthropic( base_url="https://api.cometapi.com", api_key=os.environ["COMETAPI_KEY"],)with client.messages.stream( model="claude-sonnet-5", max_tokens=4096, messages=[ { "role": "user", "content": "Search the web for the official Python 3.14 release date. Answer with the date and cite a source.", }, ], tools=[ { "type": "web_search_20250305", "name": "web_search", "max_uses": 3, }, ],) as stream: message = stream.get_final_message()for block in message.content: if block.type == "text": print(block.text)for block in message.content: if block.type == "web_search_tool_result": if isinstance(block.content, list): for result in block.content: if result.type == "web_search_result": print(result.title, result.url)
import jsonimport osimport anthropicclient = anthropic.Anthropic( base_url="https://api.cometapi.com", api_key=os.environ["COMETAPI_KEY"],)tools = [{ "name": "get_order_status", "description": "Look up the status of a demonstration order.", "input_schema": { "type": "object", "properties": { "order_id": { "type": "string", "description": "The order reference.", }, }, "required": ["order_id"], },}]messages = [{ "role": "user", "content": "Check the status of demo-order-42 using the order tool.",}]with client.messages.stream( model="claude-opus-5", max_tokens=1000, messages=messages, tools=tools,) as stream: message = stream.get_final_message()tool_call = next(b for b in message.content if b.type == "tool_use")messages.append({ "role": "assistant", "content": [block.model_dump() for block in message.content],})messages.append({ "role": "user", "content": [{ "type": "tool_result", "tool_use_id": tool_call.id, "content": json.dumps({ "status": "ready_for_pickup", "pickup_code": "COMET42", }), }],})with client.messages.stream( model="claude-opus-5", max_tokens=1000, messages=messages, tools=tools,) as stream: follow_up = stream.get_final_message()for block in follow_up.content: if block.type == "text": print(block.text)
响应示例
非流式请求会返回一个消息对象。以下示例展示了其
text 和 usage 字段,并使用了示例消息标识符:
{ "id": "msg_example", "type": "message", "role": "assistant", "model": "claude-opus-5", "content": [ { "type": "text", "text": "Here are three search queries covering different angles of the topic:\n\n1. **\"grid-scale battery storage cost trends 2024 2025\"**\n — Targets economics and recent price data for lithium-ion and other utility-scale systems.\n\n2. **\"long-duration energy storage technologies comparison flow battery vs compressed air vs thermal\"**\n — Surfaces technical comparisons of options for storage beyond the 4–8 hour range, where lithium-ion becomes less cost-effective.\n\n3. **\"green hydrogen seasonal storage feasibility round-trip efficiency\"**\n — Digs into the viability of hydrogen for multi-week or seasonal balancing, including its efficiency penalties.\n\n**A few tips for refining these:**\n- Add `site:.gov` or `site:.edu` to prioritize research and agency reports (e.g., NREL, IEA, DOE).\n- Append a region like `Europe`, `India`, or `California` if you need location-specific policy or deployment data.\n- Try `filetype:pdf` to pull up technical white papers and government studies directly.\n\nWant me to tailor these toward a specific use case — academic research, investment analysis, or policy work?" } ], "stop_reason": "end_turn", "stop_sequence": null, "usage": { "input_tokens": 23, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 0, "cache_creation": { "ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0 }, "output_tokens": 437, "output_tokens_details": { "thinking_tokens": 50 } }}
Your CometAPI key passed via the x-api-key header. Authorization: Bearer $COMETAPI_KEY is also supported.
请求头
anthropic-version
string
默认值:2023-06-01
The Anthropic API version to use. Defaults to 2023-06-01.
示例:
"2023-06-01"
anthropic-beta
string
Comma-separated feature identifiers required by a specific beta API feature. Omit this header for the examples on this page.
请求体
application/json
model
string
默认值:claude-opus-5
必填
The Claude model to use. See the Models page for available Claude model IDs.
示例:
"claude-opus-5"
messages
object[]
必填
Conversation history. Use user and assistant messages with text strings or content-block arrays. Return complete assistant content blocks when continuing a tool call.
Show child attributes
max_tokens
integer
必填
The maximum number of tokens to generate. The model may stop before reaching this limit. When using thinking, the thinking tokens count towards this limit.
必填范围: x >= 1
示例:
1024
system
stringobject[]
System prompt providing context and instructions to Claude. Can be a plain string or an array of content blocks (useful for prompt caching).
temperature
number
Sampling temperature. The examples omit sampling overrides.
必填范围: 0 <= x <= 1
top_p
number
Nucleus sampling threshold. The examples omit sampling overrides.
必填范围: 0 <= x <= 1
top_k
integer
Limits sampling to the k most likely tokens. The examples omit sampling overrides.
必填范围: x >= 0
stream
boolean
默认值:false
If true, stream the response incrementally using Server-Sent Events (SSE). Events include message_start, content_block_start, content_block_delta, content_block_stop, message_delta, and message_stop.
stop_sequences
string[]
Custom strings that cause the model to stop generating when encountered. The stop sequence is not included in the response.
thinking
object
Thinking configuration. The adaptive example uses type adaptive and sets output_config.effort separately.
Show child attributes
tools
object[]
Client tools define a name and input_schema. Server tools use a versioned type and name, such as the web_fetch and web_search examples on this page.
Show child attributes
tool_choice
object
Controls how the model uses tools.
Show child attributes
metadata
object
Request metadata for tracking and analytics.
Show child attributes
output_config
object
Configuration for reasoning effort and structured output.
Show child attributes
service_tier
enum<string>
The service tier to use. auto tries priority capacity first, standard_only uses only standard capacity.
可用选项:
auto,
standard_only
响应
Successful response. When stream is true, the response is a stream of SSE events.
id
string
Message identifier returned by the API.
type
enum<string>
Always message.
可用选项:
message
role
enum<string>
Always assistant.
可用选项:
assistant
content
object[]
The response content blocks. May include text, thinking, tool_use, and other block types.
Show child attributes
model
string
Model ID reported by the response.
stop_reason
enum<string>
Why the model stopped generating. refusal can be returned as a successful HTTP response when the model declines a request.
可用选项:
end_turn,
max_tokens,
stop_sequence,
tool_use,
pause_turn,
refusal
stop_sequence
string | null
The stop sequence that caused the model to stop, if applicable.
usage
object
Token usage statistics.
Show child attributes
最后修改于 2026年9月8日
⌘I
import os
import anthropic
client = anthropic.Anthropic(
base_url="https://api.cometapi.com",
api_key=os.environ["COMETAPI_KEY"],
)
message = client.messages.create(
model="claude-opus-5",
max_tokens=1000,
messages=[
{
"role": "user",
"content": "Suggest three search queries about renewable energy storage.",
},
],
)
for block in message.content:
if block.type == "text":
print(block.text)
{ "id": "msg_example", "type": "message", "role": "assistant", "model": "claude-opus-5", "content": [ { "type": "text", "text": "Here are three search queries covering different angles of the topic:\n\n1. **\"grid-scale battery storage cost trends 2024 2025\"**\n — Targets economics and recent price data for lithium-ion and other utility-scale systems.\n\n2. **\"long-duration energy storage technologies comparison flow battery vs compressed air vs thermal\"**\n — Surfaces technical comparisons of options for storage beyond the 4–8 hour range, where lithium-ion becomes less cost-effective.\n\n3. **\"green hydrogen seasonal storage feasibility round-trip efficiency\"**\n — Digs into the viability of hydrogen for multi-week or seasonal balancing, including its efficiency penalties.\n\n**A few tips for refining these:**\n- Add `site:.gov` or `site:.edu` to prioritize research and agency reports (e.g., NREL, IEA, DOE).\n- Append a region like `Europe`, `India`, or `California` if you need location-specific policy or deployment data.\n- Try `filetype:pdf` to pull up technical white papers and government studies directly.\n\nWant me to tailor these toward a specific use case — academic research, investment analysis, or policy work?" } ], "stop_reason": "end_turn", "stop_sequence": null, "usage": { "input_tokens": 23, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 0, "cache_creation": { "ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0 }, "output_tokens": 437, "output_tokens_details": { "thinking_tokens": 50 } }}
{"docsConfig":{"theme":"luma","$schema":"https://mintlify.com/docs.json","name":"CometAPI Documentation","description":"CometAPI developer documentation for unified API access to GPT, Claude, Gemini, Grok, Llama, DeepSeek, Mistral, Qwen, and more, including API reference, quickstart guides, and integration tutorials.","colors":{"primary":"#00ACE2","light":"#00ACE2","dark":"#0274C3"},"logo":{"light":"https://mintcdn.com/cometapi/cmhWX83dzrkf2F-2/logo/comet-light.svg?fit=max\u0026auto=format\u0026n=cmhWX83dzrkf2F-2\u0026q=85\u0026s=7ae2fde0df7785d111912bce23157ef2","dark":"https://mintcdn.com/cometapi/cmhWX83dzrkf2F-2/logo/comet-dark.svg?fit=max\u0026auto=format\u0026n=cmhWX83dzrkf2F-2\u0026q=85\u0026s=2d25d0a1c0376b7a3b5b2b06c4149fbc"},"favicon":"https://mintcdn.com/cometapi/cmhWX83dzrkf2F-2/logo/comet.svg?fit=max\u0026auto=format\u0026n=cmhWX83dzrkf2F-2\u0026q=85\u0026s=bd1150b78a8058af98088b06cbe67cdc","api":{"playground":{"display":"interactive","proxy":true},"examples":{"defaults":"required","prefill":true}},"navbar":{"links":[{"href":"https://www.cometapi.com/models/","label":"Models"}],"primary":{"type":"button","label":"Dashboard","href":"https://www.cometapi.com/console"}},"footer":{},"seo":{"metatags":{"og:site_name":"CometAPI Docs","og:type":"website","twitter:card":"summary_large_image","canonical":"https://apidoc.cometapi.com","author":"CometAPI","copyright":"Copyright 2026 CometAPI","category":"Technology","distribution":"global","coverage":"Worldwide"},"indexing":"navigable"},"integrations":{"posthog":{"apiKey":"phc_y3KwBz46V9TGDjqPtDrpuSahVg3bDky6eyzGsD8vuCYS","sessionRecording":false}},"contextual":{"options":["copy","view","chatgpt","claude","perplexity"],"display":"header"},"interaction":{"drilldown":false},"metadata":{"timestamp":true},"styling":{"latex":false},"navigation":{"languages":[{"language":"en","href":""},{"language":"zh-Hans","href":"zh-Hans"},{"language":"zh-Hant","href":"zh-Hant"},{"language":"ja","href":"ja"},{"language":"ko","href":"ko"},{"language":"fr","href":"fr"},{"language":"de","href":"de"},{"language":"es","href":"es"},{"language":"it","href":"it"},{"language":"pt","href":"pt"},{"language":"ru","href":"ru"},{"language":"ar","href":"ar"},{"language":"vi","href":"vi"},{"language":"id","href":"id"},{"language":"tr","href":"tr"},{"language":"pl","href":"pl"},{"language":"nl","href":"nl"},{"language":"no","href":"no"},{"language":"uk","href":"uk"}]}},"deployment":{"deploymentMetadataValue":{"subdomain":"cometapi","hasAudioNarration":false,"actualSubdomain":"cometapi","customDomains":["apidoc.cometapi.com"],"gitSource":{"type":"github","owner":"cometapi-dev","repo":"cometapi-docs","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"entitlements":{},"buildId":"6afebfd676d45603e0b822a1","clientVersion":"0.0.4271","searchFilterCounts":[{"language":"en","tag":"API","count":99},{"language":"en","tag":"Video Models","count":66},{"language":"en","tag":"Integrations","count":53},{"language":"en","tag":"Docs","count":37},{"language":"en","tag":"Kling","count":33},{"language":"en","tag":"Image Models","count":18},{"language":"en","tag":"AI chat clients","count":14},{"language":"en","tag":"Runway","count":13},{"language":"en","tag":"AI coding agents","count":10},{"language":"en","tag":"Core API guides","count":9}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"site-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"treatment","enabled":true,"payload":{"type":"string","value":"treatment"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"wildcard-email-auth","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[{"filePath":"style.css","content":"img[src*=\"cloudfront.net/flags/\"]{display:none!important}div.relative:has(>img[src*=\"cloudfront.net/flags/\"]){display:none!important}#localization-select-item-zh-Hans{display:none!important}nav a.link[class~=\"bg-gray-950/[0.03]\"]{background-color:rgb(var(--primary) / 0.12);box-shadow:inset 0 0 0 1px rgb(var(--primary) / 0.38), 0 1px 2px rgb(var(--primary) / 0.08);color:rgb(var(--primary))}nav a.link[class~=\"bg-gray-950/[0.03]\"]:hover,nav a.link[class~=\"bg-gray-950/[0.03]\"]:focus-visible{background-color:rgb(var(--primary) / 0.18);box-shadow:inset 0 0 0 1px rgb(var(--primary) / 0.58), 0 1px 2px rgb(var(--primary) / 0.1);color:rgb(var(--primary))}nav a.link[class~=\"bg-gray-950/[0.03]\"]:focus-visible{outline:2px solid rgb(var(--primary) / 0.45);outline-offset:2px}.dark nav a.link[class~=\"bg-gray-950/[0.03]\"]{background-color:rgb(var(--primary-light) / 0.2);box-shadow:inset 0 0 0 1px rgb(var(--primary-light) / 0.55), 0 1px 2px rgb(var(--primary-light) / 0.16);color:rgb(var(--primary-light))}.dark nav a.link[class~=\"bg-gray-950/[0.03]\"]:hover,.dark nav a.link[class~=\"bg-gray-950/[0.03]\"]:focus-visible{background-color:rgb(var(--primary-light) / 0.28);box-shadow:inset 0 0 0 1px rgb(var(--primary-light) / 0.7), 0 1px 2px rgb(var(--primary-light) / 0.18);color:rgb(var(--primary-light))}.integration-logo-grid{display:grid;grid-template-columns:repeat(3, minmax(0, 1fr));gap:12px;margin:16px 0 28px}.integration-logo-card{align-items:center;background:rgba(127, 127, 127, 0.04);border:1px solid rgba(127, 127, 127, 0.22);border-radius:8px;color:inherit;display:flex;gap:14px;min-height:72px;padding:14px 16px;text-decoration:none!important;transition:background 160ms ease, border-color 160ms ease, transform 160ms ease}.integration-logo-card:hover,.integration-logo-card:focus-visible{background:rgba(0, 172, 226, 0.08);border-color:rgba(0, 172, 226, 0.55);transform:translateY(-1px)}.integration-logo-card:focus-visible{outline:2px solid rgba(0, 172, 226, 0.45);outline-offset:2px}.integration-logo-mark{align-items:center;background:#fff;background-position:center;background-repeat:no-repeat;background-size:28px 28px;border:1px solid rgba(127, 127, 127, 0.18);border-radius:8px;display:flex;flex:0 0 38px;height:38px;justify-content:center;overflow:hidden;width:38px}.integration-logo-body{display:flex;flex-direction:column;gap:2px;min-width:0}.integration-logo-title{font-size:0.95rem;font-weight:600;line-height:1.3}.integration-logo-subtitle{color:rgba(90, 90, 90, 0.92);font-size:0.78rem;line-height:1.3;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.integration-card-arrow{color:rgba(90, 90, 90, 0.7);flex:0 0 16px;font-size:0.9rem;margin-left:auto;text-align:right}.integration-card-arrow::before{content:\"\\2197\"}.integration-logo-ai-sdk{background-image:url(\"/images/integrations/logos/ai-sdk.png\")}.integration-logo-agno{background-image:url(\"/images/integrations/logos/agno.png\")}.integration-logo-claude-code{background-image:url(\"/images/integrations/logos/claude-code.png\")}.integration-logo-claude-desktop{background-image:url(\"/images/integrations/logos/claude-desktop.png\")}.integration-logo-codex{background-image:url(\"/images/integrations/logos/codex.png\")}.integration-logo-dify{background-image:url(\"/images/integrations/logos/dify.png\")}.integration-logo-gemini-cli{background-image:url(\"/images/integrations/logos/gemini-cli.png\")}.integration-logo-hermes-agent{background-image:url(\"/images/integrations/logos/hermes-agent.png\");background-size:34px 34px}.integration-logo-langchain{background-image:url(\"/images/integrations/logos/langchain.png\")}.integration-logo-langflow{background-image:url(\"/images/integrations/logos/langflow.png\")}.integration-logo-langfuse{background-image:url(\"/images/integrations/logos/langfuse.png\")}.integration-logo-litellm{background-image:url(\"/images/integrations/logos/litellm.png\")}.integration-logo-llamaindex{background-image:url(\"/images/integrations/logos/llamaindex.png\")}.integration-logo-lobe-chat{background-image:url(\"/images/integrations/logos/lobe-chat.jpg\")}.integration-logo-make{background-image:url(\"/images/integrations/logos/make.jpg\")}.integration-logo-n8n{background-image:url(\"/images/integrations/logos/n8n.png\")}.integration-logo-open-webui{background-image:url(\"/images/integrations/logos/open-webui.png\")}.integration-logo-workbuddy-ai{background-image:url(\"/images/integrations/logos/workbuddy-ai.svg\")}.integration-logo-openclaw{background-image:url(\"/images/integrations/logos/openclaw.svg\")}.integration-logo-opencode{background-image:url(\"/images/integrations/logos/opencode.png\")}.integration-logo-pi{background-image:url(\"/images/integrations/logos/pi.svg\")}.integration-logo-promptfoo{background-image:url(\"/images/integrations/logos/promptfoo.png\")}.dark .integration-logo-card{background:rgba(255, 255, 255, 0.035);border-color:rgba(255, 255, 255, 0.14)}.dark .integration-logo-card:hover,.dark .integration-logo-card:focus-visible{background:rgba(0, 172, 226, 0.14);border-color:rgba(0, 172, 226, 0.65)}.dark .integration-logo-mark{background-color:rgba(255, 255, 255, 0.96)}.dark .integration-logo-subtitle{color:rgba(255, 255, 255, 0.66)}.dark .integration-card-arrow{color:rgba(255, 255, 255, 0.64)}@media (max-width: 1024px){.integration-logo-grid{grid-template-columns:repeat(2, minmax(0, 1fr))}}@media (max-width: 640px){.integration-logo-grid{grid-template-columns:1fr}.integration-logo-card{min-height:68px}}"}]}
{"page":{"pagePath":"zh-Hans/api/text/anthropic-messages","slug":"/zh-Hans/api/text/anthropic-messages","pageMetadata":{"title":"创建消息","sidebarTitle":"创建消息","openapi":"api/openapi/text/post-anthropic-messages.openapi.json POST /v1/messages","description":"通过 CometAPI Messages 端点调用 Claude,支持文本和图像输入、自适应思考、Prompt 缓存、流式输出和工具。","keywords":["CometAPI","Anthropic Messages API","POST /v1/messages","claude api","adaptive thinking","prompt caching","streaming sse","web fetch tool","effort control"],"noindex":true,"href":"/zh-Hans/api/text/anthropic-messages"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"通过 CometAPI Messages 端点调用 Claude,支持文本和图像输入、自适应思考、Prompt 缓存、流式输出和工具。\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,li:`li`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,CodeGroup,Heading,Note,Tab,Tabs,Tip}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!CodeGroup)_missingMdxReference(`CodeGroup`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Note)_missingMdxReference(`Note`,true);if(!Tab)_missingMdxReference(`Tab`,true);if(!Tabs)_missingMdxReference(`Tabs`,true);if(!Tip)_missingMdxReference(`Tip`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`使用 `,_jsx(_components.code,{children:`POST /v1/messages`}),` 以 Anthropic 消息格式发送 Claude 请求。\n这些示例使用 CometAPI 基础 URL 配置官方 Anthropic SDK,并\n从 `,_jsx(_components.code,{children:`$COMETAPI_KEY`}),` 读取您的 API 密钥。`]}),`\n`,_jsx(Tip,{children:_jsxs(_components.p,{children:[`有关字段定义和模型特定选项,请参阅官方\n`,_jsx(_components.a,{href:`https://platform.claude.com/docs/en/api/messages/create`,children:`Messages API 参考`}),`.\n对于 OpenAI 兼容请求,请参阅 `,_jsx(_components.a,{href:`/api/text/chat`,children:`聊天补全`}),`.`]})}),`\n`,_jsx(Note,{children:_jsxs(_components.p,{children:[`使用 `,_jsx(_components.code,{children:`x-api-key`}),` 或 `,_jsx(_components.code,{children:`Authorization: Bearer`}),` 进行身份验证。Anthropic SDK 使用\n`,_jsx(_components.code,{children:`x-api-key`}),`。HTTP 示例包含 `,_jsx(_components.code,{children:`anthropic-version: 2023-06-01`}),`。`]})}),`\n`,_jsx(Heading,{level:`2`,id:`快速开始`,children:`快速开始`}),`\n`,_jsxs(_components.p,{children:[`以下示例请求三个搜索查询。请设置 `,_jsx(_components.code,{children:`$COMETAPI_KEY`}),` 后再\n运行这些示例。对于 Python,请安装 `,_jsx(_components.code,{children:`anthropic`}),`;对于 JavaScript,请安装 `,_jsx(_components.code,{children:`@anthropic-ai/sdk`}),`:`]}),`\n`,_jsxs(CodeGroup,{children:[_jsx(CodeBlock,{filename:`Shell`,numberOfLines:`14`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`14`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`curl`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"https://api.cometapi.com/v1/messages\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Content-Type: application/json\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"x-api-key: `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`$COMETAPI_KEY`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"anthropic-version: 2023-06-01\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -d`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"model\": \"claude-opus-5\",`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"max_tokens\": 1000,`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"messages\": [`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` {`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"role\": \"user\",`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"content\": \"Suggest three search queries about renewable energy storage.\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` ]`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`}'`})}),`\n`]})})}),_jsx(CodeBlock,{filename:`Python`,numberOfLines:`22`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`22`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` os`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` anthropic`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`client `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` anthropic.Anthropic(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` base_url`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"https://api.cometapi.com\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` api_key`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`os.environ[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"COMETAPI_KEY\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`message `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` client.messages.create(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` model`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"claude-opus-5\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` max_tokens`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1000`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` messages`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Suggest three search queries about renewable energy storage.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ],`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` block `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` message.content:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` block.type `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"text\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(block.text)`})]}),`\n`]})})}),_jsx(CodeBlock,{filename:`JavaScript`,numberOfLines:`21`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`21`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` Anthropic`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"@anthropic-ai/sdk\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` client`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` Anthropic`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` apiKey:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` process`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`env`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`COMETAPI_KEY`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` baseURL:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"https://api.cometapi.com\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` message`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` client`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`messages`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`create`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"model\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"claude-opus-5\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"max_tokens\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1000`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"messages\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Suggest three search queries about renewable energy storage.\"`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ]`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` block`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` of`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` message`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`block`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`type`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"text\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`block`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`text`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})})]}),`\n`,_jsxs(_components.p,{children:[`响应包含一个 `,_jsx(_components.code,{children:`content`}),` 数组。读取 `,_jsx(_components.code,{children:`type`}),` 为 `,_jsx(_components.code,{children:`text`}),` 的块;\n思考和工具块可能出现在文本之前。`]}),`\n`,_jsx(Heading,{level:`2`,id:`控制自适应思考`,children:`控制自适应思考`}),`\n`,_jsxs(_components.p,{children:[`将 `,_jsx(_components.code,{children:`thinking.type`}),` 设置为 `,_jsx(_components.code,{children:`adaptive`}),`,并选择一个 `,_jsx(_components.code,{children:`output_config.effort`}),` 值。\n以下示例使用 `,_jsx(_components.code,{children:`xhigh`}),`,并从流中读取完成的消息:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`29`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`29`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` os`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` anthropic`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`client `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` anthropic.Anthropic(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` base_url`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"https://api.cometapi.com\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` api_key`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`os.environ[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"COMETAPI_KEY\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` client.messages.stream(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` model`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"claude-opus-5\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` max_tokens`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`4096`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` messages`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"A shop sells notebooks for $7 each. Buying three earns a $4 discount. A customer pays $20 for three notebooks. Calculate the total and the change, and explain your steps.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ],`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` thinking`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"adaptive\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` output_config`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"effort\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"xhigh\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` stream:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` message `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` stream.get_final_message()`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` block `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` message.content:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` block.type `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"text\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(block.text)`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`思考会占用 `,_jsx(_components.code,{children:`max_tokens`}),` 输出上限。请为最终\n答案和思考预留空间。响应可以包含文本,而不带可见的\n思考块。请在对话\n历史记录中原样保留任何返回的思考块。`]}),`\n`,_jsxs(_components.p,{children:[`有关特定模型的思考配置,请参阅\n`,_jsx(_components.a,{href:`https://platform.claude.com/docs/en/build-with-claude/extended-thinking`,children:`思考`}),`.\n这些示例省略了 `,_jsx(_components.code,{children:`temperature`}),`、`,_jsx(_components.code,{children:`top_p`}),` 和 `,_jsx(_components.code,{children:`top_k`}),`;在添加采样控制参数之前,请查阅所选\n模型的参数文档。`]}),`\n`,_jsx(Heading,{level:`2`,id:`缓存-prompt`,children:`缓存 Prompt`}),`\n`,_jsxs(_components.p,{children:[`为在请求之间重复使用的参考资料设置缓存断点。\n在运行此示例之前,将参考资料保存为 UTF-8 `,_jsx(_components.code,{children:`reference.txt`}),` 文件。\n使用符合所选模型\n`,_jsx(_components.a,{href:`https://platform.claude.com/docs/en/build-with-claude/prompt-caching#cache-limitations`,children:`最小可缓存长度`}),`:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`37`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`37`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` os`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` pathlib `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Path`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` anthropic`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`client `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` anthropic.Anthropic(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` base_url`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"https://api.cometapi.com\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` api_key`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`os.environ[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"COMETAPI_KEY\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`reference `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Path(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"reference.txt\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`).read_text(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`encoding`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"utf-8\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` client.messages.stream(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` model`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"claude-sonnet-5\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` max_tokens`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1024`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` messages`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"How long can customers return damaged books, and what must they provide?\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ],`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` system`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"text\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"text\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: reference,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"cache_control\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"ephemeral\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ],`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` stream:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` message `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` stream.get_final_message()`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` block `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` message.content:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` block.type `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"text\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(block.text)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(message.usage.model_dump_json())`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`使用相同的模型、参考文本和思考设置再次运行请求。\n检查用量计数器,以确定请求是否复用了某个前缀:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`cache_creation_input_tokens`}),` 统计写入缓存的 Token 数。`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`cache_read_input_tokens`}),` 统计从缓存读取的 Token 数。`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`input_tokens`}),` 统计在这些缓存计数器之外处理的输入。`]}),`\n`]}),`\n`,_jsxs(_components.p,{children:[`在重复请求中,`,_jsx(_components.code,{children:`cache_read_input_tokens`}),` 会报告有多少输入 Token\n是从缓存中读取的。OpenAPI `,_jsx(_components.strong,{children:`Prompt 缓存`}),`\n示例包含一份完整的虚构参考资料,你可以将其保存为\n`,_jsx(_components.code,{children:`reference.txt`}),` 以试用该示例。`]}),`\n`,_jsx(Heading,{level:`2`,id:`流式传输响应`,children:`流式传输响应`}),`\n`,_jsxs(_components.p,{children:[`将 `,_jsx(_components.code,{children:`stream: true`}),` 设置为使用 Server-Sent Events。SDK 会在文本片段\n到达时将其公开:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`20`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`20`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` os`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` anthropic`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`client `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` anthropic.Anthropic(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` base_url`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"https://api.cometapi.com\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` api_key`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`os.environ[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"COMETAPI_KEY\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` client.messages.stream(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` model`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"claude-opus-5\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` max_tokens`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1024`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` messages`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Write a two-line poem about a comet.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ],`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` stream:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` text `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` stream.text_stream:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(text, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`end`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`flush`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`消息流包含 `,_jsx(_components.code,{children:`message_start`}),`、内容块事件、`,_jsx(_components.code,{children:`message_delta`}),`,\n以及 `,_jsx(_components.code,{children:`message_stop`}),`。内容块可以包含文本、思考或工具活动。\n对于文本块,`,_jsx(_components.code,{children:`content_block_delta`}),` 包含一个 `,_jsx(_components.code,{children:`text_delta`}),`。读取最终用量\n以及来自 `,_jsx(_components.code,{children:`message_delta`}),` 的停止原因。`]}),`\n`,_jsx(Heading,{level:`2`,id:`控制推理强度`,children:`控制推理强度`}),`\n`,_jsxs(_components.p,{children:[`设置 `,_jsx(_components.code,{children:`output_config.effort`}),` 以引导推理量。本示例使用\n`,_jsx(_components.code,{children:`low`}),` 来获取简短说明,并等待流式消息完成:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`26`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`26`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` os`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` anthropic`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`client `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` anthropic.Anthropic(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` base_url`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"https://api.cometapi.com\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` api_key`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`os.environ[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"COMETAPI_KEY\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` client.messages.stream(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` model`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"claude-opus-5\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` max_tokens`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1000`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` messages`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Summarize the benefit of automated tests in one sentence.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ],`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` output_config`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"effort\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"low\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` stream:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` message `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` stream.get_final_message()`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` block `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` message.content:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` block.type `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"text\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(block.text)`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`使用官方\n`,_jsx(_components.a,{href:`https://platform.claude.com/docs/en/build-with-claude/effort`,children:`effort 参考文档`}),`\n来选择强度级别。单独设置 `,_jsx(_components.code,{children:`max_tokens`}),` 以限制输出长度。`]}),`\n`,_jsx(Heading,{level:`2`,id:`使用服务器工具`,children:`使用服务器工具`}),`\n`,_jsx(_components.p,{children:`服务器工具会在 API 请求期间执行,并与\nClaude 的回答一同返回结果块。`}),`\n`,_jsxs(Tabs,{children:[_jsxs(Tab,{title:`网页获取`,id:`%E7%BD%91%E9%A1%B5%E8%8E%B7%E5%8F%96`,children:[_jsxs(_components.p,{children:[`获取一篇论文,并要求 Claude 在回答中使用检索到的文档。\n此示例以流式方式返回响应,并检查最终文本和\n`,_jsx(_components.code,{children:`web_fetch_tool_result`}),` 块:`]}),_jsx(CodeBlock,{filename:``,numberOfLines:`34`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`34`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` os`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` anthropic`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`client `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` anthropic.Anthropic(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` base_url`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"https://api.cometapi.com\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` api_key`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`os.environ[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"COMETAPI_KEY\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` client.messages.stream(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` model`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"claude-sonnet-5\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` max_tokens`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`2048`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` messages`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Fetch https://arxiv.org/abs/1512.03385 and state the paper title and the proposed learning framework in two sentences.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ],`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` tools`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"web_fetch_20250910\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"name\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"web_fetch\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"max_uses\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`3`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ],`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` stream:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` message `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` stream.get_final_message()`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` block `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` message.content:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` block.type `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"text\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(block.text)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` block `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` message.content:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` block.type `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"web_fetch_tool_result\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(block.model_dump_json())`})]}),`\n`]})})}),_jsxs(_components.p,{children:[`响应会将一个 `,_jsx(_components.code,{children:`server_tool_use`}),` 块与一个 `,_jsx(_components.code,{children:`web_fetch_tool_result`}),` 块配对,后者\n包含获取的文档或工具错误。`]})]}),_jsxs(Tab,{title:`网页搜索`,id:`%E7%BD%91%E9%A1%B5%E6%90%9C%E7%B4%A2`,children:[_jsx(_components.p,{children:`搜索正式发布日期,并要求 Claude 引用其来源。\n此示例以流式方式返回响应,收集最终消息,并打印\n返回的搜索来源:`}),_jsx(CodeBlock,{filename:``,numberOfLines:`37`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`37`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` os`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` anthropic`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`client `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` anthropic.Anthropic(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` base_url`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"https://api.cometapi.com\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` api_key`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`os.environ[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"COMETAPI_KEY\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` client.messages.stream(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` model`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"claude-sonnet-5\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` max_tokens`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`4096`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` messages`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Search the web for the official Python 3.14 release date. Answer with the date and cite a source.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ],`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` tools`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"web_search_20250305\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"name\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"web_search\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"max_uses\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`3`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ],`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` stream:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` message `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` stream.get_final_message()`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` block `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` message.content:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` block.type `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"text\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(block.text)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` block `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` message.content:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` block.type `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"web_search_tool_result\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` isinstance`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(block.content, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`list`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` result `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` block.content:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` result.type `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"web_search_result\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(result.title, result.url)`})]}),`\n`]})})}),_jsxs(_components.p,{children:[`响应会将一个 `,_jsx(_components.code,{children:`server_tool_use`}),` 块与一个 `,_jsx(_components.code,{children:`web_search_tool_result`}),` 块配对,后者\n包含来源。请从此结果块中读取来源标题和 URL。`]})]})]}),`\n`,_jsx(Heading,{level:`2`,id:`返回客户端工具结果`,children:`返回客户端工具结果`}),`\n`,_jsxs(_components.p,{children:[`对于客户端工具,Claude 会返回一个 `,_jsx(_components.code,{children:`tool_use`}),` 块。运行您的应用函数\n并在包含匹配 `,_jsx(_components.code,{children:`tool_result`}),` 的 `,_jsx(_components.code,{children:`tool_use_id`}),` 块中发送其结果。\n在两次请求之间保留完整的 assistant 内容。`]}),`\n`,_jsx(_components.p,{children:`此示例提供了一个虚构的订单结果,并要求 Claude 使用该结果:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`63`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`63`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` json`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` os`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` anthropic`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`client `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` anthropic.Anthropic(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` base_url`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"https://api.cometapi.com\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` api_key`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`os.environ[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"COMETAPI_KEY\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`tools `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [{`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"name\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"get_order_status\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"description\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Look up the status of a demonstration order.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"input_schema\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"object\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"properties\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"order_id\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"string\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"description\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"The order reference.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"required\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"order_id\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}]`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`messages `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [{`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Check the status of demo-order-42 using the order tool.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}]`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` client.messages.stream(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` model`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"claude-opus-5\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` max_tokens`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1000`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` messages`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`messages,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` tools`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`tools,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` stream:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` message `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` stream.get_final_message()`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`tool_call `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` next`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(b `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` b `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` message.content `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` b.type `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"tool_use\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`messages.append({`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"assistant\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [block.model_dump() `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` block `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` message.content],`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`})`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`messages.append({`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [{`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"tool_result\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"tool_use_id\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: tool_call.id,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: json.dumps({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"status\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"ready_for_pickup\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"pickup_code\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"COMET42\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }),`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }],`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`})`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` client.messages.stream(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` model`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"claude-opus-5\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` max_tokens`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1000`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` messages`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`messages,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` tools`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`tools,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` stream:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` follow_up `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` stream.get_final_message()`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` block `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` follow_up.content:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` block.type `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"text\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(block.text)`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`响应示例`,children:`响应示例`}),`\n`,_jsx(_components.p,{children:`非流式请求会返回一个消息对象。以下示例展示了其\ntext 和 usage 字段,并使用了示例消息标识符:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`27`,language:`json`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`json`,children:_jsxs(_components.code,{language:`json`,numberOfLines:`27`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"id\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"msg_example\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"message\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"assistant\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"model\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"claude-opus-5\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"text\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:' \"text\": \"Here are three search queries covering different angles of the topic:\\\\n\\\\n1. **\\\\\"grid-scale battery storage cost trends 2024 2025\\\\\"**\\\\n — Targets economics and recent price data for lithium-ion and other utility-scale systems.\\\\n\\\\n2. **\\\\\"long-duration energy storage technologies comparison flow battery vs compressed air vs thermal\\\\\"**\\\\n — Surfaces technical comparisons of options for storage beyond the 4–8 hour range, where lithium-ion becomes less cost-effective.\\\\n\\\\n3. **\\\\\"green hydrogen seasonal storage feasibility round-trip efficiency\\\\\"**\\\\n — Digs into the viability of hydrogen for multi-week or seasonal balancing, including its efficiency penalties.\\\\n\\\\n**A few tips for refining these:**\\\\n- Add `site:.gov` or `site:.edu` to prioritize research and agency reports (e.g., NREL, IEA, DOE).\\\\n- Append a region like `Europe`, `India`, or `California` if you need location-specific policy or deployment data.\\\\n- Try `filetype:pdf` to pull up technical white papers and government studies directly.\\\\n\\\\nWant me to tailor these toward a specific use case — academic research, investment analysis, or policy work?\"'})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ],`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"stop_reason\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"end_turn\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"stop_sequence\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`null`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"usage\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"input_tokens\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`23`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"cache_creation_input_tokens\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"cache_read_input_tokens\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"cache_creation\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"ephemeral_5m_input_tokens\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"ephemeral_1h_input_tokens\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"output_tokens\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`437`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"output_tokens_details\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"thinking_tokens\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`50`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`停止原因描述下一步操作。`,_jsx(_components.code,{children:`end_turn`}),` 表示回答已完成,\n`,_jsx(_components.code,{children:`max_tokens`}),` 表示输出已达到限制,而 `,_jsx(_components.code,{children:`tool_use`}),` 请求客户端工具\n结果。对于返回 `,_jsx(_components.code,{children:`pause_turn`}),` 的服务器工具轮次,请继续使用\n原样返回的 assistant 内容。`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"创建消息","sidebarTitle":"创建消息","openapi":"api/openapi/text/post-anthropic-messages.openapi.json POST /v1/messages","description":"通过 CometAPI Messages 端点调用 Claude,支持文本和图像输入、自适应思考、Prompt 缓存、流式输出和工具。","keywords":["CometAPI","Anthropic Messages API","POST /v1/messages","claude api","adaptive thinking","prompt caching","streaming sse","web fetch tool","effort control"],"noindex":true,"href":"/zh-Hans/api/text/anthropic-messages"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"快速开始","slug":"快速开始","depth":2,"children":[]},{"title":"控制自适应思考","slug":"控制自适应思考","depth":2,"children":[]},{"title":"缓存 Prompt","slug":"缓存-prompt","depth":2,"children":[]},{"title":"流式传输响应","slug":"流式传输响应","depth":2,"children":[]},{"title":"控制推理强度","slug":"控制推理强度","depth":2,"children":[]},{"title":"使用服务器工具","slug":"使用服务器工具","depth":2,"children":[]},{"title":"返回客户端工具结果","slug":"返回客户端工具结果","depth":2,"children":[]},{"title":"响应示例","slug":"响应示例","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":["/_mintlify/custom/cometapi/430a303ac1007180/analytics.js"],"openApiReferenceData":{"operation":{"summary":"Anthropic Messages","operationId":"anthropic_messages","description":"通过 CometAPI Messages 端点调用 Claude,支持文本和图像输入、自适应思考、Prompt 缓存、流式输出和工具。","parameters":["c0c1ea46-657f-4fbb-8cbc-ef036d66b820","c209249d-4c9e-4e35-be30-3090e0add122"],"requestBody":"b32a271f-ad00-4463-ab2f-e8041b1874ca","responses":{"200":"1032aebb-739d-48e8-8890-b9f6a600141a"},"x-codeSamples":[{"lang":"Python","label":"Basic","source":"import os\nimport anthropic\n\nclient = anthropic.Anthropic(\n base_url=\"https://api.cometapi.com\",\n api_key=os.environ[\"COMETAPI_KEY\"],\n)\n\nmessage = client.messages.create(\n model=\"claude-opus-5\",\n max_tokens=1000,\n messages=[\n {\n \"role\": \"user\",\n \"content\": \"Suggest three search queries about renewable energy storage.\",\n },\n ],\n)\n\nfor block in message.content:\n if block.type == \"text\":\n print(block.text)\n"},{"lang":"Python","label":"Prompt Cache","source":"import os\nfrom pathlib import Path\nimport anthropic\n\nclient = anthropic.Anthropic(\n base_url=\"https://api.cometapi.com\",\n api_key=os.environ[\"COMETAPI_KEY\"],\n)\n\nreference = Path(\"reference.txt\").read_text(encoding=\"utf-8\")\n\nwith client.messages.stream(\n model=\"claude-sonnet-5\",\n max_tokens=1024,\n messages=[\n {\n \"role\": \"user\",\n \"content\": \"How long can customers return damaged books, and what must they provide?\",\n },\n ],\n system=[\n {\n \"type\": \"text\",\n \"text\": reference,\n \"cache_control\": {\n \"type\": \"ephemeral\",\n },\n },\n ],\n) as stream:\n message = stream.get_final_message()\n\nfor block in message.content:\n if block.type == \"text\":\n print(block.text)\n\nprint(message.usage.model_dump_json())\n"},{"lang":"Python","label":"Adaptive thinking","source":"import os\nimport anthropic\n\nclient = anthropic.Anthropic(\n base_url=\"https://api.cometapi.com\",\n api_key=os.environ[\"COMETAPI_KEY\"],\n)\n\nwith client.messages.stream(\n model=\"claude-opus-5\",\n max_tokens=4096,\n messages=[\n {\n \"role\": \"user\",\n \"content\": \"A shop sells notebooks for $7 each. Buying three earns a $4 discount. A customer pays $20 for three notebooks. Calculate the total and the change, and explain your steps.\",\n },\n ],\n thinking={\n \"type\": \"adaptive\",\n },\n output_config={\n \"effort\": \"xhigh\",\n },\n) as stream:\n message = stream.get_final_message()\n\nfor block in message.content:\n if block.type == \"text\":\n print(block.text)\n"},{"lang":"Python","label":"Effort control","source":"import os\nimport anthropic\n\nclient = anthropic.Anthropic(\n base_url=\"https://api.cometapi.com\",\n api_key=os.environ[\"COMETAPI_KEY\"],\n)\n\nwith client.messages.stream(\n model=\"claude-opus-5\",\n max_tokens=1000,\n messages=[\n {\n \"role\": \"user\",\n \"content\": \"Summarize the benefit of automated tests in one sentence.\",\n },\n ],\n output_config={\n \"effort\": \"low\",\n },\n) as stream:\n message = stream.get_final_message()\n\nfor block in message.content:\n if block.type == \"text\":\n print(block.text)\n"},{"lang":"Python","label":"Streaming","source":"import os\nimport anthropic\n\nclient = anthropic.Anthropic(\n base_url=\"https://api.cometapi.com\",\n api_key=os.environ[\"COMETAPI_KEY\"],\n)\n\nwith client.messages.stream(\n model=\"claude-opus-5\",\n max_tokens=1024,\n messages=[\n {\n \"role\": \"user\",\n \"content\": \"Write a two-line poem about a comet.\",\n },\n ],\n) as stream:\n for text in stream.text_stream:\n print(text, end=\"\", flush=True)\n"},{"lang":"Python","label":"Web Fetch","source":"import os\nimport anthropic\n\nclient = anthropic.Anthropic(\n base_url=\"https://api.cometapi.com\",\n api_key=os.environ[\"COMETAPI_KEY\"],\n)\n\nwith client.messages.stream(\n model=\"claude-sonnet-5\",\n max_tokens=2048,\n messages=[\n {\n \"role\": \"user\",\n \"content\": \"Fetch https://arxiv.org/abs/1512.03385 and state the paper title and the proposed learning framework in two sentences.\",\n },\n ],\n tools=[\n {\n \"type\": \"web_fetch_20250910\",\n \"name\": \"web_fetch\",\n \"max_uses\": 3,\n },\n ],\n) as stream:\n message = stream.get_final_message()\n\nfor block in message.content:\n if block.type == \"text\":\n print(block.text)\n\nfor block in message.content:\n if block.type == \"web_fetch_tool_result\":\n print(block.model_dump_json())\n"},{"lang":"Python","label":"Image Input","source":"import os\nimport anthropic\n\nclient = anthropic.Anthropic(\n base_url=\"https://api.cometapi.com\",\n api_key=os.environ[\"COMETAPI_KEY\"],\n)\n\nwith client.messages.stream(\n model=\"claude-opus-5\",\n max_tokens=1000,\n messages=[\n {\n \"role\": \"user\",\n \"content\": [\n {\n \"type\": \"image\",\n \"source\": {\n \"type\": \"url\",\n \"url\": \"https://picsum.photos/seed/comet/800/600.jpg\",\n },\n },\n {\n \"type\": \"text\",\n \"text\": \"Describe the visible scene in one sentence.\",\n },\n ],\n },\n ],\n) as stream:\n message = stream.get_final_message()\n\nfor block in message.content:\n if block.type == \"text\":\n print(block.text)\n"},{"lang":"JavaScript","label":"Basic","source":"import Anthropic from \"@anthropic-ai/sdk\";\n\nconst client = new Anthropic({\n apiKey: process.env.COMETAPI_KEY,\n baseURL: \"https://api.cometapi.com\",\n});\n\nconst message = await client.messages.create({\n \"model\": \"claude-opus-5\",\n \"max_tokens\": 1000,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Suggest three search queries about renewable energy storage.\"\n }\n ]\n});\n\nfor (const block of message.content) {\n if (block.type === \"text\") console.log(block.text);\n}\n"},{"lang":"JavaScript","label":"Prompt Cache","source":"import Anthropic from \"@anthropic-ai/sdk\";\nimport fs from \"node:fs\";\n\nconst client = new Anthropic({\n apiKey: process.env.COMETAPI_KEY,\n baseURL: \"https://api.cometapi.com\",\n});\n\nconst reference = fs.readFileSync(\"reference.txt\", \"utf8\");\n\nconst stream = client.messages.stream({\n \"model\": \"claude-sonnet-5\",\n \"max_tokens\": 1024,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"How long can customers return damaged books, and what must they provide?\"\n }\n ],\n \"system\": [\n {\n \"type\": \"text\",\n \"text\": reference,\n \"cache_control\": {\n \"type\": \"ephemeral\"\n }\n }\n ]\n});\nconst message = await stream.finalMessage();\n\nfor (const block of message.content) {\n if (block.type === \"text\") console.log(block.text);\n}\n\nconsole.log(message.usage);\n"},{"lang":"JavaScript","label":"Adaptive thinking","source":"import Anthropic from \"@anthropic-ai/sdk\";\n\nconst client = new Anthropic({\n apiKey: process.env.COMETAPI_KEY,\n baseURL: \"https://api.cometapi.com\",\n});\n\nconst stream = client.messages.stream({\n \"model\": \"claude-opus-5\",\n \"max_tokens\": 4096,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"A shop sells notebooks for $7 each. Buying three earns a $4 discount. A customer pays $20 for three notebooks. Calculate the total and the change, and explain your steps.\"\n }\n ],\n \"thinking\": {\n \"type\": \"adaptive\"\n },\n \"output_config\": {\n \"effort\": \"xhigh\"\n }\n});\nconst message = await stream.finalMessage();\n\nfor (const block of message.content) {\n if (block.type === \"text\") console.log(block.text);\n}\n"},{"lang":"JavaScript","label":"Effort control","source":"import Anthropic from \"@anthropic-ai/sdk\";\n\nconst client = new Anthropic({\n apiKey: process.env.COMETAPI_KEY,\n baseURL: \"https://api.cometapi.com\",\n});\n\nconst stream = client.messages.stream({\n \"model\": \"claude-opus-5\",\n \"max_tokens\": 1000,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Summarize the benefit of automated tests in one sentence.\"\n }\n ],\n \"output_config\": {\n \"effort\": \"low\"\n }\n});\nconst message = await stream.finalMessage();\n\nfor (const block of message.content) {\n if (block.type === \"text\") console.log(block.text);\n}\n"},{"lang":"JavaScript","label":"Streaming","source":"import Anthropic from \"@anthropic-ai/sdk\";\n\nconst client = new Anthropic({\n apiKey: process.env.COMETAPI_KEY,\n baseURL: \"https://api.cometapi.com\",\n});\n\nconst stream = client.messages.stream({\n \"model\": \"claude-opus-5\",\n \"max_tokens\": 1024,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Write a two-line poem about a comet.\"\n }\n ]\n});\nstream.on(\"text\", (text) => process.stdout.write(text));\nawait stream.finalMessage();\n"},{"lang":"JavaScript","label":"Web Fetch","source":"import Anthropic from \"@anthropic-ai/sdk\";\n\nconst client = new Anthropic({\n apiKey: process.env.COMETAPI_KEY,\n baseURL: \"https://api.cometapi.com\",\n});\n\nconst stream = client.messages.stream({\n \"model\": \"claude-sonnet-5\",\n \"max_tokens\": 2048,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Fetch https://arxiv.org/abs/1512.03385 and state the paper title and the proposed learning framework in two sentences.\"\n }\n ],\n \"tools\": [\n {\n \"type\": \"web_fetch_20250910\",\n \"name\": \"web_fetch\",\n \"max_uses\": 3\n }\n ]\n});\nconst message = await stream.finalMessage();\n\nfor (const block of message.content) {\n if (block.type === \"text\") console.log(block.text);\n}\n\nfor (const block of message.content) {\n if (block.type === \"web_fetch_tool_result\") console.log(block);\n}\n"},{"lang":"JavaScript","label":"Image Input","source":"import Anthropic from \"@anthropic-ai/sdk\";\n\nconst client = new Anthropic({\n apiKey: process.env.COMETAPI_KEY,\n baseURL: \"https://api.cometapi.com\",\n});\n\nconst stream = client.messages.stream({\n \"model\": \"claude-opus-5\",\n \"max_tokens\": 1000,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": [\n {\n \"type\": \"image\",\n \"source\": {\n \"type\": \"url\",\n \"url\": \"https://picsum.photos/seed/comet/800/600.jpg\"\n }\n },\n {\n \"type\": \"text\",\n \"text\": \"Describe the visible scene in one sentence.\"\n }\n ]\n }\n ]\n});\nconst message = await stream.finalMessage();\n\nfor (const block of message.content) {\n if (block.type === \"text\") console.log(block.text);\n}\n"},{"lang":"Shell","label":"Basic","source":"curl \"https://api.cometapi.com/v1/messages\" \\\n -H \"Content-Type: application/json\" \\\n -H \"x-api-key: $COMETAPI_KEY\" \\\n -H \"anthropic-version: 2023-06-01\" \\\n -d '{\n \"model\": \"claude-opus-5\",\n \"max_tokens\": 1000,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Suggest three search queries about renewable energy storage.\"\n }\n ]\n}'\n"},{"lang":"Shell","label":"Prompt Cache","source":"request_body=$(jq -n --rawfile reference reference.txt '\n{\n \"model\": \"claude-sonnet-5\",\n \"max_tokens\": 1024,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"How long can customers return damaged books, and what must they provide?\"\n }\n ],\n \"system\": [\n {\n \"type\": \"text\",\n \"text\": $reference,\n \"cache_control\": {\n \"type\": \"ephemeral\"\n }\n }\n ],\n \"stream\": true\n}\n')\n\ncurl \"https://api.cometapi.com/v1/messages\" \\\n -H \"Content-Type: application/json\" \\\n -H \"x-api-key: $COMETAPI_KEY\" \\\n -H \"anthropic-version: 2023-06-01\" \\\n --no-buffer \\\n --data-binary \"$request_body\"\n"},{"lang":"Shell","label":"Adaptive thinking","source":"curl \"https://api.cometapi.com/v1/messages\" \\\n -H \"Content-Type: application/json\" \\\n -H \"x-api-key: $COMETAPI_KEY\" \\\n -H \"anthropic-version: 2023-06-01\" \\\n --no-buffer \\\n -d '{\n \"model\": \"claude-opus-5\",\n \"max_tokens\": 4096,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"A shop sells notebooks for $7 each. Buying three earns a $4 discount. A customer pays $20 for three notebooks. Calculate the total and the change, and explain your steps.\"\n }\n ],\n \"thinking\": {\n \"type\": \"adaptive\"\n },\n \"output_config\": {\n \"effort\": \"xhigh\"\n },\n \"stream\": true\n}'\n"},{"lang":"Shell","label":"Effort control","source":"curl \"https://api.cometapi.com/v1/messages\" \\\n -H \"Content-Type: application/json\" \\\n -H \"x-api-key: $COMETAPI_KEY\" \\\n -H \"anthropic-version: 2023-06-01\" \\\n --no-buffer \\\n -d '{\n \"model\": \"claude-opus-5\",\n \"max_tokens\": 1000,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Summarize the benefit of automated tests in one sentence.\"\n }\n ],\n \"output_config\": {\n \"effort\": \"low\"\n },\n \"stream\": true\n}'\n"},{"lang":"Shell","label":"Streaming","source":"curl \"https://api.cometapi.com/v1/messages\" \\\n -H \"Content-Type: application/json\" \\\n -H \"x-api-key: $COMETAPI_KEY\" \\\n -H \"anthropic-version: 2023-06-01\" \\\n --no-buffer \\\n -d '{\n \"model\": \"claude-opus-5\",\n \"max_tokens\": 1024,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Write a two-line poem about a comet.\"\n }\n ],\n \"stream\": true\n}'\n"},{"lang":"Shell","label":"Web Fetch","source":"curl \"https://api.cometapi.com/v1/messages\" \\\n -H \"Content-Type: application/json\" \\\n -H \"x-api-key: $COMETAPI_KEY\" \\\n -H \"anthropic-version: 2023-06-01\" \\\n --no-buffer \\\n -d '{\n \"model\": \"claude-sonnet-5\",\n \"max_tokens\": 2048,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Fetch https://arxiv.org/abs/1512.03385 and state the paper title and the proposed learning framework in two sentences.\"\n }\n ],\n \"tools\": [\n {\n \"type\": \"web_fetch_20250910\",\n \"name\": \"web_fetch\",\n \"max_uses\": 3\n }\n ],\n \"stream\": true\n}'\n"},{"lang":"Shell","label":"Image Input","source":"curl \"https://api.cometapi.com/v1/messages\" \\\n -H \"Content-Type: application/json\" \\\n -H \"x-api-key: $COMETAPI_KEY\" \\\n -H \"anthropic-version: 2023-06-01\" \\\n --no-buffer \\\n -d '{\n \"model\": \"claude-opus-5\",\n \"max_tokens\": 1000,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": [\n {\n \"type\": \"image\",\n \"source\": {\n \"type\": \"url\",\n \"url\": \"https://picsum.photos/seed/comet/800/600.jpg\"\n }\n },\n {\n \"type\": \"text\",\n \"text\": \"Describe the visible scene in one sentence.\"\n }\n ]\n }\n ],\n \"stream\": true\n}'\n"},{"lang":"Python","label":"Web Search","source":"import os\nimport anthropic\n\nclient = anthropic.Anthropic(\n base_url=\"https://api.cometapi.com\",\n api_key=os.environ[\"COMETAPI_KEY\"],\n)\n\nwith client.messages.stream(\n model=\"claude-sonnet-5\",\n max_tokens=4096,\n messages=[\n {\n \"role\": \"user\",\n \"content\": \"Search the web for the official Python 3.14 release date. Answer with the date and cite a source.\",\n },\n ],\n tools=[\n {\n \"type\": \"web_search_20250305\",\n \"name\": \"web_search\",\n \"max_uses\": 3,\n },\n ],\n) as stream:\n message = stream.get_final_message()\n\nfor block in message.content:\n if block.type == \"text\":\n print(block.text)\n\nfor block in message.content:\n if block.type == \"web_search_tool_result\":\n if isinstance(block.content, list):\n for result in block.content:\n if result.type == \"web_search_result\":\n print(result.title, result.url)\n"},{"lang":"JavaScript","label":"Web Search","source":"import Anthropic from \"@anthropic-ai/sdk\";\n\nconst client = new Anthropic({\n apiKey: process.env.COMETAPI_KEY,\n baseURL: \"https://api.cometapi.com\",\n});\n\nconst stream = client.messages.stream({\n \"model\": \"claude-sonnet-5\",\n \"max_tokens\": 4096,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Search the web for the official Python 3.14 release date. Answer with the date and cite a source.\"\n }\n ],\n \"tools\": [\n {\n \"type\": \"web_search_20250305\",\n \"name\": \"web_search\",\n \"max_uses\": 3\n }\n ]\n});\nconst message = await stream.finalMessage();\n\nfor (const block of message.content) {\n if (block.type === \"text\") console.log(block.text);\n if (block.type === \"web_search_tool_result\" \u0026\u0026 Array.isArray(block.content)) {\n for (const result of block.content) {\n if (result.type === \"web_search_result\") console.log(result.title, result.url);\n }\n }\n}\n"},{"lang":"Shell","label":"Web Search","source":"curl \"https://api.cometapi.com/v1/messages\" \\\n -H \"Content-Type: application/json\" \\\n -H \"x-api-key: $COMETAPI_KEY\" \\\n -H \"anthropic-version: 2023-06-01\" \\\n --no-buffer \\\n -d '{\n \"model\": \"claude-sonnet-5\",\n \"max_tokens\": 4096,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Search the web for the official Python 3.14 release date. Answer with the date and cite a source.\"\n }\n ],\n \"tools\": [\n {\n \"type\": \"web_search_20250305\",\n \"name\": \"web_search\",\n \"max_uses\": 3\n }\n ],\n \"stream\": true\n}'\n"}],"method":"post","type":"path","servers":["42ec33ae-30ca-46e9-8152-affa55393c1d"],"security":["ec2a85d8-bb88-476c-8d6e-56cae8457eeb"],"path":"/v1/messages","baseUrlOptions":["https://api.cometapi.com"],"title":"Anthropic Messages","codeSamples":[{"label":"Basic","lang":"Python","source":"import os\nimport anthropic\n\nclient = anthropic.Anthropic(\n base_url=\"https://api.cometapi.com\",\n api_key=os.environ[\"COMETAPI_KEY\"],\n)\n\nmessage = client.messages.create(\n model=\"claude-opus-5\",\n max_tokens=1000,\n messages=[\n {\n \"role\": \"user\",\n \"content\": \"Suggest three search queries about renewable energy storage.\",\n },\n ],\n)\n\nfor block in message.content:\n if block.type == \"text\":\n print(block.text)\n"},{"label":"Prompt Cache","lang":"Python","source":"import os\nfrom pathlib import Path\nimport anthropic\n\nclient = anthropic.Anthropic(\n base_url=\"https://api.cometapi.com\",\n api_key=os.environ[\"COMETAPI_KEY\"],\n)\n\nreference = Path(\"reference.txt\").read_text(encoding=\"utf-8\")\n\nwith client.messages.stream(\n model=\"claude-sonnet-5\",\n max_tokens=1024,\n messages=[\n {\n \"role\": \"user\",\n \"content\": \"How long can customers return damaged books, and what must they provide?\",\n },\n ],\n system=[\n {\n \"type\": \"text\",\n \"text\": reference,\n \"cache_control\": {\n \"type\": \"ephemeral\",\n },\n },\n ],\n) as stream:\n message = stream.get_final_message()\n\nfor block in message.content:\n if block.type == \"text\":\n print(block.text)\n\nprint(message.usage.model_dump_json())\n"},{"label":"Adaptive thinking","lang":"Python","source":"import os\nimport anthropic\n\nclient = anthropic.Anthropic(\n base_url=\"https://api.cometapi.com\",\n api_key=os.environ[\"COMETAPI_KEY\"],\n)\n\nwith client.messages.stream(\n model=\"claude-opus-5\",\n max_tokens=4096,\n messages=[\n {\n \"role\": \"user\",\n \"content\": \"A shop sells notebooks for $7 each. Buying three earns a $4 discount. A customer pays $20 for three notebooks. Calculate the total and the change, and explain your steps.\",\n },\n ],\n thinking={\n \"type\": \"adaptive\",\n },\n output_config={\n \"effort\": \"xhigh\",\n },\n) as stream:\n message = stream.get_final_message()\n\nfor block in message.content:\n if block.type == \"text\":\n print(block.text)\n"},{"label":"Effort control","lang":"Python","source":"import os\nimport anthropic\n\nclient = anthropic.Anthropic(\n base_url=\"https://api.cometapi.com\",\n api_key=os.environ[\"COMETAPI_KEY\"],\n)\n\nwith client.messages.stream(\n model=\"claude-opus-5\",\n max_tokens=1000,\n messages=[\n {\n \"role\": \"user\",\n \"content\": \"Summarize the benefit of automated tests in one sentence.\",\n },\n ],\n output_config={\n \"effort\": \"low\",\n },\n) as stream:\n message = stream.get_final_message()\n\nfor block in message.content:\n if block.type == \"text\":\n print(block.text)\n"},{"label":"Streaming","lang":"Python","source":"import os\nimport anthropic\n\nclient = anthropic.Anthropic(\n base_url=\"https://api.cometapi.com\",\n api_key=os.environ[\"COMETAPI_KEY\"],\n)\n\nwith client.messages.stream(\n model=\"claude-opus-5\",\n max_tokens=1024,\n messages=[\n {\n \"role\": \"user\",\n \"content\": \"Write a two-line poem about a comet.\",\n },\n ],\n) as stream:\n for text in stream.text_stream:\n print(text, end=\"\", flush=True)\n"},{"label":"Web Fetch","lang":"Python","source":"import os\nimport anthropic\n\nclient = anthropic.Anthropic(\n base_url=\"https://api.cometapi.com\",\n api_key=os.environ[\"COMETAPI_KEY\"],\n)\n\nwith client.messages.stream(\n model=\"claude-sonnet-5\",\n max_tokens=2048,\n messages=[\n {\n \"role\": \"user\",\n \"content\": \"Fetch https://arxiv.org/abs/1512.03385 and state the paper title and the proposed learning framework in two sentences.\",\n },\n ],\n tools=[\n {\n \"type\": \"web_fetch_20250910\",\n \"name\": \"web_fetch\",\n \"max_uses\": 3,\n },\n ],\n) as stream:\n message = stream.get_final_message()\n\nfor block in message.content:\n if block.type == \"text\":\n print(block.text)\n\nfor block in message.content:\n if block.type == \"web_fetch_tool_result\":\n print(block.model_dump_json())\n"},{"label":"Image Input","lang":"Python","source":"import os\nimport anthropic\n\nclient = anthropic.Anthropic(\n base_url=\"https://api.cometapi.com\",\n api_key=os.environ[\"COMETAPI_KEY\"],\n)\n\nwith client.messages.stream(\n model=\"claude-opus-5\",\n max_tokens=1000,\n messages=[\n {\n \"role\": \"user\",\n \"content\": [\n {\n \"type\": \"image\",\n \"source\": {\n \"type\": \"url\",\n \"url\": \"https://picsum.photos/seed/comet/800/600.jpg\",\n },\n },\n {\n \"type\": \"text\",\n \"text\": \"Describe the visible scene in one sentence.\",\n },\n ],\n },\n ],\n) as stream:\n message = stream.get_final_message()\n\nfor block in message.content:\n if block.type == \"text\":\n print(block.text)\n"},{"label":"Basic","lang":"JavaScript","source":"import Anthropic from \"@anthropic-ai/sdk\";\n\nconst client = new Anthropic({\n apiKey: process.env.COMETAPI_KEY,\n baseURL: \"https://api.cometapi.com\",\n});\n\nconst message = await client.messages.create({\n \"model\": \"claude-opus-5\",\n \"max_tokens\": 1000,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Suggest three search queries about renewable energy storage.\"\n }\n ]\n});\n\nfor (const block of message.content) {\n if (block.type === \"text\") console.log(block.text);\n}\n"},{"label":"Prompt Cache","lang":"JavaScript","source":"import Anthropic from \"@anthropic-ai/sdk\";\nimport fs from \"node:fs\";\n\nconst client = new Anthropic({\n apiKey: process.env.COMETAPI_KEY,\n baseURL: \"https://api.cometapi.com\",\n});\n\nconst reference = fs.readFileSync(\"reference.txt\", \"utf8\");\n\nconst stream = client.messages.stream({\n \"model\": \"claude-sonnet-5\",\n \"max_tokens\": 1024,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"How long can customers return damaged books, and what must they provide?\"\n }\n ],\n \"system\": [\n {\n \"type\": \"text\",\n \"text\": reference,\n \"cache_control\": {\n \"type\": \"ephemeral\"\n }\n }\n ]\n});\nconst message = await stream.finalMessage();\n\nfor (const block of message.content) {\n if (block.type === \"text\") console.log(block.text);\n}\n\nconsole.log(message.usage);\n"},{"label":"Adaptive thinking","lang":"JavaScript","source":"import Anthropic from \"@anthropic-ai/sdk\";\n\nconst client = new Anthropic({\n apiKey: process.env.COMETAPI_KEY,\n baseURL: \"https://api.cometapi.com\",\n});\n\nconst stream = client.messages.stream({\n \"model\": \"claude-opus-5\",\n \"max_tokens\": 4096,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"A shop sells notebooks for $7 each. Buying three earns a $4 discount. A customer pays $20 for three notebooks. Calculate the total and the change, and explain your steps.\"\n }\n ],\n \"thinking\": {\n \"type\": \"adaptive\"\n },\n \"output_config\": {\n \"effort\": \"xhigh\"\n }\n});\nconst message = await stream.finalMessage();\n\nfor (const block of message.content) {\n if (block.type === \"text\") console.log(block.text);\n}\n"},{"label":"Effort control","lang":"JavaScript","source":"import Anthropic from \"@anthropic-ai/sdk\";\n\nconst client = new Anthropic({\n apiKey: process.env.COMETAPI_KEY,\n baseURL: \"https://api.cometapi.com\",\n});\n\nconst stream = client.messages.stream({\n \"model\": \"claude-opus-5\",\n \"max_tokens\": 1000,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Summarize the benefit of automated tests in one sentence.\"\n }\n ],\n \"output_config\": {\n \"effort\": \"low\"\n }\n});\nconst message = await stream.finalMessage();\n\nfor (const block of message.content) {\n if (block.type === \"text\") console.log(block.text);\n}\n"},{"label":"Streaming","lang":"JavaScript","source":"import Anthropic from \"@anthropic-ai/sdk\";\n\nconst client = new Anthropic({\n apiKey: process.env.COMETAPI_KEY,\n baseURL: \"https://api.cometapi.com\",\n});\n\nconst stream = client.messages.stream({\n \"model\": \"claude-opus-5\",\n \"max_tokens\": 1024,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Write a two-line poem about a comet.\"\n }\n ]\n});\nstream.on(\"text\", (text) => process.stdout.write(text));\nawait stream.finalMessage();\n"},{"label":"Web Fetch","lang":"JavaScript","source":"import Anthropic from \"@anthropic-ai/sdk\";\n\nconst client = new Anthropic({\n apiKey: process.env.COMETAPI_KEY,\n baseURL: \"https://api.cometapi.com\",\n});\n\nconst stream = client.messages.stream({\n \"model\": \"claude-sonnet-5\",\n \"max_tokens\": 2048,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Fetch https://arxiv.org/abs/1512.03385 and state the paper title and the proposed learning framework in two sentences.\"\n }\n ],\n \"tools\": [\n {\n \"type\": \"web_fetch_20250910\",\n \"name\": \"web_fetch\",\n \"max_uses\": 3\n }\n ]\n});\nconst message = await stream.finalMessage();\n\nfor (const block of message.content) {\n if (block.type === \"text\") console.log(block.text);\n}\n\nfor (const block of message.content) {\n if (block.type === \"web_fetch_tool_result\") console.log(block);\n}\n"},{"label":"Image Input","lang":"JavaScript","source":"import Anthropic from \"@anthropic-ai/sdk\";\n\nconst client = new Anthropic({\n apiKey: process.env.COMETAPI_KEY,\n baseURL: \"https://api.cometapi.com\",\n});\n\nconst stream = client.messages.stream({\n \"model\": \"claude-opus-5\",\n \"max_tokens\": 1000,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": [\n {\n \"type\": \"image\",\n \"source\": {\n \"type\": \"url\",\n \"url\": \"https://picsum.photos/seed/comet/800/600.jpg\"\n }\n },\n {\n \"type\": \"text\",\n \"text\": \"Describe the visible scene in one sentence.\"\n }\n ]\n }\n ]\n});\nconst message = await stream.finalMessage();\n\nfor (const block of message.content) {\n if (block.type === \"text\") console.log(block.text);\n}\n"},{"label":"Basic","lang":"Shell","source":"curl \"https://api.cometapi.com/v1/messages\" \\\n -H \"Content-Type: application/json\" \\\n -H \"x-api-key: $COMETAPI_KEY\" \\\n -H \"anthropic-version: 2023-06-01\" \\\n -d '{\n \"model\": \"claude-opus-5\",\n \"max_tokens\": 1000,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Suggest three search queries about renewable energy storage.\"\n }\n ]\n}'\n"},{"label":"Prompt Cache","lang":"Shell","source":"request_body=$(jq -n --rawfile reference reference.txt '\n{\n \"model\": \"claude-sonnet-5\",\n \"max_tokens\": 1024,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"How long can customers return damaged books, and what must they provide?\"\n }\n ],\n \"system\": [\n {\n \"type\": \"text\",\n \"text\": $reference,\n \"cache_control\": {\n \"type\": \"ephemeral\"\n }\n }\n ],\n \"stream\": true\n}\n')\n\ncurl \"https://api.cometapi.com/v1/messages\" \\\n -H \"Content-Type: application/json\" \\\n -H \"x-api-key: $COMETAPI_KEY\" \\\n -H \"anthropic-version: 2023-06-01\" \\\n --no-buffer \\\n --data-binary \"$request_body\"\n"},{"label":"Adaptive thinking","lang":"Shell","source":"curl \"https://api.cometapi.com/v1/messages\" \\\n -H \"Content-Type: application/json\" \\\n -H \"x-api-key: $COMETAPI_KEY\" \\\n -H \"anthropic-version: 2023-06-01\" \\\n --no-buffer \\\n -d '{\n \"model\": \"claude-opus-5\",\n \"max_tokens\": 4096,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"A shop sells notebooks for $7 each. Buying three earns a $4 discount. A customer pays $20 for three notebooks. Calculate the total and the change, and explain your steps.\"\n }\n ],\n \"thinking\": {\n \"type\": \"adaptive\"\n },\n \"output_config\": {\n \"effort\": \"xhigh\"\n },\n \"stream\": true\n}'\n"},{"label":"Effort control","lang":"Shell","source":"curl \"https://api.cometapi.com/v1/messages\" \\\n -H \"Content-Type: application/json\" \\\n -H \"x-api-key: $COMETAPI_KEY\" \\\n -H \"anthropic-version: 2023-06-01\" \\\n --no-buffer \\\n -d '{\n \"model\": \"claude-opus-5\",\n \"max_tokens\": 1000,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Summarize the benefit of automated tests in one sentence.\"\n }\n ],\n \"output_config\": {\n \"effort\": \"low\"\n },\n \"stream\": true\n}'\n"},{"label":"Streaming","lang":"Shell","source":"curl \"https://api.cometapi.com/v1/messages\" \\\n -H \"Content-Type: application/json\" \\\n -H \"x-api-key: $COMETAPI_KEY\" \\\n -H \"anthropic-version: 2023-06-01\" \\\n --no-buffer \\\n -d '{\n \"model\": \"claude-opus-5\",\n \"max_tokens\": 1024,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Write a two-line poem about a comet.\"\n }\n ],\n \"stream\": true\n}'\n"},{"label":"Web Fetch","lang":"Shell","source":"curl \"https://api.cometapi.com/v1/messages\" \\\n -H \"Content-Type: application/json\" \\\n -H \"x-api-key: $COMETAPI_KEY\" \\\n -H \"anthropic-version: 2023-06-01\" \\\n --no-buffer \\\n -d '{\n \"model\": \"claude-sonnet-5\",\n \"max_tokens\": 2048,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Fetch https://arxiv.org/abs/1512.03385 and state the paper title and the proposed learning framework in two sentences.\"\n }\n ],\n \"tools\": [\n {\n \"type\": \"web_fetch_20250910\",\n \"name\": \"web_fetch\",\n \"max_uses\": 3\n }\n ],\n \"stream\": true\n}'\n"},{"label":"Image Input","lang":"Shell","source":"curl \"https://api.cometapi.com/v1/messages\" \\\n -H \"Content-Type: application/json\" \\\n -H \"x-api-key: $COMETAPI_KEY\" \\\n -H \"anthropic-version: 2023-06-01\" \\\n --no-buffer \\\n -d '{\n \"model\": \"claude-opus-5\",\n \"max_tokens\": 1000,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": [\n {\n \"type\": \"image\",\n \"source\": {\n \"type\": \"url\",\n \"url\": \"https://picsum.photos/seed/comet/800/600.jpg\"\n }\n },\n {\n \"type\": \"text\",\n \"text\": \"Describe the visible scene in one sentence.\"\n }\n ]\n }\n ],\n \"stream\": true\n}'\n"},{"label":"Web Search","lang":"Python","source":"import os\nimport anthropic\n\nclient = anthropic.Anthropic(\n base_url=\"https://api.cometapi.com\",\n api_key=os.environ[\"COMETAPI_KEY\"],\n)\n\nwith client.messages.stream(\n model=\"claude-sonnet-5\",\n max_tokens=4096,\n messages=[\n {\n \"role\": \"user\",\n \"content\": \"Search the web for the official Python 3.14 release date. Answer with the date and cite a source.\",\n },\n ],\n tools=[\n {\n \"type\": \"web_search_20250305\",\n \"name\": \"web_search\",\n \"max_uses\": 3,\n },\n ],\n) as stream:\n message = stream.get_final_message()\n\nfor block in message.content:\n if block.type == \"text\":\n print(block.text)\n\nfor block in message.content:\n if block.type == \"web_search_tool_result\":\n if isinstance(block.content, list):\n for result in block.content:\n if result.type == \"web_search_result\":\n print(result.title, result.url)\n"},{"label":"Web Search","lang":"JavaScript","source":"import Anthropic from \"@anthropic-ai/sdk\";\n\nconst client = new Anthropic({\n apiKey: process.env.COMETAPI_KEY,\n baseURL: \"https://api.cometapi.com\",\n});\n\nconst stream = client.messages.stream({\n \"model\": \"claude-sonnet-5\",\n \"max_tokens\": 4096,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Search the web for the official Python 3.14 release date. Answer with the date and cite a source.\"\n }\n ],\n \"tools\": [\n {\n \"type\": \"web_search_20250305\",\n \"name\": \"web_search\",\n \"max_uses\": 3\n }\n ]\n});\nconst message = await stream.finalMessage();\n\nfor (const block of message.content) {\n if (block.type === \"text\") console.log(block.text);\n if (block.type === \"web_search_tool_result\" \u0026\u0026 Array.isArray(block.content)) {\n for (const result of block.content) {\n if (result.type === \"web_search_result\") console.log(result.title, result.url);\n }\n }\n}\n"},{"label":"Web Search","lang":"Shell","source":"curl \"https://api.cometapi.com/v1/messages\" \\\n -H \"Content-Type: application/json\" \\\n -H \"x-api-key: $COMETAPI_KEY\" \\\n -H \"anthropic-version: 2023-06-01\" \\\n --no-buffer \\\n -d '{\n \"model\": \"claude-sonnet-5\",\n \"max_tokens\": 4096,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Search the web for the official Python 3.14 release date. Answer with the date and cite a source.\"\n }\n ],\n \"tools\": [\n {\n \"type\": \"web_search_20250305\",\n \"name\": \"web_search\",\n \"max_uses\": 3\n }\n ],\n \"stream\": true\n}'\n"}],"requiredOnlyExamples":true,"requestExampleType":"codeSamples","responseExampleType":"generated","prefillPlaygroundWithExample":true,"prefillPlaygroundExamples":[{"body.model":"claude-opus-5","body.messages.items.0.role":"user","body.messages.items.0.content.oneOf.0":"Suggest three search queries about renewable energy storage.","body.max_tokens":1000},{"body.model":"claude-opus-5","body.messages.items.0.role":"user","body.messages.items.0.content.oneOf.1.items.0.type":"image","body.messages.items.0.content.oneOf.1.items.0.source.type":"url","body.messages.items.0.content.oneOf.1.items.0.source.url":"https://picsum.photos/seed/comet/800/600.jpg","body.messages.items.0.content.oneOf.1.items.1.type":"text","body.messages.items.0.content.oneOf.1.items.1.text":"Describe the visible scene in one sentence.","body.max_tokens":1000,"body.stream":true},{"body.model":"claude-sonnet-5","body.messages.items.0.role":"user","body.messages.items.0.content.oneOf.0":"How long can customers return damaged books, and what must they provide?","body.max_tokens":1024,"body.system.oneOf.1.items.0.type":"text","body.system.oneOf.1.items.0.text":"Comet Books sample reference. The following policies describe a fictional bookstore.\n\nSection 1: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 2: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 3: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 4: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 5: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 6: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 7: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 8: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 9: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 10: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 11: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 12: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 13: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 14: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 15: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 16: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 17: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 18: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 19: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 20: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 21: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 22: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 23: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 24: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 25: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 26: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 27: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 28: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.","body.system.oneOf.1.items.0.cache_control.type":"ephemeral","body.stream":true},{"body.model":"claude-opus-5","body.messages.items.0.role":"user","body.messages.items.0.content.oneOf.0":"Write a two-line poem about a comet.","body.max_tokens":1024,"body.stream":true},{"body.model":"claude-sonnet-5","body.messages.items.0.role":"user","body.messages.items.0.content.oneOf.0":"Fetch https://arxiv.org/abs/1512.03385 and state the paper title and the proposed learning framework in two sentences.","body.max_tokens":2048,"body.stream":true,"body.tools.items.0.name":"web_fetch","body.tools.items.0.type":"web_fetch_20250910","body.tools.items.0.max_uses":3},{"body.model":"claude-opus-5","body.messages.items.0.role":"user","body.messages.items.0.content.oneOf.0":"A shop sells notebooks for $7 each. Buying three earns a $4 discount. A customer pays $20 for three notebooks. Calculate the total and the change, and explain your steps.","body.max_tokens":4096,"body.stream":true,"body.thinking.type":"adaptive","body.output_config.effort":"xhigh"},{"body.model":"claude-opus-5","body.messages.items.0.role":"user","body.messages.items.0.content.oneOf.0":"Summarize the benefit of automated tests in one sentence.","body.max_tokens":1000,"body.stream":true,"body.output_config.effort":"low"},{"body.model":"claude-sonnet-5","body.messages.items.0.role":"user","body.messages.items.0.content.oneOf.0":"Search the web for the official Python 3.14 release date. Answer with the date and cite a source.","body.max_tokens":4096,"body.stream":true,"body.tools.items.0.name":"web_search","body.tools.items.0.type":"web_search_20250305","body.tools.items.0.max_uses":3}]},"dependencies":{"parameters":{"c0c1ea46-657f-4fbb-8cbc-ef036d66b820":{"name":"anthropic-version","in":"header","required":false,"description":"The Anthropic API version to use. Defaults to `2023-06-01`.","schema":{"type":"string","default":"2023-06-01","example":"2023-06-01","isRequired":false,"description":"The Anthropic API version to use. Defaults to `2023-06-01`.","uniqueKey":"","typeLabel":"string"}},"c209249d-4c9e-4e35-be30-3090e0add122":{"name":"anthropic-beta","in":"header","required":false,"description":"Comma-separated feature identifiers required by a specific beta API feature. Omit this header for the examples on this page.","schema":{"type":"string","isRequired":false,"description":"Comma-separated feature identifiers required by a specific beta API feature. Omit this header for the examples on this page.","uniqueKey":"","typeLabel":"string"}}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["model","messages","max_tokens"],"properties":{"model":{"type":"string","description":"The Claude model to use. See the [Models page](/overview/models) for available Claude model IDs.","example":"claude-opus-5","default":"claude-opus-5","isRequired":true,"uniqueKey":"model","typeLabel":"string"},"messages":{"type":"array","description":"Conversation history. Use user and assistant messages with text strings or content-block arrays. Return complete assistant content blocks when continuing a tool call.","items":{"type":"object","required":["role","content"],"properties":{"role":{"type":"string","description":"The role of the message author.","enum":["user","assistant"],"isRequired":true,"uniqueKey":"messages.items.[INDEX].role","typeLabel":"enum\u003cstring>"},"content":{"oneOf":[{"type":"string","description":"The message content. Either a plain string or an array of content blocks for multimodal input.","isRequired":true,"uniqueKey":"messages.items.[INDEX].content.oneOf.0","typeLabel":"string"},{"type":"array","items":{"type":"object","properties":{"type":{"type":"string","description":"The content block type.","enum":["text","image","document","thinking","redacted_thinking","tool_use","tool_result","server_tool_use","web_fetch_tool_result","web_search_tool_result"],"uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].type","typeLabel":"enum\u003cstring>"},"text":{"type":"string","description":"Text content (for `text` type blocks).","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].text","typeLabel":"string"},"source":{"type":"object","description":"Source data for `image` or `document` blocks.","properties":{"type":{"type":"string","enum":["base64","url"],"description":"Image source type: `url` for a public image URL, or `base64` for inline data.","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].source.type","typeLabel":"enum\u003cstring>"},"media_type":{"type":"string","description":"Image MIME type for base64 sources, such as `image/jpeg` or `image/png`.","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].source.media_type","typeLabel":"string"},"data":{"type":"string","description":"Base64-encoded image bytes when `type` is `base64`.","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].source.data","typeLabel":"string"},"url":{"type":"string","description":"Public HTTPS URL for the image or document.","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].source.url","typeLabel":"string"}},"uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].source","typeLabel":"object"},"cache_control":{"type":"object","description":"Cache control for prompt caching. Set `{\"type\": \"ephemeral\"}` to cache this content block.","properties":{"type":{"type":"string","enum":["ephemeral"],"description":"Cache control type. Use `ephemeral`.","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].cache_control.type","typeLabel":"enum\u003cstring>"},"ttl":{"type":"string","enum":["5m","1h"],"description":"Cache lifetime. Use 5m for five minutes or 1h for one hour. The default is 5m.","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].cache_control.ttl","typeLabel":"enum\u003cstring>"}},"uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].cache_control","typeLabel":"object"},"id":{"type":"string","description":"The ID from a returned tool_use block. Preserve this value in assistant history.","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].id","typeLabel":"string"},"name":{"type":"string","description":"The function name in a tool_use block.","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].name","typeLabel":"string"},"input":{"type":"object","description":"Function arguments in a tool_use block.","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].input","typeLabel":"object"},"tool_use_id":{"type":"string","description":"The ID of the tool_use block answered by this tool_result.","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].tool_use_id","typeLabel":"string"},"content":{"oneOf":[{"type":"string","description":"Tool result content: a string, an array of content blocks, or a server-tool result or error object.","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].content.oneOf.0","typeLabel":"string"},{"type":"array","items":{"type":"object","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].content.oneOf.1.items.[INDEX]","typeLabel":"object"},"description":"Tool result content: a string, an array of content blocks, or a server-tool result or error object.","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].content.oneOf.1","typeLabel":"object[]"},{"type":"object","description":"Tool result content: a string, an array of content blocks, or a server-tool result or error object.","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].content.oneOf.2","typeLabel":"object"}],"uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].content","typeLabel":"string | object[] | object"},"is_error":{"type":"boolean","description":"Set true when a client tool_result reports a failed tool execution.","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].is_error","typeLabel":"boolean"},"thinking":{"type":"string","description":"Thinking content returned in an assistant block. Preserve it unchanged in conversation history.","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].thinking","typeLabel":"string"},"signature":{"type":"string","description":"Thinking signature returned by the API. Preserve it unchanged with its thinking block.","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].signature","typeLabel":"string"}},"uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX]","typeLabel":"object"},"description":"The message content. Either a plain string or an array of content blocks for multimodal input.","isRequired":true,"uniqueKey":"messages.items.[INDEX].content.oneOf.1","typeLabel":"object[]"}],"isRequired":true,"uniqueKey":"messages.items.[INDEX].content","typeLabel":"string | object[]"}},"uniqueKey":"messages.items.[INDEX]","typeLabel":"object"},"isRequired":true,"uniqueKey":"messages","typeLabel":"object[]"},"max_tokens":{"type":"integer","description":"The maximum number of tokens to generate. The model may stop before reaching this limit. When using `thinking`, the thinking tokens count towards this limit.","minimum":1,"example":1024,"isRequired":true,"uniqueKey":"max_tokens","typeLabel":"integer"},"system":{"oneOf":[{"type":"string","description":"System prompt providing context and instructions to Claude. Can be a plain string or an array of content blocks (useful for prompt caching).","uniqueKey":"system.oneOf.0","typeLabel":"string"},{"type":"array","items":{"type":"object","properties":{"type":{"type":"string","enum":["text"],"description":"Content block type, `text`.","uniqueKey":"system.oneOf.1.items.[INDEX].type","typeLabel":"enum\u003cstring>"},"text":{"type":"string","description":"System prompt text for this block.","uniqueKey":"system.oneOf.1.items.[INDEX].text","typeLabel":"string"},"cache_control":{"type":"object","properties":{"type":{"type":"string","enum":["ephemeral"],"description":"Cache control type. Use `ephemeral`.","uniqueKey":"system.oneOf.1.items.[INDEX].cache_control.type","typeLabel":"enum\u003cstring>"},"ttl":{"type":"string","enum":["5m","1h"],"description":"Cache lifetime. Use 5m for five minutes or 1h for one hour. The default is 5m.","uniqueKey":"system.oneOf.1.items.[INDEX].cache_control.ttl","typeLabel":"enum\u003cstring>"}},"description":"Marks this system block as a prompt-cache breakpoint.","uniqueKey":"system.oneOf.1.items.[INDEX].cache_control","typeLabel":"object"}},"uniqueKey":"system.oneOf.1.items.[INDEX]","typeLabel":"object"},"description":"System prompt providing context and instructions to Claude. Can be a plain string or an array of content blocks (useful for prompt caching).","uniqueKey":"system.oneOf.1","typeLabel":"object[]"}],"uniqueKey":"system","typeLabel":"string | object[]"},"temperature":{"type":"number","description":"Sampling temperature. The examples omit sampling overrides.","minimum":0,"maximum":1,"uniqueKey":"temperature","typeLabel":"number"},"top_p":{"type":"number","description":"Nucleus sampling threshold. The examples omit sampling overrides.","minimum":0,"maximum":1,"uniqueKey":"top_p","typeLabel":"number"},"top_k":{"type":"integer","description":"Limits sampling to the k most likely tokens. The examples omit sampling overrides.","minimum":0,"uniqueKey":"top_k","typeLabel":"integer"},"stream":{"type":"boolean","description":"If `true`, stream the response incrementally using Server-Sent Events (SSE). Events include `message_start`, `content_block_start`, `content_block_delta`, `content_block_stop`, `message_delta`, and `message_stop`.","default":false,"uniqueKey":"stream","typeLabel":"boolean"},"stop_sequences":{"type":"array","description":"Custom strings that cause the model to stop generating when encountered. The stop sequence is not included in the response.","items":{"type":"string","uniqueKey":"stop_sequences.items.[INDEX]","typeLabel":"string"},"uniqueKey":"stop_sequences","typeLabel":"string[]"},"thinking":{"type":"object","description":"Thinking configuration. The adaptive example uses type adaptive and sets output_config.effort separately.","properties":{"type":{"type":"string","description":"Thinking mode. Use adaptive for the example on this page. Other values depend on the selected model.","enum":["adaptive","disabled","enabled"],"uniqueKey":"thinking.type","typeLabel":"enum\u003cstring>"},"budget_tokens":{"type":"integer","description":"Token budget for models that support manual thinking with type enabled. Omit this field when using type adaptive.","minimum":1024,"uniqueKey":"thinking.budget_tokens","typeLabel":"integer"},"display":{"type":"string","description":"Controls visible thinking blocks on models that support display selection. `summarized` returns a readable thinking summary; `omitted` returns an empty thinking field with continuity metadata where applicable.","enum":["summarized","omitted"],"uniqueKey":"thinking.display","typeLabel":"enum\u003cstring>"}},"uniqueKey":"thinking","typeLabel":"object"},"tools":{"type":"array","description":"Client tools define a name and input_schema. Server tools use a versioned type and name, such as the web_fetch and web_search examples on this page.","items":{"type":"object","properties":{"name":{"type":"string","description":"Tool name. The model repeats it in `tool_use` blocks when it calls the tool.","uniqueKey":"tools.items.[INDEX].name","typeLabel":"string"},"description":{"type":"string","description":"A description of what the tool does.","uniqueKey":"tools.items.[INDEX].description","typeLabel":"string"},"input_schema":{"type":"object","description":"JSON Schema defining the tool's input parameters.","uniqueKey":"tools.items.[INDEX].input_schema","typeLabel":"object"},"type":{"type":"string","description":"Versioned server tool type. The basic examples use web_fetch_20250910 and web_search_20250305.","uniqueKey":"tools.items.[INDEX].type","typeLabel":"string"},"max_uses":{"type":"integer","description":"Maximum uses of this server tool within one request.","uniqueKey":"tools.items.[INDEX].max_uses","typeLabel":"integer"}},"uniqueKey":"tools.items.[INDEX]","typeLabel":"object"},"uniqueKey":"tools","typeLabel":"object[]"},"tool_choice":{"type":"object","description":"Controls how the model uses tools.","properties":{"type":{"type":"string","description":"The tool choice mode: `auto` (model decides), `any` (must use a tool), `tool` (must use a specific tool), or `none` (no tools).","enum":["auto","any","tool","none"],"uniqueKey":"tool_choice.type","typeLabel":"enum\u003cstring>"},"name":{"type":"string","description":"The specific tool name to use. Required when `type` is `tool`.","uniqueKey":"tool_choice.name","typeLabel":"string"},"disable_parallel_tool_use":{"type":"boolean","description":"If `true`, prevent the model from calling multiple tools in parallel.","uniqueKey":"tool_choice.disable_parallel_tool_use","typeLabel":"boolean"}},"uniqueKey":"tool_choice","typeLabel":"object"},"metadata":{"type":"object","description":"Request metadata for tracking and analytics.","properties":{"user_id":{"type":"string","description":"An external identifier for the user making the request. Used for abuse detection.","uniqueKey":"metadata.user_id","typeLabel":"string"}},"uniqueKey":"metadata","typeLabel":"object"},"output_config":{"type":"object","description":"Configuration for reasoning effort and structured output.","properties":{"effort":{"type":"string","description":"Reasoning effort. The examples use low for a brief answer and xhigh with adaptive thinking.","enum":["low","medium","high","xhigh","max"],"example":"medium","uniqueKey":"output_config.effort","typeLabel":"enum\u003cstring>"},"format":{"type":"object","description":"Structured output configuration for supported models. See the [structured outputs documentation](https://platform.claude.com/docs/en/build-with-claude/structured-outputs) for schema requirements.","required":["type","schema"],"properties":{"type":{"type":"string","enum":["json_schema"],"description":"Set json_schema to request output matching the supplied schema.","isRequired":true,"uniqueKey":"output_config.format.type","typeLabel":"enum\u003cstring>"},"schema":{"type":"object","description":"JSON Schema that describes the requested output.","isRequired":true,"uniqueKey":"output_config.format.schema","typeLabel":"object"}},"uniqueKey":"output_config.format","typeLabel":"object"}},"uniqueKey":"output_config","typeLabel":"object"},"service_tier":{"type":"string","description":"The service tier to use. `auto` tries priority capacity first, `standard_only` uses only standard capacity.","enum":["auto","standard_only"],"uniqueKey":"service_tier","typeLabel":"enum\u003cstring>"}},"uniqueKey":"","typeLabel":"object"},"examples":{"Default":{"title":"Default","summary":"Basic message","value":{"model":"claude-opus-5","max_tokens":1000,"messages":[{"role":"user","content":"Suggest three search queries about renewable energy storage."}]}},"Image Input":{"title":"Image Input","summary":"Image Input","value":{"model":"claude-opus-5","max_tokens":1000,"messages":[{"role":"user","content":[{"type":"image","source":{"type":"url","url":"https://picsum.photos/seed/comet/800/600.jpg"}},{"type":"text","text":"Describe the visible scene in one sentence."}]}],"stream":true}},"Prompt Cache":{"title":"Prompt Cache","summary":"With prompt caching","description":"The code samples read this reference material from a local UTF-8 reference.txt file. Keep the cached prefix unchanged when repeating the request.","value":{"model":"claude-sonnet-5","max_tokens":1024,"messages":[{"role":"user","content":"How long can customers return damaged books, and what must they provide?"}],"system":[{"type":"text","text":"Comet Books sample reference. The following policies describe a fictional bookstore.\n\nSection 1: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 2: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 3: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 4: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 5: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 6: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 7: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 8: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 9: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 10: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 11: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 12: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 13: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 14: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 15: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 16: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 17: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 18: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 19: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 20: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 21: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 22: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 23: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 24: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 25: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 26: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 27: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.\nSection 28: Damaged books may be returned within 30 days. A receipt is required. Unopened stationery may be exchanged within 14 days. Digital downloads are final. Staff record the order reference and explain the return steps clearly.","cache_control":{"type":"ephemeral"}}],"stream":true}},"Streaming":{"title":"Streaming","summary":"Streaming response","value":{"model":"claude-opus-5","max_tokens":1024,"messages":[{"role":"user","content":"Write a two-line poem about a comet."}],"stream":true}},"Web Fetch":{"title":"Web Fetch","summary":"With web fetch tool","value":{"model":"claude-sonnet-5","max_tokens":2048,"messages":[{"role":"user","content":"Fetch https://arxiv.org/abs/1512.03385 and state the paper title and the proposed learning framework in two sentences."}],"tools":[{"type":"web_fetch_20250910","name":"web_fetch","max_uses":3}],"stream":true}},"Adaptive Thinking":{"title":"Adaptive Thinking","summary":"With adaptive thinking and effort","value":{"model":"claude-opus-5","max_tokens":4096,"messages":[{"role":"user","content":"A shop sells notebooks for $7 each. Buying three earns a $4 discount. A customer pays $20 for three notebooks. Calculate the total and the change, and explain your steps."}],"thinking":{"type":"adaptive"},"output_config":{"effort":"xhigh"},"stream":true}},"Effort control":{"title":"Effort control","summary":"Stream a concise response with low effort","value":{"model":"claude-opus-5","max_tokens":1000,"messages":[{"role":"user","content":"Summarize the benefit of automated tests in one sentence."}],"output_config":{"effort":"low"},"stream":true}},"Web Search":{"title":"Web Search","summary":"Web Search","value":{"model":"claude-sonnet-5","max_tokens":4096,"messages":[{"role":"user","content":"Search the web for the official Python 3.14 release date. Answer with the date and cite a source."}],"tools":[{"type":"web_search_20250305","name":"web_search","max_uses":3}],"stream":true}}},"exampleType":"examples"}},"exampleType":"examples"},"responses":{"1032aebb-739d-48e8-8890-b9f6a600141a":{"description":"Successful response. When `stream` is `true`, the response is a stream of SSE events.","content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string","description":"Message identifier returned by the API.","uniqueKey":"id","typeLabel":"string"},"type":{"type":"string","description":"Always `message`.","enum":["message"],"uniqueKey":"type","typeLabel":"enum\u003cstring>"},"role":{"type":"string","description":"Always `assistant`.","enum":["assistant"],"uniqueKey":"role","typeLabel":"enum\u003cstring>"},"content":{"type":"array","description":"The response content blocks. May include `text`, `thinking`, `tool_use`, and other block types.","items":{"type":"object","properties":{"type":{"type":"string","description":"Content block type, such as text, thinking, tool_use, server_tool_use, web_fetch_tool_result, or web_search_tool_result.","uniqueKey":"content.items.[INDEX].type","typeLabel":"string"},"text":{"type":"string","description":"The generated text (for `text` blocks).","uniqueKey":"content.items.[INDEX].text","typeLabel":"string"},"thinking":{"type":"string","description":"Thinking text or summary for `thinking` blocks when the selected model returns visible thinking content.","uniqueKey":"content.items.[INDEX].thinking","typeLabel":"string"},"signature":{"type":"string","description":"Cryptographic signature for the thinking block.","uniqueKey":"content.items.[INDEX].signature","typeLabel":"string"},"id":{"type":"string","description":"Tool use ID (for `tool_use` blocks).","uniqueKey":"content.items.[INDEX].id","typeLabel":"string"},"name":{"type":"string","description":"Tool name (for `tool_use` blocks).","uniqueKey":"content.items.[INDEX].name","typeLabel":"string"},"input":{"type":"object","description":"Tool input arguments (for `tool_use` blocks).","uniqueKey":"content.items.[INDEX].input","typeLabel":"object"},"tool_use_id":{"type":"string","description":"The server tool call answered by this result block.","uniqueKey":"content.items.[INDEX].tool_use_id","typeLabel":"string"},"content":{"oneOf":[{"type":"object","description":"Server tool results or an error object. Inspect the block type before reading its fields.","uniqueKey":"content.items.[INDEX].content.oneOf.0","typeLabel":"object"},{"type":"array","items":{"type":"object","uniqueKey":"content.items.[INDEX].content.oneOf.1.items.[INDEX]","typeLabel":"object"},"description":"Server tool results or an error object. Inspect the block type before reading its fields.","uniqueKey":"content.items.[INDEX].content.oneOf.1","typeLabel":"object[]"}],"uniqueKey":"content.items.[INDEX].content","typeLabel":"object | object[]"},"citations":{"type":"array","description":"Source citations attached to a text block when returned.","items":{"type":"object","uniqueKey":"content.items.[INDEX].citations.items.[INDEX]","typeLabel":"object"},"uniqueKey":"content.items.[INDEX].citations","typeLabel":"object[]"}},"uniqueKey":"content.items.[INDEX]","typeLabel":"object"},"uniqueKey":"content","typeLabel":"object[]"},"model":{"type":"string","description":"Model ID reported by the response.","uniqueKey":"model","typeLabel":"string"},"stop_reason":{"type":"string","description":"Why the model stopped generating. `refusal` can be returned as a successful HTTP response when the model declines a request.","enum":["end_turn","max_tokens","stop_sequence","tool_use","pause_turn","refusal"],"uniqueKey":"stop_reason","typeLabel":"enum\u003cstring>"},"stop_sequence":{"oneOf":[{"type":"string","description":"The stop sequence that caused the model to stop, if applicable.","uniqueKey":"stop_sequence.oneOf.0","typeLabel":"string"},{"type":"null","description":"The stop sequence that caused the model to stop, if applicable.","uniqueKey":"stop_sequence.oneOf.1","typeLabel":"null"}],"uniqueKey":"stop_sequence","typeLabel":"string | null"},"usage":{"type":"object","description":"Token usage statistics.","properties":{"input_tokens":{"type":"integer","description":"Uncached input tokens processed for the request. Cache creation and cache reads have separate counters.","uniqueKey":"usage.input_tokens","typeLabel":"integer"},"output_tokens":{"type":"integer","description":"Total output tokens, including thinking when the model uses thinking.","uniqueKey":"usage.output_tokens","typeLabel":"integer"},"cache_creation_input_tokens":{"type":"integer","description":"Number of input tokens used to create the prompt cache.","uniqueKey":"usage.cache_creation_input_tokens","typeLabel":"integer"},"cache_read_input_tokens":{"type":"integer","description":"Number of input tokens read from the prompt cache.","uniqueKey":"usage.cache_read_input_tokens","typeLabel":"integer"},"cache_creation":{"type":"object","description":"Detailed cache creation token breakdown by TTL tier.","properties":{"ephemeral_5m_input_tokens":{"type":"integer","description":"Tokens written to 5-minute ephemeral cache.","uniqueKey":"usage.cache_creation.ephemeral_5m_input_tokens","typeLabel":"integer"},"ephemeral_1h_input_tokens":{"type":"integer","description":"Tokens written to 1-hour ephemeral cache.","uniqueKey":"usage.cache_creation.ephemeral_1h_input_tokens","typeLabel":"integer"}},"uniqueKey":"usage.cache_creation","typeLabel":"object"},"output_tokens_details":{"type":"object","description":"Detailed output token breakdown when returned by the selected model.","properties":{"thinking_tokens":{"type":"integer","description":"Number of output tokens used for model thinking when reported.","uniqueKey":"usage.output_tokens_details.thinking_tokens","typeLabel":"integer"}},"uniqueKey":"usage.output_tokens_details","typeLabel":"object"},"server_tool_use":{"type":"object","description":"Server tool request counts when server tools are used.","properties":{"web_fetch_requests":{"type":"integer","description":"Number of web fetch requests.","uniqueKey":"usage.server_tool_use.web_fetch_requests","typeLabel":"integer"},"web_search_requests":{"type":"integer","description":"Number of web search requests.","uniqueKey":"usage.server_tool_use.web_search_requests","typeLabel":"integer"}},"uniqueKey":"usage.server_tool_use","typeLabel":"object"}},"uniqueKey":"usage","typeLabel":"object"}},"example":{"id":"msg_example","type":"message","role":"assistant","model":"claude-opus-5","content":[{"type":"text","text":"Here are three search queries covering different angles of the topic:\n\n1. **\"grid-scale battery storage cost trends 2024 2025\"**\n — Targets economics and recent price data for lithium-ion and other utility-scale systems.\n\n2. **\"long-duration energy storage technologies comparison flow battery vs compressed air vs thermal\"**\n — Surfaces technical comparisons of options for storage beyond the 4–8 hour range, where lithium-ion becomes less cost-effective.\n\n3. **\"green hydrogen seasonal storage feasibility round-trip efficiency\"**\n — Digs into the viability of hydrogen for multi-week or seasonal balancing, including its efficiency penalties.\n\n**A few tips for refining these:**\n- Add `site:.gov` or `site:.edu` to prioritize research and agency reports (e.g., NREL, IEA, DOE).\n- Append a region like `Europe`, `India`, or `California` if you need location-specific policy or deployment data.\n- Try `filetype:pdf` to pull up technical white papers and government studies directly.\n\nWant me to tailor these toward a specific use case — academic research, investment analysis, or policy work?"}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":23,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":437,"output_tokens_details":{"thinking_tokens":50}}},"uniqueKey":"","typeLabel":"object"},"example":{"id":"msg_example","type":"message","role":"assistant","model":"claude-opus-5","content":[{"type":"text","text":"Here are three search queries covering different angles of the topic:\n\n1. **\"grid-scale battery storage cost trends 2024 2025\"**\n — Targets economics and recent price data for lithium-ion and other utility-scale systems.\n\n2. **\"long-duration energy storage technologies comparison flow battery vs compressed air vs thermal\"**\n — Surfaces technical comparisons of options for storage beyond the 4–8 hour range, where lithium-ion becomes less cost-effective.\n\n3. **\"green hydrogen seasonal storage feasibility round-trip efficiency\"**\n — Digs into the viability of hydrogen for multi-week or seasonal balancing, including its efficiency penalties.\n\n**A few tips for refining these:**\n- Add `site:.gov` or `site:.edu` to prioritize research and agency reports (e.g., NREL, IEA, DOE).\n- Append a region like `Europe`, `India`, or `California` if you need location-specific policy or deployment data.\n- Try `filetype:pdf` to pull up technical white papers and government studies directly.\n\nWant me to tailor these toward a specific use case — academic research, investment analysis, or policy work?"}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":23,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":437,"output_tokens_details":{"thinking_tokens":50}}},"examples":{"Example":{"title":"Example","value":{"id":"msg_example","type":"message","role":"assistant","model":"claude-opus-5","content":[{"type":"text","text":"Here are three search queries covering different angles of the topic:\n\n1. **\"grid-scale battery storage cost trends 2024 2025\"**\n — Targets economics and recent price data for lithium-ion and other utility-scale systems.\n\n2. **\"long-duration energy storage technologies comparison flow battery vs compressed air vs thermal\"**\n — Surfaces technical comparisons of options for storage beyond the 4–8 hour range, where lithium-ion becomes less cost-effective.\n\n3. **\"green hydrogen seasonal storage feasibility round-trip efficiency\"**\n — Digs into the viability of hydrogen for multi-week or seasonal balancing, including its efficiency penalties.\n\n**A few tips for refining these:**\n- Add `site:.gov` or `site:.edu` to prioritize research and agency reports (e.g., NREL, IEA, DOE).\n- Append a region like `Europe`, `India`, or `California` if you need location-specific policy or deployment data.\n- Try `filetype:pdf` to pull up technical white papers and government studies directly.\n\nWant me to tailor these toward a specific use case — academic research, investment analysis, or policy work?"}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":23,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":437,"output_tokens_details":{"thinking_tokens":50}}}}},"exampleType":"examples"},"text/event-stream":{"schema":{"type":"string","description":"Anthropic SSE events. A completed message ends with message_stop; text_delta events contain text fragments.","uniqueKey":"","typeLabel":"string"},"examples":{"Example":{"title":"Example","value":"\u003cstring>"}},"exampleType":"generated"}},"exampleType":"examples"}},"security":{"ec2a85d8-bb88-476c-8d6e-56cae8457eeb":{"apiKeyAuth":{"type":"apiKey","in":"header","name":"x-api-key","description":"Your CometAPI key passed via the `x-api-key` header. `Authorization: Bearer $COMETAPI_KEY` is also supported.","scopes":[]}}},"servers":{"42ec33ae-30ca-46e9-8152-affa55393c1d":{"url":"https://api.cometapi.com"}},"processedSecurityOptions":[{"schemes":[{"scheme":{"type":"apiKey","in":"header","name":"x-api-key","description":"Your CometAPI key passed via the `x-api-key` header. `Authorization: Bearer $COMETAPI_KEY` is also supported.","scopes":[]},"schema":{"title":"x-api-key","type":"string","description":"Your CometAPI key passed via the `x-api-key` header. `Authorization: Bearer $COMETAPI_KEY` is also supported.","isRequired":true,"typeLabel":"string","deprecated":false},"schemeName":"apiKeyAuth","name":"x-api-key"}],"title":"apiKeyAuth"}]},"originalFileLocation":"api/openapi/text/post-anthropic-messages.openapi.json"},"subdomain":"cometapi","siteName":"CometAPI Documentation","title":"创建消息 - CometAPI Documentation","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{"en":{"href":"/api/text/anthropic-messages","matchLevel":1},"zh-Hans":{"href":"/zh-Hans/api/text/anthropic-messages","matchLevel":0},"zh-Hant":{"href":"/zh-Hant/api/text/anthropic-messages","matchLevel":1,"noindex":true},"ja":{"href":"/ja/api/text/anthropic-messages","matchLevel":1,"noindex":true},"ko":{"href":"/ko/api/text/anthropic-messages","matchLevel":1,"noindex":true},"fr":{"href":"/fr/api/text/anthropic-messages","matchLevel":1,"noindex":true},"de":{"href":"/de/api/text/anthropic-messages","matchLevel":1,"noindex":true},"es":{"href":"/es/api/text/anthropic-messages","matchLevel":1,"noindex":true},"it":{"href":"/it/api/text/anthropic-messages","matchLevel":1,"noindex":true},"pt":{"href":"/pt/api/text/anthropic-messages","matchLevel":1,"noindex":true},"ru":{"href":"/ru/api/text/anthropic-messages","matchLevel":1,"noindex":true},"ar":{"href":"/ar/api/text/anthropic-messages","matchLevel":1,"noindex":true},"vi":{"href":"/vi/api/text/anthropic-messages","matchLevel":1,"noindex":true},"id":{"href":"/id/api/text/anthropic-messages","matchLevel":1,"noindex":true},"tr":{"href":"/tr/api/text/anthropic-messages","matchLevel":1,"noindex":true},"pl":{"href":"/pl/api/text/anthropic-messages","matchLevel":1,"noindex":true},"nl":{"href":"/nl/api/text/anthropic-messages","matchLevel":1,"noindex":true},"no":{"href":"/no/api/text/anthropic-messages","matchLevel":1,"noindex":true},"uk":{"href":"/uk/api/text/anthropic-messages","matchLevel":1,"noindex":true}}},"lastModified":"2026-09-08T03:43:41.703Z","gitLastModified":"2026-09-08T02:59:59.000Z","originalFileLocation":"zh-Hans/api/text/anthropic-messages.mdx","locale":"zh-Hans"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"通过 CometAPI Messages 端点调用 Claude,支持文本和图像输入、自适应思考、Prompt 缓存、流式输出和工具。\">\u003cmeta data-mint-head name=\"application-name\" content=\"CometAPI Documentation\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003cmeta data-mint-head name=\"robots\" content=\"noindex\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/cometapi/Jhcr00uAqm6Ci9Vs/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/cometapi/Jhcr00uAqm6Ci9Vs/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/cometapi/Jhcr00uAqm6Ci9Vs/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/cometapi/Jhcr00uAqm6Ci9Vs/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/cometapi/Jhcr00uAqm6Ci9Vs/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/cometapi/Jhcr00uAqm6Ci9Vs/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/cometapi/Jhcr00uAqm6Ci9Vs/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/cometapi/Jhcr00uAqm6Ci9Vs/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/cometapi/Jhcr00uAqm6Ci9Vs/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"创建消息 - CometAPI Documentation\">\u003cmeta data-mint-head property=\"og:description\" content=\"通过 CometAPI Messages 端点调用 Claude,支持文本和图像输入、自适应思考、Prompt 缓存、流式输出和工具。\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"CometAPI Docs\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://apidoc.cometapi.com/zh-Hans/api/text/anthropic-messages\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://cometapi.mintlify.site/_mintlify/api/og/v2?division=%E6%96%87%E6%9C%AC%E6%A8%A1%E5%9E%8B\u0026amp;title=%E5%88%9B%E5%BB%BA%E6%B6%88%E6%81%AF\u0026amp;description=%E9%80%9A%E8%BF%87+CometAPI+Messages+%E7%AB%AF%E7%82%B9%E8%B0%83%E7%94%A8+Claude%EF%BC%8C%E6%94%AF%E6%8C%81%E6%96%87%E6%9C%AC%E5%92%8C%E5%9B%BE%E5%83%8F%E8%BE%93%E5%85%A5%E3%80%81%E8%87%AA%E9%80%82%E5%BA%94%E6%80%9D%E8%80%83%E3%80%81Prompt+%E7%BC%93%E5%AD%98%E3%80%81%E6%B5%81%E5%BC%8F%E8%BE%93%E5%87%BA%E5%92%8C%E5%B7%A5%E5%85%B7%E3%80%82\u0026amp;theme=d910b0d04a2d93f2b29ac00c\u0026amp;signature=efa90f47a7ad36969258bc5e7b6feac006593329afe46935a376f7a7edb0d2ae\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"创建消息 - CometAPI Documentation\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"通过 CometAPI Messages 端点调用 Claude,支持文本和图像输入、自适应思考、Prompt 缓存、流式输出和工具。\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://cometapi.mintlify.site/_mintlify/api/og/v2?division=%E6%96%87%E6%9C%AC%E6%A8%A1%E5%9E%8B\u0026amp;title=%E5%88%9B%E5%BB%BA%E6%B6%88%E6%81%AF\u0026amp;description=%E9%80%9A%E8%BF%87+CometAPI+Messages+%E7%AB%AF%E7%82%B9%E8%B0%83%E7%94%A8+Claude%EF%BC%8C%E6%94%AF%E6%8C%81%E6%96%87%E6%9C%AC%E5%92%8C%E5%9B%BE%E5%83%8F%E8%BE%93%E5%85%A5%E3%80%81%E8%87%AA%E9%80%82%E5%BA%94%E6%80%9D%E8%80%83%E3%80%81Prompt+%E7%BC%93%E5%AD%98%E3%80%81%E6%B5%81%E5%BC%8F%E8%BE%93%E5%87%BA%E5%92%8C%E5%B7%A5%E5%85%B7%E3%80%82\u0026amp;theme=d910b0d04a2d93f2b29ac00c\u0026amp;signature=efa90f47a7ad36969258bc5e7b6feac006593329afe46935a376f7a7edb0d2ae\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/cometapi/Jhcr00uAqm6Ci9Vs/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"CometAPI Documentation\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#00ACE2\">\u003cmeta data-mint-head name=\"author\" content=\"CometAPI\">\u003cmeta data-mint-head name=\"copyright\" content=\"Copyright 2026 CometAPI\">\u003cmeta data-mint-head name=\"category\" content=\"Technology\">\u003cmeta data-mint-head name=\"distribution\" content=\"global\">\u003cmeta data-mint-head name=\"coverage\" content=\"Worldwide\">\u003clink data-mint-head rel=\"canonical\" href=\"https://apidoc.cometapi.com/zh-Hans/api/text/anthropic-messages\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/zh-Hans/api/text/anthropic-messages.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"CometAPI Documentation\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"CometAPI Documentation\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/zh-Hans/api/text/anthropic-messages.md","siteName":"CometAPI Documentation","nav":{"global":null,"languages":[{"language":"en","pages":[{"title":"en","href":"/api/text/anthropic-messages"}]},{"language":"zh-Hans","tabs":[{"tab":"Docs","pages":[{"title":"Docs","href":"/zh-Hans"}]},{"tab":"API","groups":[{"group":"文本模型","icon":"message","root":{"title":"文本与聊天 API","sidebarTitle":"文本与聊天 API","href":"/zh-Hans/api/text"},"expanded":false,"pages":[{"title":"创建聊天补全","sidebarTitle":"创建聊天补全","openapi":"api/openapi/text/post-chat.openapi.json POST /v1/chat/completions","href":"/zh-Hans/api/text/chat"},{"title":"创建模型响应","sidebarTitle":"创建模型响应","openapi":"api/openapi/text/post-responses.openapi.json POST /v1/responses","description":"使用 CometAPI POST /v1/responses 创建包含内置工具和函数调用(Function Calling)的多模态(Multimodal)模型响应和对话历史记录。","href":"/zh-Hans/api/text/responses"},{"title":"创建消息","sidebarTitle":"创建消息","openapi":"api/openapi/text/post-anthropic-messages.openapi.json POST /v1/messages","href":"/zh-Hans/api/text/anthropic-messages"},{"title":"生成内容","sidebarTitle":"生成内容","openapi":"api/openapi/text/post-gemini-generating-content.openapi.json POST /v1beta/models/{model}:{operator}","description":"通过 CometAPI 使用 Gemini 原生 API 格式进行文本生成、视频输入、思考摘要、Google 搜索依据、JSON 输出和流式输出。","href":"/zh-Hans/api/text/gemini-generating-content"}]},{"group":"图像模型","icon":"image","root":{"title":"图像生成与编辑 API","sidebarTitle":"图像模型","href":"/zh-Hans/api/image/index"},"expanded":false,"pages":[{"group":"OpenAI","pages":[{"title":"创建图像","sidebarTitle":"创建图像","openapi":"api/openapi/image/openai/post-images.openapi.json POST /v1/images/generations","href":"/zh-Hans/api/image/openai/images"},{"title":"获取图像生成任务","sidebarTitle":"获取图像任务","openapi":"api/openapi/image/openai/get-image-generation-task.openapi.json GET /v1/images/generations/{task_id}","href":"/zh-Hans/api/image/openai/image-generation-task"},{"title":"创建图像编辑","sidebarTitle":"创建图像编辑","openapi":"api/openapi/image/openai/post-image-editing.openapi.json POST /v1/images/edits","href":"/zh-Hans/api/image/openai/image-editing"}]},{"group":"Gemini","pages":[{"title":"使用 Gemini 生成图像","sidebarTitle":"使用 Gemini 生成图像","openapi":"api/openapi/image/gemini/post-gemini-generates-image.openapi.json POST /v1beta/models/{model}:generateContent","href":"/zh-Hans/api/image/gemini/gemini-generates-image"},{"title":"使用 Gemini 图像模型","sidebarTitle":"使用 Gemini 图像模型","href":"/zh-Hans/api/image/gemini/generate-image-guide"}]},{"group":"Grok","pages":[{"title":"使用 Grok 生成图像","sidebarTitle":"生成图像","openapi":"api/openapi/image/grok/post-image-generation.openapi.json POST /v1/images/generations","href":"/zh-Hans/api/image/grok/image-generation"},{"title":"使用 Grok 编辑图像","sidebarTitle":"编辑图像","openapi":"api/openapi/image/grok/post-image-editing.openapi.json POST /v1/images/edits","href":"/zh-Hans/api/image/grok/image-editing"}]},{"group":"Kling","pages":[{"title":"使用 Kling 生成图像","sidebarTitle":"使用 Kling 生成图像","openapi":"api/openapi/image/kling/post-image-generation.openapi.json POST /kling/v1/images/generations","href":"/zh-Hans/api/image/kling/image-generation"},{"title":"从多张图片生成 Kling 图像","sidebarTitle":"从多张图片生成 Kling 图像","openapi":"api/openapi/image/kling/post-multi-image-to-image.openapi.json POST /kling/v1/images/multi-image2image","href":"/zh-Hans/api/image/kling/multi-image-to-image"},{"title":"使用 Kling 扩展图像","sidebarTitle":"使用 Kling 扩展图像","openapi":"api/openapi/image/kling/post-image-expansion.openapi.json POST /kling/v1/images/editing/expand","href":"/zh-Hans/api/image/kling/image-expansion"},{"title":"创建 Kling Omni 图像任务","sidebarTitle":"创建 Kling Omni 图像任务","openapi":"api/openapi/image/kling/post-omni-image.openapi.json POST /kling/v1/images/omni-image","href":"/zh-Hans/api/image/kling/omni-image"},{"title":"获取 Kling Omni 图像任务","sidebarTitle":"获取 Kling Omni 图像任务","openapi":"api/openapi/image/kling/get-omni-image.openapi.json GET /kling/v1/images/omni-image/{task_id}","href":"/zh-Hans/api/image/kling/omni-image-query"}]},{"group":"Replicate","pages":[{"title":"创建一个 Replicate prediction","sidebarTitle":"创建一个 Replicate prediction","openapi":"api/openapi/image/replicate/post-create-predictions-general.openapi.json POST /replicate/v1/models/{models}/predictions","href":"/zh-Hans/api/image/replicate/create-predictions-general"},{"title":"获取 Replicate prediction","sidebarTitle":"获取 Replicate prediction","openapi":"api/openapi/image/replicate/get-replicate-query.openapi.json GET /replicate/v1/predictions/{id}","href":"/zh-Hans/api/image/replicate/replicate-query"}]},{"group":"Seedream","pages":[{"title":"创建 Seedream 图像任务","sidebarTitle":"创建图像任务","openapi":"api/openapi/image/seededit-seedream/post-bytedance-image-generation.openapi.json POST /v1/images/generations","href":"/zh-Hans/api/image/seededit-seedream/bytedance-image-generation"},{"title":"获取 Seedream 图像任务","sidebarTitle":"获取图像任务","openapi":"api/openapi/image/seededit-seedream/get-bytedance-image-generation-task.openapi.json GET /v1/images/generations/{task_id}","href":"/zh-Hans/api/image/seededit-seedream/bytedance-image-generation-task"}]},{"group":"Flux","pages":[{"title":"生成 FLUX 图像","sidebarTitle":"生成 FLUX 图像","openapi":"api/openapi/image/flux/post-flux-generate-image.openapi.json POST /flux/v1/{model}","href":"/zh-Hans/api/image/flux/flux-generate-image"},{"title":"获取 FLUX 图像结果","sidebarTitle":"获取 FLUX 图像结果","openapi":"api/openapi/image/flux/get-flux-query.openapi.json GET /flux/v1/get_result","href":"/zh-Hans/api/image/flux/flux-query"}]}]},{"group":"视频模型","icon":"video","root":{"title":"视频生成 API","sidebarTitle":"视频模型","href":"/zh-Hans/api/video/index"},"expanded":false,"pages":[{"group":"Seedance","pages":[{"title":"创建 Seedance 视频","sidebarTitle":"创建 Seedance 视频","openapi":"api/openapi/video/seedance/post-seedance-create.openapi.json POST /v1/videos","href":"/zh-Hans/api/video/seedance/create"},{"title":"获取 Seedance 视频","sidebarTitle":"获取 Seedance 视频","openapi":"api/openapi/video/seedance/get-seedance-query.openapi.json GET /v1/videos/{id}","href":"/zh-Hans/api/video/seedance/query"}]},{"group":"HappyHorse","pages":[{"title":"创建 HappyHorse 视频","sidebarTitle":"创建 HappyHorse 视频","openapi":"api/openapi/video/happyhorse/post-create.openapi.json POST /v1/videos","href":"/zh-Hans/api/video/happyhorse/create"},{"title":"获取 HappyHorse 视频","sidebarTitle":"获取 HappyHorse 视频","openapi":"api/openapi/video/happyhorse/get-retrieve.openapi.json GET /v1/videos/{task_id}","href":"/zh-Hans/api/video/happyhorse/retrieve"},{"title":"下载 HappyHorse 视频内容","sidebarTitle":"下载 HappyHorse 视频内容","openapi":"api/openapi/video/happyhorse/get-retrieve-content.openapi.json GET /v1/videos/{task_id}/content","href":"/zh-Hans/api/video/happyhorse/retrieve-content"}]},{"group":"MiniMax H3","pages":[{"title":"创建 MiniMax H3 视频","sidebarTitle":"创建 MiniMax H3 视频","openapi":"api/openapi/video/minimax-h3/post-create.openapi.json POST /v1/videos","href":"/zh-Hans/api/video/minimax-h3/create"},{"title":"检索 MiniMax H3 视频","sidebarTitle":"检索 MiniMax H3 视频","openapi":"api/openapi/video/minimax-h3/get-retrieve.openapi.json GET /v1/videos/{task_id}","href":"/zh-Hans/api/video/minimax-h3/retrieve"},{"title":"下载 MiniMax H3 视频内容","sidebarTitle":"下载 MiniMax H3 视频内容","openapi":"api/openapi/video/minimax-h3/get-retrieve-content.openapi.json GET /v1/videos/{task_id}/content","href":"/zh-Hans/api/video/minimax-h3/retrieve-content"}]},{"group":"Flux 3","pages":[{"title":"创建 Flux 3 视频","sidebarTitle":"创建 Flux 3 视频","openapi":"api/openapi/video/flux-3/post-create.openapi.json POST /v1/videos","href":"/zh-Hans/api/video/flux-3/create"},{"title":"获取 Flux 3 视频","sidebarTitle":"获取 Flux 3 视频","openapi":"api/openapi/video/flux-3/get-retrieve.openapi.json GET /v1/videos/{task_id}","href":"/zh-Hans/api/video/flux-3/retrieve"},{"title":"下载 Flux 3 视频内容","sidebarTitle":"下载 Flux 3 视频内容","openapi":"api/openapi/video/flux-3/get-retrieve-content.openapi.json GET /v1/videos/{task_id}/content","href":"/zh-Hans/api/video/flux-3/retrieve-content"}]},{"group":"Veo 3","pages":[{"title":"创建 Veo 3 视频","sidebarTitle":"创建 Veo 3 视频","openapi":"api/openapi/video/veo3/post-create.openapi.json POST /v1/videos","href":"/zh-Hans/api/video/veo3/create"},{"title":"获取 Veo 3 视频","sidebarTitle":"获取 Veo 3 视频","openapi":"api/openapi/video/veo3/get-retrieve.openapi.json GET /v1/videos/{video_id}","href":"/zh-Hans/api/video/veo3/retrieve"}]},{"group":"Wan","pages":[{"title":"创建 Wan 视频","sidebarTitle":"创建 Wan 视频","openapi":"api/openapi/video/wan/post-create.openapi.json POST /v1/videos","href":"/zh-Hans/api/video/wan/create"},{"title":"获取 Wan 视频","sidebarTitle":"获取 Wan 视频","openapi":"api/openapi/video/wan/get-retrieve.openapi.json GET /v1/videos/{task_id}","href":"/zh-Hans/api/video/wan/retrieve"},{"title":"下载 Wan 视频内容","sidebarTitle":"下载 Wan 视频内容","openapi":"api/openapi/video/wan/get-retrieve-content.openapi.json GET /v1/videos/{task_id}/content","href":"/zh-Hans/api/video/wan/retrieve-content"}]},{"group":"xAI","pages":[{"title":"使用 Grok 创建视频","sidebarTitle":"创建 Grok 视频","openapi":"api/openapi/video/xai/post-video-generation.openapi.json POST /grok/v1/videos/generations","href":"/zh-Hans/api/video/xai/video-generation"},{"title":"创建 xAI 视频编辑","sidebarTitle":"创建 xAI 视频编辑","openapi":"api/openapi/video/xai/post-video-edit.openapi.json POST /grok/v1/videos/edits","href":"/zh-Hans/api/video/xai/video-edit"},{"title":"获取 xAI 视频结果","sidebarTitle":"获取 xAI 视频结果","openapi":"api/openapi/video/xai/get-get-video-generation-results.openapi.json GET /grok/v1/videos/{request_id}","href":"/zh-Hans/api/video/xai/get-video-generation-results"}]},{"group":"Vidu","pages":[{"title":"创建 Vidu 视频","sidebarTitle":"创建 Vidu 视频","openapi":"api/openapi/video/vidu/post-create.openapi.json POST /v1/videos","href":"/zh-Hans/api/video/vidu/create"},{"title":"获取 Vidu 视频","sidebarTitle":"获取 Vidu 视频","openapi":"api/openapi/video/vidu/get-retrieve.openapi.json GET /v1/videos/{task_id}","href":"/zh-Hans/api/video/vidu/retrieve"},{"title":"下载 Vidu 视频内容","sidebarTitle":"下载 Vidu 视频内容","openapi":"api/openapi/video/vidu/get-retrieve-content.openapi.json GET /v1/videos/{task_id}/content","href":"/zh-Hans/api/video/vidu/retrieve-content"}]},{"group":"Omni","tag":"Beta","pages":[{"title":"通过文本、图像或视频创建 Omni 视频","sidebarTitle":"创建 Omni 视频","openapi":"api/openapi/video/omni/post-create.openapi.json POST /v1/videos","href":"/zh-Hans/api/video/omni/create"},{"title":"获取一个 Omni 视频","sidebarTitle":"获取一个 Omni 视频","openapi":"api/openapi/video/omni/get-retrieve.openapi.json GET /v1/videos/{task_id}","href":"/zh-Hans/api/video/omni/retrieve"},{"title":"下载 Omni 视频内容","sidebarTitle":"下载 Omni 视频内容","openapi":"api/openapi/video/omni/get-retrieve-content.openapi.json GET /v1/videos/{task_id}/content","href":"/zh-Hans/api/video/omni/retrieve-content"}]},{"group":"Kling","pages":[{"group":"多模态视频编辑","pages":[{"title":"初始化 Kling 编辑会话","sidebarTitle":"初始化 Kling 编辑会话","openapi":"api/openapi/video/kling/multimodal-video-editing/post-initialize-video-for-editing.openapi.json POST /kling/v1/videos/multi-elements/init-selection","href":"/zh-Hans/api/video/kling/multimodal-video-editing/initialize-video-for-editing"},{"title":"添加 Kling 视频选区","sidebarTitle":"添加 Kling 视频选区","openapi":"api/openapi/video/kling/multimodal-video-editing/post-add-video-selection.openapi.json POST /kling/v1/videos/multi-elements/add-selection","href":"/zh-Hans/api/video/kling/multimodal-video-editing/add-video-selection"},{"title":"删除 Kling 视频选区","sidebarTitle":"删除 Kling 视频选区","openapi":"api/openapi/video/kling/multimodal-video-editing/post-delete-video-selection.openapi.json POST /kling/v1/videos/multi-elements/delete-selection","href":"/zh-Hans/api/video/kling/multimodal-video-editing/delete-video-selection"},{"title":"清除 Kling 视频选择","sidebarTitle":"清除 Kling 视频选择","openapi":"api/openapi/video/kling/multimodal-video-editing/post-clear-video-selection.openapi.json POST /kling/v1/videos/multi-elements/clear-selection","href":"/zh-Hans/api/video/kling/multimodal-video-editing/clear-video-selection"},{"title":"预览 Kling 视频选区","sidebarTitle":"预览 Kling 视频选区","openapi":"api/openapi/video/kling/multimodal-video-editing/post-preview-selected-video-area.openapi.json POST /kling/v1/videos/multi-elements/preview-selection","href":"/zh-Hans/api/video/kling/multimodal-video-editing/preview-selected-video-area"},{"title":"创建一个 Kling 多模态编辑任务","sidebarTitle":"创建一个 Kling 多模态编辑任务","openapi":"api/openapi/video/kling/multimodal-video-editing/post-create-task.openapi.json POST /kling/v1/videos/multi-elements","href":"/zh-Hans/api/video/kling/multimodal-video-editing/create-task"}]},{"group":"模型接口","pages":[{"title":"按模型创建 Kling 文本生成视频任务","sidebarTitle":"文本生成视频","openapi":"api/openapi/video/kling/model-routes/post-text-to-video.openapi.json POST /text-to-video/{model}","href":"/zh-Hans/api/video/kling/model-routes/text-to-video"},{"title":"按模型创建 Kling 图生视频任务","sidebarTitle":"图生视频","openapi":"api/openapi/video/kling/model-routes/post-image-to-video.openapi.json POST /image-to-video/{model}","href":"/zh-Hans/api/video/kling/model-routes/image-to-video"},{"title":"创建 Kling Omni 视频","sidebarTitle":"Omni 视频","openapi":"api/openapi/video/kling/model-routes/post-omni-video.openapi.json POST /omni-video/{model}","href":"/zh-Hans/api/video/kling/model-routes/omni-video"},{"title":"创建 Kling 动作控制视频","sidebarTitle":"动作控制","openapi":"api/openapi/video/kling/model-routes/post-motion-control.openapi.json POST /motion-control/{model}","href":"/zh-Hans/api/video/kling/model-routes/motion-control"},{"title":"获取 Kling 模型路由任务","sidebarTitle":"获取 Kling 任务","openapi":"api/openapi/video/kling/model-routes/get-tasks.openapi.json GET /tasks","href":"/zh-Hans/api/video/kling/model-routes/tasks"}]},{"title":"创建一个 Kling 文生视频任务","sidebarTitle":"创建一个 Kling 文生视频任务","openapi":"api/openapi/video/kling/post-text-to-video.openapi.json POST /kling/v1/videos/text2video","href":"/zh-Hans/api/video/kling/text-to-video"},{"title":"创建一个 Kling 图生视频任务","sidebarTitle":"创建一个 Kling 图生视频任务","openapi":"api/openapi/video/kling/post-image-to-video.openapi.json POST /kling/v1/videos/image2video","href":"/zh-Hans/api/video/kling/image-to-video"},{"title":"创建 Kling Motion Control 任务","sidebarTitle":"创建 Kling Motion Control 任务","openapi":"api/openapi/video/kling/post-motion-control.openapi.json POST /kling/v1/videos/motion-control","href":"/zh-Hans/api/video/kling/motion-control"},{"title":"创建一个 Kling 多图视频任务","sidebarTitle":"创建一个 Kling 多图视频任务","openapi":"api/openapi/video/kling/post-multi-image-to-video.openapi.json POST /kling/v1/videos/multi-image2video","href":"/zh-Hans/api/video/kling/multi-image-to-video"},{"title":"延长一个 Kling 视频","sidebarTitle":"延长一个 Kling 视频","openapi":"api/openapi/video/kling/post-video-extension.openapi.json POST /kling/v1/videos/video-extend","href":"/zh-Hans/api/video/kling/video-extension"},{"title":"创建 Kling 语音","sidebarTitle":"创建 Kling 语音","openapi":"api/openapi/video/kling/post-tts.openapi.json POST /kling/v1/audio/tts","href":"/zh-Hans/api/video/kling/tts"},{"title":"创建 Kling 数字人视频","sidebarTitle":"创建 Kling 数字人视频","openapi":"api/openapi/video/kling/post-avatar.openapi.json POST /kling/v1/videos/avatar/image2video","href":"/zh-Hans/api/video/kling/avatar"},{"title":"为 Kling 唇形同步识别人脸","sidebarTitle":"为 Kling 唇形同步识别人脸","openapi":"api/openapi/video/kling/post-lip-sync.openapi.json POST /kling/v1/videos/identify-face","href":"/zh-Hans/api/video/kling/lip-sync"},{"title":"创建 Kling 高级口型同步任务","sidebarTitle":"创建 Kling 高级口型同步任务","openapi":"api/openapi/video/kling/post-counterpart-creating-tasks.openapi.json POST /kling/v1/videos/advanced-lip-sync","href":"/zh-Hans/api/video/kling/counterpart-creating-tasks"},{"title":"应用 Kling 视频特效","sidebarTitle":"应用 Kling 视频特效","openapi":"api/openapi/video/kling/post-video-effects.openapi.json POST /kling/v1/videos/effects","href":"/zh-Hans/api/video/kling/video-effects"},{"title":"创建 Kling 文本转音频","sidebarTitle":"创建 Kling 文本转音频","openapi":"api/openapi/video/kling/post-text-to-audio.openapi.json POST /kling/v1/audio/text-to-audio","href":"/zh-Hans/api/video/kling/text-to-audio"},{"title":"创建 Kling 视频转音频","sidebarTitle":"创建 Kling 视频转音频","openapi":"api/openapi/video/kling/post-video-to-audio.openapi.json POST /kling/v1/audio/video-to-audio","href":"/zh-Hans/api/video/kling/video-to-audio"},{"title":"使用 Kling 识别图像","sidebarTitle":"使用 Kling 识别图像","openapi":"api/openapi/video/kling/post-image-recognize.openapi.json POST /kling/v1/videos/image-recognize","href":"/zh-Hans/api/video/kling/image-recognize"},{"title":"获取 Kling 任务","sidebarTitle":"获取 Kling 任务","openapi":"api/openapi/video/kling/get-individual-queries.openapi.json GET /kling/v1/{action}/{action2}/{task_id}","href":"/zh-Hans/api/video/kling/individual-queries"},{"title":"创建 Kling Omni 视频","sidebarTitle":"创建 Kling Omni 视频","openapi":"api/openapi/video/kling/post-omni-video.openapi.json POST /kling/v1/videos/omni-video","href":"/zh-Hans/api/video/kling/omni-video"},{"title":"获取 Kling Omni 视频","sidebarTitle":"获取 Kling Omni 视频","openapi":"api/openapi/video/kling/get-omni-query.openapi.json GET /kling/v1/videos/omni-video/{task_id}","href":"/zh-Hans/api/video/kling/omni-query"},{"title":"使用 Kling 回调 URL","sidebarTitle":"使用 Kling 回调 URL","href":"/zh-Hans/api/video/kling/callback_url"}]},{"group":"Runway","pages":[{"title":"Runway API 概览","sidebarTitle":"概览","href":"/zh-Hans/api/video/runway/overview"},{"group":"图像","pages":[{"title":"创建 Runway 图像","sidebarTitle":"创建 Runway 图像","openapi":"api/openapi/video/runway/official-format/post-generate-an-image-from-text.openapi.json POST /runwayml/v1/text_to_image","href":"/zh-Hans/api/video/runway/official-format/generate-an-image-from-text"}]},{"group":"视频","pages":[{"title":"创建 Runway 图像转视频任务","sidebarTitle":"创建 Runway 图像转视频任务","openapi":"api/openapi/video/runway/official-format/post-runway-images-raw-video.openapi.json POST /runwayml/v1/image_to_video","href":"/zh-Hans/api/video/runway/official-format/runway-images-raw-video"},{"title":"创建 Runway 文本转视频任务","sidebarTitle":"创建 Runway 文本转视频任务","openapi":"api/openapi/video/runway/official-format/post-generate-a-video-from-text.openapi.json POST /runwayml/v1/text_to_video","href":"/zh-Hans/api/video/runway/official-format/generate-a-video-from-text"},{"title":"创建 Runway 视频转视频任务","sidebarTitle":"创建 Runway 视频转视频任务","openapi":"api/openapi/video/runway/official-format/post-generate-a-video-from-a-video.openapi.json POST /runwayml/v1/video_to_video","href":"/zh-Hans/api/video/runway/official-format/generate-a-video-from-a-video"},{"title":"创建 Runway 角色表演","sidebarTitle":"创建 Runway 角色表演","openapi":"api/openapi/video/runway/official-format/post-control-a-character.openapi.json POST /runwayml/v1/character_performance","href":"/zh-Hans/api/video/runway/official-format/control-a-character"},{"title":"放大 Runway 视频","sidebarTitle":"放大 Runway 视频","openapi":"api/openapi/video/runway/official-format/post-upscale-a-video.openapi.json POST /runwayml/v1/video_upscale","href":"/zh-Hans/api/video/runway/official-format/upscale-a-video"}]},{"group":"音频","pages":[{"title":"生成 Runway 音效","sidebarTitle":"生成 Runway 音效","openapi":"api/openapi/video/runway/official-format/post-generate-sound-effects.openapi.json POST /runwayml/v1/sound_effect","href":"/zh-Hans/api/video/runway/official-format/generate-sound-effects"},{"title":"根据文本生成 Runway 语音","sidebarTitle":"根据文本生成 Runway 语音","openapi":"api/openapi/video/runway/official-format/post-generate-speech-from-text.openapi.json POST /runwayml/v1/text_to_speech","href":"/zh-Hans/api/video/runway/official-format/generate-speech-from-text"},{"title":"转换 Runway 语音","sidebarTitle":"转换 Runway 语音","openapi":"api/openapi/video/runway/official-format/post-convert-speech.openapi.json POST /runwayml/v1/speech_to_speech","href":"/zh-Hans/api/video/runway/official-format/convert-speech"},{"title":"为 Runway 音频配音","sidebarTitle":"为 Runway 音频配音","openapi":"api/openapi/video/runway/official-format/post-dub-audio.openapi.json POST /runwayml/v1/voice_dubbing","href":"/zh-Hans/api/video/runway/official-format/dub-audio"},{"title":"分离 Runway 语音","sidebarTitle":"分离 Runway 语音","openapi":"api/openapi/video/runway/official-format/post-isolate-voice.openapi.json POST /runwayml/v1/voice_isolation","href":"/zh-Hans/api/video/runway/official-format/isolate-voice"}]},{"group":"任务","pages":[{"title":"获取 Runway 任务","sidebarTitle":"获取 Runway 任务","openapi":"api/openapi/video/runway/official-format/get-runway-to-get-task-details.openapi.json GET /runwayml/v1/tasks/{id}","href":"/zh-Hans/api/video/runway/official-format/runway-to-get-task-details"}]}]}]},{"group":"音频模型","icon":"volume-high","root":{"title":"音频 API","sidebarTitle":"音频模型","href":"/zh-Hans/api/audio/index"},"expanded":false,"pages":[{"title":"创建语音","sidebarTitle":"创建语音","openapi":"api/openapi/audio/post-create-speech.openapi.json POST /v1/audio/speech","href":"/zh-Hans/api/audio/create-speech"},{"title":"创建转录","sidebarTitle":"创建转录","openapi":"api/openapi/audio/post-create-transcription.openapi.json POST /v1/audio/transcriptions","href":"/zh-Hans/api/audio/create-transcription"},{"title":"创建翻译","sidebarTitle":"创建翻译","openapi":"api/openapi/audio/post-create-translation.openapi.json POST /v1/audio/translations","href":"/zh-Hans/api/audio/create-translation"}]},{"group":"嵌入","icon":"database","root":{"title":"嵌入 API","sidebarTitle":"嵌入","href":"/zh-Hans/api/embeddings/index"},"expanded":false,"pages":[{"title":"创建嵌入","sidebarTitle":"创建嵌入","openapi":"api/openapi/text/post-embeddings.openapi.json POST /v1/embeddings","href":"/zh-Hans/api/text/embeddings"}]},{"group":"内容审核","icon":"shield-check","expanded":false,"pages":[{"title":"创建审核","sidebarTitle":"创建审核","openapi":"api/openapi/content-moderation/create-moderation.openapi.json POST /v1/moderations","href":"/zh-Hans/api/content-moderation/create-moderation"}]},{"group":"API 密钥","icon":"key","expanded":false,"pages":[{"title":"获取当前 API 密钥","sidebarTitle":"获取当前 API 密钥","openapi":"api/openapi/api-keys/get-current-api-key.openapi.json GET /api/usage/token","href":"/zh-Hans/api/api-keys/get-current-api-key"},{"title":"列出 API 密钥","sidebarTitle":"列出 API 密钥","openapi":"api/openapi/api-keys/list-api-keys.openapi.json GET /api/token/","href":"/zh-Hans/api/api-keys/list-api-keys"},{"title":"创建 API 密钥","sidebarTitle":"创建 API 密钥","openapi":"api/openapi/api-keys/create-api-key.openapi.json POST /api/token/","href":"/zh-Hans/api/api-keys/create-api-key"},{"title":"获取 API 密钥","sidebarTitle":"获取 API 密钥","openapi":"api/openapi/api-keys/get-api-key.openapi.json GET /api/token/{id}","href":"/zh-Hans/api/api-keys/get-api-key"},{"title":"删除一个 API 密钥","sidebarTitle":"删除一个 API 密钥","openapi":"api/openapi/api-keys/delete-api-key.openapi.json DELETE /api/token/{id}","href":"/zh-Hans/api/api-keys/delete-api-key"},{"title":"更新 API 密钥","sidebarTitle":"更新 API 密钥","openapi":"api/openapi/api-keys/update-api-key.openapi.json PUT /api/token/","href":"/zh-Hans/api/api-keys/update-api-key"}]}]},{"tab":"Integrations","pages":[{"title":"Integrations","href":"/zh-Hans/integrations"}]}]},{"language":"zh-Hant","pages":[{"title":"zh-Hant","href":"/zh-Hant/api/text/anthropic-messages"}]},{"language":"ja","pages":[{"title":"ja","href":"/ja/api/text/anthropic-messages"}]},{"language":"ko","pages":[{"title":"ko","href":"/ko/api/text/anthropic-messages"}]},{"language":"fr","pages":[{"title":"fr","href":"/fr/api/text/anthropic-messages"}]},{"language":"de","pages":[{"title":"de","href":"/de/api/text/anthropic-messages"}]},{"language":"es","pages":[{"title":"es","href":"/es/api/text/anthropic-messages"}]},{"language":"it","pages":[{"title":"it","href":"/it/api/text/anthropic-messages"}]},{"language":"pt","pages":[{"title":"pt","href":"/pt/api/text/anthropic-messages"}]},{"language":"ru","pages":[{"title":"ru","href":"/ru/api/text/anthropic-messages"}]},{"language":"ar","pages":[{"title":"ar","href":"/ar/api/text/anthropic-messages"}]},{"language":"vi","pages":[{"title":"vi","href":"/vi/api/text/anthropic-messages"}]},{"language":"id","pages":[{"title":"id","href":"/id/api/text/anthropic-messages"}]},{"language":"tr","pages":[{"title":"tr","href":"/tr/api/text/anthropic-messages"}]},{"language":"pl","pages":[{"title":"pl","href":"/pl/api/text/anthropic-messages"}]},{"language":"nl","pages":[{"title":"nl","href":"/nl/api/text/anthropic-messages"}]},{"language":"no","pages":[{"title":"no","href":"/no/api/text/anthropic-messages"}]},{"language":"uk","pages":[{"title":"uk","href":"/uk/api/text/anthropic-messages"}]}]},"basePath":"","title":"创建消息 - CometAPI Documentation","deploymentId":"dpl_Em2U4NQQ2N2DE3HPbPUJVZLnAtvc","buildId":"dpl_Em2U4NQQ2N2DE3HPbPUJVZLnAtvc","dynamics":["c2aa737661","b0f84f53ff","a9bb46feb3","2b790eda92"],"chunks":["OpenApiReferenceProvider-_HcdDqS2.js","snippetPresets-CXnm-WO6.js","utils-Dg59J__o.js","style-to-object-BY3JEAdk.js","utils-D8TRpdk7.js","v4-DIgz8zy6.js","addUniqueKeysToSchema-B6QaxWc5.js","conditional-requirements-CFM0id0Q.js","cloneDeep-DeMZ-lcM.js","_Uint8Array-BjA2mcVW.js","isObject-FP1Yky1u.js","Page-DuqezyvM.js","CodeSnippet-B373COAT.js","DynamicMarkdown-5yMTCLas.js","SectionHeading-BxT1HYfP.js","icon-DYJTTD3g.js","ApiExamples-cjPyMv63.js","usePlaygroundInputsStore-D7BWoaw4.js","shallow-Z1ceDNSG.js","isEqual-BObTuQrO.js","CodeSnippets-D1UZ1AE-.js","getApiPlaygroundDisplay-CfL-UuDS.js","MethodPill-4AyycJeu.js","getPastedJson-Bp3WV6cN.js","Check2Icon-PhZu6Gry.js","axios-CsQoIw0U.js","Markdown-Dy9a8hT8.js","AssistantPageLink-87tSPwGm.js","dist-CXMB3QQU.js","lib-DMeTj1gb.js","lib-B8HbPgcC.js","katex-Dbtb6Wk7.js","html-void-elements-mCSPHezU.js","marked.esm-CZWythHk.js"]}