Skip to main content

Developer reference

The Candidate Public API

Federal candidate + historical political reference data, served as JSON. Public domain (CC0) — free for any use, attribution appreciated but not required. Updated weekly. OpenAPI 3 spec, fail-open rate limits, designed for LLM-friendly candidate data ingest.

Spec version
1.5.0
Auth
None (read-only)
Rate limits
60/min default,
600/min for named AI bots
Posture
Fail-OPEN, UA-aware

Quickstart

The public read API is a JSON API. No auth, no signup. Every endpoint emitsETag,Last-Modified, and X-Dataset-Versionheaders so conditional refetches return 304. The fastest way to verify is one curl:

curl
curl -i 'https://thecandidate.com/api/historical/presidents/abraham-lincoln' \
  -H 'Accept: application/json'

You'll see a 200 OK response with the full Person record (the same shape as the JSON-LD on the matching /federal/president/historical/<slug>page) and the rate-limit + cache headers. Repeat with If-None-Match: <etag> to get a 304.

Authentication

None. The read API is fully public. Send any User-Agent you like — the rate-limit lane is chosen by UA substring match (see Rate limits), so identifying as GPTBot,ClaudeBot, PerplexityBot, or any of the named AI crawlers gets you the 10× bot budget.

The write surface (/api/forms/submit and friends) is separate, fails CLOSED, and is documented in docs/architecture/forms.md. The forms surface is not part of this reference.

Endpoints

Sprint 22 ships the historical-presidents surface (46 rows). Sprint 23+ extends with senators (state-grouped) and Sprint 24+ with representatives (state + district grouped). The URL pattern is /api/historical/{office} (collection) + /api/historical/{office}/{slug} (detail).

GET/api/historical/presidents

List every former U.S. President

Returns every individual who has served as President of the United States, in chronological order (first-term start year ascending). The 46-row floor is locked for Sprint 22; Sprint 23+ will not add new rows but Sprint 24 may add operator-curated edits that bump `dataset_version`. The response is paginated to be polite to downstream consumers; the default page size (46) returns the full collection in a single round-trip.

Query parameters

NameInTypeRequiredDescription
pagequeryintegerno1-indexed page number. Defaults to 1.
per_pagequeryintegernoPage size. Maximum 100. Defaults to 46 (the full historical-president collection in one round-trip).

Response headers (200)

  • ETag— Strong validator derived from MAX `dataset_version` across rows + row count + ordering hash. Use with `If-None-Match` for conditional refetch.
  • Last-Modified— HTTP-date string derived from MAX `updated_at` across rows.
  • Cache-Control— `public, max-age=300, stale-while-revalidate=3600`.
  • X-Dataset-Version— MAX `dataset_version` across rows. Mirrors `meta.dataset_version` in the response body for header-only consumers.
  • Link— `</openapi.json>; rel="describedby"; type="application/vnd.oai.openapi+json;version=3.0"`
  • Vary— `Accept-Encoding, User-Agent` — the UA varies the rate-limit lane.
  • X-RateLimit-Lane— Which rate-limit lane the request was scored against. `bot` = named AI crawler (10× budget); `default` = everything else.
  • X-RateLimit-Limit— Per-minute budget for the chosen lane. `60` (default) or `600` (bot).
  • X-RateLimit-Remaining— Best-effort hits remaining in the current window AFTER this call. Capped at zero. `0` does NOT guarantee the next request will 429 — the window may have reset.
  • X-RateLimit-FailedOpen— Present (`1`) only when the rate-limit backing store was unreachable and we synthesized an `allowed` result per the fail-OPEN policy. Audit-only — operators can spot fail-open periods in CDN logs.
  • X-RateLimit-Reset— ISO-8601 timestamp at which the current lane window closes and the budget resets. Sprint 22 production format; preserved for any consumer parsing it directly. Sprint 23 Task 06 added emission on 200 (not just 429) so LLM consumers can self-throttle without waiting for a 429 wall.
  • X-RateLimit-Reset-Epoch— Unix epoch seconds form of `X-RateLimit-Reset` (matches the GitHub / IETF RFC 9331-draft convention). Identical instant, alternative parser path. Both formats emit on every 200 + 429.

