Create chat completion
OpenAI Chat Completions–compatible JSON body (model, messages, optional stream, tools, etc.). The server injects conversation history for the session, applies a default model when needed, and runs inference for you. Responses may be JSON or text/event-stream — server-sent events.
If the last user message is exactly /new, the API creates a new session and returns a minimal SSE stream without calling inference.
Billing: Requires spendable balance for the project; otherwise 402.
curl --request POST \
--url https://ageneral.ai/v1/chat/completions \
--header 'Ageneral-Project-Id: <ageneral-project-id>' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{}
],
"model": "openai/gpt-4o-mini",
"stream": true,
"temperature": 123,
"max_tokens": 123,
"tools": [
{}
]
}
'import requests
url = "https://ageneral.ai/v1/chat/completions"
payload = {
"messages": [{}],
"model": "openai/gpt-4o-mini",
"stream": True,
"temperature": 123,
"max_tokens": 123,
"tools": [{}]
}
headers = {
"Ageneral-Project-Id": "<ageneral-project-id>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'Ageneral-Project-Id': '<ageneral-project-id>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
messages: [{}],
model: 'openai/gpt-4o-mini',
stream: true,
temperature: 123,
max_tokens: 123,
tools: [{}]
})
};
fetch('https://ageneral.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://ageneral.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([
'messages' => [
[
]
],
'model' => 'openai/gpt-4o-mini',
'stream' => true,
'temperature' => 123,
'max_tokens' => 123,
'tools' => [
[
]
]
]),
CURLOPT_HTTPHEADER => [
"Ageneral-Project-Id: <ageneral-project-id>",
"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://ageneral.ai/v1/chat/completions"
payload := strings.NewReader("{\n \"messages\": [\n {}\n ],\n \"model\": \"openai/gpt-4o-mini\",\n \"stream\": true,\n \"temperature\": 123,\n \"max_tokens\": 123,\n \"tools\": [\n {}\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Ageneral-Project-Id", "<ageneral-project-id>")
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://ageneral.ai/v1/chat/completions")
.header("Ageneral-Project-Id", "<ageneral-project-id>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {}\n ],\n \"model\": \"openai/gpt-4o-mini\",\n \"stream\": true,\n \"temperature\": 123,\n \"max_tokens\": 123,\n \"tools\": [\n {}\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://ageneral.ai/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Ageneral-Project-Id"] = '<ageneral-project-id>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"messages\": [\n {}\n ],\n \"model\": \"openai/gpt-4o-mini\",\n \"stream\": true,\n \"temperature\": 123,\n \"max_tokens\": 123,\n \"tools\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_body{}Authorizations
Session JWT from Ageneral sign-in. Send as Authorization: Bearer <token>.
Headers
Project id. You must be a member with access.
Existing platform chat session to continue. Omit to create a new session on first non-/new turn.
Body
Aligned with OpenAI Create chat completion. The server may override or fill model and merges prior turns from storage.
Response
Success. JSON completion object or text/event-stream when streaming.
OpenAI-compatible chat completion object when not streaming.
curl --request POST \
--url https://ageneral.ai/v1/chat/completions \
--header 'Ageneral-Project-Id: <ageneral-project-id>' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{}
],
"model": "openai/gpt-4o-mini",
"stream": true,
"temperature": 123,
"max_tokens": 123,
"tools": [
{}
]
}
'import requests
url = "https://ageneral.ai/v1/chat/completions"
payload = {
"messages": [{}],
"model": "openai/gpt-4o-mini",
"stream": True,
"temperature": 123,
"max_tokens": 123,
"tools": [{}]
}
headers = {
"Ageneral-Project-Id": "<ageneral-project-id>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'Ageneral-Project-Id': '<ageneral-project-id>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
messages: [{}],
model: 'openai/gpt-4o-mini',
stream: true,
temperature: 123,
max_tokens: 123,
tools: [{}]
})
};
fetch('https://ageneral.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://ageneral.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([
'messages' => [
[
]
],
'model' => 'openai/gpt-4o-mini',
'stream' => true,
'temperature' => 123,
'max_tokens' => 123,
'tools' => [
[
]
]
]),
CURLOPT_HTTPHEADER => [
"Ageneral-Project-Id: <ageneral-project-id>",
"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://ageneral.ai/v1/chat/completions"
payload := strings.NewReader("{\n \"messages\": [\n {}\n ],\n \"model\": \"openai/gpt-4o-mini\",\n \"stream\": true,\n \"temperature\": 123,\n \"max_tokens\": 123,\n \"tools\": [\n {}\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Ageneral-Project-Id", "<ageneral-project-id>")
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://ageneral.ai/v1/chat/completions")
.header("Ageneral-Project-Id", "<ageneral-project-id>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {}\n ],\n \"model\": \"openai/gpt-4o-mini\",\n \"stream\": true,\n \"temperature\": 123,\n \"max_tokens\": 123,\n \"tools\": [\n {}\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://ageneral.ai/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Ageneral-Project-Id"] = '<ageneral-project-id>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"messages\": [\n {}\n ],\n \"model\": \"openai/gpt-4o-mini\",\n \"stream\": true,\n \"temperature\": 123,\n \"max_tokens\": 123,\n \"tools\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_body{}