API Reference
Complete API reference for the isA Model Service.
Base URL: http://localhost:8082
Authentication
All requests require an API key via the Authorization header or X-API-Key header:
RBAC: When
RBAC_ENABLED=true, each endpoint additionally requires a specificresource:actionpermission in the JWT. See RBAC for the full permission matrix.
curl -H "Authorization: Bearer YOUR_API_KEY" http://localhost:8082/api/v1/modelsInference
POST /api/v1/invoke
Unified inference endpoint. Supports chat completions, streaming, tool calling, and structured outputs.
curl -X POST http://localhost:8082/api/v1/invoke \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gpt-4o-mini",
"messages": [
{"role": "user", "content": "Hello!"}
],
"stream": false
}'Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model identifier |
messages | array | Yes | Chat messages array |
stream | boolean | No | Enable streaming (default: false) |
tools | array | No | Tool definitions for function calling |
tool_choice | string | No | Tool selection strategy |
response_format | object | No | Structured output schema |
temperature | number | No | Sampling temperature (0-2) |
max_tokens | integer | No | Maximum tokens to generate |
Response:
{
"id": "chatcmpl-abc123",
"model": "gpt-4o-mini",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 8,
"total_tokens": 18
}
}POST /api/v1/invoke/v2
Extended invoke route with additional routing and observability features.
GET /api/v1/models
List available LLM models across all configured providers.
curl http://localhost:8082/api/v1/modelsResponse:
{
"models": [
{"id": "gpt-4o-mini", "provider": "openai"},
{"id": "claude-sonnet-4-5-20250929", "provider": "anthropic"},
{"id": "llama3.2", "provider": "ollama"}
]
}Providers
The Model Service routes requests to the appropriate provider based on the model identifier:
| Provider | Models | Config Variable |
|---|---|---|
| OpenAI | gpt-4o, gpt-4o-mini, gpt-4.1-* | OPENAI_API_KEY |
| Anthropic | claude-* | ANTHROPIC_API_KEY |
| OpenRouter | anthropic/*, deepseek/*, openai/*, 200+ models | OPENROUTER_API_KEY |
| Anthropic Sub | claude-* (via subscription proxy) | ANTHROPIC_SUB_PROXY_URL |
| Ollama | llama*, mistral*, codellama* | Local (no key needed) |
| Cerebras | cerebras-* | CEREBRAS_API_KEY |
| YYDS | yyds-* | YYDS_API_KEY |
| Replicate | replicate/* | REPLICATE_API_TOKEN |
Caching
GET /api/v1/cache/stats
Cache hit/miss statistics for L1 (exact) and L2 (semantic) caches.
curl http://localhost:8082/api/v1/cache/statsPOST /api/v1/cache/invalidate/{provider}/{model}
Invalidate cache entries for a specific provider and model.
curl -X POST http://localhost:8082/api/v1/cache/invalidate/openai/gpt-4o-miniPOST /api/v1/cache/clear
Clear all cache entries.
curl -X POST http://localhost:8082/api/v1/cache/clearTraining
POST /api/v1/models/training/train
Start a Lightning training pipeline.
curl -X POST http://localhost:8082/api/v1/models/training/train \
-H "Content-Type: application/json" \
-d '{
"algorithm": "closed_loop",
"dataset_id": "my-dataset",
"config": {
"epochs": 10,
"learning_rate": 0.001
}
}'Supported Algorithms:
| Algorithm | Description |
|---|---|
closed_loop | Feedback loop optimization |
apo | Automatic prompt optimization |
grpo | Group relative policy optimization |
custom | Custom training pipeline |
GET /api/v1/models/training/stats
Training job statistics and progress.
POST /api/v1/models/training/export
Export training data and artifacts.
GET /api/v1/models/training/config
Read the active training configuration.
Prediction (ML)
Generic machine learning prediction endpoints for time-series forecasting and custom models.
POST /api/v1/models/training/ml/prediction/models
Create and train a prediction model.
curl -X POST http://localhost:8082/api/v1/models/training/ml/prediction/models \
-H "Content-Type: application/json" \
-d '{
"name": "daily-sales-forecast",
"model_type": "prophet",
"data": [
{"ds": "2026-01-01", "y": 120},
{"ds": "2026-01-02", "y": 125},
{"ds": "2026-01-03", "y": 130}
]
}'Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Model display name |
model_type | string | Yes | Model type (prophet) |
data | array | Yes | Training data with ds (date) and y (value) keys |
GET /api/v1/models/training/ml/prediction/models
List prediction models. Supports pagination.
| Parameter | Type | Description |
|---|---|---|
limit | integer | Max results (default: 20) |
offset | integer | Skip N results (default: 0) |
GET /api/v1/models/training/ml/prediction/models/{model_id}
Get prediction model details including training status.
DELETE /api/v1/models/training/ml/prediction/models/{model_id}
Delete a prediction model and its artifacts.
POST /api/v1/models/inference/ml/prediction/models/{model_id}/predict
Run a prediction (forecast).
curl -X POST http://localhost:8082/api/v1/models/inference/ml/prediction/models/{model_id}/predict \
-H "Content-Type: application/json" \
-d '{
"periods": 14,
"frequency": "D",
"include_history": false
}'| Field | Type | Required | Description |
|---|---|---|---|
periods | integer | Yes | Number of periods to forecast |
frequency | string | Yes | Frequency (D, W, M, H) |
include_history | boolean | No | Include historical data in response |
GET /api/v1/models/inference/ml/prediction/models/{model_id}/predictions
List prediction runs for a model. Supports pagination (limit, offset).
Sleep Intelligence
Sleep intelligence routes are mounted under /api/v1/sleep and are used by the commercial sleep model products.
POST /api/v1/sleep/evaluate
Evaluate sleep quality and related sleep-health signals.
curl -X POST http://localhost:8082/api/v1/sleep/evaluate \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"user_id": "user_123",
"mode": "fast",
"session_data": {
"duration_min": 430,
"stage_durations": {
"W": 32,
"N1": 48,
"N2": 210,
"N3": 72,
"REM": 68
},
"movement_score": 0.18
}
}'POST /api/v1/sleep/recommend
Generate recommendations from sleep evaluation inputs or model outputs.
curl -X POST http://localhost:8082/api/v1/sleep/recommend \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"user_id": "user_123",
"sleep_history": [
{
"business_date": "2026-05-16",
"quality_score": 7.2,
"stage_distribution": {
"n1": 0.12,
"n2": 0.49,
"n3": 0.17,
"rem": 0.16,
"wake": 0.06
}
}
],
"goals": ["improve_quality"],
"context": {
"screen_time_before_bed_min": 90
}
}'Registered commercial model products include com_sleep_quality, com_sleep_stage, and com_health_risk.
Voice & Realtime
POST /realtime/sessions
Create a new realtime voice session. Returns a WebSocket URL for bidirectional audio streaming.
curl -X POST http://localhost:8082/realtime/sessions \
-H "Content-Type: application/json" \
-H "x-user-id: user-123" \
-d '{
"model": "gpt-4o-realtime-preview",
"voice": "alloy",
"instructions": "You are a helpful assistant",
"metadata": {"session_type": "support"}
}'Response:
{
"session_id": "sess_abc123",
"websocket_url": "ws://localhost:8082/realtime/ws/sess_abc123?token=sess_abc123",
"expires_at": "2026-03-02T12:15:00Z",
"model": "gpt-4o-realtime-preview",
"voice": "alloy"
}GET /realtime/ws/{session_id}
WebSocket endpoint for bidirectional voice streaming. Proxies between client and upstream realtime API with event normalization, privacy filtering, and metrics collection.
Session config sent upstream:
- Modalities:
["text", "audio"] - Audio format:
pcm16 - Turn detection:
server_vad(threshold 0.5, silence duration 200ms) - Input transcription:
whisper-1
POST /realtime/sessions/{session_id}/interrupt
Send a barge-in signal to cancel the current response and clear the audio buffer.
curl -X POST http://localhost:8082/realtime/sessions/sess_abc123/interruptIntelligent Model Routing
POST /api/v1/invoke/v2
Extended invoke route with role-based resolution, capability filtering, and cost-aware ranking.
Additional request fields (beyond standard /invoke):
| Field | Type | Description |
|---|---|---|
role | string | Agent role (reasoning, response, coding, default) |
preferred_max_latency_ms | number | Soft latency constraint |
preferred_max_cost_per_token | number | Soft cost constraint |
Resolution priority:
- Explicit
model+providerin request - Role-based defaults (see table below)
- Capability-filtered candidates ranked by cost
- Service type defaults
Service type defaults:
| Service Type | Default Model | Provider |
|---|---|---|
text | gpt-4o-mini | openai |
vision | gpt-5-mini | openai |
audio | whisper-1 | openai |
image | flux-schnell | replicate |
embedding | text-embedding-3-small | openai |
Multi-Modal Support
The invoke endpoint supports multi-modal inputs depending on the provider and model:
| Modality | Description | Example Models |
|---|---|---|
| Text | Standard chat completions | All models |
| Vision | Image understanding | gpt-4o, claude-* |
| Audio | Speech-to-text, text-to-speech | whisper-* |
| Embedding | Vector embeddings | text-embedding-* |
| Image | Image generation | dall-e-*, replicate/* |
| Video | Video understanding | replicate/* |
Python Client
from isa_model import AsyncISAModel
async with AsyncISAModel(base_url="http://localhost:8082") as client:
# Chat completion
response = await client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
# Streaming
async for chunk in await client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True
):
print(chunk.choices[0].delta.content or "", end="")Billing & Usage Endpoints
GET /api/v1/usage
Query credit balance and per-meter consumption. Requires billing:read permission.
curl "http://localhost:8082/api/v1/usage?since=2026-03-01T00:00:00Z" \
-H "Authorization: Bearer YOUR_API_KEY"See Metering & Usage API for full parameter reference and response schema.
GET /api/v1/audit
Query the immutable audit log for all write operations and auth events. Requires audit_logs:read permission.
curl "http://localhost:8082/api/v1/audit?resource=agents&limit=100" \
-H "Authorization: Bearer YOUR_API_KEY"See Audit Logging for full parameter reference.
DELETE /api/v1/tenants/{id}
GDPR cascading tenant deletion — removes all data for the tenant across PG, Redis, Qdrant, and NATS. Requires orgs:admin permission.
curl -X DELETE "http://localhost:8082/api/v1/tenants/tenant_abc123" \
-H "Authorization: Bearer YOUR_API_KEY"Response:
{
"tenant_id": "tenant_abc123",
"status": "deletion_scheduled",
"estimated_completion": "2026-03-27T14:05:00Z"
}Deletion is async — data is soft-deleted immediately and hard-deleted by the weekly cleanup CronJob.
POST /api/v1/tenants/{id}/gdpr-delete
Trigger immediate GDPR hard delete (bypasses the weekly CronJob). Requires orgs:admin permission.
curl -X POST "http://localhost:8082/api/v1/tenants/tenant_abc123/gdpr-delete" \
-H "Authorization: Bearer YOUR_API_KEY"Environment Variables
| Variable | Required | Description |
|---|---|---|
OPENAI_API_KEY | For OpenAI models | OpenAI provider key |
ANTHROPIC_API_KEY | For Claude models | Anthropic provider key |
OPENROUTER_API_KEY | For OpenRouter models | OpenRouter provider key |
ANTHROPIC_SUB_PROXY_URL | For subscription proxy | Local proxy URL (default: http://localhost:5005/v1) |
YYDS_API_KEY | For YYDS models | YYDS provider key |
REDIS_URL | For caching | Redis connection URL |
QDRANT_URL | For semantic cache | Qdrant connection URL |
NATS_URL | For events | NATS connection URL |