Orchestrator API
FastAPI service at https://api.aigatecloud.com. OpenAI & Claude compatible drop-in, plus a one-call Idea→Post pipeline with intent detection, multi-step DAG, retry, and fallback chains.
Overview
The orchestrator sits between your client and providers (Groq for text, Pollinations Flux for image). You send a high-level intent — "viral", "quality", "cost" — and AIGate handles model selection, prompt shaping, retries, and image caching.
- Base URL:
https://api.aigatecloud.com - OpenAI compat: point existing OpenAI SDK at
/v1— same request/response shape - Claude compat: Anthropic SDK works on
/v1/messages - Native:
POST /v1/generate-postreturns caption + hashtags + image in one call
Authentication
All /v1/* endpoints require an API key as a Bearer token. Generate keys in your dashboard at cp.aigatecloud.com → API Keys.
Authorization: Bearer sk-aigate-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
/demo/* endpoints accept anonymous calls but are rate-limited to 5 requests / hour / IP.
Mode selector
Pass mode instead of a model name. AIGate routes to the right Groq model (and applies fallback chains) based on the rule engine.
| Mode | Strategy | Primary model | Use for |
|---|---|---|---|
speed | Fast | llama-3.1-8b-instant | Quick replies, batch, live chat |
cost | Cheap | llama-3.1-8b-instant | High-volume content, internal tools |
quality | Best | llama-3.3-70b-versatile | Hero copy, ads, public-facing |
viral | Multi-step DAG | llama-3.3-70b-versatile | Social posts, full pipeline |
Errors & credits
- 401 — missing / invalid API key
- 402 — insufficient credits
- 429 — demo rate limit (5/hr/IP) or upstream rate limit
- 502 — all upstream models in the fallback chain failed
Credit costs (visible in credits_used field on the response):
- Text generation: 1 credit per 1k tokens (input + output, ceil)
/v1/generate-post: 5 credits base, +10 ifimage: true
POST /v1/chat/completions — OpenAI compatible
Drop-in replacement for OpenAI Chat Completions. Pass a mode name as model.
curl https://api.aigatecloud.com/v1/chat/completions \
-H "Authorization: Bearer $AIGATE_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "quality",
"messages": [{"role": "user", "content": "Write a cold-email hook for fintech CFOs"}]
}'
import openai
client = openai.OpenAI(
api_key="sk-aigate-...",
base_url="https://api.aigatecloud.com/v1",
)
resp = client.chat.completions.create(
model="quality", # or speed / cost / viral
messages=[{"role": "user", "content": "Write a cold-email hook"}],
)
print(resp.choices[0].message.content)
const r = await fetch('https://api.aigatecloud.com/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': `Bearer ${AIGATE_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'quality',
messages: [{ role: 'user', content: 'Write a cold-email hook' }],
}),
});
const data = await r.json();
console.log(data.choices[0].message.content);
POST /v1/messages — Claude compatible
Anthropic Messages API shape. Internally translates to chat.completions.
import anthropic
client = anthropic.Anthropic(
api_key="sk-aigate-...",
base_url="https://api.aigatecloud.com",
)
msg = client.messages.create(
model="quality",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
)
print(msg.content[0].text)
POST /v1/generate-post — Idea → Content
Native one-call pipeline. Detects intent, runs caption + hashtags + (optional) image in parallel via the DAG planner.
Request body
| Field | Type | Default | Description |
|---|---|---|---|
idea | string | — | Required. ≤ 200 chars. |
mode | string | viral | speed / cost / quality / viral |
lang | string | en | BCP-47 tag — caption is generated in this language |
image | boolean | false | Render an image via Pollinations Flux |
include_hashtags | boolean | true | Generate the hashtags task |
Response (200)
{
"id": "post_a92bb3f0c8c14a9e",
"mode": "viral",
"intent": "ads",
"caption": "Discover serenity in every detail. Elevate...",
"caption_model": "llama-3.3-70b-versatile",
"hashtags": ["luxuryfengshui", "highendinterior", ...],
"hashtags_model": "llama-3.3-70b-versatile",
"image_url": "https://api.aigatecloud.com/img/{sha1}.jpg",
"image_provider": "pollinations.flux+cdn",
"credits_used": 15
}
Example
curl https://api.aigatecloud.com/v1/generate-post \
-H "Authorization: Bearer $AIGATE_KEY" \
-H "Content-Type: application/json" \
-d '{
"idea": "selling luxury fengshui homes",
"mode": "viral",
"image": true
}'
idea+mode returns the cached image instantly. Cache key is sha1(mode + ":" + idea.lower()).GET /v1/models
List available modes and their human-readable labels.
curl https://api.aigatecloud.com/v1/models -H "Authorization: Bearer $AIGATE_KEY"
{
"data": [
{"id": "speed", "label": "⚡ Speed", "use": "fast"},
{"id": "cost", "label": "💰 Save Cost", "use": "cheap"},
{"id": "quality", "label": "⭐ Quality", "use": "best"},
{"id": "viral", "label": "🔥 Viral", "use": "multi_step"}
]
}
GET /img/{key}.jpg
Public CDN for cached image renders. Returned by /v1/generate-post when image:true. Cache-Control: public, max-age=2592000, immutable. No auth.
POST /v1/upload — reference image upload
multipart/form-data, field name file. Accepts jpg/png/webp up to 8 MB. Returns a stable CDN URL on api.aigatecloud.com/img/ that you can pass as reference_url or image_url to other endpoints.
curl https://api.aigatecloud.com/v1/upload \
-H "Authorization: Bearer $AIGATE_KEY" \
-F "[email protected]"
# → {"key":"upload-abc...", "url":"https://api.aigatecloud.com/img/upload-abc....jpg",
# "bytes":40208, "content_type":"image/jpeg"}
POST /v1/image-transform — text2img + img2img
Generate a new image from a prompt, or transform a previously uploaded one. Cached by sha1(mode + reference + prompt).
Request body
| Field | Type | Default | Description |
|---|---|---|---|
prompt | string | — | Required. ≤ 800 chars. |
reference_url | string | null | Optional. Must be a /v1/upload URL — switches to img2img. |
width / height | int | 1024 | Output dimensions. |
mode | string | quality | Routing mode (currently only affects logging). |
Cost: 10 credits per image. Cache hit returns instantly.
POST /v1/enhance/lowlight — brighten dark photo
Recover an underexposed photo. Identity-preserving. Three intensity levels.
| Field | Type | Default | Description |
|---|---|---|---|
image_url | string | — | Required. Must be a /v1/upload URL. |
mode | string | balanced | light / balanced / extreme |
face_priority | bool | true | Add "preserve natural skin texture" to prompt. |
noise_reduction | string | auto | auto / off / high |
output_resolution | int | 1024 | Max edge in px (clamped 512-2048). |
curl https://api.aigatecloud.com/v1/enhance/lowlight \
-H "Authorization: Bearer $AIGATE_KEY" \
-H "Content-Type: application/json" \
-d '{
"image_url": "https://api.aigatecloud.com/img/upload-abc.jpg",
"mode": "balanced"
}'
POST /v1/effects/light-trails — long-exposure night photo
Apply long-exposure light streaks to a night scene. Works in two modes:
- Transform (with
image_url): apply trails to your photo, motion blur on lights only. - Generate (with
promptonly): synthesize a night scene with light trails from scratch.
| Field | Type | Default | Description |
|---|---|---|---|
image_url | string | null | Optional. Provide for transform; omit for generate. |
prompt | string | null | Required when image_url is omitted. Describes the scene. |
intensity | string | medium | low / medium / high |
convert_to_night | bool | false | If true and image is daytime: convert to night first, then add trails. |
output_resolution | int | 1024 | Max edge in px (clamped 512-2048). |
# Generate from prompt
curl https://api.aigatecloud.com/v1/effects/light-trails \
-H "Authorization: Bearer $AIGATE_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "Tokyo Shibuya crosswalk at night",
"intensity": "high"
}'
# Transform a daytime photo
curl https://api.aigatecloud.com/v1/effects/light-trails \
-H "Authorization: Bearer $AIGATE_KEY" \
-H "Content-Type: application/json" \
-d '{
"image_url": "https://api.aigatecloud.com/img/upload-abc.jpg",
"intensity": "medium",
"convert_to_night": true
}'
POST /v1/effects/cinematic-rain — rain + neon + trails
Combo effect: rainy night + light trails + neon reflections. Three sub-presets pick the right balance for the look you want. Subjects stay sharp; motion blur applied only to lights.
| Field | Type | Default | Description |
|---|---|---|---|
image_url | string | null | Optional. /v1/upload URL for transform mode. |
prompt | string | null | Required when no image. Describes the scene. |
preset | string | cinematic | realistic · cinematic · cyberpunk |
rain_intensity | string | per preset | Override: light / medium / heavy |
neon_strength | string | per preset | Override: subtle / balanced / strong |
trail_length | string | per preset | Override: short / medium / long |
wet_reflection | bool | true | Strong reflections of neon + lights on wet ground. |
convert_to_night | bool | false | If transforming a daytime photo: night-ify first. |
preserve_subject | bool | true | Adds guards: keep humans sharp, controlled neon, accurate reflections. |
output_resolution | int | 1024 | Max edge in px (clamped 512-2048). |
Preset cheat sheet
| preset | rain | neon | trails | use for |
|---|---|---|---|---|
realistic | light | subtle | short | Documentary / discreet feel |
cinematic | medium | balanced | medium | Default movie-grade. Best for ads/social. |
cyberpunk | heavy | strong | long | Viral neon city, TikTok-ready. |
# Generate from prompt
curl https://api.aigatecloud.com/v1/effects/cinematic-rain \
-H "Authorization: Bearer $AIGATE_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "Tokyo Shinjuku alley",
"preset": "cinematic"
}'
# Transform a photo (any time of day → cinematic rainy night)
curl https://api.aigatecloud.com/v1/effects/cinematic-rain \
-H "Authorization: Bearer $AIGATE_KEY" \
-H "Content-Type: application/json" \
-d '{
"image_url": "https://api.aigatecloud.com/img/upload-abc.jpg",
"preset": "cyberpunk",
"convert_to_night": true
}'
POST /v1/edit/remove — remove people / objects
Inpaint-style cleanup. Reconstructs background where unwanted elements were removed. Subject stays sharp. Works best on simple backgrounds; complex scenes get extra geometry/lighting guard prompts.
| Field | Type | Default | Description |
|---|---|---|---|
image_url | string | — | Required. /v1/upload URL. |
target | string | people | people · objects · both |
background_complexity | string | simple | simple · complex (extra guards for architecture/perspective) |
reconstruction_strength | string | medium | light · medium · strong |
preserve_subject | bool | true | Keep main subject sharp + identity-locked. |
mask_url | string | null | Optional B&W mask (white = remove). For pro use. |
POST /v1/edit/remove-background — transparent PNG
Cuts the subject and returns a PNG with full alpha channel. Self-hosted rembg / U2Net. Hair detail preserved. Output served at /img/{key}.png.
| Field | Type | Default | Description |
|---|---|---|---|
image_url | string | — | Required. /v1/upload URL. |
edge_refinement | string | high | low / medium / high (informational; engine fixed) |
preserve_hair | bool | true | Use the alpha-matting branch for fine hair strands. |
output_format | string | png | Always PNG with alpha. |
output_resolution | int | 2048 | Max edge in px. |
curl https://api.aigatecloud.com/v1/edit/remove-background \
-H "Authorization: Bearer $AIGATE_KEY" \
-H "Content-Type: application/json" \
-d '{"image_url":"https://api.aigatecloud.com/img/upload-abc.jpg"}'
POST /v1/portrait/studio — 5 studio styles
Transform a casual portrait into a polished studio shot. Identity-locked.
| Field | Type | Default | Description |
|---|---|---|---|
image_url | string | — | Required. /v1/upload URL. |
style | string | clean | clean · artistic · corporate · moody · color_gel |
identity_lock | bool | true | Add identity-preserve guard. |
retouch | string | natural | minimal · natural · strong |
Style cheat sheet
| style | look | best for |
|---|---|---|
clean | Soft even studio lighting, neutral background | Profile photos, branding |
corporate | Formal attire, sharp confident look | LinkedIn, CV, business |
artistic | Dramatic shadows, fine art mood | Editorial, portfolios |
moody | Low-key, dark background | Branding, music covers |
color_gel | Dual-tone gel lighting | Modern social, ads |
POST /v1/edit/face-restore — GFPGAN / CodeFormer (Replicate BYOK)
Restore faces in old photos, low-res images, or AI-generated portraits. With Replicate BYOK: routes to tencentarc/gfpgan or sczhou/codeformer. Without BYOK: falls back to Pollinations img2img (lower quality but free).
| Field | Type | Default | Description |
|---|---|---|---|
image_url | string | — | Required. /v1/upload URL. |
model | string | auto | auto · gfpgan (old photos) · codeformer (AI faces) |
weight | float | 0.5 | CodeFormer fidelity 0-1 (0=quality, 1=identity) |
upscale | int | 2 | 1, 2, or 4 |
POST /v1/edit/upscale — Topaz (Replicate BYOK) / fallback
Pro-grade upscaling. With Replicate BYOK: topazlabs/image-upscale. Without: Pollinations Flux upscale.
| Field | Type | Default | Description |
|---|---|---|---|
image_url | string | — | Required. |
scale | int | 2 | 2 or 4 |
enhance | bool | true | Enable detail enhancement. |
POST /v1/edit/kontext — Flux Kontext Pro (Replicate BYOK required)
Text-driven precise image editing via black-forest-labs/flux-kontext-pro. Best-in-class prompt following for edits like "change the shirt to blue", "remove the chair", "make it sunset".
Replicate BYOK required. Returns 402 if no key in BYOK Vault.
| Field | Type | Default | Description |
|---|---|---|---|
image_url | string | — | Required. |
prompt | string | — | Required. ≤500 chars. Edit instruction in plain English. |
curl https://api.aigatecloud.com/v1/edit/kontext \
-H "Authorization: Bearer $AIGATE_KEY" \
-H "Content-Type: application/json" \
-d '{
"image_url": "https://api.aigatecloud.com/img/upload-abc.jpg",
"prompt": "change the background to a sunset beach, keep the person identical"
}'
POST /demo/generate-post — public, rate-limited
Try the pipeline without an API key. 5 requests / hour / IP. No image generation.
curl https://api.aigatecloud.com/demo/generate-post \
-H "Content-Type: application/json" \
-d '{"idea":"sell luxury watches", "mode":"viral"}'
POST /demo/compare — public, rate-limited
Run the same idea through all 4 modes in parallel. Used by the Lab Test page.
curl https://api.aigatecloud.com/demo/compare \
-H "Content-Type: application/json" \
-d '{"idea":"sell luxury watches"}'
Response shape:
{
"idea": "sell luxury watches",
"intent": "ads",
"modes": [
{"mode": "speed", "caption": "...", "hashtags": [...], "latency_ms": 1820, ...},
{"mode": "cost", ...},
{"mode": "quality", ...},
{"mode": "viral", ...}
]
}