Browse all documentation

Government debt and budget balance API reference

Government debt and budget balance by country and year, percent of GDP

Overview

How much a country's government owes, and whether it runs a surplus or a deficit, as a percent of GDP, from the IMF World Economic Outlook.

A country is its ISO 3166 alpha-3 code, such as IDN. Debt is general government gross debt. The balance is general government net lending (positive) or net borrowing (negative). Every value is a decimal string.

The route without observations returns the newest actual year. observations returns every year, oldest first. kind is actual up to the last year the IMF calls actual for that country and series, and forecast after it. Every answer names its source and its edition, the year and month of the World Economic Outlook round.

Base URL: https://api.narwhalapi.com. Each route below is an MCP tool of its own, with the same parameters.

What every account gets

WhatEvery account
One country and measureOne Economics call

See pricing for what a call costs. A request is charged at the price of its API unless a route says otherwise.

  • The last actual year differs between countries.
  • Read year and kind rather than assuming last year is actual.
  • Some countries report by fiscal year. The year is the IMF's, placed on the calendar year its note gives.
  • Only the newest edition is served. For earlier rounds of a forecast, use the forecasts route.
  • A country the IMF gives no figure for is 404 not_covered. A range with no year is 404 not_found. Neither is charged.
  • The figures are the IMF's, republished unchanged, checked weekly, and are for analysis, not financial, investment, legal or tax advice.

Endpoints

Every route is a GET and needs your key in the Authorization: Bearer header. The examples show the shape of an answer, not live data.

Get Government Debt

GET /v1/economics/{country}/government/debt

MCP: tool economics_get_government_debt.

Parameters

ParameterWhereRequiredTypeMeaning
countrypathYesstringISO 3166 alpha-3 country code, for example DEU.

Response fields

FieldTypeSentMeaning
countrystringAlwaysThe country asked for, ISO 3166 alpha-3.
indicatorone of government_debt_gdp, government_balance_gdpAlwaysgovernment_debt_gdp or government_balance_gdp.
unitalways "percent of GDP"AlwaysThe unit of every value.
yearintegerAlwaysThe year of the value.
valuestringAlwaysPercent of GDP, as the IMF writes it. A negative balance is a deficit.
kindone of actual, forecastAlwaysactual up to the last year the IMF calls actual for the country, forecast after it.
sourcealways "IMF World Economic Outlook"OptionalWho publishes the figures.
editionstringAlwaysThe World Economic Outlook round the figures come from, YYYY-MM.
Request
curl -H "Authorization: Bearer $NARWHAL_API_KEY" \
  "https://api.narwhalapi.com/v1/economics/IDN/government/debt"
Example response
{
  "country": "IDN",
  "indicator": "government_debt_gdp",
  "unit": "percent of GDP",
  "year": 2025,
  "value": "40.879735",
  "kind": "actual",
  "source": "IMF World Economic Outlook",
  "edition": "2026-10"
}

Get Government Debt History

GET /v1/economics/{country}/government/debt/observations

MCP: tool economics_get_government_debt_history.

Parameters

ParameterWhereRequiredTypeMeaning
countrypathYesstringISO 3166 alpha-3 country code, for example DEU.
startqueryNostringFirst year to return, as YYYY.
endqueryNostringLast year to return, as YYYY.

Response fields

FieldTypeSentMeaning
countrystringAlwaysThe country asked for, ISO 3166 alpha-3.
indicatorone of government_debt_gdp, government_balance_gdpAlwaysgovernment_debt_gdp or government_balance_gdp.
unitalways "percent of GDP"AlwaysThe unit of every value.
sourcealways "IMF World Economic Outlook"OptionalWho publishes the figures.
editionstringAlwaysThe World Economic Outlook round the figures come from, YYYY-MM.
observationslist of objectAlwaysOne row per year, oldest first.
observations[].yearintegerAlwaysThe year of the value.
observations[].valuestringAlwaysPercent of GDP, as the IMF writes it.
observations[].kindone of actual, forecastAlwaysactual up to the last year the IMF calls actual for the country, forecast after it.
Request
curl -H "Authorization: Bearer $NARWHAL_API_KEY" \
  "https://api.narwhalapi.com/v1/economics/IDN/government/debt/observations?start=2025&end=2026"
