Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions agent-api/build.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: "Build the plan"
openapi: "/api-reference/openapi.json POST /agent/projects/{id}/build"
description: "Build the next task in a project's plan, a custom task, or every remaining task."
---

```bash
curl --fail-with-body -X POST "https://api.pre.dev/agent/projects/$PROJECT_ID/build" \
-H "Authorization: Bearer $PREDEV_API_KEY" \
-H "Content-Type: application/json" \
-d '{"maxCredits": 50}'
```

| Body | Run |
| --- | --- |
| `{}` | Build the next task in the plan |
| `{ "task": "Add CSV export" }` | Build a custom task instead |
| `{ "all": true }` | Build every remaining task |

The call returns `202` once the build has started. Follow it on [the event stream](/agent-api/events). Check progress with [status](/agent-api/status).

`maxCredits` stops the run once it has spent that many credits on the project. The server checks spending every 15 seconds, so a run can go slightly over the cap before it stops. Limits per account: 20 build-next and 10 build-all calls per minute.

TypeScript: `client.agent.buildNext(projectId)` / `buildAll(projectId)`. Python: `client.agent.build_next(project_id)` / `build_all(project_id)`.
25 changes: 25 additions & 0 deletions agent-api/create-project.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
title: "Create a project"
openapi: "/api-reference/openapi.json POST /agent/projects"
description: "Start a project from a prompt; the coding agent begins on it right away."
---

```bash
curl --fail-with-body https://api.pre.dev/agent/projects \
-H "Authorization: Bearer $PREDEV_API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt": "A habit tracker with daily streaks", "mode": "plan"}'
```

The call returns `201` with `projectId` and the Main `sessionId` as soon as the project exists. Planning and building continue in the background: follow them with [the event stream](/agent-api/events) or poll [status](/agent-api/status).

| Field | Meaning |
| --- | --- |
| `prompt` | What to build. Up to 100,000 characters. |
| `mode` | `build` (default) builds right away. `plan` writes the plan first; build it with [build](/agent-api/build). |
| `model` | A model key. Omit it to use the default. |
| `idempotencyKey` | Send the same key on a retry and you get the same project back, not a second one. |

Starting a project needs a paid plan (`402 SUBSCRIPTION_REQUIRED` otherwise). Limit: 10 projects per minute per account.

TypeScript: `client.agent.createProject({ prompt })`. Python: `client.agent.create_project(prompt)`.
32 changes: 32 additions & 0 deletions agent-api/events.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: "Stream agent events"
openapi: "/api-reference/openapi.json GET /agent/projects/{id}/events"
description: "Server-Sent Events for a project's chat: text as it is written, tool calls, status, and a done event per run."
---

```bash
curl --fail-with-body -N "https://api.pre.dev/agent/projects/$PROJECT_ID/events" \
-H "Authorization: Bearer $PREDEV_API_KEY"
```

## Event contract

| Event | Payload | When |
| --- | --- | --- |
| `cursor` | `{ cursor }`, also sent as the SSE `id` | On connect, and after each finished message or run |
| `status` | `{ state: "running" \| "idle", agentStatus, runTitle }` | On connect, and whenever the agent's status changes |
| `message.delta` | `{ messageId, delta }` | The agent writes text |
| `message` | `{ messageId, role, content, completed, replayed? }` | A message is finished, or replayed from a cursor |
| `tool` | `{ messageId, tool, toolId, text, completed }` | The agent uses a tool |
| `done` | `{ state: "idle" }` | A run that was running has ended |
| `error` | `{ error, code }` | The stream cannot start or continue |

Lines starting with `:` are heartbeats, sent every 15 seconds. They are not events. The stream stays open across runs, so close it when you are finished.

## Resume after a disconnect

Keep the last `cursor` you received. Reconnect with `?cursor=<cursor>` or a `Last-Event-ID` header. The stream first sends every message that changed since that cursor, as `message` events with `replayed: true`, then live events. If you connect without a cursor, you get live events only.

The SDKs do this for you: `client.agent.stream(projectId)` reconnects from the last cursor and, by default, ends after `done`. Use `sessionId` to follow a session other than Main.

Limit: 30 new streams per minute per account. `503 BUSY` means the server is full; retry after a few seconds.
71 changes: 71 additions & 0 deletions agent-api/overview.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
title: "Agent API"
description: "Drive the pre.dev coding agent over REST: create a project, send messages, stream events, build the plan, check status, and stop."
---

The Agent API runs the same coding agent as the web workspace, from your own code. Projects you create with it appear in your pre.dev dashboard. You can open any of them there and keep working.

## The flow

1. [Create a project](/agent-api/create-project) from a prompt. Save `projectId`.
2. [Stream events](/agent-api/events) to watch the agent plan and write code.
3. [Build](/agent-api/build) the next task, or all of them.
4. [Send messages](/agent-api/send-message) to steer it. [Check status](/agent-api/status) for progress and credits. [Stop](/agent-api/stop) it at any time.

```bash
# 1. Create
PROJECT_ID=$(curl --fail-with-body -s https://api.pre.dev/agent/projects \
-H "Authorization: Bearer $PREDEV_API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt": "A habit tracker with daily streaks", "mode": "plan"}' | jq -r .projectId)

# 2. Watch (Ctrl-C when you see event: done)
curl -N "https://api.pre.dev/agent/projects/$PROJECT_ID/events" \
-H "Authorization: Bearer $PREDEV_API_KEY"

# 3. Build the next task
curl --fail-with-body -X POST "https://api.pre.dev/agent/projects/$PROJECT_ID/build" \
-H "Authorization: Bearer $PREDEV_API_KEY" \
-H "Content-Type: application/json" -d '{}'

# 4. Progress
curl --fail-with-body "https://api.pre.dev/agent/projects/$PROJECT_ID/status" \
-H "Authorization: Bearer $PREDEV_API_KEY"
```

