Skip to Content
模型用法Claude概覽

Claude 系列

Anthropic 的 Claude 模型,包括 Opus、Sonnet、Haiku 與 Fable 系列。建議透過 Anthropic 原生介面呼叫,延伸思考、提示快取、PDF 輸入等功能與官方 API 一致;OpenAI 相容介面同樣可用,適合已有 OpenAI SDK 程式碼的專案。

常見任務

模型

所有模型皆支援文字、圖片與 PDF 輸入,並支援工具呼叫。完整的模型清單與即時價格請參閱模型頁 ,也可透過 Models API 查詢。

常用模型 ID(呼叫時原樣複製)
Claude Opus 5.5anthropic/claude-opus-5.5
Claude Sonnet 5.5anthropic/claude-sonnet-5.5
Claude Haiku 5.5anthropic/claude-haiku-5.5
Claude Fable 5.1anthropic/claude-fable-5.1

模型 ID 可省略 anthropic/ 前綴,也可使用 Anthropic 官方的寫法,以下寫法皆指向同一模型:

寫法範例
OfoxAI 標準寫法anthropic/claude-sonnet-4.6
省略前綴claude-sonnet-4.6
官方寫法(連字號)claude-sonnet-4-6
官方含日期寫法claude-sonnet-4-6-20260217

各模型可用的別名請見 Models API 回傳的 aliases 欄位。回應中的 model 欄位一律為標準寫法。

介面選擇

重點使用延伸思考、提示快取或 Claude Code 等工具時,請使用 Anthropic 原生介面。
Anthropic 原生介面(建議)OpenAI 相容介面
位址POST https://api.ofox.ai/anthropic/v1/messagesPOST https://api.ofox.ai/v1/chat/completions
SDK base_urlhttps://api.ofox.ai/anthropichttps://api.ofox.ai/v1
驗證x-api-key: <Key>,也接受 Authorization: Bearer <Key>Authorization: Bearer <Key>
延伸思考thinking 參數,回傳 thinking 區塊reasoning 參數,回傳 reasoning_details
提示快取cache_control,usage 回傳寫入與讀取量在訊息內容區塊中加上 cache_control,usage 只回傳讀取量
PDFdocument 內容區塊file 內容區塊
網路搜尋支援(需指定 Anthropic 供應商)不支援

完整的請求參數請見 Anthropic Messages API 與 Chat Completions API。

供應商

Claude 模型由兩家供應商提供,同一模型在不同供應商上支援的功能不同:

供應商提供的模型可用介面說明
Amazon Bedrock(aws_bedrock)所有模型兩種介面預設供應商
Anthropic(anthropic)Fable 5、Opus 4.8、Opus 4.7、Sonnet 5僅 Anthropic 原生介面支援網路搜尋,需明確指定

在 Anthropic 原生介面中,可透過請求標頭指定供應商:

-H "X-OfoxAI-Provider-Type: anthropic"

指定的供應商不提供該模型時會回傳 400,錯誤訊息會列出可用的供應商,例如:

No available channel for platform 'anthropic' on model 'anthropic/claude-sonnet-4.6'. Available platforms for this model: aws_bedrock.

其他指定方式請見供應商路由。

呼叫範例

claude_basic.py
import os import anthropic client = anthropic.Anthropic( base_url="https://api.ofox.ai/anthropic", api_key=os.environ["OFOX_API_KEY"], ) message = client.messages.create( model="anthropic/claude-sonnet-4.6", max_tokens=1024, system="你是一名資深後端工程師,回答簡潔。", messages=[{"role": "user", "content": "用一句話解釋什麼是冪等性。"}], ) print(message.content[0].text)

max_tokens 為 Anthropic 原生介面的必填參數,取值不得超過模型的最大輸出。

在 Claude Code 中使用

Claude Code 透過 Anthropic 原生介面呼叫,基礎位址為 https://api.ofox.ai/anthropic。設定步驟請見 Claude Code 設定。

Claude Code 設定值
ANTHROPIC_BASE_URLhttps://api.ofox.ai/anthropic
ANTHROPIC_AUTH_TOKEN貼上你的 OfoxAI API Key

