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

# Agent

> Describe a task in plain words. An AI agent does it on a phone and returns the answer, as text or as JSON in your shape.

Agent runs a task on a phone from one prompt. You say what you want in plain words, an AI agent works the phone's apps to get it, and the task returns the answer as `data`: text, or the object your JSON Schema describes. Every run is recorded.

Use agent when the work needs judgment: signing in, searching, filling a form, or moving through an app to reach the data. When you already know the screen, [Scrape](https://docs.lusor.ai/app-data/scrape.md) reads it with fixed rules and no agent. To find the screens Lusor knows in an app, use [Map](https://docs.lusor.ai/app-data/map.md). To keep working on the screen a task ended on, send it a turn with [Interact](https://docs.lusor.ai/app-data/interact.md).

There is no `app` field. Name the app in the prompt.

## Run a task

Agent is a task. Start it with `POST /v1/agent`, then read it with `GET /v1/agent/{id}`.

```bash theme={null}
curl https://api.lusor.ai/v1/agent \
  -H "X-Api-Key: $LUSOR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "In Settings, open General, then About, and read the iOS version and the model name.",
    "schema": {
      "type": "object",
      "properties": {
        "version": { "type": "string" },
        "model": { "type": "string" }
      },
      "required": ["version", "model"]
    }
  }'
```

The request returns `202` with the task's id at once:

```json theme={null}
{
  "id": "8b2d4f71-…",
  "liveViewUrl": "https://…"
}
```

Read the task until its `status` is neither `processing` nor `awaiting_human`. `$TASK_ID` is the `id` the start call returned:

```bash theme={null}
curl "https://api.lusor.ai/v1/agent/$TASK_ID" \
  -H "X-Api-Key: $LUSOR_API_KEY"
```

### Response

```json theme={null}
{
  "success": true,
  "status": "completed",
  "data": { "version": "26.1", "model": "iPhone 13 Pro Max" },
  "expiresAt": "2026-12-24T14:20:00.000Z",
  "recordingUrl": "https://api.lusor.ai/v1/sessions/8b2d4f71-…/recording",
  "error": null,
  "creditsUsed": …
}
```

| Field | What it is |
| - | - |
| `success` | `false` once the task failed or was cancelled. |
| `status` | Where the task is. See [Start and status](#start-and-status). |
| `data` | The answer, on a completed task: the object your `schema` describes, or the answer as text when you sent no schema. |
| `expiresAt` | When the answer leaves your plan's history window. `null` when your plan keeps history without a limit. |
| `recordingUrl` | The run's recording. Fetch it with the same API key to get signed video segments. See [Recordings and replay](https://docs.lusor.ai/agents/recordings-and-replay.md). |
| `liveViewUrl` | A watch-only link to the phone while the run is live. See [Watch it run](#watch-it-run). |
| `error` | Why the task failed, when it did. |
| `stopReason` | `credit_limit_reached` when the run stopped at its `maxCredits`. Present only then. |
| `creditsUsed` | The credits the task has been charged so far. See [Spending cap](#spending-cap). |
| `metadata` | Present when the task waited for its phone. See [A busy phone queues the task](#a-busy-phone-queues-the-task). |

## Get the answer in your shape

Send `schema`, a JSON Schema, and `data` is the object it describes. Without it, `data` is the agent's answer as text.

Describe the task in `prompt` and the result's shape in `schema`. Mark the fields you always need as `required`, and use `description` to say what a field means. [Structured output](https://docs.lusor.ai/agents/structured-output.md) has more on writing a schema.

## Start and status

Every agent call is a task: it holds a phone while the agent works, so the request returns at once and you read the result when it is ready.

| Step | Request | Returns |
| - | - | - |
| Start | `POST /v1/agent` | `202` with `id`, and `liveViewUrl` when the run can be watched. |
| Status | `GET /v1/agent/{id}` | `status`, then `data` or `error`. |

`status` is one of:

| Status | Meaning |
| - | - |
| `processing` | The task is waiting for its phone, working, or writing its result. Keep reading. |
| `awaiting_human` | The agent stopped to ask a person a question. It resumes when the question is answered. |
| `completed` | `data` is in the response. |
| `failed` | `error` says why. |
| `cancelled` | The task was stopped. |

The first read that says `completed` carries `data`, and the first that says `failed` carries `error`, so you can stop at the first status that is neither `processing` nor `awaiting_human`.

The task id is also the id of its session, so the session endpoints work on it:

* `GET /v1/sessions/{id}/events` shows what the agent is doing. See [Follow a session](https://docs.lusor.ai/agents/follow-a-session.md).
* An `awaiting_human` task is answered like any session. See [Answer the agent](https://docs.lusor.ai/agents/answer-the-agent.md).
* `POST /v1/sessions/{id}/stop` stops it. See [Stop a session](https://docs.lusor.ai/agents/stop-a-session.md).

### Watch it run

While the task runs, `liveViewUrl` is a watch-only link to the phone: a player page you can open or embed with no Lusor login. Taps and typing through it are refused, and it stops working when the task ends. Send `expiresIn` (seconds) in the body, or as a query parameter on the status read, to make the link expire sooner. The response leaves `liveViewUrl` out once the run has ended, or when the phone cannot serve one.

### A busy phone queues the task

A phone runs one task at a time. A task sent to a phone that is running another task waits, reading `processing`, and starts when the phone frees. Its response then carries `metadata` with `concurrencyLimited: true` and `concurrencyQueueDurationMs`, the time from your request to the phone taking it. A task that found the phone free has no `metadata`.

A task still waiting after 15 minutes fails with `queue_expired`, without starting, and is not charged.

### Retry safely

Send an `Idempotency-Key` header with a value you choose. A retry with the same key returns the first request's task id instead of starting a second run.

## Spending cap

`maxCredits` is the most credits a run may spend. The run stops once its charge would pass it: the task ends `failed`, with `error` set to `Agent reached max credits` and `stopReason` set to `credit_limit_reached`, and it is charged at most `maxCredits`. Without `maxCredits` a default cap applies. Send a number to replace it.

```json theme={null}
{
  "success": false,
  "status": "failed",
  "error": "Agent reached max credits",
  "stopReason": "credit_limit_reached",
  "creditsUsed": …
}
```

`creditsUsed` is what the task has been charged so far. Charges are written when a run ends, so a running task reads less than it will cost. Phone minutes on a Lusor Phone are billed apart and are not in it. See [Credits and minutes](https://docs.lusor.ai/billing/credits-and-minutes.md).

## Options

| Field | Required | Meaning |
| - | - | - |
| `prompt` | Yes | The task, in plain words. Up to 8,192 characters. Name the app here. |
| `schema` | No | A JSON Schema for the answer. `data` is then that object. |
| `maxCredits` | No | The most credits this run may spend. See [Spending cap](#spending-cap). |
| `device` | When the workspace has more than one phone | The id of the phone to run on. A workspace with one phone uses it. |
| `workspaceId` | No | The workspace, for a credential that can reach several. An API key is bound to one workspace and can leave it out. |
| `expiresIn` | No | Shortens the live view link, in seconds. |

Fields agent does not know are ignored.

## Errors

Errors are JSON with an `error` code and a `message`. See [Errors](https://docs.lusor.ai/billing/errors.md).

| Status | `error` | Meaning |
| - | - | - |
| `400` | `bad_request` | The body is invalid: `prompt` is missing or too long, or `maxCredits` is not a whole number of at least 1. |
| `400` | `device_required` | The workspace has several phones and the request did not name one. `devices` lists their ids. |
| `400` | `no_device` | The workspace has no phone. |
| `400` | `unknown_device` | `device` is not one of the workspace's phones. `devices` lists their ids. |
| `401` | `unauthenticated`, `invalid_api_key` | The API key is missing, wrong or revoked. |
| `402` | `credits_exhausted` | The workspace is out of credits. Nothing ran. |
| `404` | `not_found` | On `GET`: no task with this id in the key's workspace. |
| `429` | `device_busy` | The phone is being updated and cannot take a task yet. Try again shortly. A phone that is running another task queues the task instead. |

## Known limits

* **`data` is filled only on a completed task.** A task that fails or is stopped returns no partial answer.
* **One task per phone at a time.** Tasks on the same phone run one after another. To run tasks side by side, send them to different phones with `device`.
* **The answer leaves with your history.** After `expiresAt`, the task's answer is no longer kept.

## Related

> [card] [Scrape](https://docs.lusor.ai/app-data/scrape.md)
>
> Read a screen you already know, with no agent.

> [card] [Map](https://docs.lusor.ai/app-data/map.md)
>
> List the screens Lusor knows in an app.

> [card] [Interact](https://docs.lusor.ai/app-data/interact.md)
>
> Keep working on the screen this task ended on.


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