文本与多模态对话
curl --request POST \
--url https://api.chenyu.cn/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"messages": [
{}
],
"messages[].role": "<string>",
"messages[].content": {},
"stream": true,
"temperature": 123,
"max_tokens": 123
}
'import requests
url = "https://api.chenyu.cn/v1/chat/completions"
payload = {
"model": "<string>",
"messages": [{}],
"messages[].role": "<string>",
"messages[].content": {},
"stream": True,
"temperature": 123,
"max_tokens": 123
}
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: '<string>',
messages: [{}],
'messages[].role': '<string>',
'messages[].content': {},
stream: true,
temperature: 123,
max_tokens: 123
})
};
fetch('https://api.chenyu.cn/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.chenyu.cn/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",
CURLOPT_POSTFIELDS => json_encode([
'model' => '<string>',
'messages' => [
[
]
],
'messages[].role' => '<string>',
'messages[].content' => [
],
'stream' => true,
'temperature' => 123,
'max_tokens' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.chenyu.cn/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"messages\": [\n {}\n ],\n \"messages[].role\": \"<string>\",\n \"messages[].content\": {},\n \"stream\": true,\n \"temperature\": 123,\n \"max_tokens\": 123\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))
}HttpResponse<String> response = Unirest.post("https://api.chenyu.cn/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"messages\": [\n {}\n ],\n \"messages[].role\": \"<string>\",\n \"messages[].content\": {},\n \"stream\": true,\n \"temperature\": 123,\n \"max_tokens\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.chenyu.cn/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"messages\": [\n {}\n ],\n \"messages[].role\": \"<string>\",\n \"messages[].content\": {},\n \"stream\": true,\n \"temperature\": 123,\n \"max_tokens\": 123\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"object": "<string>",
"model": "<string>",
"choices": [
{
"message.role": "<string>",
"message.content": "<string>",
"finish_reason": "<string>"
}
],
"usage": {}
}直接 API 调用
文本与多模态对话
使用 OpenAI Chat Completions 格式调用文本和视觉模型
POST
/
v1
/
chat
/
completions
文本与多模态对话
curl --request POST \
--url https://api.chenyu.cn/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"messages": [
{}
],
"messages[].role": "<string>",
"messages[].content": {},
"stream": true,
"temperature": 123,
"max_tokens": 123
}
'import requests
url = "https://api.chenyu.cn/v1/chat/completions"
payload = {
"model": "<string>",
"messages": [{}],
"messages[].role": "<string>",
"messages[].content": {},
"stream": True,
"temperature": 123,
"max_tokens": 123
}
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: '<string>',
messages: [{}],
'messages[].role': '<string>',
'messages[].content': {},
stream: true,
temperature: 123,
max_tokens: 123
})
};
fetch('https://api.chenyu.cn/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.chenyu.cn/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",
CURLOPT_POSTFIELDS => json_encode([
'model' => '<string>',
'messages' => [
[
]
],
'messages[].role' => '<string>',
'messages[].content' => [
],
'stream' => true,
'temperature' => 123,
'max_tokens' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.chenyu.cn/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"messages\": [\n {}\n ],\n \"messages[].role\": \"<string>\",\n \"messages[].content\": {},\n \"stream\": true,\n \"temperature\": 123,\n \"max_tokens\": 123\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))
}HttpResponse<String> response = Unirest.post("https://api.chenyu.cn/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"messages\": [\n {}\n ],\n \"messages[].role\": \"<string>\",\n \"messages[].content\": {},\n \"stream\": true,\n \"temperature\": 123,\n \"max_tokens\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.chenyu.cn/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"messages\": [\n {}\n ],\n \"messages[].role\": \"<string>\",\n \"messages[].content\": {},\n \"stream\": true,\n \"temperature\": 123,\n \"max_tokens\": 123\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"object": "<string>",
"model": "<string>",
"choices": [
{
"message.role": "<string>",
"message.content": "<string>",
"finish_reason": "<string>"
}
],
"usage": {}
}文本与多模态对话
使用 OpenAI Chat Completions 兼容格式调用文本模型或视觉模型。支持普通文本、图片输入、多图输入和流式响应。请求参数
对话消息列表
消息角色,支持
system、user、assistant消息内容。文本模型可传字符串;视觉模型可传 OpenAI 多模态 content 数组
是否使用 Server-Sent Events 流式响应
采样温度
最大输出 token 数
响应参数
响应 ID
响应类型,通常为
chat.completion实际调用的模型 ID
token 用量
代码示例
import requests
url = "https://api.chenyu.cn/v1/chat/completions"
headers = {
"Authorization": "Bearer your_api_key",
"Content-Type": "application/json"
}
payload = {
"model": "doubao-seed-2-0-lite-260428",
"messages": [
{"role": "user", "content": "你好,简单介绍一下你自己"}
]
}
response = requests.post(url, headers=headers, json=payload)
print(response.json()["choices"][0]["message"]["content"])
const axios = require('axios');
axios.post('https://api.chenyu.cn/v1/chat/completions', {
model: 'doubao-seed-2-0-lite-260428',
messages: [
{ role: 'user', content: '你好,简单介绍一下你自己' }
]
}, {
headers: {
Authorization: 'Bearer your_api_key',
'Content-Type': 'application/json'
}
}).then((response) => {
console.log(response.data.choices[0].message.content);
});
curl -X POST "https://api.chenyu.cn/v1/chat/completions" \
-H "Authorization: Bearer your_api_key" \
-H "Content-Type: application/json" \
-d '{
"model": "doubao-seed-2-0-lite-260428",
"messages": [
{"role": "user", "content": "你好,简单介绍一下你自己"}
]
}'
多模态示例
{
"model": "doubao-seed-1-6-vision-250815",
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": "这张图片里有什么?"},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/image.png"
}
}
]
}
]
}
响应示例
{
"id": "chatcmpl_xxx",
"object": "chat.completion",
"created": 1780000000,
"model": "doubao-seed-2-0-lite-260428",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好,我是晨羽智云大模型服务。"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 12,
"total_tokens": 32
}
}
⌘I