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/modelsReturns 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 /keysCreate Key
POST /keys{ "name": "My API Key"}Delete Key
DELETE /keys/:idUsage
Get Usage Stats
GET /ai/usage?period=30dReturns aggregated AI usage statistics for the authenticated user.
Admin Endpoints
Provider Management
| Method | Path | Description |
|---|---|---|
GET | /admin/ai/providers | List all providers |
POST | /admin/ai/providers | Add a provider |
PUT | /admin/ai/providers/:id | Update a provider |
Model Management
| Method | Path | Description |
|---|---|---|
GET | /admin/ai/models | List all models |
POST | /admin/ai/models | Register a model |
PUT | /admin/ai/models/:id | Update a model |
Usage Statistics
| Method | Path | Description |
|---|---|---|
GET | /admin/ai/stats | Aggregate usage stats |
GET | /admin/ai/usage | Detailed usage logs |