Python SDK
The official CID222 Python SDK for integrating content safety into your Python applications.
Coming Soon
The Python SDK is currently under development. Check back soon for updates, or use the REST API directly in the meantime.
Planned Features
- Async Support — Full async/await support with asyncio
- Type Hints — Complete type annotations for IDE support
- Streaming — Native generator-based streaming
- Auto-retry — Built-in retry logic with exponential backoff
- Pydantic Models — Request/response validation
API Preview
Here's a preview of what the SDK will look like:
from cid222 import CID222
client = CID222(api_key="your-api-key")
# Simple chat completion
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "user", "content": "Hello, world!"}
]
)
print(response.choices[0].message.content)
# Async streaming
async for chunk in client.chat.completions.create(
model="gpt-4o",
messages=[...],
stream=True
):
print(chunk.choices[0].delta.content, end="")Current Alternative
While the SDK is in development, you can use the REST API directly with the requests library:
import json
import os
import requests
# /chat/completions always responds with Server-Sent Events
response = requests.post(
'https://api.cid222.ai/chat/completions',
headers={
'Authorization': f'Bearer {os.environ["CID222_API_KEY"]}',
'Content-Type': 'application/json',
},
json={
'model': 'gpt-4o',
'messages': [
{'role': 'user', 'content': 'Hello, world!'}
]
},
stream=True,
)
answer = ''
for line in response.iter_lines():
if not line:
continue
line = line.decode('utf-8')
if not line.startswith('data: '):
continue
data = line[6:]
if data == '[DONE]':
break
event = json.loads(data)
if 'error' in event: # input blocked (type "content_rejected")
raise RuntimeError('Blocked: ' + event['error'])
if event.get('type') == 'output_content_rejected':
raise RuntimeError('Blocked: ' + str(event.get('reason', '')))
if not event.get('type') and isinstance(event.get('content'), str):
# Model text. The gateway buffers and filters the output, then
# sends the full answer as one event (id "filtered-response",
# finish_reason "stop").
if event.get('finish_reason') == 'stop':
answer = event['content']
else:
answer += event['content']
print(answer)See the Integration Examples for more Python code samples.