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.

ServiceURL
APIhttp://localhost:3001
Dashboardhttp://localhost:3002
TierWhenKeys needed
free (default)You don’t ask for premiumAI Gate project key only
premiumtier: "premium"Project key + provider key in dashboard
autoMix free + available premiumSame 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:

  1. Register / sign in — creates your user and a default organization.
  2. Create a project — generates an API key shown once. Copy it immediately.
  3. Open a project — manage keys, providers, usage, and recent requests.
  4. Rotate / revoke API keys — rotate shows a new key once; revoke disables a key.
  5. Toggle free providers — enable/disable Gemini, NVIDIA, OpenRouter, Pollinations, Groq, etc.
  6. Save premium credentials — OpenAI / Anthropic keys encrypted at rest (never returned).
  7. Watch usage — requests, tokens, latency, success rate, provider distribution.

Go to Projects after signing in.

Get an API key

  1. Open the dashboard → register / sign in
  2. Create a project
  3. Copy the key once (ai_live_…)
  4. 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 history

Pin 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 / knowledgeBases501 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? }
ModalityRuntimeHow
chatYesai.generate()
imageYesai.image()
video / audio / embedding / otherCatalog onlyai.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 }]
}

Premium setup

  1. Open your project in the dashboard
  2. Under Premium providers, pick OpenAI or Anthropic
  3. Paste the provider API key → Save encrypted key
  4. Call with tier: "premium"
await fetch(`http://localhost:3001/projects/${projectId}/credentials`, {
  method: "PUT",
  headers: {
    "Content-Type": "application/json",
    Authorization: `Bearer ${sessionToken}`,
  },
  body: JSON.stringify({ provider: "openai", apiKey: "sk-…" }),
});

Keys are AES-256-GCM encrypted and never returned (only a hint like ••••••91).

Errors to handle

HTTPMeaningUI hint
400Validation failedFix request body
401Bad API / session keyRe-auth / check AI_API_KEY
402PREMIUM_KEY_REQUIREDAdd provider key in dashboard
429Rate limit or quotaBack off / show usage
501RAG_NOT_ENABLEDDon’t send knowledgeBase yet
502All models failedShow attempts[] errors

Capability matrix

FeatureSDKREST
Free chat autoai.generatePOST /v1/generate
Pin chat modelmodel:same
Stream chatai.streamPOST /v1/generate/stream
Free image autoai.imagePOST /v1/images/generate
Premium chat/imagetier: "premium"same
List modelsai.listModelsGET /v1/models
Usage analyticsGET /projects/:id/usage
RAGNot enabled (501)

Full markdown copy also lives at docs/FRONTEND.md in the repo.