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": {
"role": "system",
"content": "<string>"
},
"finish_reason": "<string>"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123
}
}{
"error": 123,
"message": "<string>"
}Text
/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": {
"role": "system",
"content": "<string>"
},
"finish_reason": "<string>"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123
}
}{
"error": 123,
"message": "<string>"
}チャット会話のモデル応答を作成します。
既存の OpenAI SDK、チャット クライアント、または従来のチャット完了ワークフローとの互換性が必要な場合、このエンドポイントが依然として最も安全なデフォルトです。サポートされるフィールドは、特に推論、ツールの使用、マルチモーダル入力など、モデルによって異なります。
統合ガイダンス
Authorization: Bearer {API_KEY}で認証する- これを既存の OpenAI スタイルのチャット統合のデフォルトのエントリ ポイントとして使用します
- 構造化された出力、マルチモーダル入力、およびツールのためのより統合されたインターフェイスが必要な場合は、
/v1/responsesをお勧めします。 - ストリーミング クライアントは、最後の JSON 応答を待つのではなく、SSE チャンクを段階的に処理する必要があります。
リクエストのハイライト
messagesが必要であり、会話履歴を保持しますmodelは必須であり、ターゲットモデルを選択しますtemperatureとtop_pは両方ともサンプリングに影響しますが、ほとんどの統合ではどちらか 1 つだけを調整する必要があります。- トークンレベルの確率が必要な場合は、
logprobsとtop_logprobsを組み合わせます。 - キャッシュと安全性の帰属については、
prompt_cache_keyおよびsafety_identifierを推奨します。
回答のハイライト
- 通常、プレーンテキストは
choices[0].message.contentから読み取られます。 - ツール呼び出しは
message.tool_callsから読み取ることができます - ストリーミング応答は SSE チャンクとして到着するため、段階的にマージする必要があります
- 使用状況のアカウンティングは、より詳細なトークンの内訳を含め、
usageを通じて公開されます。
承認
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
ボディ
application/json
