MacroLens / Guides

GDP and inflation API for AI agents

An agent writing a market note or a risk summary should quote real numbers, with a year and a unit. Here is a way to get them as JSON in one request.

The problem

Macro statistics are public, but the plumbing is awkward. The World Bank API expects indicator codes such as FP.CPI.TOTL.ZG, wraps results in a two-element array, returns nulls for missing years and mixes countries with regional aggregates. A model that has to learn that format will often fall back on remembered figures that are years out of date.

How /indicator answers it

GET /indicator?country=DE&indicator=inflation accepts an ISO2 or ISO3 country code (aggregates such as WLD and EUU work too) and a friendly key: gdp, gdp_per_capita, gdp_growth, inflation, unemployment, population, debt_to_gdp, current_account, interest_rate and about two dozen more. You can also pass any raw World Bank indicator code. The response gives the indicator's code, name and units, a latest observation, and a series of the most recent years (1-60, default 10), newest first, with empty years removed. For a one-call snapshot of a country, /country-profile returns the latest value of thirteen headline indicators, each with its year.

Request and response

Example: German consumer-price inflation, last three years.

$ curl -i "https://macrolens.imac2014ville.workers.dev/indicator?country=DE&indicator=inflation&years=3"
HTTP/2 402
payment-required: eyJ4NDAyVmVyc2lvbiI6Mi4uLn0=   # base64 JSON: scheme "exact", network eip155:8453,
                                                  # asset USDC, amount 5000 (= $0.005)
# An x402 client signs the payment, then retries with a PAYMENT-SIGNATURE header.

The paid response (World Bank data as served on the day of capture):

{
  "ok": true,
  "country": { "iso2": "DE", "iso3": "DEU", "name": "Germany" },
  "indicator": { "key": "inflation", "code": "FP.CPI.TOTL.ZG", "name": "Inflation, consumer prices (annual %)", "units": "%" },
  "latest": { "year": 2025, "value": 2.17178770949721 },
  "count": 3,
  "series": [
    { "year": 2025, "value": 2.17178770949721 },
    { "year": 2024, "value": 2.2564981433876 },
    { "year": 2023, "value": 5.94643667725823 }
  ],
  "source": "World Bank Open Data (CC BY 4.0)",
  "sourceUpdated": "2026-10-08"
}

JavaScript with @x402/fetch

import { wrapFetchWithPaymentFromConfig } from "@x402/fetch";
import { ExactEvmScheme } from "@x402/evm";
import { privateKeyToAccount } from "viem/accounts";

const signer = privateKeyToAccount(process.env.PRIVATE_KEY); // wallet holding USDC on Base
const pay = wrapFetchWithPaymentFromConfig(fetch, {
  schemes: [{ network: "eip155:8453", client: new ExactEvmScheme(signer) }],
});
const res = await pay("https://macrolens.imac2014ville.workers.dev/indicator?country=DE&indicator=inflation&years=5");
const { indicator, latest, series } = await res.json();
console.log(`${indicator.name}: ${latest.value.toFixed(1)}${indicator.units} in ${latest.year}`);

Pricing

/indicator costs $0.005 per call; /country-profile costs $0.01. There is no API key and no account: each request is paid in USDC on Base over x402. Malformed input returns 400 and failed lookups return a non-2xx status, so those are not charged.

Limitations

More guides

Sister services