按能力
对话
选模型、复制请求、读回复。所有对话模型都用同一种 OpenAI 格式的请求。
#1. 选模型
gpt-6.1-sol输入 $0.20 · 输出 $1.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.1 Sol",
"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 或报错信息发给我们,我们来查。