PROJECT STUDY

Model Gateway & Evals

One door for every model call, one gate for every change.

An OpenAI-compatible model gateway with Rupiah budgets, provider failover and a guard for Indonesian identifiers, plus a statistical evaluation gate that blocks prompt and model regressions in CI.

Explore the build
Gateway console illustration with a request log, a prompt shown as sent upstream with two fields redacted, a routing chain where the primary model's circuit is open and a fallback is serving, and an evaluation of two prompt versions that passes the release gate.
Original interface illustration · Synthetic demo data.View larger

At a glance

Industry
Technology
Capabilities
8
Technologies
12
Year
2026

The challenge

When several teams adopt language models on their own, model access spreads faster than anyone can govern it.

API keys end up scattered across applications, spending is discovered only on the invoice, personal data such as NIK, NPWP and phone numbers travels to outside providers, a slowing provider goes unnoticed, and a prompt or model change can quietly make answers worse.

Model Gateway & Evals is built for companies in Indonesia that run language models across teams. One gateway centralises access, spending and personal-data policy, and an evaluation harness turns answer quality into a release gate that every prompt or model change has to pass.

What we built

Model Gateway & Evals combines a policy-enforcing gateway, an evaluation harness and an operator console in one TypeScript workspace.

One OpenAI-compatible endpoint

Applications send chat completions to one Hono service on Node.js with any OpenAI SDK, streamed over Server-Sent Events or returned whole. Adapters translate each call into the OpenAI Chat Completions, Anthropic Messages, Gemini generateContent or Ollama chat format behind one interface

One OpenAI-compatible endpoint

Applications send chat completions to one Hono service on Node.js with any OpenAI SDK, streamed over Server-Sent Events or returned whole. Adapters translate each call into the OpenAI Chat Completions, Anthropic Messages, Gemini generateContent or Ollama chat format behind one interface

Routing with failover

Model aliases resolve to provider chains, with a circuit breaker per provider, retries with full-jitter backoff that honour Retry-After, per-attempt and per-request deadlines, and failover only before the first token reaches the client

Policy per API key

Request and token limits per minute, the aliases a key may call, and a monthly Rupiah budget that reserves the worst case before each call and settles to actual usage after it

A guard for Indonesian identifiers

NIK, NPWP, +62 and 08 phone numbers, email addresses, Luhn-checked card numbers and bank account numbers after a keyword are found before a request leaves, then blocked, redacted or tokenised into placeholders that are restored in the answer, as the key's policy says

Cache, metering and traces

An exact-match cache for deterministic requests, scoped per team and holding guarded text only, one SQLite row per request with tokens, cost, latency, time to first token and attempts, OpenTelemetry-style spans for each step and provider attempt, and Prometheus metrics

A prompt registry

Prompt templates are versioned and released through labels such as production and staging, and a request can name a prompt by label with its variables instead of sending the text

Evaluations as a release gate

JSONL datasets graded by exact match, regex, JSON Schema, citation or an LLM judge, a paired comparison of baseline and candidate with a seeded bootstrap interval, and a command-line tool whose exit code lets CI block a regression

An operator console

Traffic, latency, spend and provider health, a request log whose trace drawer shows only guarded text, keys and budgets, routing with a test request, evaluation runs compared case by case, prompts and a PII guard playground

How it works

  1. Check the key's policy

    Every application calls the gateway with its own key, stored only as a SHA-256 hash. The gateway checks that the key may use the requested alias, charges its per-minute request and token buckets and runs the PII guard in the key's mode, so a blocked identifier never leaves and a tokenised one leaves only as a placeholder.

  2. Route down the chain

    A deterministic request can be answered from the team's exact-match cache. Otherwise the gateway reserves the worst-case cost across the alias's whole fallback chain, tries each provider in order under the request's deadline, skips any whose circuit is open, and returns the answer, streamed or whole, with placeholders restored.

  3. Meter every call

    The reservation is replaced by the cost from the provider's reported usage, or by an estimate flagged as such. The request row and its spans go to SQLite, and the Prometheus counters for requests, provider attempts, tokens, cost, cache lookups, PII detections and breaker transitions move.

  4. Gate every change

    The eval tool runs a JSONL dataset through the gateway for the baseline and the candidate with temperature 0, no cache and no failover, so a fallback cannot hide a regression. It grades both the same way, bootstraps the paired differences and exits with an error when the candidate fails the gate, so CI stops the release.

Engineering insights

The gateway treats every model call as a policy decision before it becomes a network call, and every prompt or model change as a release that has to pass a test.

Stack by layer

Frontend
  • React
  • TypeScript
  • Vite
  • React Router
  • TanStack Query
  • Tailwind CSS
  • Lucide icons
  • SVG charts