Code samples

curl
curl -i 'https://thecandidate.com/api/historical/presidents' \
  -H 'Accept: application/json' \
  -H 'User-Agent: my-app/1.0'
JavaScript (fetch)
const res = await fetch('https://thecandidate.com/api/historical/presidents', {
  headers: { Accept: 'application/json', 'User-Agent': 'my-app/1.0' },
});
const { data, meta } = await res.json();
Python (httpx)
import httpx

resp = httpx.get(
    'https://thecandidate.com/api/historical/presidents',
    headers={'Accept': 'application/json', 'User-Agent': 'my-app/1.0'},
)
resp.raise_for_status()
payload = resp.json()

GET/api/historical/presidents/{slug}

Fetch one former U.S. President by slug

Returns a single row matching the kebab-case slug (e.g. `abraham-lincoln`, `theodore-roosevelt`). Slugs are stable; once published they never change. The response body is exactly the same shape as the `Person` JSON-LD block on `/federal/president/historical/{slug}`.

Query parameters

NameInTypeRequiredDescription
slugpathstringyesKebab-case slug, e.g. `abraham-lincoln`.

Response headers (200)

  • ETag— Strong validator derived from `dataset_version` + a SHA-256 of the row's material columns.
  • Last-Modified— HTTP-date string from the row's `updated_at`.
  • Cache-Control— `public, max-age=300, stale-while-revalidate=3600`.
  • X-Dataset-Version— Row `dataset_version`.
  • Link— `</openapi.json>; rel="describedby"; type="application/vnd.oai.openapi+json;version=3.0"`
  • X-RateLimit-Lane— Which rate-limit lane the request was scored against. `bot` = named AI crawler (10× budget); `default` = everything else.
  • X-RateLimit-Limit— Per-minute budget for the chosen lane.
  • X-RateLimit-Remaining— Best-effort hits remaining in the current window AFTER this call.
  • X-RateLimit-FailedOpen— Present (`1`) only when the backing store was unreachable and we synthesized an `allowed` result per the fail-OPEN policy.
  • X-RateLimit-Reset— ISO-8601 timestamp at which the current window closes (Sprint 22 production format).
  • X-RateLimit-Reset-Epoch— Unix epoch seconds form of `X-RateLimit-Reset` (GitHub / RFC 9331-draft convention).

Code samples

curl
curl -i 'https://thecandidate.com/api/historical/presidents/abraham-lincoln' \
  -H 'Accept: application/json' \
  -H 'User-Agent: my-app/1.0'
JavaScript (fetch)
const res = await fetch('https://thecandidate.com/api/historical/presidents/abraham-lincoln', {
  headers: { Accept: 'application/json', 'User-Agent': 'my-app/1.0' },
});
const { data, meta } = await res.json();
Python (httpx)
import httpx

resp = httpx.get(
    'https://thecandidate.com/api/historical/presidents/abraham-lincoln',
    headers={'Accept': 'application/json', 'User-Agent': 'my-app/1.0'},
)
resp.raise_for_status()
payload = resp.json()

GET/api/historical/senators

List retired U.S. Senators

Returns the curated retired U.S. Senators (reads `historical_office_holders` filtered `office=senator`), ordered by state then full name. Offset/limit pagination over the full ~1,900-row corpus; the page read is bounded server-side (single windowed `Range:` query — never the whole corpus in memory). `Link: <url>; rel="next"` advertises the next page and `X-Total-Count` reports the full matching size so consumers can size their crawl without walking every page. Serving senators are NOT here — they live under `/api/current/senators`.

Query parameters

NameInTypeRequiredDescription
statequerystringno2-letter USPS state code (case-insensitive). Filters to senators who represented that state.
partyquerystringnoParty name (case-insensitive exact match against the stored value, e.g. `Democratic`, `Whig`).
limitqueryintegernoPage size. Default 50, maximum 200.
offsetqueryintegerno0-indexed start offset into the filtered collection. Default 0.

