Skip to content
Spacefolder Docs
Esc
↑↓navigate↵open⌘Jpreview
On this page

Get started

Create a World, Fold sales and compare two pricing actions on seven days of revenue.

Create a World for your application, Fold observed events into it, then Navigate to predict outcomes and compare possible actions. This example compares continuing standard pricing with continuing a promotion. The goal is to maximize one store’s revenue over the next seven days.

1. Get an API key

Sign in to Spacefolder, select your workspace, and create a key in API keys. Set it in your server environment:

export SPACEFOLDER_API_KEY='your-workspace-api-key'

The SDKs and CLI already connect to the hosted API. Your key grants access to the selected workspace; keep it on your server. Keys expire after 30 days by default, with an expiry of up to 365 days available in the platform.

2. Create a World

The examples use curl, so you can start without installing a package. Choose an unused World ID:

curl --fail-with-body https://api.spacefolder.com/v1/worlds \
  -H "Authorization: Bearer $SPACEFOLDER_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"id":"my_app","name":"My application"}'

Use my_app as the world_id in the following requests. Worlds keep independent streams of event history and learned state.

3. Fold observed events

Save the example sales history as fold.json. It contains two simulated pricing histories for the same store. Each has two sales per day for eight days. Each sale carries its dollar amount in data.usd and its pricing action in data.forecast_action. Use the complete file so both actions have enough history for a seven-day forecast.

curl --fail-with-body https://api.spacefolder.com/v1/fold \
  -H "Authorization: Bearer $SPACEFOLDER_API_KEY" \
  -H 'Content-Type: application/json' --data-binary @fold.json

The Fold receipt returns run_id, world_version, accepted_count, and deduplicated_count. Reuse an event’s id when retrying its delivery. Continue folding events as your application observes them, including actions taken and their measured outcomes.

4. Compare weekly revenue

Save this as navigate.json:

{
  "world_id": "my_app",
  "nav_id": "weekly_revenue",
  "entity_type": "store",
  "entity_id": "store_42",
  "context": {},
  "actions": {
    "standard": { "name": "pricing.standard" },
    "promotion": { "name": "pricing.promotion" }
  },
  "predictions": {
    "revenue": {
      "event": "sale.completed.data.usd",
      "aggregation": "sum",
      "horizon": "7d",
      "interval": "1d"
    }
  },
  "objectives": { "revenue": { "direction": "maximize" } }
}

Navigate adds sales within each day and uses the same sum operation on the seven daily action scores to rank the week. Each action still returns seven forecast points. Reuse nav_id for later runs of this decision. Navigate generates a separate run_id for each call.

curl --fail-with-body https://api.spacefolder.com/v1/navigate \
  -H "Authorization: Bearer $SPACEFOLDER_API_KEY" \
  -H 'Content-Type: application/json' --data-binary @navigate.json

Read actions.promotion.predictions.revenue.points and actions.standard.predictions.revenue.points for the daily forecasts. Each point has an ended_at timestamp and a dollar value. The rank on each action gives the comparison result. Read actions.promotion.predictions.revenue.confidence for the confidence score for the whole promotion forecast.

In this synthetic replay, the seven displayed forecasts total $924 for promotion (rank 1) and $854 for standard pricing (rank 2). These are forecasts for continuing each recorded pricing strategy. For a live decision, Fold the action actually taken, its sales and a coverage receipt before the verification deadline. Metric verification

Use the CLI or an SDK

Once their first releases are published, install the packages:

npm install -g @spacefolder/cli
spacefolder auth status
spacefolder fold fold.json
spacefolder navigate navigate.json
npm install @spacefolder/sdk
# or, for Python:
pip install spacefolder-sdk

All three clients read SPACEFOLDER_API_KEY. See SDKs for source installation before the first release, or the CLI reference for commands and JSON input.