Documentation
Code Examples
TypeScript and Python code examples using the Pixelated Empathy SDKs
Code Examples
Real-world integration patterns using the auto-generated TypeScript and Python SDKs. These SDKs are generated from ourOpenAPI 3.1 specification and support all API endpoints.
Table of Contents
- SDK Installation
- Initialization
- Content Search
- Bias Analysis
- Memory Operations
- Error Handling
- Retry & Backoff
SDK Installation
npm install @pixelated-empathy/auto-sdk
# or
pnpm add @pixelated-empathy/auto-sdkpip install pixelated-empathy-sdk
# or
uv add pixelated-empathy-sdkInitialization
import { Configuration, DefaultApi } from '@pixelated-empathy/auto-sdk';
const config = new Configuration({
apiKey: process.env.PIXELATED_API_KEY!,
basePath: 'https://api.pixelatedempathy.com',
});
const client = new DefaultApi(config);import os
from pixelated_empathy_sdk import Configuration, DefaultApi
config = Configuration(
api_key=os.environ["PIXELATED_API_KEY"],
host="https://api.pixelatedempathy.com",
)
client = DefaultApi(config)Content Search
// Search for content
const results = await client.searchContent({
q: 'anxiety management techniques',
limit: 10,
});
console.log(results.data);
// [{ id: 'doc-123', title: 'CBT for Anxiety', ... }, ...]# Search for content
results = client.search_content(
q="anxiety management techniques",
limit=10,
)
for result in results.data:
print(result.title, result.id)Bias Analysis
// Analyze a session for bias indicators
const analysis = await client.analyzeBias({
sessionId: 'session-abc-123',
demographics: {
age: '25-34',
gender: 'female',
ethnicity: 'hispanic',
},
});
console.log(analysis.bias_indicators);
console.log(analysis.confidence_score);# Analyze a session for bias indicators
analysis = client.analyze_bias(
session_id="session-abc-123",
demographics={
"age": "25-34",
"gender": "female",
"ethnicity": "hispanic",
},
)
print(analysis.bias_indicators)
print(analysis.confidence_score)Memory Operations
// Create a memory entry
const memory = await client.createMemory({
userId: 'user-123',
content: 'Patient responded well to CBT session 3',
metadata: { sessionType: 'cbt', week: 3 },
});
// Search memories
const results = await client.searchMemories({
userId: 'user-123',
query: 'CBT response',
limit: 5,
});# Create a memory entry
memory = client.create_memory(
user_id="user-123",
content="Patient responded well to CBT session 3",
metadata={"sessionType": "cbt", "week": 3},
)
# Search memories
results = client.search_memories(
user_id="user-123",
query="CBT response",
limit=5,
)Error Handling
import { ApiException } from '@pixelated-empathy/auto-sdk';
try {
const result = await client.searchContent({ q: 'test' });
} catch (error) {
if (error instanceof ApiException) {
if (error.status === 429) {
console.log('Rate limited. Retry after:', error.headers['retry-after']);
} else if (error.status === 401) {
console.log('Invalid API key');
} else {
console.log('API error:', error.message);
}
}
}from pixelated_empathy_sdk import ApiException
try:
result = client.search_content(q="test")
except ApiException as e:
if e.status == 429:
print(f"Rate limited. Retry after: {e.headers.get('Retry-After')}")
elif e.status == 401:
print("Invalid API key")
else:
print(f"API error: {e.message}")Retry & Backoff
const config = new Configuration({
apiKey: process.env.PIXELATED_API_KEY!,
basePath: 'https://api.pixelatedempathy.com',
// Built-in retry with exponential backoff
retry: {
maxRetries: 3,
initialDelayMs: 500,
maxDelayMs: 5000,
retryOnStatus: [429, 500, 502, 503],
},
});
const client = new DefaultApi(config);config = Configuration(
api_key=os.environ["PIXELATED_API_KEY"],
host="https://api.pixelatedempathy.com",
retry_config=RetryConfig(
max_retries=3,
initial_delay_ms=500,
max_delay_ms=5000,
retry_on_status=[429, 500, 502, 503],
),
)