创建聊天补全
curl --request POST \
--url https://api.bianxie.ai/v1/chat/completionsimport requests
url = "https://api.bianxie.ai/v1/chat/completions"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.bianxie.ai/v1/chat/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.bianxie.ai/v1/chat/completions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.bianxie.ai/v1/chat/completions"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.bianxie.ai/v1/chat/completions")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.bianxie.ai/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_bodyOpenAI
创建聊天补全
根据消息列表生成回复
POST
/
v1
/
chat
/
completions
创建聊天补全
curl --request POST \
--url https://api.bianxie.ai/v1/chat/completionsimport requests
url = "https://api.bianxie.ai/v1/chat/completions"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.bianxie.ai/v1/chat/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.bianxie.ai/v1/chat/completions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.bianxie.ai/v1/chat/completions"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.bianxie.ai/v1/chat/completions")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.bianxie.ai/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_body使用 Bearer API Key。请求体为 JSON。
非流式响应包含
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 实时模型页中的模型 ID。 |
messages | array | 是 | 按顺序排列的 system、developer、user、assistant 或 tool 消息;内容可为字符串或内容块。 |
temperature | number | 否 | 采样温度。通常不要与 top_p 同时调整。 |
top_p | number | 否 | 核采样概率质量。 |
max_completion_tokens | integer | 否 | 生成 token 上限。 |
stream | boolean | 否 | 返回 SSE 增量;默认 false。 |
stop | string/array | 否 | 停止序列。是否支持取决于模型。 |
n | integer | 否 | 每个输入生成的选项数。 |
presence_penalty / frequency_penalty | number | 否 | 控制重复与新主题倾向。 |
response_format | object | 否 | 文本、JSON 对象或 JSON Schema 输出配置。 |
tools / tool_choice | array/object/string | 否 | 可调用工具定义及选择策略。 |
seed, user, metadata | mixed | 否 | 可复现提示、用户标识和元数据;支持情况依模型而定。 |
curl https://api.bianxie.ai/v1/chat/completions \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "your-model",
"messages": [{"role": "user", "content": "你好"}],
"temperature": 0.7
}'
client.chat.completions.create(model="your-model", messages=[{"role":"user","content":"你好"}])
await client.chat.completions.create({ model: "your-model", messages: [{ role: "user", content: "Hello" }] });
id、object、created、model、choices[] 和 usage。每个 choice 包含 index、message 与 finish_reason。流式响应返回增量 choices[].delta,直至结束事件。⌘I
