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 authenticate with a Bearer token in the Authorization header — either a tenant API key or a user JWT:
# Tenant API key (server-to-server)Authorization: Bearer cid_key_your_api_key# User JWT (from POST /auth/login)Authorization: Bearer eyJ0eXAiOiJKV1Qi...
Which token where?
Chat, detection, image, and document endpoints accept a tenant API key (cid_key_...) or a JWT. Session and /admin endpoints require a user JWT.
API Endpoints
Chat Endpoints
| Method | Endpoint | Description |
|---|---|---|
POST | /chat/completions | Streamed completion with input/output safety filtering (SSE) |
POST | /chat/harden-prompt | Rewrite a prompt to be safer and more robust |
GET | /chat/providers | List available LLM providers |
GET | /models | List models enabled for your tenant |
Detection & Files
| Method | Endpoint | Description |
|---|---|---|
POST | /api/v1/guardrails/detect | Scan text for PII, secrets, toxicity, and jailbreak |
POST | /image-analysis/analyze | Image PII + OCR + redaction |
POST | /document-analysis/analyze | PDF / DOCX / TXT / CSV PII + redaction |
GET | /document-analysis/:id/download | Download a redacted document |
Session Endpoints
| Method | Endpoint | Description |
|---|---|---|
POST | /sessions | Create a conversation session |
GET | /sessions | List your tenant's sessions |
GET | /sessions/:id | Get session details with history |
POST | /sessions/:id/messages | Send a message in a 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 ' + process.env.CID222_API_KEY,'Content-Type': 'application/json',},body: JSON.stringify({model: 'gpt-4o',messages: [{ role: 'system', content: 'You are a helpful assistant.' },{ role: 'user', content: 'Hello!' }]})});
Response Format
Chat and session messages stream Server-Sent Events. Non-streaming endpoints return JSON; errors include a status code and message:
SSE Response (chat)
data: {"id":"filtered-response","content":"Hello! How can I help you today?","finish_reason":"stop","filtered":false,"entities_masked":0}data: {"type":"token_usage","usage":{"prompt_tokens":20,"completion_tokens":10,"total_tokens":30}}data: [DONE]
JSON Error Response (non-streaming endpoints)
{"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-Reset
Streaming 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 ' + process.env.CID222_API_KEY,'Content-Type': 'application/json',},body: JSON.stringify({ model: 'gpt-4o', messages: [...] })});const reader = response.body.getReader();const decoder = new TextDecoder();while (true) {const { done, value } = await reader.read();if (done) break;for (const line of decoder.decode(value).split('\n')) {if (!line.startsWith('data: ')) continue;const data = line.slice(6);if (data === '[DONE]') break;const event = JSON.parse(data);if (event.error) {// Input blocked (type: "content_rejected") or server errorconsole.error('Blocked:', event.error);} else if (event.type === 'output_content_rejected') {console.error('Blocked:', event.reason);} else if (!event.type && typeof event.content === 'string') {// Model text. The gateway buffers and filters the output, so the// complete answer arrives as one event (id: "filtered-response",// finish_reason: "stop").process.stdout.write(event.content);}}}
Next Steps
- Chat API — Detailed chat completion documentation
- Content Detection — Scan text with the Guardrails API
- Sessions API — Session management for conversations