# 🌐 KORA UNIFIED API & ENDPOINT MASTER SPECIFICATION > **TARGET AGENT**: API Architect & Backend Infrastructure Engineer > **MISSION**: Implement and deploy the unified API gateway and webhook system for the entire **Kontyra / Kora ecosystem** (Chat, Reasoning, Coding, Vision & Image Generation). > **SCOPE**: Cloud, Container, DevOS Integrations, and Vercel Hybrid Deployment. --- ## 1. Ecosystem Architectural Overview: "One Kora, Two Runtimes" The Kontyra / Kora ecosystem operates as a unified platform spanning two coordinated runtimes: 1. **Edge Frontend & Fast Inference (Vercel)**: Hosts the web interface and the ultra-lightweight **NanoKora-25M** ONNX model (<26 MB) for sub-millisecond conversation and arithmetic. 2. **Dedicated Cloud Compute (Your Self-Hosted Custom Endpoint)**: Hosts the heavy computational models (**Kora Coder 0.5B**, **Watermark-Free Image Generator**, **Vision UI-to-Code**, and **Multi-Agent Task Orchestrator**). ``` ┌──────────────────────────────────────────────┐ │ USER / CLIENT │ │ (Web Browser, DevOS, CLI, Agents) │ └──────────────────────┬───────────────────────┘ │ │ HTTPS (kora-three-alpha.vercel.app) ▼ ┌──────────────────────────────────────────────┐ │ VERCEL EDGE LAYER (KORA) │ │ │ │ • Kontyra Docs Design System UI │ │ • NanoKora-25M ONNX Runtime (CPU, <26 MB) │ │ • Smart Router & Proxy (api/chat.py) │ └──────┬────────────────────────────────┬──────┘ │ │ [General Chat / │ │ [Coding / Images / Vision / Math / Low Latency]│ │ Multi-Agent Swarm] ▼ │ ┌────────────────────┐ │ (Proxies via HTTPS using │ NanoKora-25M Local │ │ KORA_CUSTOM_ENDPOINT) │ (In-Memory ONNX) │ ▼ └────────────────────┘ ┌────────────────────────────────────────┐ │ YOUR CUSTOM CLOUD ENDPOINT │ │ (gateway.py :8000) │ │ │ │ • Kora Coder (Qwen2.5-Coder-0.5B) │ │ • Image Studio (Watermark-Free) │ │ • Vision Analyzer (UI-to-Code) │ │ • Multi-Agent Swarm Orchestrator │ │ • DevOS Webhook Engine │ └────────────────────────────────────────┘ ``` > **Why a Custom Endpoint?** > Vercel has a strict 250 MB serverless deployment bundle limit and 10–60s execution timeouts. Multi-gigabyte models like Qwen2.5-Coder and generative image diffusion pipelines cannot be bundled into Vercel directly. By hosting your own custom endpoint, Kora on Vercel acts as **ONE unified frontend and gateway** that transparently delegates heavy tasks to your custom endpoint while handling quick interactions locally. --- ## 2. Master Route Table to Implement Your custom endpoint (`gateway.py`) must expose the following standard endpoints: | Endpoint | Method | Engine | Description | |---|---|---|---| | `/health` | `GET` | All | Aggregate health status across all active engines | | `/v1/models` | `GET` | Gateway | Lists available models (`nanokora-25m`, `kora-coder-0.5b`, `kora-vision`, `kora-image`, `kora-agent`) | | `/v1/chat/completions` | `POST` | Kora Coder / NanoKora | Standard OpenAI chat completions (supports SSE streaming) | | `/v1/coder/generate` | `POST` | Kora Coder | Production-ready code generation with strict anti-tutorial filter | | `/v1/coder/fix` | `POST` | Kora Coder | Automated bug diagnosis and syntax/logic code repair | | `/v1/images/generations` | `POST` | Kora Image Studio | OpenAI-compatible text-to-image generation (pristine, 100% watermark-free) | | `/v1/vision/analyze` | `POST` | Kora Vision | Upload screenshot/mockup $\to$ outputs clean HTML/Tailwind code | | `/v1/agent/distribute` | `POST` | Agent Swarm | Decomposes complex goals into Backend, Frontend, and QA subtasks | | `/api/devos/webhook` | `POST` | DevOS Bridge | Webhook dispatcher for background coding events, PR reviews, and build repair | --- ## 3. Detailed Endpoint Specifications ### A. Health & Diagnostics (`GET /health`) **Response (HTTP 200)**: ```json { "status": "healthy", "device": "cuda", "models": { "coder": "Qwen2.5-Coder-0.5B-Instruct", "vision": "Kora Multimodal Engine", "image": "Kora Clean Studio Engine", "agent": "Kora Autonomous Orchestrator" }, "cors": "enabled" } ``` --- ### B. Chat & Code Completions (`POST /v1/chat/completions`) Full OpenAI-compatible request body: ```json { "model": "kora-coder-0.5b", "messages": [ {"role": "system", "content": "You are Kora Coder in DevOS. Direct production code only."}, {"role": "user", "content": "Write a FastAPI route with Pydantic validation for user onboarding."} ], "temperature": 0.2, "max_tokens": 1024, "stream": true } ``` * **Routing Logic**: * Default model: `kora-coder-0.5b` (Qwen2.5-Coder). * Auto-injects anti-tutorial system prompt if not present. * **Streaming Protocol**: When `stream: true`, return chunks via Server-Sent Events (`data: {...}\n\n`) terminating with `data: [DONE]\n\n`. --- ### C. Direct Code Generation & Repair #### 1. Generate (`POST /v1/coder/generate`) ```json { "prompt": "Create a Redis token bucket rate limiter in Python", "language": "python", "max_tokens": 1024 } ``` #### 2. Repair Broken Code (`POST /v1/coder/fix`) ```json { "broken_code": "def query_db(uid):\n cursor.execute('SELECT * FROM users WHERE id = ' + uid)", "error_message": "SQL injection vulnerability detected / Syntax error on string concat", "language": "python" } ``` --- ### D. Image Generation (`POST /v1/images/generations`) DALL-E compatible request body: ```json { "prompt": "Futuristic dark minimalist Kontyra AI glowing neon cyber emblem, 3d isometric render", "n": 1, "size": "1024x1024", "response_format": "url" } ``` * **Response (HTTP 200)**: ```json { "created": 1728073200, "data": [ { "revised_prompt": "Futuristic dark minimalist Kontyra AI glowing neon cyber emblem, 3d isometric render", "url": "https://kora.kontyra.name.ng/assets/kontyra_emblem_clean.png" } ] } ``` * **Pristine Quality Guarantee**: Must run watermark-stripping filter (`nologo=true` + PIL boundary scan) to ensure zero unwanted third-party stamps or logos. --- ### E. Multimodal Vision UI-to-Code (`POST /v1/vision/analyze`) Request Body: ```json { "image": "data:image/png;base64,iVBORw0KGgoAAA...", "prompt": "Convert this dashboard mockup into clean Tailwind CSS components.", "task_type": "ui_to_code" } ``` * **Response (HTTP 200)**: ```json { "task_type": "ui_to_code", "analysis": "Identified top navigation bar, 3 metric cards, and a dark themed activity table.", "code": "