API Documentation
Integrate with AI Coordinator using the OpenAI-compatible REST API.
1 Authentication
All API requests require a valid API key passed via the Authorization header.
Authorization: Bearer aic_<48 hex characters>
API keys are created and managed via the admin dashboard.
Authentication errors
| Status | Condition | Message |
|---|---|---|
| 401 | Missing header | No API key provided. Please set your API key in the Authorization header. |
| 401 | Invalid/revoked key | Incorrect API key provided. You can manage your API keys at the dashboard. |
| 403 | Deactivated app | This application has been deactivated. |
2 Chat Completions
/v1/chat/completions
read
Proxies to the OpenAI Chat Completions API. Supports all OpenAI parameters — the request body is forwarded as-is to the upstream provider.
Request body
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | required | Model ID, e.g. "gpt-4o", "gpt-4o-mini" |
| messages | array | required | Array of message objects with role and content |
| stream | boolean | optional | Set true for Server-Sent Events streaming |
| ...others | varies | optional | All other OpenAI-compatible params (temperature, max_tokens, etc.) are forwarded as-is |
Response (non-streaming)
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1700000000,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 8,
"total_tokens": 20
}
}
Streaming
When stream: true, the response uses Server-Sent Events. Each event is a JSON chunk prefixed with data: . The stream terminates with data: [DONE].
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]
curl examples
# Non-streaming
curl https://aicoordinator.spacebread.dev/v1/chat/completions \
-H "Authorization: Bearer aic_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "user", "content": "Hello!"}
]
}'
# Streaming
curl https://aicoordinator.spacebread.dev/v1/chat/completions \
-H "Authorization: Bearer aic_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-N \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "user", "content": "Hello!"}
],
"stream": true
}'
3 Embeddings
/v1/embeddings
read
Proxies to the OpenAI Embeddings API. Generates vector representations of text for use in search, clustering, and similarity tasks.
Request body
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | required | e.g. "text-embedding-3-small", "text-embedding-3-large" |
| input | string | array | required | Text to embed. A string or array of strings. |
Response
{
"object": "list",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [0.0023064255, -0.009327292, ...]
}
],
"model": "text-embedding-3-small",
"usage": {
"prompt_tokens": 5,
"total_tokens": 5
}
}
curl example
curl https://aicoordinator.spacebread.dev/v1/embeddings \
-H "Authorization: Bearer aic_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-3-small",
"input": "The quick brown fox jumps over the lazy dog"
}'
4 Audio Transcriptions
/v1/audio/transcriptions
read
Proxies to the OpenAI Whisper API for speech-to-text transcription. Falls back to a local whisper-base model if the upstream API is unreachable.
Request body (multipart/form-data)
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | required | "whisper-1" |
| file | file | required | Audio file (wav, mp3, m4a, webm, etc.) |
| prompt | string | optional | Context or vocabulary hint to guide transcription |
| response_format | string | optional | e.g. "json" |
Response
{
"text": "Good morning, how are you doing today?",
"duration": 3.5,
"provider": "openai",
"model": "whisper-1",
"fallback_reason": null
}
Provider metadata fields
Successful transcription responses include metadata indicating which engine processed the audio and why.
| Field | Type | Description |
|---|---|---|
| provider | string | "openai" or "local_whisper" |
| model | string | Model used, e.g. "whisper-1" (OpenAI) or "whisper-base" (local) |
| fallback_reason | string | null | null when OpenAI succeeded. Otherwise: "force_local", "openai_timeout", "openai_5xx", "openai_connection_failed", or "openai_error" |
curl example
curl https://aicoordinator.spacebread.dev/v1/audio/transcriptions \
-H "Authorization: Bearer aic_YOUR_API_KEY" \
-F model="whisper-1" \
-F file="@recording.wav" \
-F response_format="json"
5 Text-to-Speech
/v1/audio/speech
read
Proxies to the OpenAI Text-to-Speech API. Generates audio from text input. Returns binary audio data (not JSON).
--output file.mp3 with curl to save the output.
Request body
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | required | "tts-1", "tts-1-hd", or "gpt-4o-mini-tts" |
| input | string | required | The text to generate audio for. Maximum 4096 characters. |
| voice | string | required | "alloy", "ash", "coral", "echo", "fable", "onyx", "nova", "sage", or "shimmer" |
| response_format | string | optional | Output format. Default: "mp3" |
| speed | number | optional | Speed of speech, 0.25 to 4.0. Default: 1.0 |
| instructions | string | optional | Instructions for the voice style (gpt-4o-mini-tts only) |
Response format content types
| Format | Content-Type |
|---|---|
| mp3 | audio/mpeg |
| opus | audio/opus |
| aac | audio/aac |
| flac | audio/flac |
| wav | audio/wav |
| pcm | audio/pcm |
curl example
curl https://aicoordinator.spacebread.dev/v1/audio/speech \
-H "Authorization: Bearer aic_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "tts-1",
"input": "Hello! How are you doing today?",
"voice": "alloy"
}' \
--output speech.mp3
6 List Models
/v1/models
read
Lists available models from the upstream provider. No request body required.
Response
{
"object": "list",
"data": [
{
"id": "gpt-4o",
"object": "model",
"created": 1700000000,
"owned_by": "openai"
},
{
"id": "gpt-4o-mini",
"object": "model",
"created": 1700000000,
"owned_by": "openai"
}
]
}
curl example
curl https://aicoordinator.spacebread.dev/v1/models \
-H "Authorization: Bearer aic_YOUR_API_KEY"
7 List API Keys
/v1/admin/api_keys
admin
Lists all API keys and their usage statistics. Requires an admin-scoped API key.
Response
{
"object": "list",
"data": [
{
"id": 1,
"name": "Production Key",
"scope": "read",
"active": true,
"client_app": "My App",
"request_count": 1542,
"last_used_at": "2025-01-15T10:30:00Z",
"expires_at": null,
"created_at": "2024-12-01T08:00:00Z"
}
]
}
curl example
curl https://aicoordinator.spacebread.dev/v1/admin/api_keys \
-H "Authorization: Bearer aic_YOUR_ADMIN_API_KEY"
Error with non-admin key
// 403 Forbidden
{
"error": {
"message": "This endpoint requires an admin-scoped API key.",
"type": "insufficient_scope",
"param": null,
"code": "insufficient_scope"
}
}
8 Error Handling
All errors follow the OpenAI error response format:
{
"error": {
"message": "Human-readable description of the error",
"type": "error_type",
"param": null,
"code": "error_code"
}
}
HTTP status codes
| Status | Meaning | Common causes |
|---|---|---|
| 400 | Bad Request | Invalid parameters, malformed JSON, forwarded provider errors |
| 401 | Unauthorized | Missing, invalid, expired, or revoked API key |
| 403 | Forbidden | Deactivated application, insufficient scope for endpoint |
| 404 | Not Found | Endpoint does not exist |
| 500 | Internal Server Error | Unexpected server error |
| 502 | Bad Gateway | Upstream provider connection failed |
| 504 | Gateway Timeout | Upstream provider timed out |
9 Notes & Constraints
OpenAI SDK compatibility
The API is fully OpenAI-compatible. Most OpenAI SDK clients (Python, Node.js, etc.) work by simply changing the base URL to https://aicoordinator.spacebread.dev/v1.
# Python example with OpenAI SDK
from openai import OpenAI
client = OpenAI(
api_key="aic_YOUR_API_KEY",
base_url="https://aicoordinator.spacebread.dev/v1"
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}]
)
Request timeouts
Chat completions & embeddings: 120 seconds
Audio transcription: 600 seconds (10 minutes)
Text-to-speech: 300 seconds (5 minutes)
Audio transcription limits
When using the local whisper-base fallback, audio files are limited to 5 minutes in duration. Files longer than this may be truncated or rejected.
Request logging
All requests are logged and tracked for cost estimation. Logged data includes endpoint, model, token counts, latency, and HTTP status. Request and response bodies are not stored.