curl --request POST \
--url https://api.apiyi.com/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gpt-4o",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello, please introduce yourself."
}
]
}
'import requests
url = "https://api.apiyi.com/v1/chat/completions"
payload = {
"model": "gpt-4o",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello, please introduce yourself."
}
]
}
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: [
{role: 'system', content: 'You are a helpful assistant.'},
{role: 'user', content: 'Hello, please introduce yourself.'}
]
})
};
fetch('https://api.apiyi.com/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.apiyi.com/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' => [
[
'role' => 'system',
'content' => 'You are a helpful assistant.'
],
[
'role' => 'user',
'content' => 'Hello, please introduce yourself.'
]
]
]),
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.apiyi.com/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"gpt-4o\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are a helpful assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Hello, please introduce yourself.\"\n }\n ]\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.apiyi.com/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"gpt-4o\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are a helpful assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Hello, please introduce yourself.\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.apiyi.com/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 \"role\": \"system\",\n \"content\": \"You are a helpful assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Hello, please introduce yourself.\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1702855400,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! I'm an AI assistant, happy to help you. I can answer questions, write content, write code, and more. How can I assist you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 42,
"total_tokens": 67
}
}{
"error": {
"message": "Invalid API key provided",
"type": "invalid_request_error",
"param": "<string>",
"code": "invalid_api_key"
}
}{
"error": {
"message": "Invalid API key provided",
"type": "invalid_request_error",
"param": "<string>",
"code": "invalid_api_key"
}
}{
"error": {
"message": "Invalid API key provided",
"type": "invalid_request_error",
"param": "<string>",
"code": "invalid_api_key"
}
}{
"error": {
"message": "Invalid API key provided",
"type": "invalid_request_error",
"param": "<string>",
"code": "invalid_api_key"
}
}Chat Completions
Online playground for the chat completions endpoint — enter your API Key to send requests and view responses. POST /v1/chat/completions
curl --request POST \
--url https://api.apiyi.com/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gpt-4o",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello, please introduce yourself."
}
]
}
'import requests
url = "https://api.apiyi.com/v1/chat/completions"
payload = {
"model": "gpt-4o",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello, please introduce yourself."
}
]
}
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: [
{role: 'system', content: 'You are a helpful assistant.'},
{role: 'user', content: 'Hello, please introduce yourself.'}
]
})
};
fetch('https://api.apiyi.com/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.apiyi.com/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' => [
[
'role' => 'system',
'content' => 'You are a helpful assistant.'
],
[
'role' => 'user',
'content' => 'Hello, please introduce yourself.'
]
]
]),
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.apiyi.com/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"gpt-4o\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are a helpful assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Hello, please introduce yourself.\"\n }\n ]\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.apiyi.com/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"gpt-4o\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are a helpful assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Hello, please introduce yourself.\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.apiyi.com/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 \"role\": \"system\",\n \"content\": \"You are a helpful assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Hello, please introduce yourself.\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1702855400,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! I'm an AI assistant, happy to help you. I can answer questions, write content, write code, and more. How can I assist you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 42,
"total_tokens": 67
}
}{
"error": {
"message": "Invalid API key provided",
"type": "invalid_request_error",
"param": "<string>",
"code": "invalid_api_key"
}
}{
"error": {
"message": "Invalid API key provided",
"type": "invalid_request_error",
"param": "<string>",
"code": "invalid_api_key"
}
}{
"error": {
"message": "Invalid API key provided",
"type": "invalid_request_error",
"param": "<string>",
"code": "invalid_api_key"
}
}{
"error": {
"message": "Invalid API key provided",
"type": "invalid_request_error",
"param": "<string>",
"code": "invalid_api_key"
}
}Authorizations
API Key obtained from the APIYI Console
Body
Model name. APIYI supports 400+ models — just change the model name to switch between providers.
"gpt-4o"
"gpt-4o-mini"
"gpt-5-chat-latest"
"claude-sonnet-4-20250514"
"claude-opus-4-1-20250805"
"claude-3-5-haiku-20241022"
"gemini-2.5-pro"
"gemini-2.5-flash"
"gemini-2.0-flash"
"deepseek-r1"
"deepseek-v3-0324"
"grok-4-0709"
"grok-3"
"o4-mini"
"o3"
"qwen-max"
"glm-4-plus"
Array of conversation messages, supports multi-turn dialogue
Show child attributes
Show child attributes
[
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello, please introduce yourself."
}
]
Sampling temperature. Higher values (e.g., 0.8) make output more random, lower values (e.g., 0.2) make it more deterministic.
0 <= x <= 2Maximum number of tokens to generate. Different models have different limits.
x >= 1Nucleus sampling parameter. It is generally recommended not to modify both temperature and top_p.
0 <= x <= 1Number of completions to generate for each message.
x >= 1Whether to stream results. The Playground does not support streaming preview — use an SDK to test.
Stop sequence(s). Generation stops when this sequence is encountered. Up to 4.
Presence penalty. Positive values increase the likelihood of talking about new topics.
-2 <= x <= 2Frequency penalty. Positive values decrease the likelihood of repeating the same text verbatim.
-2 <= x <= 2A unique identifier for the end user, used for monitoring and abuse detection.
Response
Successfully returned chat completion result
Unique identifier for the request
"chatcmpl-abc123"
chat.completion "chat.completion"
Creation timestamp (Unix seconds)
1702855400
The model actually used
"gpt-4o"
Show child attributes
Show child attributes
Token usage statistics
Show child attributes
Show child attributes
Was this page helpful?