# Kazzle template context

This app was created from the `ai` template. It's a multi-modality starter and a live regression suite for Kazzle's AI gateway. The Hono server exposes five endpoints, each a thin proxy over `/ai/*`:

| Template route | Kazzle route | Default model |
|---|---|---|
| `POST /chat` | `POST /ai/chat/completions` | `openai/gpt-5.5` |
| `POST /image` | `POST /ai/images/generations` | `google/gemini-2.5-flash-image` |
| `POST /speech` | `POST /ai/audio/speech` | `openai/gpt-audio` |
| `POST /transcribe` | `POST /ai/audio/transcriptions` | `google/gemini-3.5-flash` |
| `POST /video` + `GET /video/:id` | `POST /ai/video/generations` + `GET /ai/responses/:id` | `bytedance/seedance-2.0-mini` |

Auth is one `kzl_…` API key (`KAZZLE_API_KEY`) plus the matching environment API root (`KAZZLE_API_URL`). The browser never sees either value — every modality round-trips through the server so customers can layer their own auth/rate-limits/business rules on top. Billing is metered against the Kazzle space that owns the key.

Override any model per-request via the JSON body (`{ model: '…' }`) or globally via env: `KAZZLE_AI_MODEL`, `KAZZLE_IMAGE_MODEL`, `KAZZLE_SPEECH_MODEL`, `KAZZLE_TRANSCRIPTION_MODEL`, `KAZZLE_VIDEO_MODEL`. The gateway is `${KAZZLE_API_URL}/ai`.

For extraction, classification, translation metadata, calorie parsing, or any feature that needs data instead of prose, use structured output on `POST /chat`. The UI helper `sendStructuredChat<T>()` sends OpenAI-style `response_format: { type: 'json_schema', json_schema: ... }`; the server forwards it to `/ai/chat/completions` and returns parsed JSON as `structured`. Before changing AI request/response behavior, call `api_docs` for `POST /ai/chat/completions` so the app follows the current gateway schema instead of guessing from memory.

The UI is a tabbed playground (`components/ui/src/App.tsx` → `tabs/*`) — one minimal panel per modality. The Extract tab is the structured-output reference path. Each panel is a reference impl, not a polished product surface. Replace or extend as needed; the API surface stays the same.

Do not move the API call into the browser, do not add streaming until the user asks for it, and do not persist chat history server-side without an explicit request — those are larger product decisions, not template defaults.
