Europe/Zurich

One gateway in front of every model call

November 4, 2026
One gateway in front of every model call

Abstract cover: a glowing gateway routing cool network lines on one side and warm flowing nodes on the other

If you are putting AI into a production product, the model name is the easy choice. The harder work is what sits in front of every call: who can hit which model, how much they can spend, what is allowed to leave, and who unlocks when the answer is not enough.

I run that layer for trama (formerly Ayentic) and for some of my other projects. It is self-hosted, models through Amazon Bedrock.

I first tried keeping the rules in prompt and config files for each tool. That gave me no single place to control cost and access. A gateway with virtual keys did: one place that can hold definitions and reach other tools, so prompts, tool servers and agents can be managed together. My bots propose changes to that layer and I approve them before they go live.

Here is what I would copy on day one, then a real week of numbers, then thirty days of spend with what testing actually costs, then what went wrong.

What I would copy

  1. Put a gateway in front of every model call, even if you only have two keys.
  2. Give every key a daily budget and a model allowlist. Raise the budget on purpose, not by accident. Keep evaluation on its own keys.
  3. Tag every request with tenant, environment, audience and purpose.
  4. One key per audience, and no silent fallback to the wrong agent.
  5. Write the test cases before you touch the prompt. A separate judge scores answers. You decide the cut.
  6. Measure a real week: requests, tokens, spend, errors, p50 and p95.
  7. Expect evaluation waves to cost more than product traffic. Budget for that on purpose.

What the gateway does

Four jobs before a model sees a request:

  1. Identity. Every caller gets a virtual key tied to a team, a purpose and an audience. Keys do not share models or tools by accident.
  2. Money. Every key we audited has a daily budget and a rate limit, with team budgets above those tiers. When the cap is hit, the call stops.
  3. Policy. Guardrails on by default: a secrets filter, and an after-response filter that stops internal content leaking to customers.
  4. Judgment where code is not enough. A typed advisor returns choices, scores and yes or no answers with probabilities. It advises. I still unlock.

Flow from channels and apps through a virtual key and the gateway into the model, plus the agent approval loop with test file, judge, pass bar and three of three runs

A real week of traffic

Numbers below come from the production gateway spend logs for 19 to 25 October 2026, Europe/Zurich. They are product traffic only. Health checks the gateway runs on itself, and development and evaluation traffic, are excluded.

  • Requests: about 1,700
  • Tokens: about 8 million
  • Spend: under USD 11
  • Error rate: about 3%
  • Latency p50: 1.90 s
  • Latency p95: 3.62 s

Models on that path: Claude Sonnet and Claude Haiku through Amazon Bedrock, plus embeddings for memory. We track errors per request.

That quiet week is the useful baseline. The next section shows what happens when certification waves sit on the same gateway.

Thirty days of spend, and what testing costs

Rounded figures from the same proxy spend logs for 5 October to 4 November 2026 (UTC calendar days; 4 November was a partial day at pull). About USD 308 of model spend in that window.

Spend by model

Almost all of it went to one model:

  • Claude Sonnet (via Bedrock): about USD 301, roughly 98% of spend, about 19,300 requests, about USD 0.016 per request on average, about 1.9 s average latency (latency is a sample)
  • Claude Haiku (via Bedrock): about USD 3.9
  • Embeddings: high volume, near-zero spend

Horizontal bar chart of 30-day spend by model, Sonnet dominant at about 98 percent

I did not run a clean A/B model swap with paired cost and quality. We standardized on Sonnet for the agent runtimes we certify. A plan to move some jobs to Haiku exists; it is not evidenced here with before and after metrics.

Daily shape: two evaluation spikes

Plot the same thirty days day by day and the story is not a smooth customer curve. Two UTC days dominate:

  • 10 October: about USD 99
  • 28 October: about USD 123

Those are certification and development waves, not a sudden rush of customer chat.

Bar chart of daily gateway spend over about 30 days with 10 October and 28 October highlighted as evaluation spike days

For the calendar month of October, proxy spend was about USD 306, with roughly 90% attributed to evaluation and development (runbook estimate, not a per-request breakdown).

