# AI gateway

URL: /code/platform/ai-gateway · Id: `capability:ai-gateway`

> AI gateway routes every model call by Policy, checks cost Limits before the call, and keeps the full request and response.

AI gateway carries every model call a [Startup](/business/nouns/startup) makes. It picks the model by [Policy](/business/nouns/policy), checks cost [Limits](/business/nouns/limit) before the call, and keeps the full request and response.

## Contract
- Four operations: generate, embed, classify and transcribe. Every [Agent](/business/nouns/agent), [Function](/business/nouns/function) and [Evaluator](/business/nouns/evaluator) calls models through them.
- Code names a task class, never a model: `classify`, `judge`, `draft`, `agent`, `embed` or `transcribe`.
- A Policy maps each class to a ranked list of models, cheapest capable first. Policies inherit from [Studio](/business/nouns/studio) to Startup to call, like a [Setting](/business/nouns/setting).
- Changing a model is a [Change](/business/nouns/change) to a Policy, never to code.
- A call over its cost Limit waits for an [Approval](/business/nouns/approval).
- Every request and response is kept forever, with its tokens, latency, [Cost](/business/nouns/cost) and the [Task](/business/nouns/task) it served.
- Results stream as they generate.
- A Policy can split by [Flag](/business/nouns/flag), so a cheaper model runs as an [Experiment](/business/nouns/experiment), judged on cost per accepted outcome.
- [AI models](/code/platform/ai-models) explains how a Startup chooses and grades its models.

## Verbs
None.

## Interfaces
- [API](/code/api/reference)
- [SDK](/code/sdk/reference)
- [CLI](/code/cli/reference)
- [MCP](/code/mcp/reference)

## Example
```ts
// replydesk.io answers support email for small online shops. Its agent names task classes, never models.
import { $ } from 'startup-builder'

await $.Agent.create({
  instructions: 'Label each email refund, shipping or other, then draft the reply.',
  model: 'draft',
  tools: ['Conversation.answer'],
})
```