Allocator API

The Allocator API exposes the NTS household optimizer as an asynchronous job service.

Base path (examples):

All routes documented here are relative to the allocator service base.


Authentication

Every request must include a header:

x-api-token: <token>

Tokens are configured server‑side via the API_TOKENS environment variable (comma‑separated). Requests without a valid token receive 401 Unauthorized.


Job Model

AllocJobSpec

This is the core job configuration embedded in the submission request.

{
  "household_id": "demo-house",
  "objective": "custom",
  "local_iters": 50,
  "grid_step": 0.05,
  "n_sims": 1000,
  "notes": "optional notes about this run"
}

Fields:

SubmitAllocReq

Full request payload:

{
  "job": { /* AllocJobSpec */ },
  "tenant": "nts",
  "idem_hint": null,
  "dry_run": false
}

Fields:

SubmitAllocAck

Response from the submit endpoint:

{
  "accepted": true,
  "job_id": "1764792929054-0",
  "idem_key": "ops:idem:...",
  "message": "Queued"
}

Fields:


Idempotency

The Allocator API enforces lightweight idempotency per job:

Semantics:

This protects against client retries while keeping the implementation simple.


Endpoints

POST /allocator/jobs

Description: Submit a new household optimization job.

Request:

Example:

curl -X POST "$ALLOC_BASE/allocator/jobs"   -H "Content-Type: application/json"   -H "x-api-token: $API_TOKEN"   -d '{
    "job": {
      "household_id": "demo-house",
      "objective": "custom",
      "n_sims": 3000,
      "local_iters": 4,
      "grid_step": 0.10,
      "notes": "Quickstart demo"
    },
    "tenant": "nts",
    "dry_run": false
  }'

Responses:


GET /allocator/jobs

Description: List jobs with optional status filters.

Query params:

Response:

[
  {
    "job_id": "1764792929054-0",
    "status": "DONE",
    "created_at": "2025-12-03T11:40:42.188Z",
    "updated_at": "2025-12-03T11:48:31.833Z",
    "artifact_s3_key": "jobs/1764792929054-0/report.pptx"
  },
  {
    "job_id": "...",
    "status": "RUNNING",
    "created_at": "...",
    "updated_at": "..."
  }
]

GET /allocator/jobs/{job_id}

Description: Fetch detailed status and parameters for a single job.

Path params:

Response:

{
  "job_id": "1764792929054-0",
  "status": "DONE",
  "created_at": "2025-12-03T11:40:42.188Z",
  "updated_at": "2025-12-03T11:48:31.833Z",
  "artifact_s3_key": "jobs/1764792929054-0/report.pptx",
  "params": {
    "n_sims": 3000,
    "n_jobs": 16,
    "local_iters": 4,
    "grid_step": 0.1,
    "start_crt": 8500000.0,
    "start_tax": 7500000.0,
    "years": 30,
    "payout_rate": 0.085
  }
}

Errors:


GET /allocator/artifacts/{job_id}/report

Description: Return a presigned URL to download the PPTX report for a completed job.

Response:

{
  "job_id": "1764792929054-0",
  "report_url": "https://s3-region.amazonaws.com/nts-household-artifacts/jobs/1764.../report.pptx?X-Amz-Algorithm=..."
}

Notes:


Job Lifecycle

Typical lifecycle:

  1. POST /allocator/jobs ⇒ job created, status PENDING.
  2. Worker claims the job ⇒ status RUNNING.
  3. Worker completes optimization and uploads report ⇒ status DONE, artifact_s3_key populated.
  4. In case of failure, status ERROR with an error field describing the issue.

The Streamlit demo UI consumes these same endpoints and provides a reference user interface for the API.