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:
The stage-specific webhook for the last stage that ran (e.g., audit.completed if audit-only)
The pipeline.completed webhook once all URLs in the batch have finished
Webhook events per configuration
Configuration Webhooks fired (per URL) Final webhook (per batch) Audit only (default) audit.completed— Audit + optimize audit.completed → optimization.completed— Audit + optimize + stage (stage_axp: true) audit.completed → optimization.completed (status: "staged")— Audit + optimize + deploy (deploy_axp: true) audit.completed → optimization.completed → deployment.completedpipeline.completed
pipeline.completed fires only for deploy_axp: true batches — other configurations end with the last per-URL webhook.
Stage Triggered by Webhook event Key data returned Site Audit Always runs audit.completedscore, issues, recommendationsContent Optimizer optimize: trueoptimization.completedoptimization_run_id, title, descriptionAXP Stage stage_axp: true + site_idoptimization.completed with status: "staged"optimization_run_id, title, descriptionAXP Deploy deploy_axp: true + site_iddeployment.completedaxp_version_id, site_idPipeline done All 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
Prefix Stage ORCH-INIT-*Request validation ORCH-AUDIT-*Page audit ORCH-OPT-*Content optimization ORCH-DEPLOY-*AXP deployment ORCH-HOOK-*Webhook delivery
Code Cause Fix ORCH-INIT-004URL domain doesn’t match the registered site Ensure 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 optimize Ensure the page has substantial text content ORCH-DEPLOY-002Site not found for the given site_id Verify 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 results — Your Brand → Site Audits
Content Optimizer results — Your Brand → Optimizer → History
AXP deployments — Your 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.