Model Gateway

Every model call, checked before it ever leaves.

The Model Gateway is the part of Kryex Server that every Kryex Code model call passes through before it reaches a provider: one API for your tools, your provider keys kept on the server, and per-person access, quotas and usage.

What happens on every call

1

Authenticate

The caller presents a short-lived Kryex license — an RS256-signed token — never a raw provider API key. Clients never see or hold the upstream credentials for gateway models.

2

Check live account status

Every call re-checks the account, the device and the block list in the database. A suspension in the admin console takes effect on the very next call, not when the license expires up to 24 hours later.

3

Resolve model access

Is the model enabled, and is this person either granted it directly or covered by "Everyone in this organization"? If not, the call is refused with a clear model-access error.

4

Enforce quota

The most specific limit wins: a per-person override for that model, then the model's default limit, then the person's shared token pool or their tier's default. Only one layer is charged per call.

5

Proxy the call

The request is translated to the provider's own format where needed — Anthropic Messages or Gemini — and streamed back in the shape the client expects.

6

Record usage

Tokens in and out, cached tokens, latency and outcome are recorded against the person and the model. Accounting is built so it can never break a completion.

One API, many providers

Clients talk to the gateway in one format — the OpenAI-compatible chat completions API — whichever provider serves the model. The gateway translates to Anthropic's Messages API (including tools, images and PDFs) and to Gemini's native API, and streams responses back as server-sent events. Admins add a provider once in LLM config, test the connection, and the provider key is stored encrypted with the organization's own key.

How it connectsProviders
Native APIsAnthropic, Google Gemini, Azure OpenAI
OpenAI-compatibleOpenAI, OpenRouter, Mistral, DeepSeek, Groq, Together, Fireworks, Cohere, xAI, Perplexity, Cerebras, DeepInfra, NVIDIA, AWS Bedrock (API key), any OpenAI-compatible endpoint, including your own

Local models (Ollama, LM Studio) and AWS Bedrock with AWS credentials run on the developer's machine through Kryex Code's own keys, not through the gateway — see Bring Your Own Model.

Who can use which model

A model is usable only when it's enabled and the person is covered — either everyone in the organization, or only selected people. New models start disabled, so adding one never exposes it by accident. Grants are managed per person in Access & quotas.

Quotas that explain themselves

LayerWhat it limits
Per-person overrideOne person's tokens on one model, over a rolling window of hours.
Model defaultEvery person's tokens on that model, over a rolling window.
Shared poolA person's total across models — their own pool, or their tier's default for the organization.

Limits reset either daily at midnight UTC or on a rolling window that starts from first use. When someone reaches a limit, the gateway says exactly when it resets and which other models they can still use. Successful responses carry the person's current usage, so the client can show it before they reach the limit.

Requesting more access, without friction

When a developer hits a quota or access wall, they can request more directly from the client. The request lands in the administrator's inbox; granting the model or raising the limit unblocks the person immediately and resolves the request automatically, and the person is told by email. Only one request per person and model can be pending at a time.

Prompt caching on Anthropic models

For Anthropic models, the gateway marks the stable parts of each request — the tool list, the system prompt and the conversation so far — for the provider's prompt cache, so a long agent session doesn't pay full price for the same context on every turn. Cached tokens are recorded per call and shown in usage.

What the gateway keeps

Usage metadata only: who called which model, tokens in and out, cached tokens, latency and whether it succeeded. The gateway does not store prompt or completion content and holds no conversation state between requests. Admins read usage by model and by person over a day, 7, 14 or 30 days, or a custom range, and export it to CSV.

The Model Gateway governs the brain — the prompt and completion. What the model's output is then used to do is the Tool Proxy's job, covered in Tool Calling & Governed Actions. Together they're the two chokepoints described in How Kryex Works.

Why the live check, specifically

Suspending someone should mean something immediately

The problem

Most token-based auth trusts a claim baked into the token at issuance — a license or session token can be valid for hours after an administrator decides someone shouldn't have access anymore. That gap between 'admin clicked suspend' and 'access actually stops' is exactly where damage happens.

How Kryex solves it

The Model Gateway re-checks account status live, on the actual request — never from a cached claim inside the license. A suspension takes effect on the very next call, not after a token expires up to 24 hours later.

Example

An administrator suspends a departing contractor at 2:00 PM. Under a cached-claim approach, their still-valid license keeps working until it naturally expires — potentially the next day. Under Kryex, their very next model call is denied at 2:00 PM.

The impact

Administrative control is immediate, not eventual — the gap between a decision and its effect is one request, not up to a day.

Questions

What does the Kryex Model Gateway do?

It sits between Kryex Code and the model providers, inside Kryex Server. It authenticates every call, decides who may use which model and how much, holds the provider keys, and records usage — so developers never handle a provider key.

Does the Kryex Model Gateway store prompts or completions?

No. The gateway records usage metadata — token counts, latency and outcome — not the content of prompts or completions, and it keeps no conversation state between requests.

Which model providers does the Kryex Model Gateway support?

OpenAI, Anthropic, Google Gemini, Azure OpenAI, OpenRouter, Mistral, DeepSeek, Groq, Together, Fireworks, Cohere, xAI, Perplexity, Cerebras, DeepInfra, NVIDIA, AWS Bedrock through its API key, and any OpenAI-compatible endpoint, including your company's own.

What happens when a developer runs out of tokens?

The gateway answers with a clear quota error that says when the limit resets and lists up to five other models the person can still use. They can request more from inside the app; granting it resolves the request automatically.

The Model Gateway is Kryex's equivalent of what the industry calls an AI gateway — a distinct layer from a traditional API Management (APIM) gateway. If your organization already runs one, see Kryex & API Management (APIM) for how the two fit together.

CtrlI