Create chat completion
curl --request POST \
--url https://api.aisa.one/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gpt-4.1",
"messages": [
{
"role": "user",
"content": "<string>"
}
],
"stream": false,
"logprobs": true,
"top_logprobs": 123,
"functions": [
{
"name": "<string>",
"description": "<string>",
"parameters": {}
}
],
"function_call": "auto"
}
'import requests
url = "https://api.aisa.one/v1/chat/completions"
payload = {
"model": "gpt-4.1",
"messages": [
{
"role": "user",
"content": "<string>"
}
],
"stream": False,
"logprobs": True,
"top_logprobs": 123,
"functions": [
{
"name": "<string>",
"description": "<string>",
"parameters": {}
}
],
"function_call": "auto"
}
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-4.1',
messages: [{role: 'user', content: '<string>'}],
stream: false,
logprobs: true,
top_logprobs: 123,
functions: [{name: '<string>', description: '<string>', parameters: {}}],
function_call: 'auto'
})
};
fetch('https://api.aisa.one/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.aisa.one/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-4.1',
'messages' => [
[
'role' => 'user',
'content' => '<string>'
]
],
'stream' => false,
'logprobs' => true,
'top_logprobs' => 123,
'functions' => [
[
'name' => '<string>',
'description' => '<string>',
'parameters' => [
]
]
],
'function_call' => 'auto'
]),
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.aisa.one/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"gpt-4.1\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"<string>\"\n }\n ],\n \"stream\": false,\n \"logprobs\": true,\n \"top_logprobs\": 123,\n \"functions\": [\n {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {}\n }\n ],\n \"function_call\": \"auto\"\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.aisa.one/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"gpt-4.1\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"<string>\"\n }\n ],\n \"stream\": false,\n \"logprobs\": true,\n \"top_logprobs\": 123,\n \"functions\": [\n {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {}\n }\n ],\n \"function_call\": \"auto\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.aisa.one/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-4.1\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"<string>\"\n }\n ],\n \"stream\": false,\n \"logprobs\": true,\n \"top_logprobs\": 123,\n \"functions\": [\n {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {}\n }\n ],\n \"function_call\": \"auto\"\n}"
response = http.request(request)
puts response.read_bodyChat API
OpenAI Chat
Create chat completion
POST
https://api.aisa.one/v1
/
chat
/
completions
Create chat completion
curl --request POST \
--url https://api.aisa.one/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gpt-4.1",
"messages": [
{
"role": "user",
"content": "<string>"
}
],
"stream": false,
"logprobs": true,
"top_logprobs": 123,
"functions": [
{
"name": "<string>",
"description": "<string>",
"parameters": {}
}
],
"function_call": "auto"
}
'import requests
url = "https://api.aisa.one/v1/chat/completions"
payload = {
"model": "gpt-4.1",
"messages": [
{
"role": "user",
"content": "<string>"
}
],
"stream": False,
"logprobs": True,
"top_logprobs": 123,
"functions": [
{
"name": "<string>",
"description": "<string>",
"parameters": {}
}
],
"function_call": "auto"
}
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-4.1',
messages: [{role: 'user', content: '<string>'}],
stream: false,
logprobs: true,
top_logprobs: 123,
functions: [{name: '<string>', description: '<string>', parameters: {}}],
function_call: 'auto'
})
};
fetch('https://api.aisa.one/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.aisa.one/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-4.1',
'messages' => [
[
'role' => 'user',
'content' => '<string>'
]
],
'stream' => false,
'logprobs' => true,
'top_logprobs' => 123,
'functions' => [
[
'name' => '<string>',
'description' => '<string>',
'parameters' => [
]
]
],
'function_call' => 'auto'
]),
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.aisa.one/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"gpt-4.1\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"<string>\"\n }\n ],\n \"stream\": false,\n \"logprobs\": true,\n \"top_logprobs\": 123,\n \"functions\": [\n {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {}\n }\n ],\n \"function_call\": \"auto\"\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.aisa.one/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"gpt-4.1\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"<string>\"\n }\n ],\n \"stream\": false,\n \"logprobs\": true,\n \"top_logprobs\": 123,\n \"functions\": [\n {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {}\n }\n ],\n \"function_call\": \"auto\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.aisa.one/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-4.1\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"<string>\"\n }\n ],\n \"stream\": false,\n \"logprobs\": true,\n \"top_logprobs\": 123,\n \"functions\": [\n {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {}\n }\n ],\n \"function_call\": \"auto\"\n}"
response = http.request(request)
puts response.read_bodyCreates a model response for the given chat conversation. Learn more in the
text generation, vision,
and audio guides.
Parameter support can differ depending on the model used to generate the
response, particularly for newer reasoning models. Parameters that are only
supported for reasoning models are noted below. For the current state of
unsupported parameters in reasoning models,
refer to the reasoning guide.
Streaming responses
Set"stream": true to receive server-sent events (SSE) as each token is generated. This produces a lower time-to-first-token and is ideal for chat UIs.
curl https://api.aisa.one/v1/chat/completions \
-H "Authorization: Bearer $AISA_API_KEY" \
-H "Content-Type: application/json" \
-N \
-d '{
"model": "gpt-5",
"messages": [{"role": "user", "content": "Write a haiku about APIs."}],
"stream": true
}'
from openai import OpenAI
client = OpenAI(base_url="https://api.aisa.one/v1", api_key="sk-aisa-...")
stream = client.chat.completions.create(
model="gpt-5",
messages=[{"role": "user", "content": "Write a haiku about APIs."}],
stream=True,
)
for chunk in stream:
delta = chunk.choices[0].delta.content or ""
print(delta, end="", flush=True)
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.aisa.one/v1",
apiKey: process.env.AISA_API_KEY,
});
const stream = await client.chat.completions.create({
model: "gpt-5",
messages: [{ role: "user", content: "Write a haiku about APIs." }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
Stream anatomy
Each line of the SSE stream looks like:data: {"id":"chatcmpl-...","choices":[{"delta":{"content":"Quiet"},"index":0}]}
data: {"id":"chatcmpl-...","choices":[{"delta":{"content":" packets"},"index":0}]}
...
data: {"id":"chatcmpl-...","choices":[{"delta":{},"finish_reason":"stop","index":0}]}
data: [DONE]
- Each
data:line is a JSON object. The first chunk includes therole; subsequent chunks contain onlydelta.content. - The stream ends with a final chunk whose
finish_reasonis set, followed by a literaldata: [DONE]line. - If tool calls are used,
delta.tool_callsarrives incrementally and should be concatenated byindex.
Handling errors and timeouts
- Mid-stream errors arrive as a normal SSE event with an
errorkey instead ofchoices. Close the stream and surface the error to the caller. - Stream disconnects (network blip, client timeout) cannot be resumed — restart the request. The partial response is not billed beyond the tokens you received.
- Idle timeout: AIsa closes streams that are idle (no tokens) for more than 60 s. Set your client read timeout to 120 s to give a safety margin.
- Client backpressure: stop reading from the stream if your downstream consumer is slow — AIsa throttles delivery rather than dropping tokens.
Streaming bills the same per-token rate as non-streaming. You pay for tokens that were delivered, even if the stream is cut off mid-response.
Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
application/json
Response
200
Successful completion