How it works

What ModelGate does to every LLM call — shown on real examples.

One base URL puts the gateway between your app and OpenAI, Anthropic, Gemini or Azure. From then on it does three things: prices every call, finds and cuts the waste, and screens traffic for safety and reliability. Everything that changes a request is off until you turn it on.

I · See every cost

Change the request. Watch the price, the waste score and the rules move.

This sample audit runs in your browser with the same waste rules and rate table as the gateway. Pick a scenario or edit the numbers.

Sample requestWorked example

A retrieval pipeline stuffing the whole context window to get a short answer.

System: You answer only from the supplied documents.
User: [12 retrieved passages] — Which clause covers early termination?
What the gateway recordsgpt-4o · $2.50 in / $10.00 out per 1M
Input$0.01506,000 tokens
Output$0.001800180 tokens
Charged$0.0168billed by the provider
Waste score30/100Medium
RuleFires whenWeight
EXPENSIVE_MODEL_SMALL_REQUESTpremium model name, and input + output ≤ 400 tokens—
LARGE_CONTEXT→ PROMPT_COMPRESSIONinput ≥ 4,000 tokens+20
REPEATED_PROMPTthis exact prompt hash was seen before, and was not served from cache—
LOW_OUTPUT_VS_INPUT→ MAX_TOKENS_REDUCTIONoutput × 4 < input+10
LATENCY_ISSUElatency ≥ 8,000 ms—
ERROR_WASTEthe request errored — you paid for nothing—
Waste scoresum of the rules that fired, capped at 10030

Computed in your browser from ModelGate’s published rate table and the same rule set the gateway applies. Token counts are yours to change — a real request’s counts come from the provider.

Requests route through the gateway

ModelGate authenticates your key, applies your rate, token and spend ceilings, and forwards the call using the provider credential you stored. Prompt bodies are not persisted unless you ask for it.

Each call is priced exactly

Token counts come from the provider; rates come from a versioned table. Fixed-point arithmetic, no floating-point drift — and if a model has no published rate, the call is logged without a cost rather than with a guess.

Waste is flagged and quantified

Six rules produce a 0–100 score and named flags, and a worker turns them into recommendations carrying a computed saving, a confidence level and a risk rating.

II · Cut it

Four ways AI quietly overpays — and what the gateway does about each.

The checks are deterministic and published. When one matches your traffic, the finding lands on your dashboard with the flag that raised it.

Repeated prompts

Your assistant answers the same question all day.

A support bot or internal helpdesk fires near-identical prompts thousands of times a week — same system prompt, same FAQs — and pays the provider in full for each one. ModelGate hashes the normalized prompt, sees the repeat, and can serve it from an exact cache.

Waste flag raisedREPEATED_PROMPT
Optimization proposedCACHE_CANDIDATE
What a cache hit costs$0.00

Premium model, trivial task

You're running a flagship model to label a sentence.

Sentiment tags, field extraction, short classifications — work a value-tier model handles — quietly run on a premium model. ModelGate flags the mismatch, and with routing switched on it moves small, simple, low-temperature calls to the same provider's value model — gpt-4o to gpt-4o-mini, claude-sonnet-5 to claude-haiku-4-5, gemini-2.5-pro to gemini-2.5-flash.

Waste flag raisedEXPENSIVE_MODEL_SMALL_REQUEST
Optimization proposedMODEL_DOWNGRADE
gpt-4o → gpt-4o-mini per token−94%

Context beyond usefulness

You send 6,000 tokens to get a 180-token answer.

RAG pipelines and long chats keep stuffing history into every request well past the point it changes the answer. ModelGate records the input-to-output ratio on every call, so the features where context stopped earning its cost are visible rather than assumed.

Waste flags raisedLARGE_CONTEXT · LOW_OUTPUT_VS_INPUT
Optimizations proposedPROMPT_COMPRESSION · MAX_TOKENS_REDUCTION
Thresholdsinput ≥ 4,000 · output × 4 < input

No model needed

You're paying a model to do what a regex does.

Pulling an email address out of a message, sorting tickets into a handful of labels, reshaping JSON, reading a QR code, checking whether a scan is blank — some calls have an exact answer a few lines of code can give. ModelGate finds them in your recorded traffic, writes the code, and only shows it once it matches the model's own answers on calls it was never shown.

Finding raisedREPLACE_WITH_CODE
Shown only at≥ 95% match · ≥ 30 unseen calls
What the code costs per call$0.00

Some LLM calls should be an if statement.

