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

# Local Composer API

> Internal endpoints of the EISPATCH v1.1.0 Local Composer server used by Codex, Claude Code, and OpenCode, with status codes for session, approval, and replay failures.

The Local Composer (`core/local-composer.mjs`) is used by the Codex, Claude Code, and OpenCode adapters. It serves `ui/composer.html` and exposes an API under `/api/*`. The Antigravity adapter does not use it; Antigravity uses MCP App tools over stdio instead.

> [!WARNING]
>
> These endpoints are internal to the composer UI and host adapters. They are not a stable public API and may change between releases.

## Server

* **Base URL**: `http://127.0.0.1:<port>`. The port is ephemeral (`0`) unless an adapter passes one.
* **Binding**: `127.0.0.1` only.
* **Lifetime**: `startLocalComposerServer` has no idle timeout by default (`idleTimeoutMs = 0`). The launcher used by the Codex and Claude Code hooks (`core/launch-local-composer.mjs`) sets 30 minutes, configurable with `--idle-ms`. Each request resets the timer. The OpenCode plugin starts the server without an idle timeout and closes the previous server when a new prompt is intercepted.

## Request checks

Checks run in this order:

1. **Host header** (all requests): must be `127.0.0.1:<port>` or `localhost:<port>`. Otherwise **403** `Invalid Host header.`
2. **Origin and Referer** (`/api/*`): if present, must be `http://127.0.0.1:<port>` or `http://localhost:<port>`. Otherwise **403** `Cross-origin request rejected.` or `Cross-origin referer rejected.`
3. **Session token** (`/api/*`): the `X-EISPATCH-Token` header must equal the per-session token (constant-time comparison). Otherwise **401** `Missing or invalid EISPATCH session token.`

```http theme={null}
X-EISPATCH-Token: <per-session-token>
```

The token is injected into the served page as `window.__EISPATCH_LOCAL_SESSION__`, together with `host`, `hostLabel`, and `initialPrompt`.

Request bodies larger than 5 MB are rejected. Unhandled errors, including oversized bodies and library errors, return **500** with `{ "error": "<message>" }`. Unknown routes return **404**.

## Endpoints

| Method | Endpoint | Summary |
| - | - | - |
| POST | `/api/compose` | Discover capabilities, recommend, and build the graph. Clears the active approval. |
| POST | `/api/breakdown` | Build task sections. Clears the active approval. |
| POST | `/api/compile` | Compile the prompt and manifest. Clears the active approval. |
| POST | `/api/approve` | Issue an approval token bound to the SHA-256 hash of the prompt. |
| POST | `/api/revoke-approval` | Revoke an approval token. |
| POST | `/api/dispatch` | Verify and consume the approval, then dispatch or return clipboard fallback. |
| GET | `/api/library` | List the library. |
| POST | `/api/library/save` | Save or overwrite an entry. |
| POST | `/api/library/update` | Update or duplicate an entry. |
| POST | `/api/library/delete` | Delete an entry. |
| POST | `/api/library/validate` | Check an entry's capabilities against current discovery. |
| GET | `/api/library/export` | Export entries as JSON. |
| POST | `/api/library/import` | Import entries from JSON. |

## Compose

Body fields: `prompt` (defaults to the initial prompt), `workspacePath`, `tasks` (optional seed tasks).

Response fields: `host`, `hostLabel`, `prompt`, `projectContext`, `suggestedMetadata`, `counts`, `telemetry`, `graph`, `tasks`, `preview` (a compile result).

## Breakdown

Body fields: `prompt`, `workspacePath`, `tasks`. If `tasks` is empty, EISPATCH suggests tasks from the prompt.

Response fields: `prompt`, `tasks`, `preview`.

## Compile

Body fields: `prompt`, `selectedNodes`, `tasks`, `globalNotes`, `manualFinalPrompt`.

Response: the compile result (`compiledPrompt`, `generatedPrompt`, `manifest`, `summary`). See [Compiled prompt](https://eispatch.framewire.io/reference/compiled-prompt.md).

## Approve

Body: `{ "compiledPrompt": "<exact text>" }`. An empty prompt returns **400** `Cannot approve an empty prompt.`

**ok** `boolean`

`true` on success.

**approvalToken** `string`

Random token required by the next dispatch. Only one approval is active at a time; a new approval replaces the previous one.

**promptHash** `string`

SHA-256 hex digest of `compiledPrompt`.

## Revoke approval

Body: `{ "approvalToken": "<token>" }` (optional). The token, or the active token if none is given, is marked as consumed and the active approval is cleared. Returns `{ "ok": true }`.

## Dispatch

Body: `{ "compiledPrompt": "<exact text>", "approvalToken": "<token>" }`.

| Status | Error | Cause |
| - | - | - |
| **403** | `Approval required: ...` | No `approvalToken`. |
| **409** | `Replay rejected: ...` | Token already consumed by a dispatch or revoked. |
| **403** | `Invalid or revoked approvalToken. ...` | Token is not the active approval (for example, cleared by compose, breakdown, or compile). |
| **409** | `Prompt integrity mismatch: ...` | SHA-256 of `compiledPrompt` differs from the approved hash. |

On success, the token is consumed before the adapter's dispatch handler runs.

* **With an adapter dispatch handler** (OpenCode): `{ dispatchId: "disp_<timestamp>", host, promptHash, ...result }`. The OpenCode result `mode` is `opencode-session-prompt`, `opencode-http-session`, or `clipboard-fallback`.
* **Without a handler** (Codex and Claude Code): `{ dispatchId: "copy_<timestamp>", host, promptHash, mode: "clipboard-fallback", note }`. The composer UI then copies the prompt for you to paste.

## Library endpoints

These call the functions in `core/library.mjs`. See [Prompt library](https://eispatch.framewire.io/guides/prompt-library.md) for the entry schema.

| Endpoint | Input | Output |
| - | - | - |
| `GET /api/library` | Query `workspacePath` (optional) | `version`, `libraryPath`, `totalCount`, `projects`, `entries`, `projectContext` |
| `POST /api/library/save` | `{ entry }` or the entry object | `{ entry, library }` |
| `POST /api/library/update` | `{ id, patch }`, or `{ action: "duplicate", id, patch }` | `{ entry, library }` |
| `POST /api/library/delete` | `{ id }` | `{ deletedId, library }` |
| `POST /api/library/validate` | `{ id, workspacePath }` | `{ valid, missingCapabilities, entry }`, or **404** if the entry does not exist |
| `GET /api/library/export` | Query `projectKey` (optional) | `{ json }` |
| `POST /api/library/import` | `{ json }` | `{ importedCount, library }` |

## Getting help

If an endpoint returns an unexpected status, check that the request carries the session token from the page that the composer served, that it is sent from the same loopback origin, and that the server is still running. For persistent issues, open an issue at [github.com/FrameScope/eispatch/issues](https://github.com/FrameScope/eispatch/issues).


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