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

# Optimize and Deploy Pipeline API Overview

> Run a single async pipeline to audit pages, optimize content for AI search visibility, and deploy results to AXP with polling or webhooks.

## One endpoint to rule them all

The Optimize and Deploy API lets you run a multi-stage pipeline that audits your pages, optimizes their content for AI search visibility, and optionally deploys the results to AXP — all from a single API call. One endpoint to bind your audit, optimization, and deployment workflows together.

Each pipeline is asynchronous. You submit URLs, receive tracking tokens, and then poll for status or receive webhook callbacks as each stage completes.

<Warning>
  The Optimize and Deploy API is currently in **early access** and available on request. Contact your Customer Success representative to get access enabled for your organization.
</Warning>

***

## How it works

The pipeline chains three Scrunch products together. Each stage is optional — use only what you need.

```mermaid theme={null}
flowchart LR
    A["Submit URLs"] --> B["🔍 Site Audit"]
    B --> C{"optimize?"}
    C -- "true" --> D["✨ Content Optimizer"]
    C -- "false" --> G["✅ Done"]
    D --> E{"deploy_axp?"}
    E -- "true" --> F["🚀 AXP Deploy"]
    E -- "false" --> G
    F --> G
```

| Product               | Pipeline stage | What it does                                                                            | Required?                          |
| --------------------- | -------------- | --------------------------------------------------------------------------------------- | ---------------------------------- |
| **Site Audit**        | `audit`        | Evaluates AI discoverability: robots.txt, bot access, content quality, content delivery | Always runs                        |
| **Content Optimizer** | `optimizing`   | Rewrites page content to improve AI visibility for target prompts and personas          | Set `optimize: true`               |
| **AXP (stage)**       | `optimizing`   | Stages optimized content to AXP for review without publishing live                      | Set `stage_axp: true` + `site_id`  |
| **AXP (deploy)**      | `deploying`    | Publishes optimized content to your AXP site as a new version                           | Set `deploy_axp: true` + `site_id` |

### Configuration per product

Each product in the pipeline has its own configuration:

* **Site Audit** — runs automatically on each URL, no extra config needed
* **Content Optimizer** — optionally configure `target_prompts`, `target_personas`, `target_sources`, `override_suggestions`, and per-URL `custom_instructions`
* **AXP** — requires a `site_id` (the RegisteredSite ULID). All URLs must belong to the site's domain. Per-URL `retain_schema_types` controls which JSON-LD schema types are kept (omit to retain all)

***

## Pipeline stages

Every URL you submit moves through these stages in order:

| Stage        | `orchestration_status` | What happens                                                                                    |
| ------------ | ---------------------- | ----------------------------------------------------------------------------------------------- |
| **Audit**    | `audit`                | Page is fetched and evaluated for AI discoverability (robots.txt, content quality, bot access)  |
| **Optimize** | `optimizing`           | Content is analyzed and rewritten to improve AI visibility for your target prompts and personas |
| **Deploy**   | `deploying`            | Optimized content is published to AXP as a new version                                          |
| **Done**     | `completed`            | All stages finished successfully                                                                |
| **Error**    | `failed`               | Pipeline stopped at the failing stage                                                           |

```mermaid theme={null}
stateDiagram-v2
    [*] --> audit
    audit --> optimizing : optimize = true
    audit --> completed : optimize = false
    audit --> failed : error
    optimizing --> deploying : deploy_axp = true
    optimizing --> completed : deploy_axp = false
    optimizing --> failed : error
    deploying --> completed : success
    deploying --> failed : error
```

<Note>
  The optimize and deploy stages only run if you set `optimize: true` and `deploy_axp: true` in the request. With defaults, only the audit stage runs. To stage content for review without publishing live, set `stage_axp: true` instead of `deploy_axp` — see the [orchestration lifecycle guide](/guides/orchestration-lifecycle) for the stage-only flow.
</Note>

***

## When to use it

* You want to audit, optimize, and deploy pages without multiple API calls
* You need batch processing across many URLs
* You want webhook notifications when stages complete
* You're building automated content optimization pipelines

## When not to use it

* You only need audit results — use the **Site Audit API** directly
* You want to query existing visibility data — use the **Query API**
* You need manual control over each optimization — use the Scrunch dashboard

