# API quickstart

Run your first agent in about five minutes: one request starts it in its own cloud sandbox, you watch it work, and you read its answer. Claude Code, Codex and OpenCode run behind one HTTP API at `api.phoenix.so`.

Base URL: `https://api.phoenix.so`

**You need** a Rush account and an API key. Signing up gives you your own org, and any member of an org creates a key on the console's [Developers](https://cloud.getrush.ai/console/developers) page, where it is shown once. The example request on that page already names your org in its path, `/o/<your-org>/sessions`. Runs use Rush's models: your account's one-time $1 free credit pays first, then prepaid credits you buy in the console's Billing.

**Working in Claude Code, Codex or Cursor?** Hand the task to Rush from there instead: add the [MCP server](/docs/concepts/mcp-server) with `claude mcp add --transport http rush https://api.phoenix.so/mcp --header "Authorization: Bearer $RUSH_API_KEY"`, or tell the agent to read [getrush.ai/SKILL.md](/SKILL.md) and follow it.

## Quickstart

### 1. Set your key

Put the key and your org (the `<your-org>` in the Developers page's example path) in your shell. Every sample on these pages reads them from there.

```bash
export RUSH_API_KEY=rk_live_...
export RUSH_ORG=your-org
```

### 2. Start a session

Send the task with an `agent`: `claude`, `codex` or `opencode`. Rush answers `202` at once with the session, before its sandbox is ready. Keep its `execution_id` (`export SESSION_ID=<execution_id>`); every other call names it. This task needs no repository.

Reference: [Start a session](https://getrush.ai/docs/api/create-session.md)

```bash
curl -X POST "https://api.phoenix.so/o/$RUSH_ORG/sessions" \
  -H "Authorization: Bearer $RUSH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agent": "claude",
    "input": "Write a Python function that parses ISO 8601 durations like P1DT2H30M, with tests. Run the tests and report the result."
  }'
```

### 3. Watch it work

Hold the event stream to watch the agent think, run its tools and finish, in its own sandbox. The stream closes after `done`. If your connection drops, reconnect with `Last-Event-ID` and it picks up where it left off.

Reference: [Follow a session live](https://getrush.ai/docs/api/stream-session.md)

```bash
curl -N "https://api.phoenix.so/o/$RUSH_ORG/sessions/$SESSION_ID/events" \
  -H "Authorization: Bearer $RUSH_API_KEY" \
  -H "Accept: text/event-stream"
```

### 4. Read the answer

The session carries the agent's answer in `result`. When the task touches a repository, it also carries the `branch` and the pull request it opened in `pr_url`.

Reference: [Get one session](https://getrush.ai/docs/api/get-session.md)

```bash
curl "https://api.phoenix.so/o/$RUSH_ORG/sessions/$SESSION_ID" \
  -H "Authorization: Bearer $RUSH_API_KEY"
```

If everything worked:

```json
{
  "status": "completed",
  "result": "I wrote `parse_duration` and its tests, and all 4 tests pass: `python3 -m unittest -v test_iso_duration` printed \"Ran 4 tests ... OK\"."
}
```

## What happened

- `queued`, then `allocating`: Rush gave the run its own sandbox, a microVM no other run shares.
- `running`: the agent wrote the code, ran the tests and read the output, each step an event on the stream.
- `completed`: the turn ended with its answer in `result` and every step in the session's record.
- Then the sandbox parked with its disk and memory. It costs nothing parked, and a follow-up wakes it where it left off.

## Next

### 5. Send a follow-up

Continue the same session in the same sandbox, with everything the agent did still on its disk. Sent while a turn is running, it waits in line and runs next; the answer names its turn to wait on.

Reference: [Send a follow-up](https://getrush.ai/docs/api/post-session-message.md)

```bash
curl -X POST "https://api.phoenix.so/o/$RUSH_ORG/sessions/$SESSION_ID/messages" \
  -H "Authorization: Bearer $RUSH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input": "Add support for week durations like P2W and rerun the tests."
  }'
```

### 6. Get a webhook when a turn ends

Give the key a public `https` endpoint on the console's **Developers** page, and every run it starts posts `run.completed`, `run.failed` or `run.cancelled` there, signed per [Standard Webhooks](https://www.standardwebhooks.com/). No stream to hold, no polling. The request beside this step is the call that page makes with an admin's session; an API key cannot set its own webhook.

Reference: [Set, change or remove the key's webhook](https://getrush.ai/docs/api/update-api-key-webhook.md)

```bash
curl -X PATCH "https://api.phoenix.so/o/$RUSH_ORG/api-keys/$KEY_ID" \
  -H "Authorization: Bearer $RUSH_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "webhook_url": "https://hooks.acme.dev/rush"
  }'
```

Authentication, errors, limits, pagination and every session status: https://getrush.ai/docs/api.md
