> ## 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 Quickstart

> Step-by-step guide to submitting pages for AI search audit, content optimization, and AXP deployment using a single Scrunch pipeline API call.

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

### Prerequisites

* A Scrunch workspace with **Optimize and Deploy** access enabled
* An API key with **Configure** access
* A **brand ID** for the brand you want to optimize
* (Optional) A **site ID** if you want to deploy to AXP

***

### Run your first pipeline

<Tabs>
  <Tab title="cURL">
    <Steps>
      <Step title="Set your credentials">
        ```bash theme={null}
        export SCRUNCH_API_KEY="your-api-key-here"
        export SCRUNCH_BRAND_ID="your-brand-id"
        ```
      </Step>

      <Step title="Submit URLs for audit and optimization">
        This example submits two URLs for audit and content optimization:

        ```bash theme={null}
        curl -X POST "https://api.scrunchai.com/v2/orchestration/optimize-and-deploy/$SCRUNCH_BRAND_ID" \
          -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
          }'
        ```

        **Example response:**

        ```json theme={null}
        {
          "pipeline_id": null,
          "tokens": [
            {
              "token": "01JABC00000000000000001",
              "url": "https://example.com/page-a",
              "status": "pending",
              "orchestration_status": "audit"
            },
            {
              "token": "01JABC00000000000000002",
              "url": "https://example.com/page-b",
              "status": "pending",
              "orchestration_status": "audit"
            }
          ],
          "status": "pending"
        }
        ```
      </Step>

      <Step title="Poll for status">
        Use a token from the response to check progress:

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

        **Example response (completed):**

        ```json theme={null}
        {
          "token": "01JABC00000000000000001",
          "url": "https://example.com/page-a",
          "status": "completed",
          "orchestration_status": "completed",
          "optimization_run_id": "01JOPTRUN0000000000000",
          "axp_version_id": null,
          "result": {
            "checks": [],
            "access_controls_score": 100,
            "content_delivery_score": 90,
            "content_quality_score": 85
          },
          "created_at": "2025-02-06T10:00:00Z",
          "updated_at": "2025-02-06T10:02:30Z"
        }
        ```
      </Step>
    </Steps>
  </Tab>

  <Tab title="Python">
    <Steps>
      <Step title="Install dependencies">
        ```bash theme={null}
        pip install requests
        ```
      </Step>

      <Step title="Submit and poll">
        ```python theme={null}
        import requests
        import time

        API_KEY = "your-api-key"
        BRAND_ID = "your-brand-id"
        BASE = f"https://api.scrunchai.com/v2/orchestration/optimize-and-deploy/{BRAND_ID}"
        HEADERS = {"Authorization": f"Bearer {API_KEY}"}

        # Submit URLs
        resp = requests.post(BASE, headers=HEADERS, json={
            "urls": [
                "https://example.com/page-a",
                "https://example.com/page-b",
            ],
            "optimize": True,
        }, timeout=30)
        resp.raise_for_status()
        pipeline = resp.json()

        # Poll each token until done
        for record in pipeline["tokens"]:
            token = record["token"]
            while True:
                status = requests.get(
                    f"{BASE}/{token}", headers=HEADERS, timeout=30
                ).json()
                stage = status["orchestration_status"]
                print(f"{token}: {stage}")
                if stage in ("completed", "failed"):
                    break
                time.sleep(5)
        ```
      </Step>

      <Step title="Run your script">
        ```bash theme={null}
        python orchestration.py
        ```
      </Step>
    </Steps>
  </Tab>

  <Tab title="JavaScript / TypeScript">
    <Steps>
      <Step title="Install Axios">
        ```bash theme={null}
        npm install axios
        ```
      </Step>

      <Step title="Submit and poll">
        ```javascript theme={null}
        import axios from "axios";

        const API_KEY = "your-api-key";
        const BRAND_ID = "your-brand-id";
        const BASE = `https://api.scrunchai.com/v2/orchestration/optimize-and-deploy/${BRAND_ID}`;
        const headers = { Authorization: `Bearer ${API_KEY}` };

        async function main() {
          // Submit URLs
          const { data: pipeline } = await axios.post(BASE, {
            urls: [
              "https://example.com/page-a",
              "https://example.com/page-b",
            ],
            optimize: true,
          }, { headers });

          // Poll each token
          for (const record of pipeline.tokens) {
            let stage = record.orchestration_status;
            while (stage !== "completed" && stage !== "failed") {
              await new Promise((r) => setTimeout(r, 5000));
              const { data: status } = await axios.get(
                `${BASE}/${record.token}`, { headers }
              );
              stage = status.orchestration_status;
              console.log(`${record.token}: ${stage}`);
            }
          }
        }

        main().catch(console.error);
        ```
      </Step>

      <Step title="Run your code">
        ```bash theme={null}
        node orchestration.js
        ```
      </Step>
    </Steps>
  </Tab>
</Tabs>

***

## Next steps

<CardGroup cols={3}>
  <Card title="Orchestration overview" icon="sitemap" href="/api-reference/optimize-deploy">
    Learn about pipeline stages, error codes, and request patterns.
  </Card>

  <Card title="Pipeline lifecycle guide" icon="arrows-spin" href="/guides/orchestration-lifecycle">
    Walk through the full lifecycle from submission to completion.
  </Card>

  <Card title="Set up webhooks" icon="bell" href="/api-reference/webhooks/overview">
    Get notified in real time instead of polling.
  </Card>
</CardGroup>
