Route your model traffic through ModelGate.
ModelGate is a drop-in gateway in front of OpenAI, Anthropic, Google and Azure. Change one base URL and every request is logged, priced to the token, and audited for waste — with optional automatic caching and model routing.
Quickstart
Four steps, about five minutes:
- Open an account and sign in to the dashboard.
- Add a provider key. Under Provider credentials, paste your own OpenAI, Anthropic or Google key. It’s encrypted at rest and never shown again.
- Create a ModelGate API key under API keys. Copy it — it’s shown once.
- Point your SDK at ModelGate by changing the base URL (below). Your existing code keeps working.
Authentication
Every request carries your ModelGate API key in the x-api-key header. The key identifies your project; provider keys are looked up server-side, so no provider secret ever leaves your dashboard.
x-api-key: mg_live_xxxxxxxxxxxxxxxxxxxxxxxxKeys can be revoked any time from the dashboard; a revoked key stops working immediately.
Making a request
The gateway speaks the OpenAI Chat Completions format at POST https://gw.modelgatehq.com/v1/chat/completions. Send the same body you’d send to OpenAI — model and messages — and ModelGate forwards it to whichever provider owns that model, using your stored key.
curl
curl https://gw.modelgatehq.com/v1/chat/completions \
-H "content-type: application/json" \
-H "x-api-key: $MODELGATE_API_KEY" \
-d '{
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "Ping"}]
}'OpenAI SDK (Python)
from openai import OpenAI
client = OpenAI(
base_url="https://gw.modelgatehq.com/v1",
api_key="unused", # ignored; ModelGate uses x-api-key
default_headers={"x-api-key": "YOUR_MODELGATE_KEY"},
)
resp = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Ping"}],
)
print(resp.choices[0].message.content)OpenAI SDK (Node)
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://gw.modelgatehq.com/v1",
apiKey: "unused",
defaultHeaders: { "x-api-key": process.env.MODELGATE_API_KEY },
});
const resp = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: "Ping" }],
});The response comes back in the same OpenAI shape regardless of which provider served it, so anything that parses a Chat Completions response keeps working.
Streaming
Set stream: true and the gateway forwards the response as OpenAI-format server-sent events (chat.completion.chunk), whichever provider serves it — so an OpenAI SDK’s streaming iterator works unchanged. Cost, token counts and the waste score are computed on the assembled response when the stream finishes, so a streamed call is metered exactly like a buffered one.
stream = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Count to five"}],
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")One limit: if a project has outbound secret-leak or PII enforcement turned on, streaming is refused with 409 — redaction can’t be applied to a response before it has been fully received. Use a non-streaming request, or set those guardrails to DETECT. Inbound prompt-injection enforcement is unaffected and still applies to streamed requests.
Supported models
Use the provider’s own model name. Prices below are per million tokens, for reference.
| Provider | Model | Input / 1M | Output / 1M |
|---|---|---|---|
| OpenAI | gpt-4o | $2.50 | $10.00 |
| OpenAI | gpt-4o-mini | $0.15 | $0.60 |
| Anthropic | claude-sonnet-5 | $3.00 | $15.00 |
| Anthropic | claude-haiku-4-5 | $1.00 | $5.00 |
gemini-2.5-pro | $1.25 | $10.00 | |
gemini-2.5-flash | $0.30 | $2.50 |
Pricing is stored in a versioned rate table and used to cost every request exactly — no estimates, no sampling. Rates change; the dashboard always reflects the table in force at the time of each call.
Optimization
ModelGate watches your traffic for two kinds of waste and can act on them. Each is configured per project in Settings, and each has a safe middle setting that only recommends before it ever changes a request.
Exact-response caching
Identical, deterministic requests (same model, same messages, temperature 0) can be served from a cache instead of paying the provider again.
OFF— never cache.RECOMMENDATION_ONLY— measure how much caching would save, change nothing.AUTO— serve repeats from cache. A cache hit costs $0; the saving is what the original call cost.
Model routing
When a small, simple call is running on a premium model, ModelGate can route it to a cheaper model that does the same job.
OFF/RECOMMENDATION_ONLY— leave requests untouched; flag candidates.SAFE_AUTO— downgrade only clear-cut cases, with legal/medical/financial/security prompts protected.AGGRESSIVE_AUTO— downgrade wherever the heuristics find a cheaper model that fits.
The savings from automatic caching and downgrades are what we call realized savings — measured at the gateway, shown on your dashboard, and the basis for the success fee.
Security guardrails
The gateway can inspect traffic in both directions and act on it. Each category is a per-project setting in Settings with three levels — the same OFF → DETECT → ENFORCE ladder as the optimizations. Detect logs incidents to the Security page without changing any request; Enforce blocks or redacts. Incidents are stored with a masked snippet only — the raw secret or PII value is never persisted.
- Prompt-injection shield (inbound) — scores untrusted input for jailbreak and instruction-override attempts;
ENFORCErefuses a high-risk request with403 blocked_by_guardrailsbefore it reaches a provider. - Secret-leak prevention (outbound) — signature + entropy detection for API keys, tokens, private keys and connection strings;
ENFORCEredacts them from the response. - PII protection (outbound) — emails, Luhn-valid card numbers, SSNs and more;
ENFORCEmasks them before the response is returned.
DETECT is available on every plan. ENFORCE (active blocking/redaction) is a paid capability, like the automatic optimizations.
Reliability
The gateway also scores whether your bot is stable — does it answer the same task the same way, keep its format, and avoid contradicting itself. Deterministic detectors (format breaks, degenerate output, refusals) run inline and free on every plan and feed a consistency score with a daily trend. Judge-based detectors (contradiction, instruction drift, grounding) read a whole conversation and are part of the Reliability add-on. Every setting lives in Settings under Reliability, and incidents appear on the Reliability page with masked evidence.
Conversation stitching
To reason about a whole thread, the gateway needs to know which turns belong together. Pass a stable conversation id and it’s exact; omit it and turns are stitched heuristically by prompt overlap within a time window.
x-modelgate-conversation-id: conv_8f31a2 # optional; otherwise stitched heuristicallyResponse capture (opt-in)
The judge detectors and the evidence drill-down need the answer text. Response storage is off by default, enabled per project under Store response bodies, and retention-capped — a purge job clears stored responses older than your window (default 14 days). The deterministic consistency score needs none of it; it works from response hashes.
The regression gate
An active Consistency Test fires several paraphrased variants of one prompt through the same model and returns a varianceScore (0–100, higher = more consistent). Call it from CI to fail a deploy when a change makes a critical prompt less stable. Active tests spend your provider tokens, so they’re metered.
curl -s -X POST https://gw.modelgatehq.com/v1/dashboard/reliability/test \
-H "x-api-key: $MODELGATE_API_KEY" \
-H "content-type: application/json" \
-d '{"promptTemplate": "Is a refund available after 30 days?",
"model": "gpt-4o-mini", "provider": "OPENAI", "variantCount": 6}'
# → {"testId":"…","status":"COMPLETED","varianceScore":83.5,"variantCount":6}Deterministic detection and the consistency score are free on every plan. Judge detection, the confusion map, response capture and active tests are the Reliability add-on ($49/mo + metered runs). See how reliability works and pricing.
Spend controls
Managed at the gate, before you’re billed by a provider. Set them per project in Settings:
- Requests per minute — a rate ceiling per API key.
- Max prompt / output tokens — reject oversized calls.
- Monthly spend cap (USD) — once the month’s provider spend hits the cap, further requests are refused with
402until the cap is raised or the month rolls over.
Errors
| Status | Meaning |
|---|---|
401 | Missing or invalid ModelGate API key. |
402 | Monthly spend cap reached, or a billable optimization used after the trial without a Pro plan. |
403 | Blocked by guardrails — the request tripped the prompt-injection shield in enforce mode. |
409 | Streaming requested while outbound secret/PII enforcement is on. Send without stream, or set those guardrails to detect. |
429 | Rate limit exceeded for the key. |
4xx / 5xx | Passed through from the upstream provider, or a gateway error. The body carries the detail. |
Billing
Every account starts with a 3-month free trial — the full product, no card, no charge. After that, Pro is $99/month plus 30% of the savings the gateway realizes for you. If nothing is saved, there’s nothing to pay beyond the base.
The $99 base is a PayPal subscription. The 30% success fee is billed once a month as a separate PayPal invoice for 30% of that month’s realized savings. Full detail is on your dashboard’s Billing page. See also the Terms and Privacy Policy.
Questions
Email support@modelgatehq.com and we’ll help you get set up.