> ## Documentation Index
> Fetch the complete documentation index at: https://docs.duraton.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# AI

> Run AI agents that ask a human before the risky move, pick up where they stopped after a crash without paying the model twice, and record what every run cost.

This page is for the code path - calling a model as a durable step by hand. To build an agent
without code, start with [Build your first agent](/start/first-agent).

Duraton is where your AI agents run. They park on a human decision when the next move is risky, and
wait as long as it takes. They pick up where they stopped after a crash, a restart, or a deploy - never
redoing a model call that already finished. And every run keeps a record of what it did and what it cost.

The mechanism is one idea applied to model calls: `ctx.step.ai` makes a call a **durable step**. It runs
once, its result is recorded under the step id, and a retry after a crash returns the saved result
instead of paying for the model again. Approvals, spend caps, guardrails, and streaming are all
built on that same step record.

<Note>
  **Keep your framework.** Duraton goes underneath it: your code still decides what the agent does;
  Duraton makes sure it finishes, stops it before it overspends or acts without a person, and keeps the
  record. Wrap an existing model call with [`step.ai.wrap`](/reference/sdk/ai-steps#step-ai-wrap) and
  nothing else changes.
</Note>

```ts theme={null}
const { text } = await ctx.step.ai.generate("classify", {
  model: "claude-opus-4-8",
  prompt: `Classify this ticket: ${subject}`,
});
```

## What each page answers

| You want | Read | The mechanism |
| - | - | - |
| "It must not act without a human on the risky stuff" | [Approvals](/ai/approvals) | `step.approval` parks the run holding no worker; approve, deny, or approve-with-edits resumes it at the exact checkpoint |
| "It must never run a tool call the model got wrong" | [Guardrails](/ai/guardrails) | An automatic check on the arguments the model produced, before the tool runs; the verdict is a durable step |
| "My agent spends money and I can't sleep" | [Cost controls](/ai/cost-controls) | `cap` halts **before** the call that would cross the ceiling; `tokenThrottle` spaces out runs that share a key |
| "The model is down and my agent just fails" | [Cost controls](/ai/cost-controls) | Fallback chains advance to the next candidate; the inference cache serves an identical deterministic call at zero spend |
| "My long agent dies halfway and starts over" | [AI agents](/ai/ai-steps) | One durable step per model turn and per tool call; the loop resumes at the last committed turn |
| "The conversation outgrows the context window" | [Context management](/ai/context-management) | A trimming strategy runs as a durable step, so a replay sees the same summary |
| "I want to see what it's doing right now" | [Streaming](/ai/streaming) | Tokens stream live from the step and are replayable from token 0 |
| "I need to show someone what the agent did, and what it cost" | [AI observability](/ai/observability) | Token and cost rollups, sessions, and traces read from the durable journal |

## Your provider key stays with you

The model call happens **in your runner**, with your provider SDK and your key. Duraton records the
call's metadata (model, token counts, latency) and never receives your prompt, the response text, or
your API key: `apiKey` is passed per call into the provider client and is never persisted by the SDK
or sent to Duraton. Omit it and the provider SDK reads its conventional env var
(`ANTHROPIC_API_KEY`).

<Note>
  This describes running your own code with the SDK. A no-code workflow has no runner of its own, so
  it resolves a key you add once under [Credentials](/integrations/credentials) - still never
  persisted anywhere but that one encrypted record, and still resolved fresh for each call rather than
  held in memory between them.
</Note>

```sh theme={null}
export ANTHROPIC_API_KEY="sk-ant-..."
```

## Where to start

<CardGroup cols={2}>
  <Card title="AI quickstart" href="/start/ai-quickstart">
    Add your first durable AI step, trigger it, and watch spend land in the console.
  </Card>

  <Card title="Agent kit" href="/agent-kit">
    `agent()` and `tool()`: write an agent whose every turn and tool call is a durable step.
  </Card>

  <Card title="step.ai reference" href="/reference/sdk/ai-steps">
    Every option and return shape for `generate`, `wrap`, `embed`, and `loop`.
  </Card>

  <Card title="AI coding tools" href="/integrations/ai-coding-tools">
    Point Claude, Cursor, or any MCP client at these docs and at your project.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.