curl --request POST \
--url https://api.eachlabs.ai/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "openai/gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Write a one sentence caption."
}
]
}
'import requests
url = "https://api.eachlabs.ai/v1/chat/completions"
payload = {
"model": "openai/gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Write a one sentence caption."
}
]
}
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: 'openai/gpt-4o-mini',
messages: [{role: 'user', content: 'Write a one sentence caption.'}]
})
};
fetch('https://api.eachlabs.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.eachlabs.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' => 'openai/gpt-4o-mini',
'messages' => [
[
'role' => 'user',
'content' => 'Write a one sentence caption.'
]
]
]),
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.eachlabs.ai/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"openai/gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Write a one sentence caption.\"\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.eachlabs.ai/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"openai/gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Write a one sentence caption.\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.eachlabs.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\": \"openai/gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Write a one sentence caption.\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1773651600,
"model": "eachlabs-llm-router",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "A cinematic sunset over the ocean."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 8,
"total_tokens": 20
}
}{
"error": {
"message": "Invalid API key",
"type": "authentication_error",
"param": "model",
"code": "invalid_api_key"
}
}{
"error": {
"message": "Invalid API key",
"type": "authentication_error",
"param": "model",
"code": "invalid_api_key"
}
}{
"error": {
"message": "Invalid API key",
"type": "authentication_error",
"param": "model",
"code": "invalid_api_key"
}
}{
"error": {
"message": "Invalid API key",
"type": "authentication_error",
"param": "model",
"code": "invalid_api_key"
}
}Create Chat Completion
OpenAI-compatible chat completions endpoint backed by Eachlabs LLM Router. Use
Authorization: Bearer <API_KEY> and point an OpenAI-compatible client at
https://api.eachlabs.ai/v1.
This endpoint uses the OpenAI-compatible error envelope rather than the REST error body described in the global contract notes.
curl --request POST \
--url https://api.eachlabs.ai/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "openai/gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Write a one sentence caption."
}
]
}
'import requests
url = "https://api.eachlabs.ai/v1/chat/completions"
payload = {
"model": "openai/gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Write a one sentence caption."
}
]
}
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: 'openai/gpt-4o-mini',
messages: [{role: 'user', content: 'Write a one sentence caption.'}]
})
};
fetch('https://api.eachlabs.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.eachlabs.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' => 'openai/gpt-4o-mini',
'messages' => [
[
'role' => 'user',
'content' => 'Write a one sentence caption.'
]
]
]),
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.eachlabs.ai/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"openai/gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Write a one sentence caption.\"\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.eachlabs.ai/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"openai/gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Write a one sentence caption.\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.eachlabs.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\": \"openai/gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Write a one sentence caption.\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1773651600,
"model": "eachlabs-llm-router",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "A cinematic sunset over the ocean."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 8,
"total_tokens": 20
}
}{
"error": {
"message": "Invalid API key",
"type": "authentication_error",
"param": "model",
"code": "invalid_api_key"
}
}{
"error": {
"message": "Invalid API key",
"type": "authentication_error",
"param": "model",
"code": "invalid_api_key"
}
}{
"error": {
"message": "Invalid API key",
"type": "authentication_error",
"param": "model",
"code": "invalid_api_key"
}
}{
"error": {
"message": "Invalid API key",
"type": "authentication_error",
"param": "model",
"code": "invalid_api_key"
}
}Authorizations
API key passed as an Authorization Bearer token: Authorization: Bearer YOUR_API_KEY
Headers
Optional webhook URL for asynchronous result delivery.
Body
OpenAI-compatible chat completions request body
LLM model identifier
"openai/gpt-4o-mini"
OpenAI-compatible chat messages
[
{
"role": "user",
"content": "Write a one sentence caption."
}
]
Set to true to receive OpenAI-compatible SSE chunks (text/event-stream) instead of a buffered JSON response.
false
Optional OpenAI-compatible streaming options. When include_usage is true, the stream may include a final usage chunk before [DONE].
Show child attributes
Show child attributes
Response
OpenAI-compatible chat completion. Requests with stream: true return Server-Sent Events.