Backend
  • Node.js
  • TypeScript
  • Hono
  • Zod
  • ts-pattern
  • OpenAI-compatible API
  • Server-Sent Events
Data
  • SQLite (node:sqlite)
  • JSONL datasets
AI
  • OpenAI Chat Completions format
  • Anthropic Messages format
  • Gemini generateContent format
  • Ollama chat format
  • LLM-as-judge grading
  • Ajv JSON Schema grading
  • Paired bootstrap intervals
Infrastructure
  • Vitest
  • Playwright
  • Testing Library
  • Biome
  • esbuild
  • Prometheus metrics
  • OpenTelemetry-style traces
  1. Failover stops at the first token

    Retries stay on a provider for timeouts, 5xx responses, rate limits and overload, with full-jitter backoff between 250 ms and 2 s that honours Retry-After. A breaker opens when half of a provider's last 20 calls failed, with at least 5 made, and lets one probe through after 30 seconds. Before the first token a failed attempt can fail over invisibly; after it, a failure ends the stream with an in-band stream_interrupted event instead of switching models mid-answer

  2. NIK validated by structure, not by length

    A 16-digit number counts as a NIK only with one of the 38 province codes, a plausible regency and district, a valid birth date in which women add 40 to the day, and a non-zero serial, and a number that also passes the Luhn check with a card prefix is treated as a card unless a NIK keyword comes before it. Tokenise mode numbers placeholders by first appearance and restores them in the answer, even when a placeholder is split across stream chunks

  3. Budgets reserve the worst case, then settle

    Amounts are integers in micro-Rupiah, so no floating point enters a budget comparison. Before a call the gateway reserves the most expensive outcome across the whole fallback chain, then replaces it with the cost of actual usage. A configured model without a price is refused instead of being served for free, and the budget month follows the WIB calendar

  4. Prompt releases pass a paired bootstrap gate

    Baseline and candidate answer the same cases, and a seeded bootstrap of the paired score differences, 2,000 resamples by default, gives a 95% interval. The gate is a non-inferiority test: it passes only when the lower end of the interval stays at or above minus the margin, 0.02 by default, and an inconclusive result fails as well

  5. A week of traffic on a virtual clock

    Timeouts, backoff, breaker cooldowns, bucket refills and cache expiry all run on an injected clock, and a built-in simulator answers in all four providers' wire formats with latency profiles and staged faults. The test suite runs offline and deterministically without an API key, and a seven-day synthetic seed of 3,903 requests runs through the real gateway in about 45 seconds on a Windows 11 development machine

Design system

Operator console is dense, quiet and exact, for the platform engineers who run the gateway and the people who approve a prompt release, with light and dark themes drawn from one set of semantic tokens.

Colour palette

  • Graphite#111827Text, primary buttons and focus rings in the light theme, and the page ground in the dark theme
  • Slate#f8fafcPage background in the light theme, and text in the dark theme
  • Violet#6d28d9The one AI action: sending a test request through the gateway
  • Pass green#16a34aServed requests, healthy breakers, passed gates and passed grades, always with an icon
  • Fail red#dc2626Failed requests and attempts, open circuits and failed gates
  • Warning amber#d97706Policy refusals, half-open circuits, budgets at 80% or more and the gate margin line
  • Data blue#2a78d6The primary chart series: served requests, p95 latency, budget meters and confidence intervals
  • Colour

    Graphite on slate for everything neutral, green, red and amber only for pass, fail and warning, one data blue for the primary chart series, and violet kept for the one action that calls a model: sending a test request. Each status colour has a soft background and its own text shade per theme, because a mark colour that works for a bar can fail contrast as text

  • Typography

    Inter for the interface and JetBrains Mono for anything a user might copy or compare, such as request ids, key, model and alias names, prompts, answers, placeholders and span names, both bundled through Fontsource, with tabular figures in tables and KPI tiles

  • Components

    In-house React components on Tailwind CSS v4: badges with an icon and a label, tables with sticky headers and a keyboard row cursor, segmented controls on native radios, dialogs, budget meters and masked text that highlights placeholders, so the request log never shows the original personal data. Stacked column, line and confidence interval charts are hand-drawn SVG with a screen-reader table, and spend bullets and the trace waterfall are labelled HTML lists

  • Themes and input

    Both themes follow the system preference until toggled, and every page has its loading, empty, error and ready states. Keyboard shortcuts move between pages, search the request log and walk table rows, and the layout holds from 390 px phones to wide screens

Where this fits

Companies running language models across several teams can put one gateway and one release gate in front of them. Explore our AI solutions and IT consulting, or talk to us about governing model access in your company.

talk to us

Let’s connect the dots

Let's put these ideas to work.

Share a process, product, or problem you want to improve. We will work through the possibilities together.

Discuss your project