When a task’s answers follow a rule, ModelGate writes the rule as code and checks it against your model’s own recorded answers — it’s only suggested once it matches at least 95% of 30+ calls it never saw. The code below is exactly what the generator emits for these examples; the results are what it returns. The “before” calls are illustrative.

Two labels, picked from a handful of phrases. A keyword rule, not a model.

Before · an LLM callevery call billed
const res = await openai.chat.completions.create({
  model: "gpt-4o",
  messages: [
    { role: "system", content: "Reply with one word: urgent or normal." },
    { role: "user", content: ticket.body },
  ],
});
const priority = res.choices[0].message.content;
After · what ModelGate generates$0.00 per call
export function replacement(input: string): string {
  const text = input.toLowerCase();
  const rules = [
    {
      "label": "urgent",
      "any": ["outage", "is down", "can't log in", "charged twice", "data loss"],
      "none": ["not urgent"],
    },
  ];
  for (const r of rules) {
    if (r.any.some((k) => text.includes(k)) && !r.none.some((k) => text.includes(k))) return r.label;
  }
  return "normal";
}

// where the LLM call was:
const priority = replacement(ticket.body);
Run on sample inputreplacement() returns
Our dashboard is down for everyone since 9am"urgent"
Could you add a dark mode to the settings page?"normal"
I was charged twice for March, please help"urgent"

How code replacements are found and verified →

Up close

Two more: a free open model, and an injection blocked at the gateway.

Incoming emailHi team, this is Maria from Siemens — attaching the signed renewal for next year.
Sample email
Beforegpt-4oAn API call per email to name the sender’s company
Afterbert-base-NEROpen model (MIT), ~109 MB, runs on your servers — no API fee
replacement() returned"Siemens""Toyota""none"

When rules can’t match your model’s answers, ModelGate tries small open models — image labels, a classifier trained on your own answers, translation, object counts. Permissive licences only, pinned to the exact version tested, and held to the same 95% bar.

See the actual generated code
Before · LLM callillustrative
const res = await openai.chat.completions.create({
  model: "gpt-4o",
  temperature: 0,
  messages: [
    { role: "system", content: "Return only the name of the company the email is from, or none." },
    { role: "user", content: email },
  ],
});
const company = res.choices[0].message.content;
After · generated codeopen model
import { pipeline } from "@huggingface/transformers";

// Open model Xenova/bert-base-NER @ 8e892123e8b7 — MIT (from dslim/bert-base-NER), ~109 MB, downloaded once and cached.
const MODEL = "Xenova/bert-base-NER";
const REVISION = "8e892123e8b7c2c0c2bd1dcb598b7d244c4e53aa";
const ner = pipeline("token-classification", MODEL, { revision: REVISION, dtype: "q8" });
const GROUPS = ["ORG"];