The [TypeScript](/architect-agent/sdks/node#build-with-the-agent) and [Python](/architect-agent/sdks/python#build-with-the-agent) SDKs wrap every endpoint under `client.agent`. Their `stream()` reconnects and resumes for you.

## Endpoints

| Method | Path | Reference |
| --- | --- | --- |
| POST | `/agent/projects` | [Create a project](/agent-api/create-project) |
| POST | `/agent/projects/{id}/messages` | [Send a message](/agent-api/send-message) |
| GET | `/agent/projects/{id}/events` | [Stream agent events](/agent-api/events) |
| POST | `/agent/projects/{id}/build` | [Build the plan](/agent-api/build) |
| GET | `/agent/projects/{id}/status` | [Get project status](/agent-api/status) |
| POST | `/agent/projects/{id}/stop` | [Stop the agent](/agent-api/stop) |

## Access, billing, and limits

- **Key.** Use the same API key as every other endpoint (see [authentication](/api-reference/authentication)). It needs an active plan.
- **Projects.** A key can reach projects its account owns or is a member of. Sending, building, and stopping need edit access. Status and events need view access.
- **Credits.** Agent runs are billed like runs in the workspace: to the project's owner, or to the team for a team project. `maxCredits` on [build](/agent-api/build) caps one run.
- **Rate limits** per account per minute: 10 new projects, 30 messages, 20 build-next and 10 build-all calls, 30 new event streams, 120 status reads, 30 stops. A `429` carries `Retry-After`.

## Errors

Error bodies are `{ "error": "<message>", "code": "<CODE>" }`.

| Status | Code | When |
| --- | --- | --- |
| `400` | `BAD_USER_INPUT` | A field is missing or invalid |
| `401` | | Missing or invalid key |
| `402` | `SUBSCRIPTION_REQUIRED`, `INSUFFICIENT_CREDITS` | No plan, or no credits on the paying account |
| `403` | `FORBIDDEN` | The key's account cannot act on this project |
| `404` | `NOT_FOUND` | No such project, or the session is not in it |
| `409` | `NO_SESSION`, `RUNNER_CHANGED` | The project has no chat session yet, or the session is moving between a computer and the cloud. Retry. |
| `429` | `RATE_LIMITED` | Over a per-minute limit |
| `503` | `AGENT_UNAVAILABLE`, `BUSY` | The agent could not start, or the server has too many streams. Retry. |

See [errors and retries](/api-reference/errors) for retry rules.
25 changes: 25 additions & 0 deletions agent-api/send-message.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
title: "Send a message"
openapi: "/api-reference/openapi.json POST /agent/projects/{id}/messages"
description: "Send the agent a message in a project's chat and start its turn."
---

```bash
curl --fail-with-body "https://api.pre.dev/agent/projects/$PROJECT_ID/messages" \
-H "Authorization: Bearer $PREDEV_API_KEY" \
-H "Content-Type: application/json" \
-d '{"message": "Add reminders by email"}'
```

The call returns `202` once the agent has accepted the turn. If a turn is already running, the message waits behind it. The reply arrives on [the event stream](/agent-api/events).

| Field | Meaning |
| --- | --- |
| `message` | What to say to the agent. |
| `sessionId` | A chat session in the project. Omit it to use the Main session. |
| `mode` | `auto` lets the agent act. `plan` limits it to planning. The setting stays for the project until you change it. |
| `model` | Switches the project to this model key before the turn. |

Runs are billed to the project's owner (or team). If that account has no credits, the call returns `402 INSUFFICIENT_CREDITS`. Limit: 30 messages per minute per account.

TypeScript: `client.agent.send(projectId, { message })`. Python: `client.agent.send(project_id, message)`.
20 changes: 20 additions & 0 deletions agent-api/status.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
title: "Get project status"
openapi: "/api-reference/openapi.json GET /agent/projects/{id}/status"
description: "Plan progress, whether the agent is running, and credits used."
---

```bash
curl --fail-with-body "https://api.pre.dev/agent/projects/$PROJECT_ID/status" \
-H "Authorization: Bearer $PREDEV_API_KEY"
```

| Field | Meaning |
| --- | --- |
| `state` | `running` while the agent works; otherwise `idle` |
| `agentStatus` | What the agent is doing now, in a few words |
| `progress` | `percent`, `done`, `total`, `left`; `ready` counts built work whose feature checks pass |
| `features` | Each planned feature with its status and story counts |
| `creditsUsed` | Credits spent on this project so far |

Polling is fine for dashboards (limit: 120 calls per minute per account). To watch a run as it happens, use [the event stream](/agent-api/events).
16 changes: 16 additions & 0 deletions agent-api/stop.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: "Stop the agent"
openapi: "/api-reference/openapi.json POST /agent/projects/{id}/stop"
description: "Stop the agent's running turn or build."
---

```bash
curl --fail-with-body -X POST "https://api.pre.dev/agent/projects/$PROJECT_ID/stop" \
-H "Authorization: Bearer $PREDEV_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'
```

Send `sessionId` to stop one session. Without it, every run on the project stops. `stopped: false` means nothing was running. Work the agent already saved stays.

TypeScript: `client.agent.stop(projectId)`. Python: `client.agent.stop(project_id)`.
Loading
Loading