OpenAI chat completions
curl --request POST \
--url https://maas.apigo.ai/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gpt-4o",
"messages": [
{
"content": "<string>"
}
],
"temperature": 1,
"stream": true
}
'import requests
url = "https://maas.apigo.ai/v1/chat/completions"
payload = {
"model": "gpt-4o",
"messages": [{ "content": "<string>" }],
"temperature": 1,
"stream": True
}
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-4o',
messages: [{content: '<string>'}],
temperature: 1,
stream: true
})
};
fetch('https://maas.apigo.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://maas.apigo.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",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'gpt-4o',
'messages' => [
[
'content' => '<string>'
]
],
'temperature' => 1,
'stream' => true
]),
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://maas.apigo.ai/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"gpt-4o\",\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"temperature\": 1,\n \"stream\": true\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://maas.apigo.ai/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"gpt-4o\",\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"temperature\": 1,\n \"stream\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://maas.apigo.ai/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\": \"gpt-4o\",\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"temperature\": 1,\n \"stream\": true\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"object": "chat.completion",
"choices": [
{
"index": 123,
"message": {
"content": "<string>"
},
"finish_reason": "<string>"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123
}
}{
"error": 123,
"message": "<string>"
}文本
/v1/chat/completions
다중 대화, 도구 호출 및 스트리밍 응답을 위한 OpenAI 호환 채팅 완료 엔드포인트입니다.
POST
/
v1
/
chat
/
completions
OpenAI chat completions
curl --request POST \
--url https://maas.apigo.ai/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gpt-4o",
"messages": [
{
"content": "<string>"
}
],
"temperature": 1,
"stream": true
}
'import requests
url = "https://maas.apigo.ai/v1/chat/completions"
payload = {
"model": "gpt-4o",
"messages": [{ "content": "<string>" }],
"temperature": 1,
"stream": True
}
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-4o',
messages: [{content: '<string>'}],
temperature: 1,
stream: true
})
};
fetch('https://maas.apigo.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://maas.apigo.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",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'gpt-4o',
'messages' => [
[
'content' => '<string>'
]
],
'temperature' => 1,
'stream' => true
]),
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://maas.apigo.ai/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"gpt-4o\",\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"temperature\": 1,\n \"stream\": true\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://maas.apigo.ai/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"gpt-4o\",\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"temperature\": 1,\n \"stream\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://maas.apigo.ai/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\": \"gpt-4o\",\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"temperature\": 1,\n \"stream\": true\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"object": "chat.completion",
"choices": [
{
"index": 123,
"message": {
"content": "<string>"
},
"finish_reason": "<string>"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123
}
}{
"error": 123,
"message": "<string>"
}用于为一段聊天对话生成模型回复。
这个接口适合标准文本对话,也可以承载视觉、音频和工具调用等场景。具体可用参数会随着模型能力不同而变化,尤其是推理模型与通用模型之间会有差异。
接入说明
- 鉴权方式使用
Authorization: Bearer {API_KEY} - 请求体通常至少包含
messages和model - 如果你在兼容现有 OpenAI SDK、聊天前端或多轮对话工作流,这通常是默认入口
- 如果你更看重统一的结构化输出、多模态输入和后续能力扩展,可以优先评估
/v1/responses - 开启流式返回时,请按 SSE chunk 增量处理,而不是等待完整 JSON
请求重点
messages是必填字段,用于承载完整对话历史;不同模型支持的消息模态可能不同model是必填字段,用于指定本次调用的模型 IDtemperature和top_p都会影响采样行为,通常只需要重点调整其中一个- 如果需要更丰富的调试或概率信息,可以结合
logprobs与top_logprobs - 如果需要缓存优化或安全归因,优先使用
prompt_cache_key与safety_identifier
返回重点
- 常规文本结果通常从
choices[0].message.content读取 - 如果模型触发工具调用,可以从
message.tool_calls中读取工具名称和参数 - 流式模式下,返回内容会分段推送,客户端需要持续消费事件流
- 用量统计可以从
usage中读取,包括输入、输出和更细粒度的 token 明细
授权
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
请求体
application/json
⌘I