export async function replacement(input: string): Promise<string> {
  const found = (await (await ner)(input, { aggregation_strategy: "simple" })) as { entity_group: string; word: string; start?: number; end?: number }[];
  const hits = found
    .filter((e) => GROUPS.includes(e.entity_group))
    .map((e) => (typeof e.start === "number" && typeof e.end === "number" ? input.slice(e.start, e.end) : e.word.replace(/^##/, "")).trim());
  if (hits.length === 0) return "none";
  return hits[0];
}

// where the LLM call was:
const company = await replacement(email);

TypeScript is what gets tested. The Python version is a port ModelGate doesn’t run.

Only narrow tasks qualify — fixed labels, extraction, reshaping, arithmetic, image checks, and what a small open model reliably does. Most LLM work doesn’t. More examples →

In your code

Connect GitHub — the changes open as pull requests.

ModelGate sees your traffic; your repository shows where it comes from. Connect it and the setup and the fixes become pull requests you review and merge. Your source is read in memory and never stored — only file paths, line numbers and model names.

Route

Every OpenAI client onto the gateway, in one PR.

The scan finds where each SDK client is created and whether it already goes through ModelGate. One click opens a pull request that changes those lines, and creates an app key to paste into your environment.

Changedthe line where the client is created
App keyinference only · shown once

Point

Each suggestion shows the line it's about.

Calls in the code are matched to the tasks the gateway sees — by system prompt, feature tag and model — so a suggestion reads “src/support/reply.ts:42”, not just “downgrade this”.

Matched onsystem prompt · feature · model
Storedpath, line, SDK, model

Fix

One-click pull requests for the fix.

A cheaper model, a lower output limit, or the verified code that replaces a call — opened on a new branch. ModelGate never pushes to your main branch and never merges.

Branchnew modelgate/… branch
Mergingalways yours

Measure

Then the saving is measured.

When you make a change we suggested, the gateway measures what it saves before and after. It's billed at 30% for 90 days, then stops — on by default, off any time, and any change can be marked not ours.

Fee30% for 90 days
Code replacementsestimated from prior volume

How the GitHub connection works →

III · Keep it safe and reliable

Every request already passes through here. So can your security policy.

Each category is off until you turn it on: detect records incidents without touching a request, enforce blocks or redacts. These are pattern-based detectors, not guarantees — here is exactly what they match.

Inbound

Prompt-injection signals, scored.

Ten weighted signals — instruction override, system-prompt exfiltration, role hijack, jailbreak personas, safety bypass, chat-template injection, zero-width characters and more — score the untrusted part of every request from 0 to 100. It is a heuristic: it catches the common families, not every phrasing.

Recorded as an incident atscore ≥ 35
Refused with 403 in enforce mode atscore ≥ 50

Outbound

Known secret patterns, redacted.

Seventeen credential signatures — provider keys, AWS and Google keys, GitHub and Slack tokens, Stripe keys, PEM private keys, JWTs, bearer tokens, database URLs with passwords — plus a Shannon-entropy pass for tokens no signature knows.

Detectedsignature + entropy
Replaced in enforce mode with[REDACTED:RULE_NAME]

Outbound

Personal data, masked before it leaves.

Email addresses, Luhn-valid card numbers, structurally valid US Social Security numbers, phone numbers, IP addresses and IBANs. Overlapping matches resolve to the most severe, so a card number is never filed away as a phone number.

Card numbersLuhn-checked
Masked in enforce modebefore the response returns

At rest

Keys sealed, prompts not kept.

Your provider credentials are encrypted with AES-256-GCM under a master key held outside the database, and only a first-four-last-four hint is ever shown back. ModelGate API keys are stored as salted HMAC-SHA256 digests and compared in constant time.

Prompt bodies storedonly if you switch it on
Incident records keepa masked snippet, never the value

Reliability works the same way: a consistency score plus format, looping and refusal checks on live traffic, free on every plan. See the reliability demo →Security architecture →Every control and its default →

Questions

Common questions.

Do I need to change my application?
To connect, change your client’s base URL and API key — the gateway speaks the OpenAI Chat Completions API, streaming included. With GitHub connected, ModelGate can open that change as a pull request for OpenAI SDK clients in JavaScript, TypeScript or Python. Gateway savings then need no code change; code and open-model replacements do — the pull request adds the function, and you call it where the LLM call was.
What can ModelGate optimize?
Identical deterministic calls (temperature 0, no tools) through the cache; small, simple calls on premium OpenAI, Anthropic and Gemini models through routing (never for features named legal, medical, financial or security); oversized output limits and model choices through pull requests. Code replacements are narrow: classification into a few labels, extraction, JSON reshaping, arithmetic and simple image checks. When code can’t match the answers, a small open model (Hugging Face, permissive licence, run on your own servers) may: classification into up to 50 labels, named entities, translation, image labels and object counts. Both need prompt and response storage switched on and at least 50 recorded calls of the task: some build the replacement (20 for code, up to 100 for an open model), and 30 or more are held back to test it. Open-ended writing, summaries and reasoning don’t qualify.
Who approves code changes?
You do. ModelGate opens a pull request only when you click to, always on a new modelgate/ branch. It never merges, never pushes to your default branch and never runs your code. Model-switch pull requests suggest running an eval first: it replays recorded inputs through the cheaper model and scores agreement.
How are savings calculated?
Gateway savings are measured on each request: a cache hit saves exactly what the original call cost; a routed call saves the difference between the two models’ prices for the same tokens. A model or output-limit change you merge is measured from cost per call before and after. A code or open-model replacement is estimated, because the call no longer reaches the gateway: call volume and cost per call frozen before the change. The dashboard labels which is which. Billing details.
What data does ModelGate retain?
Request metadata — model, tokens, cost, latency, waste flags and one-way hashes — for every call. Prompt and response bodies only if you enable them per project. Retention controls are in progress. We'll publish the deletion schedule here once it is live. Guardrail incidents keep a masked snippet, never the raw value. See security and the privacy policy.

Roadmap Custom models trained on your own traffic are a future direction — not available today and not part of any plan.

See it on your own traffic.

Every request is logged, priced and audited from the first call. 14 days free when you add a card.