# run()

Canonical URL: https://developers.iagenify.com/sdk/ref/agent/run/
Language: en

`agent.run({ inputs, outputs?, history?, onStep?, signal? }) → Promise<Result>`

Streams a run from the platform: one callback per step, and the result when it ends.

Status: POST /api/ai/agents/run · server-sent events · errors keep their type

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `inputs` | array | required | `[{ type: "text", content }]`, images included. An empty array throws. |
| `outputs` | array |  | Overrides what the agent was created with, for this run. |
| `history` | array |  | The conversation to send. Absent uses the agent's own; `[]` starts fresh. |
| `onStep` | function |  | Called with each step as it happens. |
| `signal` | AbortSignal |  | Cancels the request. |

## What a step carries {#step}

```javascript
{
  index: 2,
  kind: "tool",
  tool: "search",
  input: "customer churn definition",
  reasoning: "I will look up how they define churn.",
  summary: "5 result(s)",
  error: "",
  credits: 7,
  durationMs: 1840,
  meta: { enginesUsed: [...], results: [...] }
}
```

`credits` is the run's running total, not this step's. `meta` is whatever the tool reports — the pages it opened, the sources it found, the figures of a generation.

## Three refusals arrive as a step's error {#refusals}

| error | When |
| --- | --- |
| Unknown tool | The model named something you did not declare. The message lists what is available. |
| Missing argument | A tool that needs one was called without it. |
| Already done | The same tool with the same argument, twice. |
| Refused: … credits needed | The declared cost would pass `budget`. |

The run continues after each of them — a refusal is information the model can act on.

## Errors keep their type through the stream {#errors}

```javascript
import { NotEnoughCredits, Unauthorized, IaGenifyError } from "iagenify";

try {
  await agent.run({ inputs });
} catch (err) {
  if (err instanceof NotEnoughCredits) { /* … */ }
}
```

> **A failure inside the stream is translated back**
>
> It travels as JSON, and is rebuilt into the same class the rest of the package throws — so instanceof works here as it does everywhere else, instead of giving you a bare Error you cannot tell from a network failure.

## An unknown builtin is refused outright {#unknown}

A tool whose `builtin` the platform does not know fails the run rather than being dropped. A workflow quietly missing the tool it was built around is the kind of failure nobody ever diagnoses.

## Local work pauses the run {#local}

When a step needs the caller's computer, the run asks and waits for your process to answer. Abandon the request and that step never completes.

- [stop()](/sdk/ref/agent/stop): Ending it.
- [api.tools](/sdk/ref/tools): The declarations.

```python
{
    "index": 2,
    "kind": "tool",
    "tool": "search",
    "input": "customer churn definition",
    "reasoning": "I will look up how they define churn.",
    "summary": "5 result(s)",
    "error": "",
    "credits": 7,
    "durationMs": 1840,
    "meta": {"enginesUsed": [...], "results": [...]},
}
```

```python
from iagenify import IaGenifyError, NotEnoughCredits, Unauthorized

try:
    agent.run(inputs=inputs)
except NotEnoughCredits:
    pass  # …
```