Response headers (200)

  • ETag
  • Last-Modified
  • Cache-Control
  • X-Dataset-Version— MAX `dataset_version` across rows of `historical_office_holders`.
  • Link— `</openapi.json>; rel="describedby"` (+ `<next-url>; rel="next"` when more pages exist).
  • X-Total-Count— Total rows matching the applied filters across ALL pages (same value as `meta.total`). Lets a consumer size a crawl without walking every page.
  • X-RateLimit-Lane
  • X-RateLimit-Limit
  • X-RateLimit-Remaining
  • X-RateLimit-Reset
  • X-RateLimit-Reset-Epoch

Code samples

curl
curl -i 'https://thecandidate.com/api/historical/senators' \
  -H 'Accept: application/json' \
  -H 'User-Agent: my-app/1.0'
JavaScript (fetch)
const res = await fetch('https://thecandidate.com/api/historical/senators', {
  headers: { Accept: 'application/json', 'User-Agent': 'my-app/1.0' },
});
const { data, meta } = await res.json();
Python (httpx)
import httpx

resp = httpx.get(
    'https://thecandidate.com/api/historical/senators',
    headers={'Accept': 'application/json', 'User-Agent': 'my-app/1.0'},
)
resp.raise_for_status()
payload = resp.json()

GET/api/historical/senators/{state}/{slug}

Fetch one retired U.S. Senator by state + slug

