# SecondGate, the AI gateway

> SecondGate is the AI gateway in SecondStack, the LLM gateway every request from people, agents and apps passes through, with deny-by-default access and budgets.

Canonical: <https://docs.secondstack.ai/gateway/>
Updated: 2026-11-06
Checked against: v3.7.2

---

SecondGate is the AI gateway of SecondStack, the LLM gateway every request from people, agents and apps passes through, with model access denied by default, budgets and a record. The Chat App, every agent, Agent Claude and your own code call the same gateway with a virtual key. Administrators set access and budgets once, for all of them.

**Labels in the app**

| Our word | Label in the app |
|---|---|
| virtual key | API Keys |
| the record (keys) | Usage Analytics & Logs |
| the record (agents) | Agent Activity |
| model access | Access via direct API |
| the budget | Budget and Spend |
| an application's key | Apps & Agents Keys |

The diagram below shows the request path at v3.7.2. People, agents and apps send a request. SecondGuard masks personal data and secrets. SecondGate applies model access and the budget, writes the record and sends the request to a provider on your account or to a model on your own GPU.

## What SecondGate does with a request

SecondGate checks the key, applies model access and the budget, routes the request to a provider on your account and writes one record.

1. The request arrives at `/gateway/api` with a virtual key, an `sg_` bearer credential that SecondGate stores only as a hash. [SecondGuard](/gateway/secondguard/) has already masked what your rules say.
2. SecondGate looks up what the key may use. Access is denied until an administrator grants a model, so a key with no grant gets an error rather than a default model.
3. SecondGate checks the budgets of the key, the person, the team and the organization. It refuses the request when one of those limits is spent.
4. SecondGate sends the request to the provider that serves the model, with your provider's own credential. On the API route it fails over across a model's provider bindings by priority, up to the attempts your site allows. On the subscription route it spreads requests across a pool in round robin.
5. SecondGate returns the answer and writes one row for every provider attempt to the ledger that ControlTower shows.

ControlTower sits beside the gateway, off the request path. A request never waits for the admin console.

## How virtual keys work

A virtual key is an `sg_` key SecondGate issues to a person, team, application or agent, shown once, with its own budget and its own model access.

- A virtual key replaces the provider key in every client.
- People create their own keys in ControlTower under **API Keys** for their scripts, coding tools and apps. [Your dashboard](/controltower/user-dashboard/) covers that page.
- Teams and administrators create **Apps & Agents Keys** for applications and background work, each with its own budget and access.
- Every connected computer gets a key of its own, so its spend and its record stay separate.
- A virtual key never reveals a provider credential. SecondGate keeps provider keys encrypted and sends them only to the provider.

## How model access and budgets apply

An administrator grants each model to everyone, to teams, to people or to keys, and SecondGate refuses any request outside those grants or beyond the budget that covers it.

- Grants have two channels, **Access from Chat App** and **Access via direct API**, so a model can be open in chat and closed to code, or the reverse. [ControlTower](/controltower/) holds the editor.
- Budgets run per day, week or month, or without a period, and apply to the organization, the team, the person, the key and the agent. ControlTower's organization and team caps are monthly.
- A request that would pass its limit stops before SecondGate calls the provider. The operator sets a small exposure limit that bounds the overshoot parallel requests can cause.
- Subscription use through a ChatGPT or Claude pool debits no budget. SecondGate records it, and the Chat App marks it with a smiley badge. [Model providers](/gateway/providers/) explains the pools.
- A key or a model can run in virtual billing: SecondGate records the full usage and its priced value and debits nothing.

## What the record keeps

Every provider attempt writes one row with the key, the billing scope, the model, the provider model, the tokens by class, the priced value, the budget debit and any request tags.

Failed attempts stay visible beside the ones that succeeded. SecondGate counts tokens as new input, cache reads, cache writes and output, so a cached conversation shows where its cost went. ControlTower shows the rows under **Usage Analytics & Logs** and shows each agent run under **Agent Activity** with its model calls. SecondGate keeps no prompts, response bodies, media or plaintext keys, so the record holds metadata only. [Call SecondGate from your code](/developers/gateway-api/) draws one record as a receipt.

## Questions

### Does SecondStack host or resell AI models?

No. SecondStack hosts no models and resells none. Your administrator connects the provider accounts your company already has, such as Anthropic, OpenAI, Google and OpenRouter. Your administrator can also add ChatGPT or Claude subscriptions as pools, or serve open-weight models from your own GPUs through vLLM. [Model providers](/gateway/providers/) lists what connects.

### Does SecondGuard scan model answers?

No. SecondGuard runs in front of SecondGate on the request path and blocks, masks or logs secrets and personal data in each request and in attachments. On the way back it only restores the values it masked, streaming included. [SecondGuard guardrails](/gateway/secondguard/) states the limits.

### Where do our chats and files live?

In your own stores. Chats and application data stay in your PostgreSQL, attachment bytes in your object storage or a local volume, and embeddings in your Qdrant. Model input still leaves for the providers your site connects. SecondGate persists no prompts or responses. [Self-hosting](/self-hosting/) describes the stack.

## What SecondGate does not do

- SecondGate does not inspect or mask content. SecondGuard does that in front of it. A site that turns SecondGuard off sends requests through unchanged.
- SecondGate stores no prompts, response bodies, media or plaintext keys. The record holds metadata and counts.
- A request on the API route never falls back to a subscription pool. A request on the subscription route never falls back to an API key.
- SecondGate does not retry a refused request on another model. A key without a grant or without budget gets an error.
- Request tags attribute traffic in the record and grant nothing. Access comes only from grants.
- Only the inference endpoints are reachable from outside. The gateway's control, metrics and broker routes stay inside the deployment.

## Related

- [SecondGuard guardrails](/gateway/secondguard/)
- [Model providers](/gateway/providers/)
- [Call SecondGate from your code](/developers/gateway-api/)
- [Models and access](/controltower/models-and-access/)
- [Budgets and spend](/controltower/budgets-and-spend/)
- [What is SecondStack](/getting-started/what-is-secondstack/)

On secondstack.ai: [How SecondGate checks every AI call](https://secondstack.ai/platform/gateway/)

## In this section

- [SecondGuard guardrails](/gateway/secondguard/): SecondGuard is the guardrail in front of SecondGate that blocks, masks or logs secrets and personal data in each request and restores masked values in answers.
- [Model providers](/gateway/providers/): Model providers in SecondStack are your own accounts: provider keys, ChatGPT and Claude subscription pools, and self-hosted LLMs on vLLM as a development setup.

See also: [Developers](/developers/), [ControlTower](/controltower/)

On secondstack.ai: [How SecondGate checks every AI call](https://secondstack.ai/platform/gateway/)
