curl
使用 HTTP 和 curl 調用 HopBase 的相容介面。
| 模型類型 | 協議與端點 | 鑑權 |
|---|---|---|
| GPT / Gemini / GLM | POST https://api.hop-base.com/v1/chat/completions | Authorization: Bearer |
| Claude | POST https://api.hop-base.com/v1/messages | x-api-key |
| 圖片 | POST https://api.hop-base.com/v1/images/generations | Authorization: Bearer |
鑑權與通用限制
| 項目 | 規則 | 不符合時 |
|---|---|---|
| 金鑰請求頭 | Authorization: Bearer sk-… 或 x-api-key: sk-…,所有端點都接受;不支援 x-goog-api-key 與 URL 參數 ?key= | 401 missing_api_key / invalid_api_key |
| 端點與分組 | 每個請求都要用該模型協議的端點(例如 Claude 模型只能透過 /v1/messages 調用) | 404「当前平台不支持该 API 路径」 |
| 模型 | 必須是當前金鑰所含分組內的模型 | 404 model_not_found |
| 請求體大小 | 整個請求體 ≤ 60 MB | 413 |
GET /v1/models | 返回當前金鑰可用的模型 ID;不計費 | — |
請使用當前分組金鑰在 GET /v1/models 中實際返回的模型 ID。金鑰只能調用它所含分組的模型。
Claude 請顯式設定 max_tokens:
Claude 請求不傳 max_tokens 不會報錯,會被補為 4096:長輸出在 4096 處截斷(stop_reason: "max_tokens"),請顯式設定。
OpenAI 協議(GPT 模型)
curl https://api.hop-base.com/v1/chat/completions \
-H "Authorization: Bearer sk-你的金鑰" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.6-sol",
"messages": [{"role": "user", "content": "你好"}]
}'Anthropic 協議(Claude 模型)
curl https://api.hop-base.com/v1/messages \
-H "x-api-key: sk-你的金鑰" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "你好"}]
}'串流輸出(加 "stream": true)
curl https://api.hop-base.com/v1/chat/completions \
-H "Authorization: Bearer sk-你的金鑰" \
-H "Content-Type: application/json" \
-d '{"model": "gpt-5.6-sol", "stream": true,
"messages": [{"role": "user", "content": "你好"}]}'下一步
- 各協議的參數限制見 OpenAI SDK、Anthropic SDK、Gemini 對話 與圖片生成 API
- 報錯時看報錯速查