import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'http://localhost:3030/api/v1/ai/chat',
apiKey: process.env.GAIA_API_KEY
});
const response = await client.chat.completions.create({
chatId: 'chat-123',
model: 'gpt-4o',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'What is RAG?' }
],
temperature: 0.7
});
console.log(response.choices[0].message.content);
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:3030/api/v1/ai/chat",
api_key="your-api-key"
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is RAG?"}
],
extra_body={"chatId": "chat-123"}
)
print(response.choices[0].message.content)
curl -X POST http://localhost:3030/api/v1/ai/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"chatId": "chat-123",
"model": "gpt-4o",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is RAG?"
}
],
"temperature": 0.7
}'
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "gpt-4o",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "RAG stands for Retrieval-Augmented Generation..."
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 100,
"total_tokens": 120
}
}
{
"success": false,
"message": "Unauthorized"
}
Chat Completions
OpenAI-compatible chat completion endpoint with streaming support
POST
/
ai
/
chat
/
completions
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'http://localhost:3030/api/v1/ai/chat',
apiKey: process.env.GAIA_API_KEY
});
const response = await client.chat.completions.create({
chatId: 'chat-123',
model: 'gpt-4o',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'What is RAG?' }
],
temperature: 0.7
});
console.log(response.choices[0].message.content);
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:3030/api/v1/ai/chat",
api_key="your-api-key"
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is RAG?"}
],
extra_body={"chatId": "chat-123"}
)
print(response.choices[0].message.content)
curl -X POST http://localhost:3030/api/v1/ai/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"chatId": "chat-123",
"model": "gpt-4o",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is RAG?"
}
],
"temperature": 0.7
}'
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "gpt-4o",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "RAG stands for Retrieval-Augmented Generation..."
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 100,
"total_tokens": 120
}
}
{
"success": false,
"message": "Unauthorized"
}
Create a chat completion with your configured AI agent. This endpoint is fully compatible with OpenAI’s API, allowing you to use existing OpenAI SDKs and tools.
Request Body
string
required
Chat session identifier for conversation continuity
array
required
string
default:"gpt-4o"
Model identifier to use for completion
string
Provider name (e.g., “openai”, “anthropic”, “ollama”)
number
Sampling temperature between 0 and 2. Higher values make output more random
number
Maximum number of tokens to generate
boolean
default:"false"
Whether to stream the response
Response
boolean
Indicates if the request was successful
string
Unique identifier for the completion
array
object
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'http://localhost:3030/api/v1/ai/chat',
apiKey: process.env.GAIA_API_KEY
});
const response = await client.chat.completions.create({
chatId: 'chat-123',
model: 'gpt-4o',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'What is RAG?' }
],
temperature: 0.7
});
console.log(response.choices[0].message.content);
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:3030/api/v1/ai/chat",
api_key="your-api-key"
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is RAG?"}
],
extra_body={"chatId": "chat-123"}
)
print(response.choices[0].message.content)
curl -X POST http://localhost:3030/api/v1/ai/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"chatId": "chat-123",
"model": "gpt-4o",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is RAG?"
}
],
"temperature": 0.7
}'
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "gpt-4o",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "RAG stands for Retrieval-Augmented Generation..."
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 100,
"total_tokens": 120
}
}
{
"success": false,
"message": "Unauthorized"
}
Streaming
Setstream: true to receive Server-Sent Events (SSE) instead of a single response:
const stream = await client.chat.completions.create({
chatId: 'chat-123',
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Hello!' }],
stream: true
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}
Notes
- Your agent will automatically use configured knowledge bases, tools, and MCP servers
- The
chatIdmaintains conversation context and history - Compatible with all OpenAI client libraries and tools

