Skip to content

Run a what-if#

A scenario simulates one airport day twice: once as planned, once with your changes. It returns the difference in delay, taxi time and queueing, and the flights that move. At VTBS a full day takes about four seconds.

This guide asks: what does closing runway 02R-20L from 10:00 to 10:30 Bangkok time do to the day?

You need scenarios:write and scenarios:read. Scenarios run on the edge only; an on-premise node does not run them. Scenarios are part of Preview 2.

What is simulated#

The baseline is the day's schedule as currently known, with stand allocations, the runway configuration and taxi routes from the airfield model. Flights already flown use their actual times up to the moment you submit the scenario; the rest of the day is simulated. Both runs use the same random seed, so every difference comes from your changes.

A scenario can contain up to 20 changes:

Change Fields
runway_closure runway, from, until
taxiway_closure taxiway, from, until
stand_closure stand, from, until
flight_delay flight, minutes

Submit the scenario#

10:00 to 10:30 in Bangkok is 03:00Z to 03:30Z.

curl https://api.surfacelens.app/v1/scenarios \
  -H "Authorization: Bearer $SURFACELENS_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "airport": "VTBS",
    "name": "02R-20L closed 10:00-10:30",
    "day": "2026-11-23",
    "changes": [
      {
        "type": "runway_closure",
        "runway": "runway:02R-20L",
        "from": "2026-11-23T03:00:00Z",
        "until": "2026-11-23T03:30:00Z"
      }
    ]
  }'
const res = await fetch("https://api.surfacelens.app/v1/scenarios", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SURFACELENS_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": crypto.randomUUID(),
  },
  body: JSON.stringify({
    airport: "VTBS",
    name: "02R-20L closed 10:00-10:30",
    day: "2026-11-23",
    changes: [
      {
        type: "runway_closure",
        runway: "runway:02R-20L",
        from: "2026-11-23T03:00:00Z",
        until: "2026-11-23T03:30:00Z",
      },
    ],
  }),
});
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
const scenario = await res.json();
import os, uuid, httpx

res = httpx.post(
    "https://api.surfacelens.app/v1/scenarios",
    headers={
        "Authorization": f"Bearer {os.environ['SURFACELENS_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "airport": "VTBS",
        "name": "02R-20L closed 10:00-10:30",
        "day": "2026-11-23",
        "changes": [
            {
                "type": "runway_closure",
                "runway": "runway:02R-20L",
                "from": "2026-11-23T03:00:00Z",
                "until": "2026-11-23T03:30:00Z",
            }
        ],
    },
)
res.raise_for_status()
scenario = res.json()

The response is 202 Accepted with the scenario in queued status and its ID, scn_5e8c1b72d9. The simulated window is the local day: 00:00 to 24:00 in Bangkok, which is 17:00Z the day before to 17:00Z.

Wait for the result#

Poll the scenario until status is succeeded or failed. One request a second is plenty.

import os, time, httpx

headers = {"Authorization": f"Bearer {os.environ['SURFACELENS_KEY']}"}
url = "https://api.surfacelens.app/v1/scenarios/scn_5e8c1b72d9"

while True:
    scenario = httpx.get(url, headers=headers).raise_for_status().json()
    if scenario["status"] in ("succeeded", "failed"):
        break
    time.sleep(1)

To show progress instead, open the scenario's event stream, which closes when the run finishes. To be told without holding a connection, subscribe to the scenario.completed webhook.

Read the comparison#

{
  "id": "scn_5e8c1b72d9",
  "status": "succeeded",
  "completed_at": "2026-11-23T02:59:06.214Z",
  "result": {
    "movements": 1046,
    "duration_ms": 3870,
    "baseline": {
      "departure_delay_min": 2184,
      "arrival_delay_min": 1312,
      "mean_taxi_out_min": 16.8,
      "max_departure_queue": 9,
      "on_time_departure_ratio": 0.812
    },
    "scenario": {
      "departure_delay_min": 3047,
      "arrival_delay_min": 1690,
      "mean_taxi_out_min": 18.1,
      "max_departure_queue": 17,
      "on_time_departure_ratio": 0.774
    },
    "difference": {
      "departure_delay_min": 863,
      "arrival_delay_min": 378,
      "mean_taxi_out_min": 1.3,
      "max_departure_queue": 8,
      "on_time_departure_ratio": -0.038
    },
    "affected_flights": 71
  }
}

Read it as: over 1,046 movements, the closure adds 863 minutes of departure delay and 378 of arrival delay, nearly doubles the worst departure queue, and costs 3.8 points of on-time performance. 71 flights move.

Which flights#

List the affected flights, largest delay first.

curl -G https://api.surfacelens.app/v1/scenarios/scn_5e8c1b72d9/flights \
  -H "Authorization: Bearer $SURFACELENS_KEY" \
  -d limit=2
{
  "object": "list",
  "data": [
    {
      "flight": "flight:TG403-20261123",
      "direction": "departure",
      "baseline": { "off_block_at": "2026-11-23T03:31:00Z", "runway": "runway:02R-20L", "runway_at": "2026-11-23T03:47:00Z" },
      "scenario": { "off_block_at": "2026-11-23T03:31:00Z", "runway": "runway:02R-20L", "runway_at": "2026-11-23T04:16:00Z" },
      "delay_min": 29,
      "reason": "knock_on"
    },
    {
      "flight": "flight:TG102-20261123",
      "direction": "departure",
      "baseline": { "off_block_at": "2026-11-23T03:05:00Z", "runway": "runway:02R-20L", "runway_at": "2026-11-23T03:19:00Z" },
      "scenario": { "off_block_at": "2026-11-23T03:05:00Z", "runway": "runway:02L-20R", "runway_at": "2026-11-23T03:44:00Z" },
      "delay_min": 25,
      "reason": "runway_closure"
    }
  ],
  "next_cursor": "c_7a20e4f1b95d3c68"
}

TG102 was due to depart during the closure and was moved to 02L-20R, behind that runway's own departures. TG403 was not due until after the runway reopened, but left into the queue the closure built: knock_on.

Compare options#

Submit one scenario per option and compare their difference blocks. Moving the closure to 13:00, or shortening it to 20 minutes, are two more requests. Scenarios are kept for 90 days.