API Reference
Complete API documentation for CoAI.Dev platform integration
API Reference
Complete reference for CoAI.Dev's REST API, including authentication, endpoints, request/response formats, and integration examples.
Base URL and Versioning
Production: https://api.chatnio.com/v1
Staging: https://staging-api.chatnio.com/v1
All API requests must include the version in the URL path. The current stable version is v1.
Authentication
CoAI.Dev API uses API keys for authentication. Include your API key in the Authorization header:
Obtaining API Keys
- Admin Panel: Navigate to Settings → API Keys
- User Dashboard: Go to Profile → API Access
- Programmatic: Use the API Key Management endpoints
Security Best Practices
- Store API keys securely (environment variables, secret managers)
- Use different keys for different environments
- Rotate keys regularly (recommended: every 90 days)
- Monitor API key usage for anomalies
Rate Limiting
API requests are subject to rate limiting:
| Tier | Requests/Minute | Requests/Hour | Requests/Day |
|---|---|---|---|
| Free | 60 | 1,000 | 10,000 |
| Pro | 300 | 10,000 | 100,000 |
| Enterprise | 1,000 | 50,000 | 1,000,000 |
Rate limit headers are included in all responses:
X-RateLimit-Limit: Total requests allowed in time windowX-RateLimit-Remaining: Requests remaining in current windowX-RateLimit-Reset: Unix timestamp when rate limit resets
Chat Completions API
Create Chat Completion
The primary endpoint for AI conversations, compatible with OpenAI's chat completions format.
Request Body:
Response:
Streaming Completions
For real-time streaming responses, set stream: true:
Message Roles
| Role | Description | Required |
|---|---|---|
system | Instructions for the AI assistant | Optional |
user | Message from the user | Required |
assistant | Previous AI response (for conversation context) | Optional |
function | Function call result (for function calling) | Optional |
Function Calling
Enable the AI to call predefined functions:
Models API
List Available Models
Response:
Get Model Details
Response:
File Upload API
Upload File
Request:
Response:
List Files
Query Parameters:
purpose(string): Filter by file purposelimit(integer): Number of files to return (default: 20)offset(integer): Pagination offset
Delete File
Users API
Get Current User
Response:
Update User Profile
Request Body:
Conversations API
List Conversations
Query Parameters:
limit(integer): Number of conversations (default: 20, max: 100)offset(integer): Pagination offsetorder(string): Sort order (ascordesc, default:desc)
Response:
Get Conversation
Create Conversation
Request Body:
Update Conversation
Delete Conversation
Channels API (Admin)
List Channels
Response:
Create Channel
Request Body:
Test Channel
Analytics API
Get Usage Statistics
Query Parameters:
start_date(string): Start date (ISO 8601)end_date(string): End date (ISO 8601)granularity(string):hour,day,week,monthmodel(string): Filter by modeluser_id(string): Filter by user
Response:
Error Handling
All API endpoints return standard HTTP status codes and error responses:
Error Response Format
Common Error Codes
| HTTP Status | Error Type | Description |
|---|---|---|
| 400 | invalid_request_error | Bad request format or missing parameters |
| 401 | authentication_error | Invalid or missing API key |
| 403 | permission_error | Insufficient permissions |
| 404 | not_found_error | Resource not found |
| 429 | rate_limit_error | Rate limit exceeded |
| 500 | internal_server_error | Server error |
| 503 | service_unavailable_error | Service temporarily unavailable |
Rate Limit Error
Webhooks
Configure webhooks to receive real-time notifications about events in your CoAI.Dev account.
Webhook Events
| Event | Description |
|---|---|
conversation.created | New conversation started |
conversation.completed | Conversation ended |
user.registered | New user registration |
usage.threshold_reached | Usage limit threshold reached |
channel.health_changed | Channel health status changed |
payment.succeeded | Payment processed successfully |
payment.failed | Payment processing failed |
Webhook Payload Example
Webhook Security
Verify webhook signatures using the provided signing secret:
SDK Examples
This API reference provides comprehensive documentation for integrating with CoAI.Dev. For additional examples and use cases, see our GitHub repository or community examples.