curl --request POST \
--url https://api.yourapp.com/api/ai/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"chatId": "chat_123",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is the capital of France?"
}
],
"model": "gpt-4o",
"temperature": 0.7,
"stream": false
}'
const response = await fetch('https://api.yourapp.com/api/ai/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
chatId: 'chat_123',
messages: [
{
role: 'system',
content: 'You are a helpful assistant.'
},
{
role: 'user',
content: 'What is the capital of France?'
}
],
model: 'gpt-4o',
temperature: 0.7,
stream: false
})
});
const data = await response.json();
import requests
url = "https://api.yourapp.com/api/ai/chat/completions"
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
payload = {
"chatId": "chat_123",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is the capital of France?"
}
],
"model": "gpt-4o",
"temperature": 0.7,
"stream": False
}
response = requests.post(url, json=payload, headers=headers)
data = response.json()
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The capital of France is Paris."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 8,
"total_tokens": 28
}
}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"role":"assistant","content":"The"},"finish_reason":null}]}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"content":" capital"},"finish_reason":null}]}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"content":" of"},"finish_reason":null}]}
data: [DONE]
{
"success": false,
"message": "Unauthorized"
}
AI
Chat Completions
OpenAI-compatible chat completion endpoint with streaming support
POST
/
api
/
ai
/
chat
/
completions
curl --request POST \
--url https://api.yourapp.com/api/ai/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"chatId": "chat_123",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is the capital of France?"
}
],
"model": "gpt-4o",
"temperature": 0.7,
"stream": false
}'
const response = await fetch('https://api.yourapp.com/api/ai/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
chatId: 'chat_123',
messages: [
{
role: 'system',
content: 'You are a helpful assistant.'
},
{
role: 'user',
content: 'What is the capital of France?'
}
],
model: 'gpt-4o',
temperature: 0.7,
stream: false
})
});
const data = await response.json();
import requests
url = "https://api.yourapp.com/api/ai/chat/completions"
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
payload = {
"chatId": "chat_123",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is the capital of France?"
}
],
"model": "gpt-4o",
"temperature": 0.7,
"stream": False
}
response = requests.post(url, json=payload, headers=headers)
data = response.json()
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The capital of France is Paris."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 8,
"total_tokens": 28
}
}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"role":"assistant","content":"The"},"finish_reason":null}]}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"content":" capital"},"finish_reason":null}]}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"content":" of"},"finish_reason":null}]}
data: [DONE]
{
"success": false,
"message": "Unauthorized"
}
Request Body
string
required
Chat session identifier
array
required
string
default:"gpt-4o"
Model identifier
string
Provider name (e.g., OpenAI, Anthropic, Google)
number
default:"0.7"
Sampling temperature (0.0 to 2.0)
number
Maximum number of tokens to generate
boolean
default:"false"
Enable streaming response
Response
string
Completion ID
string
Object type (chat.completion)
number
Unix timestamp of creation
string
Model used for completion
array
Array of completion choices
object
Token usage information
curl --request POST \
--url https://api.yourapp.com/api/ai/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"chatId": "chat_123",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is the capital of France?"
}
],
"model": "gpt-4o",
"temperature": 0.7,
"stream": false
}'
const response = await fetch('https://api.yourapp.com/api/ai/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
chatId: 'chat_123',
messages: [
{
role: 'system',
content: 'You are a helpful assistant.'
},
{
role: 'user',
content: 'What is the capital of France?'
}
],
model: 'gpt-4o',
temperature: 0.7,
stream: false
})
});
const data = await response.json();
import requests
url = "https://api.yourapp.com/api/ai/chat/completions"
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
payload = {
"chatId": "chat_123",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is the capital of France?"
}
],
"model": "gpt-4o",
"temperature": 0.7,
"stream": False
}
response = requests.post(url, json=payload, headers=headers)
data = response.json()
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The capital of France is Paris."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 8,
"total_tokens": 28
}
}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"role":"assistant","content":"The"},"finish_reason":null}]}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"content":" capital"},"finish_reason":null}]}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"content":" of"},"finish_reason":null}]}
data: [DONE]
{
"success": false,
"message": "Unauthorized"
}
⌘I

