# Aurabase AI Gateway & Sovereign LLM Reference (23 Endpoints) > Documentation: https://aurabase.dev/en/docs/ai > Base URL: `https://.aurabase.dev/v1/ai` (or `https://api.aurabase.dev/v1/ai`) > Runtimes & SDKs: TypeScript/JavaScript (`@aurabase/ai`), Python (`aurabase-py`), cURL, LangChain, LlamaIndex, MCP ## 1. Overview & Architecture The Aurabase AI Gateway (`services/aura-ai`, Tokio/Axum microservice) provides a sovereign European proxy for multi-provider LLMs, pgvector embeddings, and RAG pipelines: - **Zero CLOUD Act Exposure**: All compute, vector storage, and orchestration operate strictly in EU data centers (Hetzner Germany & Scaleway Paris). - **Multi-Model Orchestration**: Native adapters for Anthropic (Claude 3.5 Sonnet / Opus / Haiku), OpenAI (GPT-4o, GPT-4o-mini, o1/o3), Google Gemini (Gemini 1.5 Pro / Flash, Gemini 2.0), and custom OpenAI-compatible endpoints (Ollama, Mistral, Scaleway Generative APIs). - **Automated Fallback**: Configurable `fallback_provider` triggered on transient upstream failures (5xx / 408 timeouts). - **Zero-Secret Frontend Sessions**: `aura.ai.session()` mints short-lived JWT HMAC capability tickets (300s TTL) with bounded token budgets, preventing API key exposure and client cost runaway. - **AST-Verified NL2SQL**: SQL Abstract Syntax Tree validation enforcing pure read-only queries (`SELECT`) and injecting server-side `LIMIT 100` bounds (max 1000). ## 2. Complete HTTP Endpoints Inventory (23 Endpoints) | Method | Endpoint Path | Role & Purpose | Authentication | |:---|:---|:---|:---| | `POST` | `/v1/ai/{project_id}/chat` | Synchronous multi-provider chat completion | `apikey` (anon / service_role) | | `POST` | `/v1/ai/{project_id}/chat/stream` | Real-time Server-Sent Events (SSE) token streaming | `apikey` (anon / service_role) | | `POST` | `/v1/ai/{project_id}/session` | Mint an ephemeral capability session token (300s TTL) | `apikey` (client/admin) | | `POST` | `/v1/ai/{project_id}/session/chat` | Ephemeral session chat with token budget deduction | `Authorization: Bearer ` ONLY | | `POST` | `/v1/ai/{project_id}/session/chat/stream` | Ephemeral session chat streaming | `Authorization: Bearer ` ONLY | | `POST` | `/v1/ai/{project_id}/session/embed` | Ephemeral session direct vector embedding computation | `Authorization: Bearer ` ONLY | | `POST` | `/v1/ai/{project_id}/embed` | Generate and persist embedding in PostgreSQL pgvector | `apikey` (anon / service_role) | | `GET` | `/v1/ai/{project_id}/search` | Semantic vector search by cosine distance (`query`, `namespace`) | `apikey` (anon / service_role) | | `POST` | `/v1/ai/{project_id}/rag/query` | Retrieval-Augmented Generation context query | `apikey` (anon / service_role) | | `POST` | `/v1/ai/{project_id}/rag/ingest` | Large document ingestion and chunking (up to 5 MB) | `apikey` (anon / service_role) | | `GET` | `/v1/ai/{project_id}/rag/namespaces` | List all distinct RAG namespaces for the project | `apikey` (anon / service_role) | | `DELETE`| `/v1/ai/{project_id}/rag/{namespace}` | Delete a RAG namespace and its indexed vectors | `apikey` (service_role / admin) | | `POST` | `/v1/ai/{project_id}/rag/{namespace}/reindex` | Reindex a namespace with active embedding model | `apikey` (service_role / admin) | | `POST` | `/v1/ai/{project_id}/nl2sql` | Natural language to PostgreSQL (AST-checked, read-only) | `apikey` (anon / service_role) | | `GET` | `/v1/ai/{project_id}/logs` | Observability logs (latency, tokens, provider, cost) | `apikey` (service_role / admin) | | `GET` | `/v1/ai/{project_id}/settings` | Inspect project AI settings (default provider, fallback) | `apikey` (anon / service_role) | | `PUT` | `/v1/ai/{project_id}/settings` | Update project AI settings (system prompt, fallback) | `apikey` (service_role / admin) | | `GET` | `/v1/ai/{project_id}/providers` | List configured providers (API keys masked) | `apikey` (service_role / admin) | | `GET` | `/v1/ai/{project_id}/providers/{provider}` | Inspect single provider configuration | `apikey` (service_role / admin) | | `POST` | `/v1/ai/{project_id}/providers/{provider}` | Upsert provider credentials (Vault Transit encrypted) | `apikey` (service_role / admin) | | `PATCH`| `/v1/ai/{project_id}/providers/{provider}` | Partial provider update | `apikey` (service_role / admin) | | `DELETE`| `/v1/ai/{project_id}/providers/{provider}` | Remove provider configuration | `apikey` (service_role / admin) | | `POST` | `/v1/ai/{project_id}/providers/{provider}/validate` | Test upstream provider API credentials and model | `apikey` (service_role / admin) | ## 3. Detailed Request & Response Specifications ### A. Chat Completion (`POST /v1/ai/{project_id}/chat`) ```http POST /v1/ai/{project_id}/chat HTTP/1.1 Host: .aurabase.dev apikey: aura_anon_xxx Content-Type: application/json { "messages": [ { "role": "user", "content": "Explain GDPR compliance in European clouds." } ], "system": "Answer accurately in 2 concise sentences.", "provider": "anthropic", "model": "claude-3-5-sonnet", "temperature": 0.2, "max_tokens": 1024 } ``` **Response (`200 OK`)**: ```json { "data": { "content": "GDPR compliance mandates that European personal data remains under EU legal protections without third-country interception...", "model": "claude-3-5-sonnet", "provider": "anthropic", "fallback_used": false, "input_tokens": 32, "output_tokens": 58, "reasoning_tokens": null, "finish_reason": "stop" } } ``` ### B. Streaming Completion (`POST /v1/ai/{project_id}/chat/stream`) Streamed via Server-Sent Events (`text/event-stream`) without transport timeouts: ```http event: delta data: {"content": "European"} event: delta data: {"content": " data"} event: done data: {"provider":"anthropic","fallback_used":false,"finish_reason":"stop","usage":{"input_tokens":32,"output_tokens":48,"reasoning_tokens":null}} ``` ### C. Ephemeral Sessions (`POST /v1/ai/{project_id}/session`) Issues short-lived JWT HMAC tickets for client applications: ```http POST /v1/ai/{project_id}/session HTTP/1.1 Host: .aurabase.dev apikey: aura_sk_xxx Content-Type: application/json {} ``` **Response**: ```json { "data": { "ticket": "aura_sess_eyJhbGciOi...", "expires_at": 1730410300, "budget_remaining": 50000 } } ``` Subsequent calls to `/session/chat` or `/session/chat/stream` require header: `Authorization: Bearer aura_sess_eyJhbGciOi...` (passing regular `apikey` is strictly forbidden to prevent credential confusion). ### D. Embeddings & Semantic Search (pgvector) - **Store & Embed**: `POST /v1/ai/{project_id}/embed` ```json { "text": "Technical documentation for sovereign cloud storage", "namespace": "docs", "metadata": { "section": "storage", "author": "Platform Team" } } ``` Returns: `{ "data": { "id": "uuid-...", "dimensions": 1536 } }`. - **Search**: `GET /v1/ai/{project_id}/search?query=cloud+storage&namespace=docs&threshold=0.8&top_k=5` Returns matching documents with computed cosine similarity score. ### E. RAG Ingestion & Query - **Ingest Document**: `POST /v1/ai/{project_id}/rag/ingest` (up to 5 MB body limit) with `chunk_size: 1000`, `chunk_overlap: 200`. - **Query Corpus**: `POST /v1/ai/{project_id}/rag/query` with `question` and `namespace`. ### F. AST-Verified NL2SQL (`POST /v1/ai/{project_id}/nl2sql`) ```json { "question": "Which 5 users registered most recently?", "dialect": "postgresql", "limit": 5 } ``` - Validates that the generated SQL is strictly a `SELECT` statement. - Automatically injects `LIMIT 5` and blocks all mutation commands. ## 4. Model Context Protocol (MCP) Tools When using Aurabase MCP Server (`@aurabase/mcp-server`), five high-level tools map directly to the AI Gateway: - `ai_completion`: Chat completion with verified token usage and provider reporting. - `index_document`: Automatic chunking and vector persistence. - `rag_query`: Context-augmented question answering. - `vector_search`: Cosine similarity query on any table with a pgvector column. - `create_vector_index`: Automated creation of HNSW or IVFFlat indexes. ## 5. Error Codes & Troubleshooting | HTTP Code | Error Code | Meaning & Resolution | |:---|:---|:---| | `400` | `bad_request` | Invalid message roles (system in messages array), unsupported vector dimensions, or SQL mutation attempted in NL2SQL. | | `401` | `unauthorized` | Invalid or missing `apikey`, or expired ephemeral session ticket. | | `403` | `quota_exceeded` | Monthly token quota or request limit reached on the project plan. | | `404` | `model_not_found` | Requested model is unknown to the upstream provider. Check `chat_model` configuration. | | `408` | `timeout` | Upstream LLM provider did not respond within the request deadline. | | `429` | `rate_limited` / `session_budget_exceeded` | Per-project rate limit reached or ephemeral session token budget exhausted. | | `503` | `service_unavailable` | Transient upstream outage; automatic fallback is triggered if configured. |