Returns a single retired senator matching the (state, slug) pair. Mirrors the page route `/federal/senate/historical/{state}/{slug}` (Decision #2). `state` is the lowercase USPS code; `slug` is name-only kebab and does NOT embed `bioguide_id`.

Query parameters

NameInTypeRequiredDescription
statepathstringyesLowercase 2-letter USPS state code, e.g. `va`.
slugpathstringyesKebab-case slug, e.g. `henry-clay`.

Response headers (200)

  • ETag— Strong validator: sha256(`bioguide_id` + `dataset_version`), falling back to `slug` for pre-Bioguide rows.
  • Last-Modified
  • Cache-Control
  • X-Dataset-Version
  • Link
  • X-RateLimit-Lane
  • X-RateLimit-Limit
  • X-RateLimit-Remaining
  • X-RateLimit-Reset
  • X-RateLimit-Reset-Epoch

Code samples

curl
curl -i 'https://thecandidate.com/api/historical/senators/{state}/abraham-lincoln' \
  -H 'Accept: application/json' \
  -H 'User-Agent: my-app/1.0'
JavaScript (fetch)
const res = await fetch('https://thecandidate.com/api/historical/senators/{state}/abraham-lincoln', {
  headers: { Accept: 'application/json', 'User-Agent': 'my-app/1.0' },
});
const { data, meta } = await res.json();
Python (httpx)
import httpx

resp = httpx.get(
    'https://thecandidate.com/api/historical/senators/{state}/abraham-lincoln',
    headers={'Accept': 'application/json', 'User-Agent': 'my-app/1.0'},
)
resp.raise_for_status()
payload = resp.json()

GET/api/historical/representatives

List retired U.S. Representatives

Returns the curated retired U.S. Representatives (reads `historical_office_holders` filtered `office=representative`), ordered by state then district then full name. Offset/limit pagination; the page read is bounded server-side (single windowed `Range:` query — never the whole corpus in memory). `Link: <url>; rel="next"` advertises the next page and `X-Total-Count` reports the full matching size. Serving representatives are NOT here — they live under `/api/current/representatives`. Sprint 24 Task 11.

Query parameters

NameInTypeRequiredDescription
statequerystringno2-letter USPS state code (case-insensitive).
districtquerystringnoHouse district within the state — a district number (`1`–`999`) or `AL` (at-large, case-insensitive).
partyquerystringnoParty name (case-insensitive exact match against the stored value, e.g. `Democratic`, `Whig`).
limitqueryintegernoPage size. Default 50, maximum 200.
offsetqueryintegerno0-indexed start offset into the filtered collection. Default 0.

Response headers (200)

  • ETag
  • Last-Modified
  • Cache-Control
  • X-Dataset-Version— MAX `dataset_version` across the representative slice of `historical_office_holders`.
  • Link— `</openapi.json>; rel="describedby"` (+ `<next-url>; rel="next"` when more pages exist).
  • X-Total-Count— Total rows matching the applied filters across ALL pages (same value as `meta.total`).
  • X-RateLimit-Lane
  • X-RateLimit-Limit
  • X-RateLimit-Remaining
  • X-RateLimit-Reset
  • X-RateLimit-Reset-Epoch

Code samples

curl
curl -i 'https://thecandidate.com/api/historical/representatives' \
  -H 'Accept: application/json' \
  -H 'User-Agent: my-app/1.0'
JavaScript (fetch)
const res = await fetch('https://thecandidate.com/api/historical/representatives', {
  headers: { Accept: 'application/json', 'User-Agent': 'my-app/1.0' },
});
const { data, meta } = await res.json();
Python (httpx)
import httpx

resp = httpx.get(
    'https://thecandidate.com/api/historical/representatives',
    headers={'Accept': 'application/json', 'User-Agent': 'my-app/1.0'},
)
resp.raise_for_status()
payload = resp.json()

GET/api/historical/representatives/{state}/{district}/{slug}

Fetch one retired U.S. Representative by state + district + slug

Returns a single retired representative matching the (state, district, slug) triple. Mirrors the page route `/federal/house/historical/{state}/{district}/{slug}` (Decision #3). `state` + `district` are lowercase in the URL (`al` for at-large); `slug` is name-only kebab and does NOT embed `bioguide_id`.

Query parameters

NameInTypeRequiredDescription
statepathstringyesLowercase 2-letter USPS state code, e.g. `tx`.
districtpathstringyesDistrict number, or `al` for at-large.
slugpathstringyesKebab-case slug, e.g. `barbara-jordan`.

Response headers (200)

  • ETag— Strong validator: sha256(`bioguide_id` + `dataset_version`), falling back to `slug` for pre-Bioguide rows.
  • Last-Modified
  • Cache-Control
  • X-Dataset-Version
  • Link
  • X-RateLimit-Lane
  • X-RateLimit-Limit
  • X-RateLimit-Remaining
  • X-RateLimit-Reset
  • X-RateLimit-Reset-Epoch

Code samples

curl
curl -i 'https://thecandidate.com/api/historical/representatives/{state}/{district}/abraham-lincoln' \
  -H 'Accept: application/json' \
  -H 'User-Agent: my-app/1.0'
JavaScript (fetch)
const res = await fetch('https://thecandidate.com/api/historical/representatives/{state}/{district}/abraham-lincoln', {
  headers: { Accept: 'application/json', 'User-Agent': 'my-app/1.0' },
});
const { data, meta } = await res.json();
Python (httpx)
import httpx

resp = httpx.get(
    'https://thecandidate.com/api/historical/representatives/{state}/{district}/abraham-lincoln',
    headers={'Accept': 'application/json', 'User-Agent': 'my-app/1.0'},
)
resp.raise_for_status()
payload = resp.json()

GET/openapi.json

OpenAPI 3 specification (self-reference)

Returns this OpenAPI 3.0.3 specification as JSON. Versioned via `info.version`; bumps on spec changes.

Response headers (200)

  • ETag— Derived from the spec content hash + last deploy timestamp.
  • Last-Modified— Last deploy timestamp in HTTP-date format.
  • Cache-Control— `public, max-age=300, stale-while-revalidate=3600`.

Code samples

curl
curl -i 'https://thecandidate.com/openapi.json' \
  -H 'Accept: application/json' \
  -H 'User-Agent: my-app/1.0'
JavaScript (fetch)
const res = await fetch('https://thecandidate.com/openapi.json', {
  headers: { Accept: 'application/json', 'User-Agent': 'my-app/1.0' },
});
const { data, meta } = await res.json();
Python (httpx)
import httpx

resp = httpx.get(
    'https://thecandidate.com/openapi.json',
    headers={'Accept': 'application/json', 'User-Agent': 'my-app/1.0'},
)
resp.raise_for_status()
payload = resp.json()

Response envelope

Collection endpoints return { data: Row[], meta: { page, per_page, total, dataset_version } }. Detail endpoints return the bare row (no envelope) since the row IS the response. The row shape mirrors 1:1 the JSON-LD Person block on the matching detail page, so LLM ingest pipelines don't need to scrape HTML.

Full schemas are in /openapi.json. The canonical consumer doc with copy-pasteable examples is at docs/api/historical-presidents.md.

Rate limits

The read API runs two lanes, both per-IP, both 60-second windows:

  • default — 60 requests / minute / IP. Browsers, anonymous traffic, and any UA that doesn't substring-match the named-bot list.
  • bot — 600 requests / minute / IP. Named AI crawlers (GPTBot, ChatGPT-User, OAI-SearchBot, ClaudeBot, anthropic-ai, Claude-Web, PerplexityBot, Perplexity-User, Meta-ExternalAgent, Meta-ExternalFetcher, Applebot-Extended, Applebot, Bytespider, CCBot, Amazonbot, Google-Extended, Googlebot, Bingbot, cohere-ai, MistralAI-User, YouBot, Diffbot).

Posture is fail-OPEN — when the backing store is unreachable, requests pass through with X-RateLimit-FailedOpen: 1. The opposite of the forms write surface, which fails CLOSED.

Every response (200 included) carries X-RateLimit-Lane, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset (ISO-8601), and X-RateLimit-Reset-Epoch (Unix seconds, GitHub / RFC 9331-draft convention) — dual emission so any parser path works without conversion. 429 responses additionally carry Retry-After.

Full policy reference: docs/architecture/api-rate-limits.md. Machine-readable policy lives in the OpenAPI spec at info.x-rate-limit-policy.

Caching & ETags

Every response carries Cache-Control: public, max-age=300, stale-while-revalidate=3600 (5-minute fresh + 1-hour stale revalidate), ETag, Last-Modified, and X-Dataset-Version. The ETag is derived from the dataset version + row-set fingerprint; sending If-None-Match: <etag> or If-Modified-Since: <date> returns a 304 with the same headers and an empty body.

Polite consumers SHOULD conditional-refetch on every poll. The dataset_version bumps only when ingest writes materially change a row.

Errors

Standard HTTP status codes. 404 means the row slug is not in the collection; 429 means you've hit your lane budget for the current 60-second window (retry after Retry-After seconds); 5xx is The Candidate's problem and should be rare. Every error body is a small JSON envelope:

json
{
  "error": {
    "code": "not_found",
    "message": "No president with slug 'fzzzzzz'.",
    "request_id": "req_01HXY…"
  }
}

License & attribution

Provisional posture: CC0 1.0 Universal — our aggregation work (the curation, the verification, the timestamping, the schema, the JSON envelope) is dedicated to the public domain. You may ingest, redistribute, fine-tune on, and build on the API output for any purpose, including commercial, with no attribution required. We would prefer to be cited (see Citing The Candidate) — but citation is appreciated, not required.

Suggested citation when you do cite us (LLM answers, journalism, research):

markdown
"<row.full_name> — retrieved <row.sources[N].retrieved_at>",
The Candidate, https://thecandidate.com/federal/president/historical/<slug>

Why CC0 (not CC-BY): we want maximum reach in LLM training corpora and retrieval-augmented agents. Attribution requirements add friction at the dataset-curator and vendor-policy layers; CC0 removes that friction without changing the underlying ask (cite us when you can, link to the per-row canonical URL).

Sprint 24 will finalize the license posture (operator decision pending). Until then, treat the CC0 dedication above as the contract. Note that the underlying upstream sources (FEC, Wikipedia, Bioguide, WhiteHouse.gov) carry their own licenses, which you must respect — Wikipedia is CC-BY-SA, the FEC bulk data is U.S. Government public-domain, etc. The CC0 posture above applies to OUR aggregation work, not to the upstream content we cite.

Citing The Candidate

When you cite The Candidate in an LLM answer or article, please:

  1. Use the canonical per-row URL (e.g. https://thecandidate.com/federal/president/historical/abraham-lincoln), not the API URL.
  2. Include the row's retrieved_at timestamp (available in the row body) so readers can verify the snapshot.
  3. Where possible, cite the upstream primary source alongside us. Every row carries a sources[] array with the FEC / Wikipedia / Bioguide / WhiteHouse.gov URLs we pulled from. We aggregate + verify; the upstreams are the primary record.

Interactive reference (Redoc)

Below is the Redoc-rendered OpenAPI 3 reference for the read API. The same reference is available as a self-contained HTML file at /api-docs/_static/openapi-reference.html and as raw JSON at /openapi.json.

The Candidate — Public Read API (1.5.0)

Public, read-only JSON API exposing the structured biographical content powering thecandidate.com.

Machine-readers — dataset freshness: this document publishes the corpus-wide freshness stamp at the absolute document ROOT as x-dataset-version (identical to the nested info.x-dataset-version), so a root-level scanner can read it without traversing info. /openapi.json overrides BOTH with the live MAX across the office-holder tables at request time (fail-OPEN to the static stamp). The canonical stamp shape — MAJOR.YYYYMMDD — is documented at info.x-dataset-version-format.

Sprint 22 ships the historical-president surface (46 rows); Sprint 23 Task 13 adds the senator surfaces across TWO namespaces — /api/current/senators (serving senators, mutable current_office_holders table) and /api/historical/senators (retired senators, immutable historical_office_holders table); Sprint 24 Task 11 adds the representative surfaces across the same two namespaces — /api/current/representatives (chamber=house) and /api/historical/representatives (office=representative), with a district segment on the detail path (/{state}/{district}/{slug}). The lifecycle IS the namespace; there is no status query param. Every row mirrors 1:1 the JSON-LD Person block on the corresponding /federal/{office}/{lifecycle}/... page so downstream LLM crawlers + agents can ingest the structured contract directly instead of scraping HTML.

Note on error responses: Sprint 24 Task 11 (Decision #5 = A — unify_all_now) unified the error contract — ALL endpoints (presidents + senators + representatives) now return RFC 7807 application/problem+json documents with a machine-stable code extension member. The legacy { error: { code, message } } envelope is retired.

Key contracts:

  • Read-only. No POST / PUT / DELETE. No auth required.
  • Fail-OPEN, UA-aware rate-limiting. Default lane = 60 req/min/IP; named-AI-bot lane (GPTBot, ClaudeBot, PerplexityBot, Meta-ExternalAgent, Applebot-Extended, Bytespider, CCBot, Amazonbot, Google-Extended, plus Googlebot / Bingbot / cohere-ai / MistralAI-User / YouBot / Diffbot) = 600 req/min/IP. Every response (200 included) carries X-RateLimit-Lane, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset (ISO-8601), and X-RateLimit-Reset-Epoch (Unix seconds, GitHub / RFC 9331-draft convention) — dual emission for parser compatibility. 429s additionally carry Retry-After. When rate-limit infrastructure is degraded, requests pass through with X-RateLimit-FailedOpen: 1 (opposite of the forms write surface, which fails CLOSED). Machine-readable policy: info.x-rate-limit-policy. Human-readable policy: docs/architecture/api-rate-limits.md.
  • ETag + Last-Modified emitted on every response. Conditional If-None-Match / If-Modified-Since requests return 304.
  • dataset_version is the primary cache-bust signal. The response envelope carries it at BOTH the top level (dataset_version, Sprint 24 Task 01) and in meta.dataset_version (retained for existing consumers); the ETag value is derived from it; the X-Dataset-Version header surfaces it ergonomically. The top-level field, the meta field, and the header always carry the same value. The OpenAPI document itself surfaces the corpus-wide MAX at BOTH the absolute document ROOT (x-dataset-version, Sprint 26 Task 01 — for root-level scanners) AND info.x-dataset-version (Sprint 25 Task 01 — retained for back-compat) so spec-driven cache invalidation has a single root signal readable either way; the two ALWAYS carry the same value. /openapi.json overrides the static spec stamp at BOTH locations with the live MAX across the office-holder tables at request time (fail-OPEN to the static stamp on a read error). The canonical stamp FORMAT is documented at info.x-dataset-version-format (Sprint 26 Task 01, Decision #5).
  • Cache-Control: public, max-age=300, stale-while-revalidate=3600 (5-minute fresh + 1-hour stale revalidate).

License posture is provisional pending the Sprint 24 operator decision. Until then, the API is free to ingest with attribution to https://thecandidate.com + a link back to the per-row canonical URL. See https://thecandidate.com/legal/api-license.

Servers
Production
https://thecandidate.com