run_scenario
Predict KPI outcomes for what-if marketing scenarios by providing future channel activity rows to a completed model. Use the scenario template to format inputs, replace missing values with 0, and poll results for completion.
Instructions
Run a "what-if" scenario prediction on a completed model.
Takes a set of future period rows with channel activity values and
predicts the KPI outcome. Use get_scenario_template first to get
the expected format, channel names, and baseline values. Channel names are
the activity-column keys from the template/results (e.g. "search_activity"),
not the channels[].name passed to create_model.
IMPORTANT: Before submitting, replace any NaN/null values in scenario_data with 0. The template from get_scenario_template may contain NaN for channels without historical data, which will cause the prediction to fail.
This is async (returns 202 with status "pending"). Poll get_scenario_results until status is "complete" or "failed".
Workflow: get_scenario_template -> modify values -> run_scenario -> poll get_scenario_results
Args: model_hash: Hash of a completed model. scenario_data: Array of period rows, each a dict with "Date" (YYYY-MM-DD format) and channel activity columns. Channel names must match exactly what get_scenario_template returns in the "channels" field. Example: [{"Date": "2025-01-06", "TV_Impressions": 50000, "Search_Clicks": 1200}] spend_metadata: Optional per-channel spend info for ROI calculation in results. Each entry: {"channel": "TV_Impressions", "metric": "impressions", "cpm": 25.0, "total_spend": 125000, "weekly_spend": [25000, 25000, ...]} rebuild_model: Recompile the model graph before prediction. Must be True (default) for API-initiated scenarios where the model graph is not in memory. evaluate_holdout: Evaluate the scenario against held-out actuals when the scenario period overlaps observed data (default False). skip_slicing: Skip per-channel contribution slicing in the prediction output — faster when only the KPI total is needed (default False). proxy_channels: Optional list of proxy-channel mappings, each mapping a scenario channel to a fitted channel whose transforms it borrows (for channels without their own history).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| model_hash | Yes | ||
| skip_slicing | No | ||
| rebuild_model | No | ||
| scenario_data | Yes | ||
| proxy_channels | No | ||
| spend_metadata | No | ||
| evaluate_holdout | No |