What one test run costs next to a normal day

On the same model, after a prompt fix only (no model change):

  • One full development certification suite: 12 of 12 pass for about USD 0.75
  • One production smoke on critical cases: 6 of 6 critical pass for about USD 0.20 to 0.25

A quiet product day on this gateway is often about USD 1 to 2. An evaluation spike day lands around USD 100. The lesson I would copy: testing costs more than running. Put evaluation on its own keys and budgets, or a certification wave will look like a production outage when the shared monthly cap fires.

Log-scale bar chart comparing one certification run at about USD 0.75, a quiet product day at about USD 1 to 2, and an evaluation spike day at about USD 100

I do not have a clean per-round token or dollar cost for most agent scorecards. Those fields were empty in the records we checked, so I am not inventing them. The measured figures above come from the two runs where we did record spend.

Keys, teams and budgets

A handful of teams and dozens of virtual keys sit on the shared gateway. Budgets are daily caps per key and tier, with team budgets above them. Customer and internal keys cannot call each other's agents. Per-person read-only tools and demo tenants sit on their own teams.

We decided on one key per audience; the channel is a tag on the request. Test traffic has its own small daily caps. I do not paste key names, hostnames or internal URLs here.

How we approve agents

The tests come before the prompt. Each agent gets a file of about 15 to 25 cases that cover its whole scope, written before anyone edits the prompt. Cases on payments, prices and safety are critical.

A separate judge agent, from another lane with its own key, scores every answer. The agent under test never grades itself.

The bar is 100% of the critical cases and at least 90% overall. The result is tied to the prompt version. The final cut must pass three runs out of three in a row. Rounds go fix, version, rerun. After certification, a human (me) decides. The judge changes nothing in production.

Two rounded examples. An internal sales-assistant agent reached version 6, passing three of three runs at 100% critical and 100% overall, about one to two days from the first cases, then human approval. A sales agent sat at about 81% critical (13 of 16) at version 5. The causes were the runtime allowing only one tool round per turn, and two stock sources that contradicted each other. It is now at version 13 and still not certified after more than three weeks. Sometimes it is architecture or data, not the prompt.

What went wrong

Once, evaluation runs on the most expensive model ate most of the month's spend. The monthly cloud budget cap fired and blocked model calls for everything, production included. Fix: strict daily caps on development and test keys, headroom for production, and evaluation kept separate by key and budget. A small daily cap can also stop a test round halfway. That is the cap working, so we plan runs around the reset.

Once, a silent fallback routed customer messages to the internal assistant, and a customer got a staff-oriented answer, with no customer data exposed. The lesson: one key per audience that can call only its own agent, the channel as a tag, fail closed (no answer rather than the wrong agent), and an output filter that blocks internal content.

Agents can clash with each other too. One bot said a human had approved something; another treated that as approval. Rule: only the human's OK in their own words counts, each bot stays in its lane, and one bot coordinates notices.

Passing staging does not prove production. A guard that ran only in staging once hid a production bug.

Guardrails and typed advice

Two filters are on by default: a secrets filter that masks card and API-key shaped strings before the model sees them, and an after-response filter that stops internal content leaking into a customer reply. When the second one trips, the reply does not go out as written and a person takes over.

Anything that does not go through the gateway is not governed by it. Design for the features your gateway edition actually has, not the brochure.

Before decisions that touch outbound mail, money, legal, publish or anything irreversible, our bots ask a typed advisor through the same gateway. Advise-only. Shadow checks for the first patterns passed 8/8 with a verify p95 of about 191 ms: log the advice, do not change the customer reply yet.

Who uses it

The same layer fronts customer-facing autopilots, internal assistance, per-person read-only tools, an advise-only reviewer, an isolated demo tenant and evaluation runs on separate keys.

If you take one thing

You no longer have to keep editing prompt files or talking a coding assistant into updating its context. How the context your assistants work from changes over time can be coordinated in one place: an AI gateway in front of the model.

And when you measure it, budget the certification waves. In our thirty days, almost all spend was one model, and most of that month was testing, not production chat.

Related: trama product journey · Sureva: AI that survives contact with reality · trama.sureva.com