Government API Access Guide

Most government data portals provide REST APIs for programmatic access. This guide covers API key registration, rate limiting practices, pagination patterns, and data format handling across major government data providers.

API Key Registration

Most US federal APIs require a free API key for authenticated access. Keys typically provide higher rate limits and access to additional endpoints. Registration is usually free and instant.

Common registration steps:

  1. Visit the provider's API documentation or developer portal
  2. Provide name and email address (sometimes organization name)
  3. Receive API key via email (usually within minutes)
  4. Include key in requests as a query parameter or HTTP header

Authentication methods vary by provider:

  • Query parameter: ?api_key=YOUR_KEY (Census, BEA, FRED)
  • Request header: token: YOUR_TOKEN (NOAA CDO)
  • POST body: {"registrationkey":"YOUR_KEY"} (BLS v2)

Rate Limiting

Government APIs enforce rate limits to ensure fair access. When rate limited, the API returns HTTP 429 (Too Many Requests). Best practices:

  • Implement exponential backoff with jitter when receiving 429 responses
  • Cache responses locally to avoid redundant requests
  • Use bulk download for large datasets instead of paginating through the API
  • Respect the Retry-After header when present
  • Keep requests sequential rather than parallel for stricter rate limits

Bulk Download vs. API

Use the API when:

  • You need a specific subset of data
  • You need the latest data in real-time
  • Your application makes on-demand queries
  • Dataset size is manageable (under 10,000 records)

Use bulk download when:

  • You need the entire dataset or large portions
  • You are building a local analytical database
  • Rate limits would make API access impractical
  • You need historical data spanning many years

Pagination Patterns

Offset/Limit (most common)

Use offset and limit (or start/rows) parameters. Increment offset by limit for each page. Used by CKAN, FRED, NOAA.

Page/Per-Page

Use page and per_page parameters. Simpler but less precise for large datasets. Used by World Bank API.

Date/Geography Bounded

No pagination. Instead, constrain by date range and geographic area to control result size. Used by BLS, EPA, and some Census endpoints.

Data Formats

JSON

Default format for most government APIs. Lightweight, easy to parse, widely supported. Most APIs return JSON by default.

CSV

Common for bulk downloads and tabular data. Easy to import into spreadsheets and databases. Watch for encoding issues (UTF-8 BOM).

XML

Older format still supported by Census, BEA, and SDMX-based APIs (OECD, UN). More verbose but well-suited for hierarchical data.

GeoJSON

Standard for geographic data. Used by Census TIGER/Line, EPA facility locations, and spatial data portals. Renderable by mapping libraries.

Provider API Comparison

ProviderRegistrationRate LimitPaginationFormatsBulk Download
Census BureauFree API key via api.census.gov/data/key_signup.html500 requests/day (without key), higher with keyOffset-based (get parameter)JSON, XMLYes (FTP)
BLSOptional (v2 API requires registration at bls.gov)25 queries/day (v1), 500/day (v2 with key)None (specify date ranges)JSONYes (flat files via FTP)
BEAFree API key via apps.bea.gov/API/signup100 requests/minute, 100 MB/minuteNone (request specific tables/years)JSON, XMLYes (interactive tables)
FREDFree API key via fredaccount.stlouisfed.org120 requests/minuteOffset/limit parametersJSON, XMLYes (bulk data downloads)
Data.gov (CKAN)Not required for read accessVaries by underlying providerrows/start parameters (Solr-style)JSON (API), varies (datasets)Yes (direct file download)
EPA AQSEmail-based registration at aqs.epa.govNot published; reasonable use expectedNone (date/geography bounded)JSON, CSVYes (annual summary files)
NOAA CDOFree token via ncdc.noaa.gov/cdo-web/token5 requests/second, 1,000/dayOffset/limit parametersJSON, CSVYes (bulk order system)
World BankNot requiredNot enforced (fair use)page/per_page parametersJSON, XML, CSVYes (bulk download portal)