常見錯誤

重點參數類錯誤會回傳 400 並說明原因;回答被截斷並非錯誤,請檢查 stop_reason。
HTTP · type錯誤原文原因處理方式
400 ValidationExceptionprompt is too long: 280527 tokens > 200000 maximum輸入超過模型上下文縮短輸入,或改用 1M 上下文的模型(Haiku 4.5 以外的模型)
404 model_not_foundModel 'anthropic/claude-sonnet-9' not found模型 ID 拼錯或模型已下架從本頁複製模型 ID
401 invalid_api_keyInvalid or expired API keyKey 錯誤、已刪除或已過期在主控台確認 Key;原生介面請檢查 x-api-key 請求標頭
400No available channel for platform 'anthropic' on model ...指定的供應商不提供該模型移除供應商指定,或改用錯誤訊息中列出的供應商,請見供應商
200,stop_reason: "max_tokens"—輸出達到 max_tokens 上限,回答被截斷調高 max_tokens;開啟思考時,思考也會占用該額度

其他通用錯誤請見錯誤處理。

官方文件

官方文件描述的是直連 Anthropic 時的行為。在 OfoxAI 上呼叫時,模型 ID 與介面位址以本頁為準。

常見問題

Claude 的模型 ID 怎麼寫?

標準寫法為 anthropic/claude-sonnet-4.6,也可以省略 anthropic/ 前綴,或使用官方的 claude-sonnet-4-6、claude-sonnet-4-6-20260217 寫法,皆指向同一模型。

可以用 OpenAI SDK 呼叫 Claude 嗎?

可以。base_url 設為 https://api.ofox.ai/v1,模型 ID 填入 anthropic/claude-sonnet-4.6 等。需要延伸思考或完整的快取用量資訊時,建議使用 Anthropic 原生介面。

Claude 如何開啟思考模式?

原生介面傳入 thinking: {"type": "enabled", "budget_tokens": 2000},budget_tokens 至少 1024 且小於 max_tokens;或傳入 {"type": "adaptive"} 由模型決定。OpenAI 相容介面傳入 reasoning: {"max_tokens": 2000}。開啟思考時請勿設定 temperature。

Claude 提示快取沒有生效該怎麼辦?

依序檢查:是否在固定內容區塊上標記了 cache_control(兩種介面都不會自動快取);內容是否達到最小可快取長度;兩次請求的前綴是否完全一致;兩次請求的間隔是否超過 5 分鐘。

出現 prompt is too long 錯誤該怎麼辦?

輸入超過了模型上下文。Haiku 4.5 的上下文為 200K token,其餘 Claude 模型為 1M token,可改用其他模型或縮短輸入。

Claude 支援 1M 上下文嗎?需要加上 beta 請求標頭嗎?

除 Haiku 4.5 外皆支援 1M 上下文,在 OfoxAI 上不需要傳入 beta 請求標頭。

Claude 的回答被截斷了該怎麼辦?

查看回應的 stop_reason,若為 max_tokens,表示輸出已達上限,請調高 max_tokens。開啟思考時,思考內容也會占用 max_tokens 的額度。

OfoxAI 的 Claude 由哪家供應商提供?

所有模型皆由 Amazon Bedrock 提供,為預設供應商;Fable 5、Opus 4.8、Opus 4.7、Sonnet 5 另有 Anthropic 供應商,僅限 Anthropic 原生介面,需透過 X-OfoxAI-Provider-Type: anthropic 請求標頭指定。

Claude 可以網路搜尋嗎?

可以,但需指定 Anthropic 供應商,僅限 Fable 5、Opus 4.8、Opus 4.7、Sonnet 5,且僅支援 Anthropic 原生介面。在 tools 中加入 {"type": "web_search_20250305", "name": "web_search"}。

Claude 可以讀取 PDF 嗎?

可以。原生介面使用 document 內容區塊傳入 base64 編碼的 PDF;OpenAI 相容介面使用 file 內容區塊,file_data 為 data:application/pdf;base64,... 格式。

最後更新於