Browse all documentation

Make your first Narwhal API request

Get an API key, make your first request and read the response. One key works for every Narwhal API.

This guide starts with CPI, then links to references for live APIs at api.narwhalapi.com.

Economics coverage

46 Countries: ARG, AUS, AUT, BEL, BRA, CAN, CHE, CHL, CHN, COL, CZE, DEU, DNK, ESP, EST, FIN, FRA, GBR, HRV, IDN, IND, IRL, ISR, ITA, JPN, KOR, LTU, LUX, LVA, MEX, MYS, NLD, NOR, NZL, PAK, PHL, POL, PRT, QAT, SAU, SGP, SVN, SWE, THA, USA, ZAF. Coverage varies by operation and country. Each operation lists its supported countries. 215 countries in total. Countries without a national, OECD, Eurostat or BIS series have annual history from the World Bank on the history routes. Each operation page lists its countries. Every data request needs a Bearer key.

Free credit: $10 free every month, with no card. Calls cost from $2 to $10 per 1,000, depending on the API. The limit is 50 requests a minute on free credit and 500 once you add paid credit. REST and MCP use the same credit.

Set up your API key

Send the key as a Bearer token in the Authorization header—never in the URL. Create an account to get a free key, then read the authentication guide before storing it.

An AI agent can sign up for its user instead: Agent sign-up

Terminal
export NARWHAL_API_KEY="nw_live_..."

Request official CPI

Pass the ISO three-letter country code in the path. Omitting period returns the latest accepted complete release.

Request
curl --request GET \
  --url https://api.narwhalapi.com/v1/economics/USA/cpi \
  --header "Authorization: Bearer $NARWHAL_API_KEY"
Example response
{
  "country": "USA",
  "period": "2026-07",
  "value": "333.918",
  "index_base": "1982-84=100",
  "released_on": "2026-08-12"
}

Python and JavaScript examples

Use the same environment variable and endpoint in your application. These examples use built-in libraries.

Python 3
import json
import os
from urllib.request import Request, urlopen

request = Request(
    "https://api.narwhalapi.com/v1/economics/USA/cpi",
    headers={"Authorization": "Bearer " + os.environ["NARWHAL_API_KEY"]},
)
with urlopen(request, timeout=30) as response:
    data = json.load(response)
print(data)
JavaScript · Node.js 18+
const key = process.env.NARWHAL_API_KEY;
if (!key) throw new Error("Set NARWHAL_API_KEY first");
const response = await fetch(
  "https://api.narwhalapi.com/v1/economics/USA/cpi",
  { headers: { Authorization: "Bearer " + key }, signal: AbortSignal.timeout(30000) }
);
const data = await response.json();
if (!response.ok) throw new Error(JSON.stringify(data));
console.log(data);

Choose your API

APIStart with
Economics APICPI, inflation, labour, GDP, and trade data from official publishers. Coverage varies by country and indicator.
FX APICurrent rates, conversion, and paginated history with a timestamp for every rate.
Public holidays APIPublished public holidays with national, regional, and observed-day scope.
Palm oil APICPO and FFB prices from Indonesia and Malaysia, with native units and history.

Choose a country and indicator

Latest-release and matching history operations are available, with indicator coverage varying by country. The Economics API reference lists every path and response shape.

IndicatorPath suffix
CPI/cpi
Inflation/inflation
Unemployment/unemployment
Labour-force participation/labour-force-participation
GDP and growth/gdp · /gdp-growth
Trade/trade

Connect through MCP

Use the same key and schemas with an MCP client. Tool discovery lists the operations available to your account across all four APIs. See the MCP guide.

Client-neutral field map
{
  "url": "https://api.narwhalapi.com/mcp",
  "headers": {
    "Authorization": "Bearer YOUR_NARWHAL_API_KEY"
  }
}

Replace the placeholder through your MCP client's secure secret setting. Plain JSON does not expand environment variables by itself.

First tools/call
{
  "method": "tools/call",
  "params": {
    "name": "fx_get_rates",
    "arguments": { "base": "USD", "currencies": ["EUR", "JPY"] }
  }
}

Initialization and tools/list cost nothing. Each successful tools/call costs one call at the price of its API.

Read the response

Read each operation’s response schema before integrating.

RuleWhat it means
periodThe exact month, quarter, or year returned by the official release.
released_onThe official publication date.
Decimal stringsValues avoid binary floating-point surprises.
Missing dataIncomplete or unavailable releases fail closed; missing never becomes zero.

Read how Narwhal stores and updates official releases.

Credit headers on charged responses

X-Request-IDX-Narwhal-CostX-Narwhal-BalanceX-RateLimit-LimitX-RateLimit-RemainingX-RateLimit-Reset

X-RateLimit-Limit is the size of your request bucket (the burst), not a count of requests per minute. The bucket refills at your per-minute rate, X-RateLimit-Remaining is what is left in it, and X-RateLimit-Reset is when it is full again, in UTC.

Handle errors by status and code

Check the HTTP status first, then use code in application logic. detail is for logs and debugging. The errors and credits guide lists every public status.

RFC 9457 problem response
{
  "type": "https://narwhalapi.com/problems/invalid-query",
  "title": "Invalid query",
  "status": 400,
  "detail": "The request parameters are not valid for this operation.",
  "code": "invalid_query",
  "request_id": "019d1af4-8f33-7b21-91af-ef535f2dcf50"
}

Help and resources

Need help with a key? Contact Narwhal API.

See what's new in the changelog.

LLM? Read llms.txt.

Was this page helpful?