# AI Proxy

> Aerostack AI Proxy — coming soon. A unified gateway to route AI requests across providers with cost tracking, caching, and failover.

**Coming Soon** — AI Proxy is under active development. The features described below are planned for an upcoming release.

The Aerostack AI Proxy is a smart gateway for publishing, managing, and monetizing AI-powered APIs. It goes beyond traditional API gateways — with built-in consumer authentication, per-consumer billing, rate limiting, a knowledge base (RAG), content moderation, and auto-generated documentation.

## What It Will Do

```mermaid
graph TB
    REQ["Consumer Request"]
    AUTH["Edge Auth\n(consumer key validation)"]
    RATE["Rate Limit Check"]
    HOOKS_PRE["Pre-Request Hooks\n(moderation, validation)"]
    RAG["Knowledge Base\n(RAG injection)"]
    ORIGIN["Your API"]
    HOOKS_POST["Post-Response Hooks\n(filtering, enrichment)"]
    BILLING["Billing Event\n(async queue)"]
    RES["Response"]

    REQ --> AUTH --> RATE --> HOOKS_PRE --> RAG --> ORIGIN --> HOOKS_POST --> BILLING --> RES

    style REQ fill:#1e293b,stroke:#6b7280,color:#fff
    style AUTH fill:#3b82f6,stroke:#2563eb,color:#fff
    style ORIGIN fill:#10b981,stroke:#059669,color:#fff
    style RES fill:#1e293b,stroke:#6b7280,color:#fff
```

## Planned Features

- **Consumer Key Management** — SHA-256 hashed, edge-cached, scoped to plans and rate limits
- **Per-Consumer Billing** — Free, pay-per-call, subscription, tiered, usage-based billing
- **Rate Limiting** — Per consumer, per plan, per endpoint with burst protection
- **AI Pipeline** — RAG (knowledge base injection), content moderation, pre/post-request hooks
- **Auto-Generated Docs** — OpenAPI Specification with interactive explorer
- **Analytics** — Per-consumer usage, latency percentiles, geographic distribution

## How It Differs from Workspaces

| | MCP Workspaces | AI Proxy |
|---|---|---|
| **Protocol** | JSON-RPC 2.0 (MCP) | REST HTTP |
| **For** | AI tool orchestration | API publishing & monetization |
| **Auth** | Workspace tokens | Consumer API keys |
| **Billing** | Team-based | Per-consumer metered |
| **Best for** | Internal tool access | Public API products |

Both share the same Aerostack infrastructure and edge runtime.

---

*AI Proxy is powered by Aerostack Functions under the hood — the same fullstack edge runtime with native bindings to Database, Cache, Queue, AI, Vector Search, and Storage.*
