API Documentation
Complete reference for the AIBuddy Unified AI Gateway. One API key, all AI models.
Authentication
Include your AIBuddy API key in any request using one of these methods:
| Method | Example |
|---|---|
| Header | X-Api-Key: aibuddy_xxxxx |
| Bearer | Authorization: Bearer aibuddy_xxxxx |
| Body | { "api_key": "aibuddy_xxxxx" } |
Get your API key at aibuddy.life/my-account.
Base URL
https://api.aibuddy.life/v2
Note: The v1 endpoints (/v1/inference) continue to work unchanged for backward compatibility.
Quick Start
Chat (Smart Routing)
curl -X POST "https://api.aibuddy.life/v2/chat" \
-H "X-Api-Key: aibuddy_your_key" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{"role": "user", "content": "Hello, build me a React component"}
],
"language": "typescript"
}'
Image Generation
curl -X POST "https://api.aibuddy.life/v2/image/generate" \
-H "X-Api-Key: aibuddy_your_key" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A futuristic city skyline at sunset, cyberpunk style",
"size": "1024x1024",
"quality": "hd"
}'
Video Generation (Async)
curl -X POST "https://api.aibuddy.life/v2/video/generate" \
-H "X-Api-Key: aibuddy_your_key" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A drone flyover of mountain peaks at dawn",
"model": "veo-3.1-generate-preview"
}'
# Poll for result
curl "https://api.aibuddy.life/v2/tasks/task_video_abc123" \
-H "X-Api-Key: aibuddy_your_key"
POST /v2/chat
Smart-routed chat and code inference. The backend auto-selects the optimal model based on task complexity.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
messages | array | Required | Conversation messages [{role, content}] |
language | string | Optional | Language hint for routing (javascript, python, etc.) |
system | string | Optional | Custom system prompt |
max_tokens | number | Optional | Max response tokens (default: 8192) |
temperature | number | Optional | 0.0–1.0 (auto-tuned per language) |
thinking | bool/object | Optional | Enable extended thinking (Opus only) |
force_model | string | Optional | Force a specific model (bypasses smart routing) |
has_images | bool | Optional | Hint that messages contain images |
{
"success": true,
"response": "Here's your implementation...",
"thinking": "Extended thinking output (when enabled)",
"usage": { "input_tokens": 500, "output_tokens": 2000 },
"model": "gpt-5.3-codex",
"provider": "openai",
"api_cost": 0.018,
"remaining_credits": 45.50,
"routing": {
"provider": "openai",
"model": "gpt-5.3-codex",
"reason": "smart_routing"
},
"duration_ms": 3200,
"request_id": "uuid"
}
POST /v2/image/generate
Synchronous image generation via DALL-E 3.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
prompt | string | Required | Image description |
size | string | Optional | 1024x1024, 1024x1792, 1792x1024 |
quality | string | Optional | standard or hd |
style | string | Optional | vivid or natural |
{
"success": true,
"images": [{ "url": "https://...", "revised_prompt": "..." }],
"model": "dall-e-3",
"api_cost": 0.08
}
POST /v2/video/generate
Async video generation via Google Veo 3.1. Returns a task ID for polling.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
prompt | string | Required | Video description |
model | string | Optional | veo-3.1-generate-preview (default) or veo-3.1-fast-generate-preview |
imageBase64 | string | Optional | Base64 image for image-to-video |
imageMimeType | string | Optional | MIME type of the image (e.g. image/jpeg) |
{
"success": true,
"task_id": "task_video_a1b2c3d4e5f6",
"status": "processing",
"model": "veo-3.1-generate-preview",
"estimated_time_seconds": 120,
"message": "Video generation started. Poll GET /v2/tasks/{task_id}"
}
POST /v2/music/generate
Async music generation via Suno. Returns a task ID for polling.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
prompt | string | Required | Music description |
style | string | Optional | Genre/style (e.g. electronic, jazz) |
title | string | Optional | Track title |
instrumental | bool | Optional | Instrumental only (no vocals) |
negativeTags | string | Optional | Comma-separated tags to avoid |
{
"success": true,
"task_id": "task_music_a1b2c3d4e5f6",
"suno_task_id": "suno_abc123",
"status": "processing",
"model": "suno-v3.5",
"estimated_time_seconds": 60
}
GET /v2/tasks/{taskId}
Poll async task status for video and music generation.
{
"task_id": "task_video_a1b2c3d4e5f6",
"type": "video",
"status": "processing",
"created_at": "2026-03-02T04:30:00Z"
}
{
"task_id": "task_video_a1b2c3d4e5f6",
"type": "video",
"status": "completed",
"result_url": "https://storage.googleapis.com/.../video.mp4"
}
{
"task_id": "task_video_a1b2c3d4e5f6",
"type": "video",
"status": "failed",
"error": "Content filtered by safety system",
"filter_reasons": ["Violence detected"]
}
Task statuses: pending → processing → completed / failed
GET /v2/models
List all available models and their capabilities.
Smart Routing
The API automatically selects the optimal model based on task complexity, language, and content. Override with force_model when needed.
| Tier | Model | Best For | Input Cost |
|---|---|---|---|
| 1 (Economy) | DeepSeek V3 | Simple tasks, chat, quick edits | $0.27/M tokens |
| 2 (Standard) | GPT-4o | Medium tasks, images, multi-turn | $2.50/M tokens |
| 3 (Premium) | GPT-5.3-Codex | Code gen, vibe coding, features | $2/M tokens |
| 4 (Advanced) | Claude Sonnet 4 | Complex reasoning, code review | $3/M tokens |
| 5 (Expert) | Claude Opus 4.6 | Architecture, security, deep reasoning | $15/M tokens |
Error Codes
| Code | Status | Description |
|---|---|---|
MISSING_API_KEY | 401 | No API key provided |
INVALID_API_KEY | 401 | Key doesn't exist or expired |
INVALID_MESSAGES | 400 | Messages array missing or empty |
INVALID_REQUEST | 400 | Malformed JSON body |
MISSING_PROMPT | 400 | Required prompt field missing |
MISSING_TASK_ID | 400 | Task ID not provided in URL |
TASK_NOT_FOUND | 404 | No task found with given ID |
ALL_PROVIDERS_FAILED | 503 | All AI providers unavailable |
VIDEO_NOT_CONFIGURED | 503 | Video service not configured |
MUSIC_NOT_CONFIGURED | 503 | Music service not configured |
Rate Limits
Rate limits are applied per API key. Current limits:
| Endpoint | Rate Limit |
|---|---|
/v2/chat | 60 requests/minute |
/v2/image/generate | 10 requests/minute |
/v2/video/generate | 5 requests/minute |
/v2/music/generate | 5 requests/minute |
/v2/tasks/{id} | 120 requests/minute |
When rate limited, you'll receive a 429 Too Many Requests response. Wait and retry.