Anthropic 訊息
透過 CometAPI 使用 Anthropic 訊息 API,以存取具備延伸思考、Prompt 快取、工具使用、網頁搜尋/擷取、串流(Streaming)與 effort control 的 Claude 模型。
CometAPI 原生支援 Anthropic 訊息 API,讓你能直接存取 Claude 模型及所有 Anthropic 專屬功能。當你需要 Claude 專有能力,例如延伸思考、Prompt 快取與 effort control 時,請使用此端點。Documentation Index
Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
Use this file to discover all available pages before exploring further.
x-api-key 與 Authorization: Bearer 標頭進行驗證。官方 Anthropic SDK 預設使用 x-api-key。快速開始
若要搭配 CometAPI 使用官方 Anthropic SDK,請設定 base URL:啟用延伸思考
使用thinking 參數啟用 Claude 的逐步推理能力。回應會包含 thinking 內容區塊,顯示 Claude 在給出最終答案前的內部推理過程。
快取 Prompt
為了降低後續請求的延遲與成本,你可以快取大型 system Prompt 或對話前綴。請在需要快取的內容區塊中加入cache_control:
usage 欄位中回報:
cache_creation_input_tokens— 寫入快取的 tokens(以較高費率計費)cache_read_input_tokens— 從快取讀取的 tokens(以較低費率計費)
串流回應
若要使用 Server-Sent Events (SSE) 串流回應,請設定stream: true。事件會依照以下順序到達:
message_start— 包含訊息中繼資料與初始 usagecontent_block_start— 標記每個內容區塊的開始content_block_delta— 遞增文字分塊(text_delta)content_block_stop— 標記每個內容區塊的結束message_delta— 最終的stop_reason與完整的usagemessage_stop— 表示串流結束
控制 effort
若要控制 Claude 在產生回應時投入多少 effort,請使用output_config.effort:
使用伺服器工具
Claude 支援在 Anthropic 基礎架構上執行的伺服器端工具:- Web Fetch
- Web Search
回應範例
來自 CometAPI Anthropic 端點的典型回應:與 OpenAI 相容端點比較
| 功能 | Anthropic 訊息 (/v1/messages) | OpenAI-Compatible (/v1/chat/completions) |
|---|---|---|
| 延伸思考 | 帶有 budget_tokens 的 thinking 參數 | 不可用 |
| Prompt 快取 | 內容區塊上的 cache_control | 不可用 |
| Effort 控制 | output_config.effort | 不可用 |
| Web 擷取/搜尋 | 伺服器工具(web_fetch、web_search) | 不可用 |
| 驗證標頭 | x-api-key 或 Bearer | 僅 Bearer |
| 回應格式 | Anthropic 格式(content 區塊) | OpenAI 格式(choices、message) |
| 模型 | 僅 Claude | 多供應商(GPT、Claude、Gemini 等) |
授權
Your CometAPI key passed via the x-api-key header. Authorization: Bearer <key> is also supported.
標頭
The Anthropic API version to use. Defaults to 2023-06-01.
"2023-06-01"
Comma-separated list of beta features to enable. Examples: max-tokens-3-5-sonnet-2024-07-15, pdfs-2024-09-25, output-128k-2025-02-19.
主體
The Claude model to use. See the Models page for current Claude model IDs.
"claude-sonnet-4-6"
The conversation messages. Must alternate between user and assistant roles. Each message's content can be a string or an array of content blocks (text, image, document, tool_use, tool_result). There is a limit of 100,000 messages per request.
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 >= 11024
System prompt providing context and instructions to Claude. Can be a plain string or an array of content blocks (useful for prompt caching).
Controls randomness in the response. Range: 0.0–1.0. Use lower values for analytical tasks and higher values for creative tasks. Defaults to 1.0.
0 <= x <= 1Nucleus sampling threshold. Only tokens with cumulative probability up to this value are considered. Range: 0.0–1.0. Use either temperature or top_p, not both.
0 <= x <= 1Only sample from the top K most probable tokens. Recommended for advanced use cases only.
x >= 0If 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.
Custom strings that cause the model to stop generating when encountered. The stop sequence is not included in the response.
Enable extended thinking — Claude's step-by-step reasoning process. When enabled, the response includes thinking content blocks before the answer. Requires a minimum budget_tokens of 1,024.
Tools the model may use. Supports client-defined functions, web search (web_search_20250305), web fetch (web_fetch_20250910), code execution (code_execution_20250522), and more.
Controls how the model uses tools.
Request metadata for tracking and analytics.
Configuration for output behavior.
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.
Unique identifier for this message (e.g., msg_01XFDUDYJgAACzvnptvVoYEL).
Always message.
message Always assistant.
assistant The response content blocks. May include text, thinking, tool_use, and other block types.
The specific model version that generated this response (e.g., claude-sonnet-4-6).
Why the model stopped generating.
end_turn, max_tokens, stop_sequence, tool_use, pause_turn The stop sequence that caused the model to stop, if applicable.
Token usage statistics.