# AI models

URL: /code/platform/ai-models · Id: `page:code/platform/ai-models`

> How every model call runs through one gateway, chosen by Policy, metered against Limits, recorded in full, and graded by Evaluators.

Every model call in [StartupBuilder](/code/builders/startup) runs through one gateway that routes, meters and records it. A [Startup](/business/nouns/startup) chooses models by [Policy](/business/nouns/policy) per task class, never in code, so changing a model changes no [Interface](/business/nouns/interface).

## Four ways a Verb runs
A [Verb](/business/nouns/verb) is the contract; its [Function](/business/nouns/function) is how the work gets done. Callers see the Verb, never the Function, so a Startup moves work between code, models and people without breaking a client.

| Function | How it works | Example |
| --- | --- | --- |
| Code | A deterministic transformation. | Compute an [Invoice](/business/nouns/invoice) total. |
| Generative | One model call produces or classifies content. | Draft a reply. |
| Agentic | An [Agent](/business/nouns/agent) chooses and calls [Tools](/business/nouns/tool) across steps. | Research a lead and book a [Meeting](/business/nouns/meeting). |
| [Human](/business/nouns/human) | A person does the work through a [Task](/business/nouns/task). | Sign a legal opinion. |

A model inside a Function does not change what the Startup sells. [Software](/business/nouns/software) can call a model; a [Service](/business/nouns/service) can mix Agents and people under one promise.

## One gateway
The gateway serves four calls: generate, embed, classify and transcribe. It covers text, images, audio and video, across model families, under one key.

Each call is recorded with its request, response, model, tokens, latency and cost, and kept forever. Any output an [Agent](/business/nouns/agent) produced traces back to the exact call that produced it.

## Model choice is a Policy
A Policy names a model per task class, such as `draft`, `classify` or `review`, with ranked fallbacks. Policies resolve like every [Setting](/business/nouns/setting): the call overrides the Startup, the Startup overrides its [Studio](/business/nouns/studio), and a lock beats all.

```ts
import { $ } from 'startup-builder'

await $.Policy.update({
  id: 'models',
  rule: 'draft: fast. review: strong, then fast.',
})
```

When a model times out or refuses, the gateway tries the next in rank. The fallback is an [Event](/business/nouns/event), so a Startup sees how often its first choice fails.

## Cost and Limits
Every call meters into the ledger exactly once, attributed to the Startup, the [Customer](/business/nouns/customer) and the [Action](/business/nouns/action) that caused it. A [Limit](/business/nouns/limit) is checked before each call. A call past its Limit creates an [Approval](/business/nouns/approval) instead of a bill.

Attribution makes margins visible. A Service that is profitable on average but loses money on one Customer shows up as that Customer's cost per outcome.

## Evaluation
An [Evaluator](/business/nouns/evaluator) grades an output against a rubric and records its verdict as an Event. Evaluators run on Verbs, on [Workers](/business/nouns/worker) and on [Outcome Contracts](/business/nouns/outcome-contract), and [Guards](/business/nouns/guard) use them before anything leaves the Startup.

**Ask**

```text
Evaluate the latest action.
```

**API**

```bash
curl -X POST https://api.sb/routewise.dev/actions/action_1/evaluate \
  -H "Authorization: Bearer $STARTUP_BUILDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"evaluator":"Example evaluator"}'
```

```json
{
  "api": "https://api.sb/routewise.dev",
  "verdict": {},
  "action": {
    "$id": "https://api.sb/routewise.dev/actions/action_1",
    "$type": "Action",
    "status": "done",
    "mode": "try",
    "operation": "Action.evaluate"
  },
  "links": {
    "self": "https://api.sb/routewise.dev/actions/action_1"
  }
}
```

**SDK**

```ts
import { $ } from 'startup-builder'

const { verdict, action } = await $.Action.evaluate({ action: 'action_1', evaluator: 'Example evaluator' })
```

**CLI**

```bash
npx startup-builder do Action.evaluate --json '{"action":"action_1","evaluator":"Example evaluator"}'
```

**MCP**

```json
{
  "name": "do",
  "arguments": {
    "code": "return await $.Action.evaluate({ action: 'action_1', evaluator: 'Example evaluator' })"
  }
}
```

A schema check, a semantic review and a Customer's acceptance answer three different questions. Judge a model change by cost per accepted outcome, not cost per call: a cheaper model that doubles rework is the expensive one.

| Term | Kind | Definition |
| --- | --- | --- |
| [Evaluator](/business/nouns/evaluator) | Noun | An Evaluator is a versioned Function that grades an output against a rubric and returns a verdict. |
| [Guard](/business/nouns/guard) | Noun | A Guard is a check every outbound Message and publish passes, from code rules to model review to a Human for high stakes. |
| [Action.evaluate](/business/nouns/action/evaluate) | Verb | Evaluate grades an Action’s output against a rubric and records the verdict as an Event. |

## Next
- [Agents](/code/platform/capabilities/agents): the Workers that make agentic calls.
- [Analytics](/systems/data-and-insights/analytics): cost per outcome as a [Metric](/business/nouns/metric).
- [Search](/code/platform/search): embeddings behind meaning-based search.