Overview#
AI Runtime is an LLM gateway and operations console in a single Go binary. It sits between a product and the model providers. Services send a prompt name and variables over gRPC. The runtime owns the prompt text, the choice of model, the fallback chain, validation of the answer and the cost record. It was built as the AI layer of Vatary Desk, where it is the only process that holds model keys.
Why it exists. When every service calls providers directly, keys spread across the codebase, prompts live in callers' code, and switching a model means a redeploy. Nobody can say what a feature costs or why a call failed. The runtime puts all of that in one place: one key holder, one prompt registry, one cost ledger, and one console that shows what every call did, what it cost and why.
Callers ask for a prompt by name. Which model answers, at what cost, and what happens when it fails is the runtime's job.
- Go binary: gRPC service and console
- 1
- model providers behind one API
- 9
- JavaScript build steps in the console
- 0
- Go test files
- 131

Features#
Every call, logged and filterable
Each model call is a row: status, error class, provider, model, prompt, duration, tokens and cost. Filter by any of them, plus collection, user and metadata, and export the selection as JSON.

One request, end to end
The request page shows which model was asked for and which one served, the experiment it was assigned to, the prompt version, the schema verdict and the cost. It also breaks the input down by source: static prompt text, each variable and the caller's payload. A person can rate the answer good or bad, with a note.

Actions: what one click cost
Every user action carries one correlation id. The console groups its calls into a timeline, a flow and a graph, with the steps around them, the critical path and the total cost. Time spent outside the runtime is shown as a gap, not guessed.
Compare models and prompts
Latency by model, cost per 1k tokens by model, and cost by prompt, for any window. The page shows which product feature is expensive, then which model. Any window can be exported as JSON or sent to an AI review.

Prompt registry
Prompts live in the runtime, not in callers' code. Each one has tags, a base model, a version that is a hash of its text, and a request count. Select several prompts to set a new model for all of them, move them into an experiment, swap one model for another everywhere, or tag them.

A prompt's page holds its text with the variables highlighted, its history, and the strict JSON schema every answer is checked against.

Experiments without a redeploy
A collection overrides the model for a set of prompts and takes a share of traffic, for example "Haiku for triage, 15%". Assignment is sticky per user and never edits the prompts themselves. One switch stops every experiment and sends all traffic back to the base model.

Test iterations
An iteration captures whole user actions for chosen prompts over a window, together with people's thumbs-up and thumbs-down votes. An AI analysis reviews every bad case, writes one report and drafts a prompt fix. A person saves the fix, and the next iteration measures it against the previous one.

Playground and saved cases
Run any registered model by hand, with raw text or with a registry prompt through the real generate path: rendering, schema check and the prompt's routing. Each run is logged as a request, and it can be saved as a test case to replay later.

Model catalog with prices
Every model is registered with its kind (chat, embedding, transcription), input and output price, context window and capabilities. Cost is computed at call time from this table, and the default model is a single click.

Per-user usage
Requests, failures, schema-invalid answers, cost, tokens, p95 latency and top prompts for each end user, with a link to that user's actions.

The gateway#
Every call follows the same path. The runtime renders the prompt from the registry, picks a model through the router, and falls back to the next one on 429 or 5xx errors. It then checks the answer against the prompt's strict JSON schema and records tokens, cost and latency. A caller never sees a provider key, a price list or a retry loop.
- Prompt name + vars
- Render
- Route
- Provider call
- Fallback?
- Schema check
- Record cost
- Answer
- Schema-invalid
- Failed
- Providers: OpenAI, Anthropic, Gemini, xAI, Mistral, DeepSeek, Groq, Moonshot and OpenRouter, behind one interface. Models are registered with their prices, so cost is computed at call time.
- Prompt registry: prompts live in the runtime, not in callers' code. A prompt's version is a hash of its text, so every edit shows up as a step on its charts.
- Router and experiments: the model for a prompt is a routing decision that can be changed and A/B-tested from the console without redeploying a caller.
- Storage: calls, traces and the registry are kept in an embedded SQLite store, so the runtime is one container with no extra database.
The console#
The console is server-rendered from the same binary, with no JavaScript build. It covers requests, actions, unresolved failures, comparison between periods and models, the router, users, providers, models, prompts, collections, iterations, a playground and health.
- Dashboard: requests, failures, p50 and p95 latency, cost, schema-invalid and truncated answers, retries, fallbacks served and prompt-cache hit share, over 24 hours, 7 days or 30 days, optionally compared with the previous period.
- Alerts that avoid noise: a model's failure rate is judged only once it has enough requests, and a run of three or more consecutive failures is flagged on its own, because a run of that length is almost never chance.
- Actions: every user action carries one correlation id. The console opens it as a timeline, a flow and a graph, with every model call, the steps around it, the critical path and the total cost. Time spent outside the runtime is drawn as a gap rather than guessed.
- Analysis: any window can be exported as JSON or sent to an AI review.
The prompt contract#
Callers and the runtime share one vocabulary, prompt names, and nothing at runtime checks that they agree. One pure function compares the prompt names that callers use with the registry, in both directions. A missing prompt is an error, because it would break at request time. An unused prompt is a warning: dead weight or a half-done rename. The same check runs on fixtures, on the registry source in CI, and against the live registry.
Public demo#
The demo gives every visitor a private sandbox with synthetic traffic. Prompts can be edited, the playground run and the router changed, and nobody else sees the changes. Every model answer is canned and no request leaves the server. The sandbox is discarded at sign-out or after two idle hours.
Discussion
Loading comments…

