Docs
Everything you can do with AI Gate — dashboard, SDK, and REST — and how to use it.
Overview
AI Gate is one API for many AI providers. Your app uses a project API key (ai_live_…). The gateway picks free or premium models, routes by health/latency, and fails over automatically.
| Service | URL |
|---|---|
| API | http://localhost:3001 |
| Dashboard | http://localhost:3002 |
| Tier | When | Keys needed |
|---|---|---|
free (default) | You don’t ask for premium | AI Gate project key only |
premium | tier: "premium" | Project key + provider key in dashboard |
auto | Mix free + available premium | Same as above for premium candidates |
Chat and image never mix. Failover stays inside the same modality + tier pool. Call AI Gate from your backend / Route Handler — never expose the project key in browser code.
Dashboard
What you can do in the UI:
- Register / sign in — creates your user and a default organization.
- Create a project — generates an API key shown once. Copy it immediately.
- Open a project — manage keys, providers, usage, and recent requests.
- Rotate / revoke API keys — rotate shows a new key once; revoke disables a key.
- Toggle free providers — enable/disable Gemini, NVIDIA, OpenRouter, Pollinations, Groq, etc.
- Save premium credentials — OpenAI / Anthropic keys encrypted at rest (never returned).
- Watch usage — requests, tokens, latency, success rate, provider distribution.
Go to Projects after signing in.
Get an API key
- Open the dashboard → register / sign in
- Create a project
- Copy the key once (
ai_live_…) - Store it in server env — never ship it to the browser
# .env (server / BFF only) AI_API_KEY=ai_live_xxxxxxxx AI_GATE_BASE_URL=http://localhost:3001
SDKView on npm ↗
pnpm add @dartix-software-solutions/ai-gate # or: npm i @dartix-software-solutions/ai-gate
import { AIClient } from "@dartix-software-solutions/ai-gate";
export const ai = new AIClient({
apiKey: process.env.AI_API_KEY!,
baseUrl: process.env.AI_GATE_BASE_URL ?? "http://localhost:3001",
});Chat generate
Defaults: tier: "free", modality chat, model = auto (fastest healthy free chat model).
const result = await ai.generate({
prompt: "Write a short product description",
context: {
productName: "Nike Air Max",
category: "Running",
features: ["Lightweight", "Breathable"],
},
});
console.log(result.content);
console.log(result.provider); // { name, model, tier }
console.log(result.usage); // tokens
console.log(result.latency); // ms
console.log(result.attempts); // failover historyPin model or provider
await ai.generate({
prompt: "Explain this error",
model: "gemini-3.6-flash",
});
await ai.generate({
prompt: "Summarize",
provider: "openrouter",
});Premium chat
// Dashboard → project → add OpenAI / Anthropic key first
await ai.generate({
prompt: "Draft a refund email",
tier: "premium",
});
await ai.generate({
prompt: "…",
tier: "premium",
model: "gpt-4o-mini",
});No premium key on the project → 402 PREMIUM_KEY_REQUIRED. knowledgeBase / knowledgeBases → 501 until RAG (v1.1).
Streaming
for await (const chunk of ai.stream({
prompt: "Explain recursion simply",
})) {
if (chunk.content) process.stdout.write(chunk.content);
if (chunk.done) break;
}SSE may include a meta object (provider/model) before text chunks.
Image generation
const img = await ai.image({
prompt: "a blue running shoe on white background",
width: 1024,
height: 1024,
});
// img.content = image URL (or data URI for some premium providers)
console.log(img.content, img.provider, img.attempts);
await ai.image({ prompt: "…", model: "flux" });
await ai.image({ prompt: "…", tier: "premium" });List models
Use for UI dropdowns and badges:
const chatFree = await ai.listModels({ modality: "chat", tier: "free" });
const images = await ai.listModels({ modality: "image", tier: "free" });
const premiumChat = await ai.listModels({ modality: "chat", tier: "premium" });
// { id, provider, name, displayName, modality, tier, contextWindow, enabled, health? }| Modality | Runtime | How |
|---|---|---|
chat | Yes | ai.generate() |
image | Yes | ai.image() |
video / audio / embedding / other | Catalog only | ai.listModels({ modality }) |
REST API
Base: http://localhost:3001
Auth: Authorization: Bearer ai_live_…
Chat
POST /v1/generate
Content-Type: application/json
Authorization: Bearer ai_live_…
{
"prompt": "Write a tagline",
"context": { "brand": "AI Gate" },
"tier": "free",
"maxTokens": 512
}Stream
POST /v1/generate/stream
Accept: text/event-stream
Authorization: Bearer ai_live_…
# SSE: data: {"content":"…","done":false} … then data: [DONE]Image
POST /v1/images/generate
Authorization: Bearer ai_live_…
{
"prompt": "minimal logo, blue",
"width": 512,
"height": 512,
"tier": "free"
}Models
GET /v1/models?modality=chat&tier=free Authorization: Bearer ai_live_…
Response shape
{
"id": "req_…",
"content": "…", // text or image URL
"provider": { "name": "gemini", "model": "…", "tier": "free" },
"usage": { "inputTokens": 0, "outputTokens": 0, "totalTokens": 0 },
"latency": 420,
"attempts": [{ "provider": "…", "model": "…", "tier": "free", "ok": true }]
}Errors to handle
| HTTP | Meaning | UI hint |
|---|---|---|
| 400 | Validation failed | Fix request body |
| 401 | Bad API / session key | Re-auth / check AI_API_KEY |
| 402 | PREMIUM_KEY_REQUIRED | Add provider key in dashboard |
| 429 | Rate limit or quota | Back off / show usage |
| 501 | RAG_NOT_ENABLED | Don’t send knowledgeBase yet |
| 502 | All models failed | Show attempts[] errors |
Capability matrix
| Feature | SDK | REST |
|---|---|---|
| Free chat auto | ai.generate | POST /v1/generate |
| Pin chat model | model: | same |
| Stream chat | ai.stream | POST /v1/generate/stream |
| Free image auto | ai.image | POST /v1/images/generate |
| Premium chat/image | tier: "premium" | same |
| List models | ai.listModels | GET /v1/models |
| Usage analytics | — | GET /projects/:id/usage |
| RAG | — | Not enabled (501) |
Full markdown copy also lives at docs/FRONTEND.md in the repo.