API Overview
The CID222 API provides programmatic access to content safety features, session management, and administrative functions.
Base URL
https://api.cid222.ai
All API requests should be made to this base URL. For on-premises deployments, use your configured endpoint.
Authentication
All requests require authentication via Bearer token in the Authorization header:
Authorization: Bearer YOUR_API_KEY
API Endpoints
Chat Endpoints
| Method | Endpoint | Description |
|---|---|---|
POST | /chat/completions | Send chat completion with safety filtering |
GET | /chat/providers | List available LLM providers |
POST | /chat/analyze-image | OCR + PII detection on images |
Session Endpoints
| Method | Endpoint | Description |
|---|---|---|
POST | /sessions | Create a conversation session |
GET | /sessions | List all sessions |
GET | /sessions/:id | Get session details with history |
POST | /sessions/:id/messages | Send message in session (SSE) |
DELETE | /sessions/:id | Delete a session |
Request Format
All requests should use JSON format with the Content-Type: application/json header.
Example Request
const response = await fetch('https://api.cid222.ai/chat/completions', {method: 'POST',headers: {'Authorization': 'Bearer YOUR_API_KEY','Content-Type': 'application/json',},body: JSON.stringify({model: 'gpt-4',messages: [{ role: 'system', content: 'You are a helpful assistant.' },{ role: 'user', content: 'Hello!' }],stream: true})});
Response Format
Successful responses return JSON with the requested data. Error responses include status code and message:
Success Response
{"id": "chatcmpl-abc123","object": "chat.completion","created": 1699900000,"model": "gpt-4","choices": [{"index": 0,"message": {"role": "assistant","content": "Hello! How can I help you today?"},"finish_reason": "stop"}],"usage": {"prompt_tokens": 20,"completion_tokens": 10,"total_tokens": 30}}
Error Response
{"statusCode": 400,"message": "Invalid request body","error": "Bad Request"}
Rate Limits
API rate limits depend on your subscription tier:
| Tier | Requests/min | Tokens/day |
|---|---|---|
| Starter | 60 | 100,000 |
| Professional | 300 | 1,000,000 |
| Enterprise | Custom | Custom |
Rate limit headers are included in responses:
X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-ResetStreaming Responses
Chat completions support Server-Sent Events (SSE) for real-time streaming. Set stream: true in your request.
Handle SSE Stream
const response = await fetch('https://api.cid222.ai/chat/completions', {method: 'POST',headers: {'Authorization': 'Bearer YOUR_API_KEY','Content-Type': 'application/json',},body: JSON.stringify({model: 'gpt-4',messages: [...],stream: true})});const reader = response.body.getReader();const decoder = new TextDecoder();while (true) {const { done, value } = await reader.read();if (done) break;const chunk = decoder.decode(value);const lines = chunk.split('\n');for (const line of lines) {if (line.startsWith('data: ')) {const data = line.slice(6);if (data === '[DONE]') continue;const parsed = JSON.parse(data);const content = parsed.choices[0]?.delta?.content;if (content) {process.stdout.write(content);}}}}
Next Steps
- Chat API — Detailed chat completion documentation
- Sessions API — Session management for conversations
- Error Handling — Handle API errors gracefully