使用 OpenAI 兼容格式调用文本模型
POST
/
v1
/
chat
/
completions
创建聊天补全
curl --request POST \
--url https://suanwuyou.com.cn/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gpt-5.5",
"messages": [
{
"role": "user",
"content": "帮我生成一段使用 Go 语言定制的团购逻辑"
}
],
"reasoning_effort": "high",
"max_tokens": 500,
"stream": false
}
'import requests
url = "https://suanwuyou.com.cn/v1/chat/completions"
payload = {
"model": "gpt-5.5",
"messages": [
{
"role": "user",
"content": "帮我生成一段使用 Go 语言定制的团购逻辑"
}
],
"reasoning_effort": "high",
"max_tokens": 500,
"stream": False
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'gpt-5.5',
messages: [{role: 'user', content: '帮我生成一段使用 Go 语言定制的团购逻辑'}],
reasoning_effort: 'high',
max_tokens: 500,
stream: false
})
};
fetch('https://suanwuyou.com.cn/v1/chat/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://suanwuyou.com.cn/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"gpt-5.5\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"帮我生成一段使用 Go 语言定制的团购逻辑\"\n }\n ],\n \"reasoning_effort\": \"high\",\n \"max_tokens\": 500,\n \"stream\": false\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"id": "chatcmpl-example",
"object": "chat.completion",
"created": 1784246400,
"model": "gpt-5.5",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "下面给出一个使用 Go 实现的团购核心逻辑示例。"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 14,
"completion_tokens": 20,
"total_tokens": 34
}
}{
"error": {
"message": "请求参数不正确",
"type": "invalid_request_error",
"code": "invalid_parameter"
}
}{
"error": {
"message": "invalid api key",
"type": "invalid_request_error",
"code": "unauthorized"
}
}页面右侧代码会随输入参数同步更新,并支持复制。鉴权处填写算无忧控制台生成的令牌,不要填写模型厂商官方 Key。
reasoning_effort 和 max_tokens 属于模型相关扩展参数,并非所有模型都支持。当前示例不传递 thinking,并使用非流式响应,即 stream: false。Authorizations
填写完整的 Bearer 鉴权值,例如 Bearer sk-你的算无忧令牌。
Body
application/json
控制台或模型列表接口返回的模型名。
Example:
"gpt-5.5"
Minimum array length:
1Show child attributes
Show child attributes
Example:
[{ "role": "user", "content": "你好" }]是否使用流式响应。
随机程度;具体支持范围由模型决定。
Required range:
0 <= x <= 2最大输出 token;具体是否支持由模型决定。
Required range:
x >= 1模型支持时启用思考模式。
Show child attributes
Show child attributes
模型支持时设置推理强度。
Available options:
low, medium, high ⌘I
创建聊天补全
curl --request POST \
--url https://suanwuyou.com.cn/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gpt-5.5",
"messages": [
{
"role": "user",
"content": "帮我生成一段使用 Go 语言定制的团购逻辑"
}
],
"reasoning_effort": "high",
"max_tokens": 500,
"stream": false
}
'import requests
url = "https://suanwuyou.com.cn/v1/chat/completions"
payload = {
"model": "gpt-5.5",
"messages": [
{
"role": "user",
"content": "帮我生成一段使用 Go 语言定制的团购逻辑"
}
],
"reasoning_effort": "high",
"max_tokens": 500,
"stream": False
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'gpt-5.5',
messages: [{role: 'user', content: '帮我生成一段使用 Go 语言定制的团购逻辑'}],
reasoning_effort: 'high',
max_tokens: 500,
stream: false
})
};
fetch('https://suanwuyou.com.cn/v1/chat/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://suanwuyou.com.cn/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"gpt-5.5\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"帮我生成一段使用 Go 语言定制的团购逻辑\"\n }\n ],\n \"reasoning_effort\": \"high\",\n \"max_tokens\": 500,\n \"stream\": false\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"id": "chatcmpl-example",
"object": "chat.completion",
"created": 1784246400,
"model": "gpt-5.5",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "下面给出一个使用 Go 实现的团购核心逻辑示例。"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 14,
"completion_tokens": 20,
"total_tokens": 34
}
}{
"error": {
"message": "请求参数不正确",
"type": "invalid_request_error",
"code": "invalid_parameter"
}
}{
"error": {
"message": "invalid api key",
"type": "invalid_request_error",
"code": "unauthorized"
}
}