按能力
對話
選模型、複製請求、讀回覆。所有對話模型都用同一種 OpenAI 格式的請求。
#1. 選模型
gpt-6-astra輸入 $1.00 · 輸出 $5.00 / 1M限制和狀態
這個能力有 5 個線上模型,切換後下面的程式碼會跟著變。
#2. 複製請求
把 YOUR_API_KEY 換成你的金鑰再執行。顯示的選項都是這個模型支援的。
https://www.aisplice.store/v1/chat/completionsBearer API key直接回傳API_KEY="${API_KEY:-YOUR_API_KEY}"
curl --fail-with-body -sS https://www.aisplice.store/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "GPT-6 Astra",
"messages": [
{
"role": "user",
"content": "Say hello."
}
],
"stream": false
}'全部參數
這個模型支援的全部欄位和可選值。
全部參數
這個模型支援的全部欄位和可選值。
model本次請求使用的精確模型識別碼。
messagesRequired on /v1/chat/completions.
inputRequired on /v1/responses.
回應流程
檢視該端點的成功回應範例。
回應流程
檢視該端點的成功回應範例。
{
"id": "chatcmpl_xxx",
"choices": [
{
"message": {
"role": "assistant",
"content": "Hello!"
}
}
]
}#3. 拿到結果
回傳 200 時,回答在 choices[0].message.content 裡。加上 "stream": true 可以邊生成邊接收。
#出錯了怎麼辦
- 400 並提示某個欄位:這個模型不支援該選項,用第 2 步列出的取值。
- 402:餘額不夠這次請求,到「錢包」儲值後重試。
- 429:請求太快,按 Retry-After 給的秒數等一下再試。
- 503 model_not_found:模型名寫錯了或模型暫時下線,從第 1 步重新選一個。
串流邊生成邊顯示回覆。
#工作原理
設 stream:true,閘道按 OpenAI 原樣轉發 Server-Sent Events:每個增量一個 data: 訊框,以 data: [DONE] 收尾。任何 SSE 客戶端或官方 SDK 都能直接使用。
#執行看看
curl -N https://www.aisplice.store/v1/chat/completions \
-H "Authorization: Bearer sk-YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.6-luna",
"stream": true,
"messages": [
{
"role": "user",
"content": "Write a haiku about the sea."
}
]
}'from openai import OpenAI
client = OpenAI(base_url="https://www.aisplice.store/v1", api_key="sk-YOUR_KEY")
stream = client.chat.completions.create(
model="gpt-5.6-luna",
stream=True,
messages=[{"role": "user", "content": "Write a haiku about the sea."}],
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")#按實際計費
只按已串流輸出的用量計費
工具呼叫讓模型呼叫你自己的函式。
#宣告工具
傳送標準的 OpenAI tools 陣列。閘道會把它轉發給所有支援工具的模型——OpenAI、Claude、Gemini、DeepSeek——並把回覆統一成 tool_calls。支援串流工具呼叫增量。
curl https://www.aisplice.store/v1/chat/completions \
-H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
-d '{
"model": "gpt-5.6-luna",
"messages": [{"role":"user","content":"Weather in Tokyo?"}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}
}]
}'#處理 tool_calls
模型決定呼叫工具時,choice 會帶著 finish_reason:"tool_calls" 回傳,arguments 是一個字串,由你的程式碼解析並執行。
{
"choices": [{
"finish_reason": "tool_calls",
"message": {
"role": "assistant",
"tool_calls": [{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\": \"Tokyo\"}"
}
}]
}
}]
}#回傳結果
把 assistant 輪次和每個呼叫對應的一條 role:"tool" 訊息(用 tool_call_id 對齊)追加進 messages 再請求一次——模型會把結果併入最終回答。
curl https://www.aisplice.store/v1/chat/completions \
-H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
-d '{
"model": "gpt-5.6-luna",
"messages": [
{"role":"user","content":"Weather in Tokyo?"},
{"role":"assistant","tool_calls":[{"id":"call_abc123","type":"function",
"function":{"name":"get_weather","arguments":"{\"city\":\"Tokyo\"}"}}]},
{"role":"tool","tool_call_id":"call_abc123","content":"{\"temp_c\": 22, \"sky\": \"clear\"}"}
]
}'圖片輸入在文字之外再傳送圖片。
#傳送圖片
支援視覺的對話模型接受混合 text 與 image_url 分段的 content 陣列。公開 URL 或內嵌 base64 data URL 都行——用的是同一個欄位。
curl https://www.aisplice.store/v1/chat/completions \
-H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
-d '{
"model": "gpt-5.6-luna",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "What is in this image?"},
{"type": "image_url", "image_url": {"url": "https://example.com/cat.png"}}
]
}]
}'#Base64 圖片
本機檔案用 data URL 內嵌:"url": "data:image/png;base64,<bytes>"。圖片 token 按輸入 token 計費;單一請求的圖片大小和數量上限取決於廠商——傳送前先縮小能省錢。
import base64
from openai import OpenAI
client = OpenAI(base_url="https://www.aisplice.store/v1", api_key="sk-YOUR_KEY")
b64 = base64.b64encode(open("photo.png", "rb").read()).decode()
resp = client.chat.completions.create(
model="gpt-5.6-luna",
messages=[{"role": "user", "content": [
{"type": "text", "text": "Describe this photo."},
{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{b64}"}},
]}],
)
print(resp.choices[0].message.content)還是沒解決?
把請求 ID 或錯誤訊息傳給我們,我們來查。