Every API here is available over the APIs.io API and to AI agents over MCP.
openapi: 3.2.0
info:
title: StackData Resolution API
version: 0.1.0
summary: Public datasets from multilateral sources, searchable in any language, resolvable into tables and charts.
description: 'StackData indexes open government and public data and resolves a plain-language
question into a table or chart drawn from that data. Every answer links back to
its source.
Beyond the 50k-dataset catalog, the API serves **stored corpora** (China
population and economic censuses, Statistical Yearbooks 2004–2013 — 14k+ tables
with English overlays; see `GET /v1/table/{id}`), an **as-of customs-tariff API**
across the EU, US, UK and Japan with legal citations (`GET /v1/tariff`), and an
**MCP server** at `POST /mcp` so agent frameworks can mount the whole API as
tools. Machine-readable coverage lives at `/.well-known/data-manifest.json`.
## The contract this API keeps (and most don''t)
- **Unknown query parameters are a `400`, never silently ignored.** The error names
the offending parameter and lists what is allowed.
- **Every JSON response carries `meta.harvest`** — the last successful harvest time of
each source, so staleness is visible without asking.
- **Counts are typed** `{ "value": N, "exact": true|false }`, never a bare integer.
- **Empty is distinguishable from failed.** An honest empty result has a `status`; a
missing resource is a `404`; an upstream failure is a `502`. A zero is never faked.
## Authentication
Send your key in the `X-API-Key` header. **It is optional** — with no key you are on
the free tier, identified by IP address, subject to a lower daily limit. A key raises
your limit and draws on prepaid credits.
## Metering
Metered endpoints: `GET /v1/resolve`, `GET /v1/data`, `GET /v1/table/{id}`,
`POST /v1/series` and `GET /v1/tariff`. The billed unit is a single *uncached upstream fetch* (for stored
corpora: the table render / tariff lookup) — cached answers, refusals, empties and
errors are free. All other endpoints (search, boards, coverage, health) are never metered.
## Paying per answer as an agent (x402)
**x402** is an open, HTTP-native payment standard — an x402 Foundation
project under the Linux Foundation. A server answers a request it won''t serve for free with
HTTP `402 Payment Required` plus machine-readable payment terms; the caller pays from a
wallet and retries the same request. No account, no API key, no card — the payment itself is
the authorization, which is why it suits autonomous agents.
**The flow here.** When an **anonymous** caller is over the free daily quota, `GET /v1/data`
returns `402` (not a hard `429`) with the terms in the body — amount, asset, network, `payTo`
and resource. The agent signs a stablecoin authorization and reissues the request with an
`X-PAYMENT` header (base64-encoded JSON of the signed authorization). The server verifies it
through a facilitator, serves the answer, and returns the settlement receipt in the
`X-PAYMENT-RESPONSE` header (the JSON body also gains a `payment` object).
- **Price** — $0.05 per uncached answer (one upstream pull); $0.25 for premium sources (tariff schedules, China statistics). The live 402 quote is always authoritative.
- **Asset & network** — USDC on Base, settled on-chain.
- **You pay only for work** — cached answers, refusals, empties and errors are free; money moves only if the answer actually cost an uncached fetch.
- **Single-use** — each signed authorization buys exactly one answer; replaying it returns `402`.
This flow is active only when the server has `X402_PAY_TO` configured.
**Learn more:** x402.org · developer docs · reference implementation · the HTTP status itself is `402 Payment Required`.'
contact:
name: StackData
email: hello@stackdata.io
url: https://stackdata.io/contact.html
license:
name: Underlying data is licensed per-source (open government / CC BY 4.0 and equivalents)
url: https://stackdata.io/attribution.html
servers:
- url: https://api.stackdata.io
description: Production (set to your deployed API host)
- url: http://localhost:8080
description: Local development (uvicorn api:app --app-dir serve --port 8080)
security:
- {}
- ApiKeyAuth: []
tags:
- name: Resolution
description: Turn a question into a plan, a table, or a chart. Metered.
paths:
/v1/series:
post:
tags:
- Resolution
operationId: postSeries
summary: One series, every dimension named by the caller
description: 'Structured query: the caller names the dataset, ISO3 countries, an ISO period range
and a member code for every dimension (see `/v1/datasets/{id}/structure` and
`/v1/schema/series.json`). Nothing is guessed or relaxed. Status is `ok`, `empty`
(with a reason) or `refused` (`licence_unverified`, `no_data_path`,
`not_in_serve_set`, `reader_refused`, `ambiguous_selection`). Metered like `/v1/data`:
only an uncached upstream fetch is charged; refusals, empties and 4xx/5xx are free.
A body that is not JSON is `400 bad_json`.'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/SeriesRequest'
example:
dataset: ilo-sdmx:DF_UNE_DEAP_SEX_AGE_RT
countries:
- JPN
- KOR
period:
start: '2015'
end: '2024'
select:
FREQ: A
MEASURE: UNE_DEAP_RT
SEX: SEX_T
AGE: AGE_YTHADULT_YGE15
responses:
'200':
description: 'An `ok`, `empty` or `refused` answer. `ok` carries observations (each with its own
provenance, including the raw period string); `empty` carries a `reason`; `refused`
carries a `reason` and, for `reader_refused` and `ambiguous_selection`, a `detail`.
An empty `observations` array is never a bare success: it is `empty` or `refused`.
'
content:
application/json:
schema:
$ref: '#/components/schemas/SeriesResponse'
'400':
description: 'Invalid request. The body names the error `error` code, the `field` at fault, a
`detail`, and `allowed` (the valid values, when there are at most 50).
'
content:
application/json:
schema:
$ref: '#/components/schemas/StructuredError'
example:
error: missing_dimension
field: select.SEX
detail: SEX must be selected (one member)
allowed:
- SEX_F
- SEX_M
- SEX_T
'402':
description: Payment required (x402).
'404':
description: Unknown dataset (`unknown_dataset`).
content:
application/json:
schema:
$ref: '#/components/schemas/StructuredNotFound'
'429':
description: Quota exhausted.
'502':
description: Upstream source failed (`upstream_failed`). Free; nothing is settled.
content:
application/json:
schema:
$ref: '#/components/schemas/UpstreamFailed'
/v1/schema/series.json:
get:
tags:
- Resolution
operationId: getSeriesSchema
summary: JSON Schema for the POST /v1/series request
responses:
'200':
description: JSON Schema 2020-12.
content:
application/schema+json:
schema:
type: object
/v1/resolve:
get:
tags:
- Resolution
operationId: resolve
summary: Resolve a question into a plan (no data fetched)
description: 'Returns the cascade as a **plan**, not an answer — the model proposes, you inspect.
`plan.status` is explicit: `ready` means it can be executed; anything else names
exactly why not (`licence_forbids_render`, `licence_unverified`, `no_candidates`,
`dsd_unavailable`). A blocked plan is still a `200` with an honest body.
**Metered** (the embedding cost is paid on every call). May return `429`.'
parameters:
- name: q
in: query
required: true
description: The question, in English.
schema:
type: string
example: unemployment rate in Japan
responses:
'200':
description: The resolution plan.
content:
application/json:
schema:
type: object
properties:
plan:
type: object
description: The resolution plan. `status` is `ready` or a named block reason.
additionalProperties: true
meta:
$ref: '#/components/schemas/Meta'
'400':
$ref: '#/components/responses/UnknownParameter'
'429':
$ref: '#/components/responses/QuotaExceeded'
/v1/data:
get:
tags:
- Resolution
operationId: getData
summary: Resolve AND execute — return the actual table or chart
description: 'Carries a ready plan through to the data. Everything the plan would refuse still
refuses here (a licence-blocked source never reaches the fetch).
The `200` body is a **status-tagged object**. Common `status` values:
`ok`, `ok_correlation`, `ok_coverage` (success); `empty`, `no_candidates`,
`dsd_unavailable`, `multi_concept_unparsed`, `language_unsupported`,
`tariff_redirect`, `unit_mismatch` (honest non-answers). `tariff_redirect`: the
prompt names a goods code (`HS 8542.31`), so it is a tariff question; `try` holds the
`/v1/tariff` call and `needs` any parameter the prompt did not state. `unit_mismatch`:
the prompt asks per capita and no matched dataset states per capita. Both are decided
before any fetch and are never metered. With `format=html` the response is a self-contained HTML chart
(`text/html`) instead of JSON.
**Metered.** Over-quota keyed callers get `429`. Over-quota **anonymous** callers may
instead get `402` with x402 payment terms (only when the server has x402 configured).'
parameters:
- name: q
in: query
required: true
description: The question, in English (non-English prompts may be auto-translated by an LLM when configured).
schema:
type: string
example: unemployment rate in Japan
- name: start
in: query
required: false
description: First year (inclusive) to include.
schema:
type: integer
example: 2010
- name: end
in: query
required: false
description: Last year (inclusive) to include.
schema:
type: integer
example: 2023
- name: format
in: query
required: false
description: '`json` (default) returns data; `html` returns a self-contained chart.'
schema:
type: string
enum:
- json
- html
default: json
- name: dataset
in: query
required: false
description: Pin resolution to this dataset id instead of the ranked default. An empty pinned dataset returns an honest empty, never a silent fallback.
schema:
type: string
- name: X-PAYMENT
in: header
required: false
description: 'x402 payment payload (base64-encoded JSON of a signed stablecoin authorization). Send this to satisfy a prior `402`. Only relevant to anonymous, over-quota callers.
'
schema:
type: string
responses:
'200':
description: 'The answer. JSON by default; HTML when `format=html`. On a settled x402 payment,
an `X-PAYMENT-RESPONSE` header carries the receipt and the body gains a `payment` object.
'
headers:
X-PAYMENT-RESPONSE:
description: x402 settlement receipt (present only when a payment settled).
schema:
type: string
X-Billing-Charged:
description: '`true` when this answer cost an uncached upstream fetch (HTML responses only).'
schema:
type: string
content:
application/json:
schema:
$ref: '#/components/schemas/DataResponse'
text/html:
schema:
type: string
description: A self-contained HTML chart (inline styles, data-URI images, no scripts). Returned when `format=html`.
'400':
$ref: '#/components/responses/UnknownParameter'
'402':
description: 'Payment required (x402). Returned to anonymous, over-quota callers when the server
has x402 configured. The body carries the payment terms; reissue with an `X-PAYMENT`
header. Also returned if a supplied payment is invalid, already used, or fails to settle.
'
content:
application/json:
schema:
type: object
additionalProperties: true
description: x402 payment-terms body (accepts amount, asset, network, payTo, resource, …).
'429':
$ref: '#/components/responses/QuotaExceeded'
'502':
description: Upstream source failed while fetching the data. Distinct from an honest empty.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
components:
schemas:
StructuredError:
type: object
description: 'A request that cannot be served as written (HTTP 400). Nothing is guessed, defaulted or
relaxed. `allowed` is present only when the valid set has at most 50 entries.
'
required:
- error
- detail
properties:
error:
type: string
enum:
- unknown_field
- missing_dimension
- unknown_dimension
- unknown_member
- unknown_country
- bad_period
- period_frequency_mismatch
- period_out_of_range
- too_many_countries
- bad_request
- bad_json
description: '`unknown_field`: a key other than dataset, countries, period, select.
`missing_dimension`: a dimension of the dataset was not selected, or `select` is absent (`field` `select`; send `{}` when the structure lists no dimensions).
`unknown_dimension`: select names something that is not a selectable dimension.
`unknown_member`: a member code is not in that dimension''s codelist.
`unknown_country`: a country does not map to the dataset''s geography.
`bad_period`: a period is not YYYY, YYYY-Qn or YYYY-MM.
`period_frequency_mismatch`: start and end differ in frequency, or the frequency is not the selected frequency member''s `period_frequency`, or that member has none (a frequency the structured path does not support, `field` `select.<FREQ>`).
`period_out_of_range`: start is after end, or the window is outside declared coverage.
`too_many_countries`: more than 25 countries, or more distinct geographies than the structure''s `max_countries` (1 on one-geography readers).
`bad_request`: the body is not a JSON object (`field` is an empty string), or `dataset` is missing, not a string, or empty (`field` is `dataset`). Other malformed fields have their own codes: `countries` is `unknown_country` or `too_many_countries`, `period` is `bad_period`, a non-object `select` is `unknown_dimension`.
`bad_json`: the body is not valid JSON.
'
field:
type: string
description: The offending field, e.g. `select.SEX` or `countries[1]`. An empty string when the whole body is at fault (`bad_request` for a non-object body). Absent on `bad_json`, which has only `error` and `detail`.
detail:
type: string
allowed:
type: array
items:
type: string
TypedCount:
type: object
description: A count that states whether it is exact — never a bare integer.
required:
- value
- exact
properties:
value:
type: integer
exact:
type: boolean
example:
value: 2807
exact: true
SeriesResponse:
type: object
required:
- status
- request
- observations
properties:
status:
type: string
enum:
- ok
- empty
- refused
request:
type: object
additionalProperties: true
description: The request as received.
reason:
type: string
description: 'On `empty`, why there is nothing. On `refused`, one of `licence_unverified`,
`no_data_path`, `not_in_serve_set`, `reader_refused`, `ambiguous_selection`.
'
detail:
type: string
description: With `reader_refused` and `ambiguous_selection`; also an `empty` caused by a reader's own message.
dataset:
type: string
description: Present on refusals.
resolved:
type: object
description: How the request was bound.
properties:
geo:
type: object
additionalProperties:
type: string
description: Caller code to the source's own geography code.
select:
type: object
additionalProperties:
type: object
properties:
code:
type: string
label:
type: string
lang:
type: string
freq:
type: string
window:
type: array
items:
type: string
minItems: 2
maxItems: 2
observations:
type: array
items:
$ref: '#/components/schemas/SeriesObservation'
missing:
type: array
description: Requested country-periods with no observation (`{country, period}`), or `{country}` when the window is too long to enumerate. Withheld points are in `notes`, not here.
items:
type: object
properties:
country:
type: string
period:
type: string
notes:
type: array
description: 'What a plain gap would hide: from the reader (`withheld`, `window_capped`,
`eliminated`, `opened`, `truncated`, `skipped_periods`, `refused_coordinates`),
and from our own filtering — `other_frequency` (`count`, `frequencies`: points the
source returned at another frequency, left out) and `unrequested_geography`
(`count`: points for geography codes the request did not name, left out). An answer
empty only because of that filtering says so in `reason`.
'
items:
type: object
additionalProperties: true
properties:
kind:
type: string
reason:
type: string
unparsed_periods:
type: array
items:
type: string
description: Present only when the source returned period strings that could not be normalised; those points are not in `observations`.
provenance:
type: object
properties:
dataset:
type: string
source_url:
type: string
nullable: true
licence:
type: object
additionalProperties: true
attribution:
type: string
nullable: true
cache_hit:
type: boolean
billing:
type: object
additionalProperties: true
description: Metering outcome. Only an uncached upstream fetch is charged.
properties:
upstream_fetches:
type: integer
charged:
type: boolean
tier:
type: string
UpstreamFailed:
type: object
required:
- status
- reason
properties:
status:
type: string
enum:
- upstream_failed
reason:
type: string
SeriesRequest:
title: POST /v1/series request
description: One series per request. The caller names every dimension; nothing is guessed or relaxed. Build the request from GET /v1/datasets/{id}/structure.
type: object
additionalProperties: false
required:
- dataset
- countries
- period
- select
properties:
dataset:
type: string
description: A dataset id from the catalog, as returned by search (/v1/search, or the search_datasets MCP tool), e.g. "ilo-sdmx:DF_X".
countries:
type: array
minItems: 1
maxItems: 25
items:
type: string
description: ISO 3166-1 alpha-3 codes (e.g. "JPN") or an aggregate code listed in the dataset's /structure. 1 to 25 entries.
period:
type: object
additionalProperties: false
required:
- start
- end
description: 'Inclusive ISO period range. "latest" is not accepted: name the periods you want. Annual 2020, quarterly 2020-Q1, monthly 2020-01.'
properties:
start:
type: string
pattern: ^\d{4}(-Q[1-4]|-(0[1-9]|1[0-2]))?$
description: 'First period, ISO form: YYYY, YYYY-Qn or YYYY-MM. Must match a frequency the dataset serves.'
end:
type: string
pattern: ^\d{4}(-Q[1-4]|-(0[1-9]|1[0-2]))?$
description: Last period, same form and frequency as start.
select:
type: object
additionalProperties:
type: string
description: A member code for every dimension of the dataset (other than geography and time) as listed in /structure, including frequency. Every dimension must be named; a missing or unknown dimension or code is a 400, never defaulted.
Error:
type: object
properties:
error:
type: string
note:
type: string
required:
- error
example:
error: no dataset 'x'
note: absent is not an empty success
Meta:
type: object
description: Attached to every JSON response. `harvest` maps each source id to its last successful harvest timestamp.
properties:
harvest:
type: object
additionalProperties:
type: string
api_version:
type: string
example:
harvest:
ilo: '2026-08-10 03:14:22'
wb: '2026-08-10 03:15:01'
api_version: '0.1'
DataResponse:
type: object
description: 'Status-tagged answer. `status` names the outcome — success (`ok`, `ok_correlation`,
`ok_coverage`) or an honest non-answer (`empty`, `no_candidates`, `dsd_unavailable`,
`multi_concept_unparsed`, `language_unsupported`, `tariff_redirect`, `unit_mismatch`,
…). `billing.charged` says whether an
uncached fetch was paid for. `interpreted_as` appears when an LLM rewrote the prompt.
When `status` is `empty`, `reason` may begin `pin_unavailable:` — the source''s serve set
pins a statistic that this request cannot hold, and no other member is substituted.
'
properties:
status:
type: string
pin_unavailable:
type: array
description: Present on a non-ok answer when one or more candidate datasets were skipped because their serve-set pin could not hold. It accompanies the answer's own `reason` and never replaces it.
items:
type: object
properties:
dataset:
type: string
dimension:
type: string
code:
type: string
why:
type: string
pinned:
type: array
description: Present when the answer was served under a serve-set pin (the source declares one member per dimension for this dataset). Each cell also carries `pinned_by` and `pins`.
items:
type: object
properties:
dimension:
type: string
code:
type: string
rule:
type: string
enum:
- serve.pin
billing:
type: object
properties:
charged:
type: boolean
scope_note:
type: string
nullable: true
description: 'Present when the country on the series did not come from a code in the data. Either a named region is the publisher''s own aggregate (not a sum of members), or the source publishes exactly one country and this dataflow carries no geography dimension, so every value is that country''s by the publisher''s declared scope (cells then carry `country_binding: source_scope`).'
fallback:
type: object
nullable: true
description: Present when the top-ranked candidate refused by its own declared structure (for example a PxWeb table declared out of scope, or one whose time axis cannot be read) and a lower candidate answered. `skipped` is the refused dataset id and `why` its refusal. When no lower candidate answers, the response is the top candidate's own `dsd_unavailable`, with `fallback_tried` listing the ids tried.
properties:
skipped:
type: string
why:
type: string
note:
type: string
fallback_tried:
type: array
nullable: true
items:
type: string
coverage:
type: object
additionalProperties: true
withheld:
type:
- object
- 'null'
description: 'Present and non-null only when the publisher HOLDS observations in this window
and states they may not be shown as numbers — today, Statistics Canada cells
suppressed under the Statistics Act (`securityLevelCode` 1) or flagged too
unreliable to be published (`statusCode` 8). Those points are absent from
`series`, and absent is not zero, so the count, the publisher''s own stated
reasons and the affected periods are reported rather than left as a gap.
`null` for every source that flags nothing. It also appears on `status:
"empty"`, where it is the difference between "the source holds nothing" and
"the source holds it and may not show it" — and the `reason` then says so.
'
properties:
count:
$ref: '#/components/schemas/TypedCount'
note:
type:
- string
- 'null'
reasons:
type: array
items:
type: string
description: The publisher's own wording, never paraphrased.
periods:
type: array
items:
type: string
additionalProperties: true
interpreted_as:
type: object
additionalProperties: true
payment:
type: object
description: Present only on the x402 path — settlement outcome for the answer.
additionalProperties: true
meta:
$ref: '#/components/schemas/Meta'
additionalProperties: true
StructuredNotFound:
type: object
required:
- error
- detail
properties:
error:
type: string
enum:
- unknown_dataset
detail:
type: string
SeriesObservation:
type: object
required:
- country
- period
- value
- provenance
properties:
country:
type: string
description: The code the caller sent.
period:
type: string
description: ISO period (YYYY
YYYY-Qn: null
YYYY-MM).: null
value:
type: number
nullable: true
provenance:
type: object
additionalProperties: true
description: 'The nested provenance envelope for this value: the raw string it came from, the
rule that produced it, and `period_raw`, the period exactly as the source wrote it.
'
properties:
period_raw:
type: string
responses:
UnknownParameter:
description: 'An unknown query parameter was supplied. Unknown parameters are **rejected, never
silently ignored** — the error names the offenders and lists what is allowed.
'
content:
application/json:
schema:
type: object
properties:
error:
type: string
allowed:
type: array
items:
type: string
note:
type: string
example:
error: 'unknown parameter(s): limitt'
allowed:
- country
- kind
- limit
- open_only
- q
note: unknown parameters are rejected, never silently ignored
QuotaExceeded:
description: Daily free-tier limit reached (or credits exhausted). The body includes current usage.
content:
application/json:
schema:
type: object
additionalProperties: true
properties:
usage:
type: object
additionalProperties: true
securitySchemes:
ApiKeyAuth:
type: apiKey
in: header
name: X-API-Key
description: Your StackData API key. Optional — omit it to use the free tier (identified by IP).
SessionCookie:
type: apiKey
in: cookie
name: sd_session
description: The httpOnly session cookie set at sign-in (production, same-site).
BearerAuth:
type: http
scheme: bearer
description: 'The session token returned in the login body, sent as `Authorization: Bearer <token>` (the app''s cross-origin path).'