> For the complete documentation index, see [llms.txt](https://docs.pending.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pending.ai/api-reference/pai-synth.md).

# PAI Synth

Access Pending AI's high-throughput retrosynthetic tree search, one molecule at a time or in batches of up to 100,000

Pending AI's Synth capability performs a tree search over reaction templates to find synthetic routes from purchasable building blocks to a target molecule. Each result includes pricing and lead-time annotations for the building blocks used, so routes can be ranked by cost and sourcing feasibility as well as by length or novelty.

Searches run as **Plans**, one target molecule each, at `https://api.pending.ai/synth-batches/v1`. Run a single Plan and get its routes back in the same request, or screen up to 100,000 molecules at once as a **Batch**.

***

## Plans and Batches

A **Plan** is one tree search for one target molecule. A **Batch** creates a Plan for every SMILES you send, all with the same search parameters. Every Plan, whether on its own or part of a Batch, moves through the same statuses:

```mermaid
stateDiagram-v2
  pending --> processing
  processing --> completed
  processing --> failed
```

A Plan can also end up `cancelled`, and the Plans of a deleted Batch are `archived`.

### Running a single Plan

`POST /plans` runs one tree search, ahead of any Batch work on the same engine, and waits for it to finish: the response is the Plan with its `result`, in one request. With the default parameters that takes a second or two.

* **If it takes longer** than 25 seconds, the Plan comes back `pending` or `processing`. Read it with `GET /plans/{id}` until its `status` is `completed` or `failed`.
* **To return at once** without waiting, send `Prefer: respond-async`; to wait less, `Prefer: wait=<seconds>`. The response's `Preference-Applied` header says which was used.

`GET /plans/{id}` also works for a Plan created by a Batch, without knowing which Batch it belongs to.

### Screening many molecules

```mermaid
stateDiagram-v2
  a: POST /batches with a list of SMILES
  b: GET /batches/{id} until plans_created is true
  c: GET /batches/{id}/plans to follow each plan's status
  d: GET /batches/{id}/plans/{plan_id} for a completed plan's routes
  [*] --> a
  a --> b
  b --> c
  c --> d
  d --> [*]
```

1. **Create the Batch.** `POST /batches` takes up to 100,000 SMILES and one set of `parameters`. It returns straight away with the Batch's `id` and `plans_created: false`.
2. **Wait for the plans to be created.** A background worker creates and queues one Plan per SMILES, which can take a while for a large Batch. `GET /batches/{id}` shows `plans_created: true` once they're all queued; `plan_count` is known from the start.
3. **Follow progress.** `GET /batches/{id}/plans` lists the Batch's Plans with their `status`, using cursor pagination (`starting_after` / `ending_before`, or the `links` in each response). A Batch has no overall status of its own: it's done when every Plan is `completed` or `failed`.
4. **Read the results.** `GET /batches/{id}/plans/{plan_id}` returns a Plan with its `result`: the routes found, vendor pricing for their building blocks, and reagent annotations. The list endpoint leaves `result` out, so fetch each completed Plan individually.

### Choosing an engine

Each Plan runs on one retrosynthesis engine, set by `parameters.engine` (`thieme` by default, or `pistachio`). `GET /engines` lists the engines with the number of tasks currently queued for each, which is a good guide to how long new work will wait. `GET /libraries` lists the building-block libraries searched; for now that's `chemspace` for every Plan.

### Search parameters

Every Plan in a Batch shares one set of `parameters`; a single Plan has its own. They tune the search:

* **Time and depth budget** (`max_seconds`, `max_depth`) control how long the search runs and how many reaction steps it will consider.
* **Pruning masks** (`mask_trivial_solution`, `mask_bblocks_mw_gte`, `mask_usd_pricing_gte`, `mask_lead_times_gte`) exclude routes that aren't practically useful — e.g. trivial one-step "solutions", overly large building blocks, or building blocks that are prohibitively expensive or slow to source.
* **Backbone grouping** (`max_backbone_groups`, `max_backbone_group_size`, `limit_backbone_group_size_by_cost`) controls how routes sharing a synthetic backbone are clustered and truncated in the result, to keep results manageable for backbones with many equivalent building block substitutions.
* **`ships_to`** scopes pricing/lead-time annotations to a specific delivery region.

The target is standardised to its neutral, amide form before the search. A completed Plan's `result.metadata` reports how much work the search did (`search_passes`, `bblock_lookup_passes`, `expansion_passes`) and why it stopped (`stop_reason`, e.g. `solved` or `time_limit`).

See the available [Guides](/developer-tools/guides.md) for more implementation possibilities when integrating with existing drug discovery pipelines.

### Billing

Every Plan is billed as one retrosynthesis job, including each Plan in a Batch. A Batch is accepted or refused as a whole: if your team's plan doesn't cover all of its Plans, the request fails with `402` and nothing is created.

### Deleting a Batch

`DELETE /batches/{id}` removes the Batch from `GET /batches` immediately. Its Plans are archived in the background, which can take a while for a large Batch. This can't be undone.

***

## Frequently Asked Questions

<details>

<summary>Q: Why did my search return no routes?</summary>

A: A search can complete within `max_seconds` without finding any validated route to the target molecule — this is reported via `metadata.validated_routes` (0) rather than as an error, and `metadata.stop_reason` says why the search ended. Common causes are an overly restrictive `max_depth`, pruning masks (`mask_usd_pricing_gte`, `mask_bblocks_mw_gte`, `mask_lead_times_gte`) that exclude every candidate route found, or a target molecule that genuinely has no accessible synthetic route from the available building block inventory within the given depth.

</details>

<details>

<summary>Q: What does `mask_trivial_solution` do?</summary>

A: When `true` (what the CLI sends by default), routes where the target molecule is itself a purchasable building block are excluded from the result, since a zero-step "route" is rarely useful in practice.

</details>

<details>

<summary>Q: How is a route's cost calculated?</summary>

A: Each building block used in a route is annotated with vendor pricing data via `pricing_annotations`, keyed by `major_component_id`, which links back to the building block nodes in the route. `mask_usd_pricing_gte` and `mask_lead_times_gte` prune candidate building blocks during the search before routes are constructed, rather than filtering completed routes afterwards.

</details>

<details>

<summary>Q: What's the difference between `max_backbone_groups` and `max_backbone_group_size`?</summary>

A: Many distinct routes can share the same reaction backbone and differ only in which interchangeable building block was used at one or more steps. `max_backbone_groups` limits how many distinct backbones are returned; `max_backbone_group_size` limits how many building-block variations are kept per backbone. `limit_backbone_group_size_by_cost` controls whether that per-backbone limit keeps the cheapest variations first.

</details>

<details>

<summary>Q: Why was my Plan or Batch refused with <code>402</code>?</summary>

A: Each Plan is billed as one **retrosynthesis job**, from the same allowance as PAI Retro. Nothing is created, or billed, if `error.code` is:

* `NO_TEAM`: you didn't sign in to a team. Log in again and pick a team.
* `NO_PLAN`: the team has no plan, or isn't set up for billing.
* `USAGE_LIMIT_REACHED`: the team's allowance is used up, and the free trial or its overage limit allows no more.

See [Accounts, teams and billing](/getting-started/accounts-and-billing.md).

</details>

<details>

<summary>Q: Should I use a Plan or a Batch?</summary>

A: For one molecule, use `POST /plans`: it returns the routes in the same request, and the Plan is kept so you can read it again later. Use a Batch to screen a list of molecules: you submit it once and collect the results as the Plans finish, without holding a request open per molecule.

</details>

<details>

<summary>Q: Why does my Batch say <code>plans_created: false</code>?</summary>

A: The Plans are still being created and queued by a background worker. `plan_count` already tells you how many there will be. Plans that have been created appear in `GET /batches/{id}/plans` and start running straight away, so you don't need to wait for `plans_created` before following their progress.

</details>

<details>

<summary>Q: Why is <code>result</code> empty when I list a Batch's Plans?</summary>

A: Listing returns each Plan's status but not its routes. Fetch a completed Plan with `GET /batches/{id}/plans/{plan_id}` or `GET /plans/{id}` to get its `result`.

</details>