Example response
{
  "country": "IDN",
  "indicator": "government_debt_gdp",
  "unit": "percent of GDP",
  "source": "IMF World Economic Outlook",
  "edition": "2026-10",
  "observations": [
    {
      "year": 2025,
      "value": "40.879735",
      "kind": "actual"
    },
    {
      "year": 2026,
      "value": "41.698325",
      "kind": "forecast"
    }
  ]
}

Get Government Balance

GET /v1/economics/{country}/government/balance

MCP: tool economics_get_government_balance.

Parameters

ParameterWhereRequiredTypeMeaning
countrypathYesstringISO 3166 alpha-3 country code, for example DEU.

Response fields

FieldTypeSentMeaning
countrystringAlwaysThe country asked for, ISO 3166 alpha-3.
indicatorone of government_debt_gdp, government_balance_gdpAlwaysgovernment_debt_gdp or government_balance_gdp.
unitalways "percent of GDP"AlwaysThe unit of every value.
yearintegerAlwaysThe year of the value.
valuestringAlwaysPercent of GDP, as the IMF writes it. A negative balance is a deficit.
kindone of actual, forecastAlwaysactual up to the last year the IMF calls actual for the country, forecast after it.
sourcealways "IMF World Economic Outlook"OptionalWho publishes the figures.
editionstringAlwaysThe World Economic Outlook round the figures come from, YYYY-MM.
Request
curl -H "Authorization: Bearer $NARWHAL_API_KEY" \
  "https://api.narwhalapi.com/v1/economics/IDN/government/balance"
Example response
{
  "country": "IDN",
  "indicator": "government_balance_gdp",
  "unit": "percent of GDP",
  "year": 2025,
  "value": "-2.916694",
  "kind": "actual",
  "source": "IMF World Economic Outlook",
  "edition": "2026-10"
}

Get Government Balance History

GET /v1/economics/{country}/government/balance/observations

MCP: tool economics_get_government_balance_history.

Parameters

ParameterWhereRequiredTypeMeaning
countrypathYesstringISO 3166 alpha-3 country code, for example DEU.
startqueryNostringFirst year to return, as YYYY.
endqueryNostringLast year to return, as YYYY.

Response fields

FieldTypeSentMeaning
countrystringAlwaysThe country asked for, ISO 3166 alpha-3.
indicatorone of government_debt_gdp, government_balance_gdpAlwaysgovernment_debt_gdp or government_balance_gdp.
unitalways "percent of GDP"AlwaysThe unit of every value.
sourcealways "IMF World Economic Outlook"OptionalWho publishes the figures.
editionstringAlwaysThe World Economic Outlook round the figures come from, YYYY-MM.
observationslist of objectAlwaysOne row per year, oldest first.
observations[].yearintegerAlwaysThe year of the value.
observations[].valuestringAlwaysPercent of GDP, as the IMF writes it.
observations[].kindone of actual, forecastAlwaysactual up to the last year the IMF calls actual for the country, forecast after it.
Request
curl -H "Authorization: Bearer $NARWHAL_API_KEY" \
  "https://api.narwhalapi.com/v1/economics/IDN/government/balance/observations?start=2025&end=2026"
Example response
{
  "country": "IDN",
  "indicator": "government_balance_gdp",
  "unit": "percent of GDP",
  "source": "IMF World Economic Outlook",
  "edition": "2026-10",
  "observations": [
    {
      "year": 2025,
      "value": "-2.916694",
      "kind": "actual"
    },
    {
      "year": 2026,
      "value": "-2.898354",
      "kind": "forecast"
    }
  ]
}

Errors

Errors use the shared problem shape with a request_id. See Errors and credits for the shape and the credit headers. Failed requests are not charged.

CodeStatusMeaning
invalid_query400The country is not a three letter code, or start or end is not a year, or start is after end. Not charged.
not_found404No year in this range is held for this country. Not charged.
not_covered404The IMF World Economic Outlook gives no figure for this country. Not charged.
insufficient_credits402Your credit balance is less than the request costs.
economics_unavailable503Nothing is stored yet, or the stored data cannot answer. Not charged.
invalid_api_key401The Bearer key is missing, malformed, unknown, or inactive.
rate_limit_exceeded429The network or account per-minute limit was reached. Retry after the time in the Retry-After header.

Was this page helpful?