***

## Request patterns

### Simple: list of URLs

Pass `urls` when every URL should use the same optimization configuration:

```bash theme={null}
curl -X POST "https://api.scrunchai.com/v2/orchestration/optimize-and-deploy/1234" \
  -H "Authorization: Bearer $SCRUNCH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "urls": [
      "https://example.com/page-a",
      "https://example.com/page-b"
    ],
    "optimize": true,
    "deploy_axp": true,
    "site_id": "01JEXAMPLE00000000000000"
  }'
```

### Detailed: per-URL overrides

Pass `requests` when individual URLs need different prompts, personas, or sources:

```bash theme={null}
curl -X POST "https://api.scrunchai.com/v2/orchestration/optimize-and-deploy/1234" \
  -H "Authorization: Bearer $SCRUNCH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "requests": [
      {
        "url": "https://example.com/page-a",
        "target_prompts": ["best budget airlines"],
        "target_personas": [{"name": "Budget Traveler"}]
      },
      {
        "url": "https://example.com/page-b",
        "target_prompts": ["luxury travel options"]
      }
    ],
    "optimize": true,
    "deploy_axp": true,
    "site_id": "01JEXAMPLE00000000000000"
  }'
```

<Warning>
  Provide either `urls` or `requests`, not both. The API will reject requests that include both fields.
</Warning>

***

## Tracking progress

Each URL gets its own tracking token. Use it to poll for status:

```bash theme={null}
curl "https://api.scrunchai.com/v2/orchestration/optimize-and-deploy/1234/01JABCTOKEN00000000000" \
  -H "Authorization: Bearer $SCRUNCH_API_KEY"
```

The response includes the current `orchestration_status`, timestamps, and result data as it becomes available.

For real-time updates without polling, configure webhooks to receive callbacks at each stage transition.

<Card title="Set up webhooks" icon="bell" href="/api-reference/webhooks/overview">
  Get notified when audits, optimizations, and deployments complete.
</Card>

***

## Error codes

When a pipeline fails, the response includes a structured error code. Use these to identify what went wrong and where:

| Prefix        | Stage            | Example codes                                                  |
| ------------- | ---------------- | -------------------------------------------------------------- |
| `ORCH-INIT`   | Initialization   | Invalid URL, missing site\_id, domain mismatch, quota exceeded |
| `ORCH-AUDIT`  | Audit            | Fetch failed, timeout, page not found                          |
| `ORCH-OPT`    | Optimization     | No content to optimize, LLM failure, source fetch failed       |
| `ORCH-DEPLOY` | Deployment       | Site not found, AXP publish failed                             |
| `ORCH-HOOK`   | Webhook delivery | Delivery failed, SSRF blocked, timeout                         |

Each error includes a human-readable message and a short `error_hash` you can reference when contacting support.

***

## Relationship to other Scrunch products

The Optimize and Deploy API is a composition layer that chains together three standalone Scrunch products:

```mermaid theme={null}
flowchart TB
    subgraph "Optimize and Deploy API"
        direction LR
        SA["Site Audit API<br/><i>Audit pages for<br/>AI discoverability</i>"]
        CO["Content Optimizer<br/><i>Rewrite content for<br/>AI visibility</i>"]
        AXP["AXP<br/><i>Deploy optimized<br/>content at the edge</i>"]
        SA --> CO --> AXP
    end
    API["POST /orchestration/optimize-and-deploy"] --> SA
    AXP --> DONE["Results + Webhooks"]
```

* **Site Audit** is always the first stage. It runs the same checks as `POST /{brand_id}/page-audits`.
* **Content Optimizer** uses audit results plus your target prompts and personas to generate optimized content.
* **AXP** deploys the optimized content as a new version to your registered site.

Each product can also be used independently outside of this pipeline.

### Dashboard visibility

Everything the pipeline does is fully visible in the Scrunch dashboard — audit results, optimization runs, and AXP deployments all appear in their respective pages exactly as if they had been performed manually. AXP deployments are tracked in the **Version History** with full change tracking, and you can compare original vs. optimized content side by side.

<Card title="Run your first pipeline" icon="box-open" href="/getting-started/quickstart-orchestration">
  Go to the Optimize and Deploy Quickstart
</Card>
