Skip to content

AI API

The AI service provides a unified interface for AI completions across multiple providers.

Chat Completions

Send Chat Message

POST /ai/chat
{
"model": "gpt-4",
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "Hello!" }
]
}

Response:

{
"ok": true,
"data": {
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"usage": {
"prompt_tokens": 20,
"completion_tokens": 10,
"credit_cost": 5
}
}
}

List Models

GET /ai/models

Returns all available AI models for the current user:

{
"ok": true,
"data": [
{
"id": "gpt-4",
"provider": "openai",
"name": "GPT-4",
"credit_cost_per_1k": 10
}
]
}

API Keys

List Keys

GET /keys

Create Key

POST /keys
{
"name": "My API Key"
}

Delete Key

DELETE /keys/:id

Usage

Get Usage Stats

GET /ai/usage?period=30d

Returns aggregated AI usage statistics for the authenticated user.

Admin Endpoints

Provider Management

MethodPathDescription
GET/admin/ai/providersList all providers
POST/admin/ai/providersAdd a provider
PUT/admin/ai/providers/:idUpdate a provider

Model Management

MethodPathDescription
GET/admin/ai/modelsList all models
POST/admin/ai/modelsRegister a model
PUT/admin/ai/models/:idUpdate a model

Usage Statistics

MethodPathDescription
GET/admin/ai/statsAggregate usage stats
GET/admin/ai/usageDetailed usage logs