Skip to main content
The Optimize and Deploy API is currently in early access. Contact your Customer Success representative to get access enabled for your organization.

Overview

This guide walks through the complete lifecycle of an Optimize and Deploy pipeline — from submitting URLs to handling results. By the end, you’ll understand how to track progress, handle errors, and integrate the pipeline into your workflow.

Pipeline flow

Each URL cascades through up to three stages. At every stage transition, a webhook fires so you can react in real time. Stages are optional — the pipeline exits early when the last enabled stage completes. Regardless of which stage is the final one, you always receive:
  1. The stage-specific webhook for the last stage that ran (e.g., audit.completed if audit-only)
  2. The pipeline.completed webhook once all URLs in the batch have finished

Webhook events per configuration

ConfigurationWebhooks fired (per URL)Final webhook (per batch)
Audit only (default)audit.completed
Audit + optimizeaudit.completedoptimization.completed
Audit + optimize + stage (stage_axp: true)audit.completedoptimization.completed (status: "staged")
Audit + optimize + deploy (deploy_axp: true)audit.completedoptimization.completeddeployment.completedpipeline.completed
pipeline.completed fires only for deploy_axp: true batches — other configurations end with the last per-URL webhook.

What gets configured at each stage

StageTriggered byWebhook eventKey data returned
Site AuditAlways runsaudit.completedscore, issues, recommendations
Content Optimizeroptimize: trueoptimization.completedoptimization_run_id, title, description
AXP Stagestage_axp: true + site_idoptimization.completed with status: "staged"optimization_run_id, title, description
AXP Deploydeploy_axp: true + site_iddeployment.completedaxp_version_id, site_id
Pipeline doneAll URLs finish (deploy_axp: true batches only)pipeline.completedcompleted_count, failed_count, total_count

1. Submit a pipeline

Simple mode: shared configuration

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,
    "target_prompts": ["best budget airlines", "cheap flights comparison"],
    "target_personas": [{"name": "Budget Traveler", "description": "Price-sensitive consumer"}]
  }'

Stage-only mode: review before going live

Set stage_axp: true to run the full audit and optimize pipeline and push the optimized content to AXP as a staged change — without deploying a live version. Reviewers can then approve and publish from the Scrunch dashboard.
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"],
    "optimize": true,
    "stage_axp": true,
    "site_id": "01JEXAMPLE00000000000000"
  }'
The pipeline finishes at orchestration_status: completed after staging, and the final per-URL webhook is optimization.completed with status: "staged". stage_axp and deploy_axp are mutually exclusive.

Detailed mode: per-URL overrides

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/budget-page",
        "target_prompts": ["best budget airlines"],
        "target_personas": [{"name": "Budget Traveler"}]
      },
      {
        "url": "https://example.com/luxury-page",
        "target_prompts": ["luxury travel options"],
        "override_suggestions": true
      }
    ],
    "optimize": true,
    "deploy_axp": true,
    "site_id": "01JEXAMPLE00000000000000"
  }'

What gets returned

{
  "pipeline_id": "01JPIPELINE000000000000",
  "tokens": [
    {"token": "01JABC001", "url": "https://example.com/budget-page", "status": "pending", "orchestration_status": "audit"},
    {"token": "01JABC002", "url": "https://example.com/luxury-page", "status": "pending", "orchestration_status": "audit"}
  ],
  "status": "pending"
}
pipeline_id is only set when deploy_axp is true — it groups all URLs into a single AXP deployment batch.

2. Track progress

Option A: Polling

curl "https://api.scrunchai.com/v2/orchestration/optimize-and-deploy/1234/01JABC001" \
  -H "Authorization: Bearer $SCRUNCH_API_KEY"
orchestration_statusMeaning
auditPage audit running
optimizingContent optimization running
deployingAXP deployment running
completedAll stages finished successfully
failedPipeline stopped at the failing stage
Poll every 5–10 seconds. Audits typically complete in under 30 seconds; optimization may take 1–2 minutes depending on page complexity.

Option B: Webhooks

Configure a webhook URL for your brand and receive HTTP callbacks at each stage transition.

Webhook setup guide

Configure webhooks and verify signatures.

3. Handle stage transitions

Audit → Optimizing

{
  "orchestration_status": "optimizing",
  "result": {
    "access_controls_score": 100,
    "content_delivery_score": 90,
    "content_quality_score": 85
  }
}

Optimizing → Deploying

{
  "orchestration_status": "deploying",
  "optimization_run_id": "01JOPTRUN0000000000000"
}

Deploying → Completed

{
  "orchestration_status": "completed",
  "axp_version_id": 42
}

4. Handle errors

PrefixStage
ORCH-INIT-*Request validation
ORCH-AUDIT-*Page audit
ORCH-OPT-*Content optimization
ORCH-DEPLOY-*AXP deployment
ORCH-HOOK-*Webhook delivery
CodeCauseFix
ORCH-INIT-004URL domain doesn’t match the registered siteEnsure all URLs belong to the site’s domain
ORCH-AUDIT-002Page fetch failed (404, timeout, blocked)Verify the URL is accessible and not blocked by robots.txt
ORCH-OPT-002No content available to optimizeEnsure the page has substantial text content
ORCH-DEPLOY-002Site not found for the given site_idVerify the site_id is correct and belongs to your brand

5. Full working example

import requests
import time

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

urls = [
    "https://example.com/page-a",
    "https://example.com/page-b",
    "https://example.com/page-c",
]

resp = requests.post(BASE, headers=HEADERS, json={
    "urls": urls,
    "optimize": True,
    "deploy_axp": True,
    "site_id": SITE_ID,
}, timeout=30)
resp.raise_for_status()
pipeline = resp.json()

print(f"Pipeline started: {pipeline.get('pipeline_id')}")
pending = {r["token"]: r["url"] for r in pipeline["tokens"]}
while pending:
    for token in list(pending.keys()):
        status = requests.get(f"{BASE}/{token}", headers=HEADERS, timeout=30).json()
        stage = status["orchestration_status"]
        if stage in ("completed", "failed"):
            result = "OK" if stage == "completed" else "FAILED"
            print(f"  [{result}] {pending[token]}")
            if status.get("axp_version_id"):
                print(f"    AXP version: {status['axp_version_id']}")
            del pending[token]
    if pending:
        time.sleep(5)

6. Viewing results in the Scrunch dashboard

Everything the pipeline does is visible in the Scrunch dashboard — exactly as if each step had been performed manually.
  • Site Audit resultsYour Brand → Site Audits
  • Content Optimizer resultsYour Brand → Optimizer → History
  • AXP deploymentsYour Brand → AXP → [site] → Version History
To roll back a deployment, use the Redeploy option on any previous version in the AXP version history.

Best practices

  • Use webhooks for production — more efficient and lower latency than polling
  • Handle partial failures — in a batch, some URLs may succeed while others fail; check each token individually
  • Set override_suggestions: true carefully — only your explicitly provided prompts and personas are used
  • Start with audit-only — validate URLs and check audit scores before committing to optimization and deployment

Orchestration API reference

Endpoint details, error codes, and schema reference.

Webhooks reference

Event types, payload schemas, and signature verification.