Create a new Glassnode API client
Configuration object
OptionalapiKey?: stringAPI key for authentication. Required unless x402 is enabled.
OptionalapiKeyLocation?: "header" | "query"Where the API key is sent: 'query' (default) as the api_key query parameter, or
'header' as the X-Api-Key request header, which keeps the key out of URLs (and so out
of access logs, proxies, tracing and transport errors). 'header' is for server-side use:
the Glassnode API's CORS preflight does not allow X-Api-Key, so browsers block it.
With 'header', redirects are not followed (the request is sent with redirect: 'manual'):
fetch would otherwise resend X-Api-Key to whatever origin a 3xx names. A 3xx surfaces as
a non-retried GlassnodeApiError with that status; point apiUrl at the final URL.
'query' keeps fetch's default redirect handling (the URL, key included, goes wherever the
server's Location says, which only the server that already received the key controls).
OptionalapiUrl?: stringBase URL for the Glassnode API. Default https://api.glassnode.com, or
https://x402.glassnode.com when x402 is set. An explicit value always wins over the
x402 preset.
Optionalfetch?: GlassnodeFetchOptional custom fetch function (e.g. an x402-wrapped fetch, or for testing). Called with a
string URL as fetch(url) or fetch(url, init); see GlassnodeFetch.
Optionalhooks?: {Optional structured observability hooks (onRequest, onResponse, onRetry, onError),
called synchronously and never awaited; a failing hook never affects the call. See
GlassnodeHooks.
Optionallogger?: LoggerOptional logger for API call debugging; its own failures (throw/rejection) are ignored.
OptionalmaxRetries?: numberMaximum number of retries for retryable failures: a 429/5xx response, or a transport
failure (GlassnodeNetworkError, including a per-attempt timeout). Default 0 (no retries).
OptionalmaxRetryDelay?: numberUpper bound (ms) for a single retry wait, after exponential growth.
OptionalretryDelay?: numberBase delay in milliseconds between retries (doubles each attempt, then full jitter).
Optionaltimeout?: numberPer-request timeout in milliseconds. When set, each attempt is aborted via
AbortSignal.timeout() after this many ms (a fresh signal per retry). Unset = no timeout.
Optionalx402?: booleanRoute requests through the x402 paid endpoint (https://x402.glassnode.com).
Call a bulk metric endpoint (returns data for all assets at once)
Path of the metric (e.g. /market/marketcap_usd)
Query parameters (see MetricParams)
Optionaloptions: CallOptions
Per-call options: signal to cancel, timeout to override the config one
(see CallOptions)
Promise resolving to validated bulk response
Call a generic metric, validating the response against a Zod schema.
Path of the metric (e.g. /market/price_usd_close)
Query parameters for the metric (see MetricParams); pass undefined or
{} for none
Per-call options plus schema: the Zod schema the response body must match
(see CallMetricOptions), e.g. TimeSeriesResponseSchema for { t, v } metrics or
TimeSeriesObjectResponseSchema for { t, o } metrics
Promise resolving to the validated response, typed as the schema's output
const series = await api.callMetric('/market/price_usd_close', { a: 'BTC' }, {
schema: TimeSeriesResponseSchema,
}); // TimeSeriesResponse — { t: number; v: number | null }[]
Call a generic metric. The response body is returned unvalidated and cast to T — pass
{ schema } in options (see the other overload) for a validated, typed result.
Path of the metric (e.g. /accumulation_balance)
Optionalparams: MetricParams
Query parameters for the metric, e.g. { a: 'BTC', s: 1609459200, i: '24h' }
or { a: 'BTC', s: new Date('2021-01-01') } (see MetricParams)
Optionaloptions: CallOptions
Per-call options: signal to cancel, timeout to override the config one
(see CallOptions)
Promise resolving to the response data (not validated)
Get metadata for all assets
Optionaloptions: CallOptions
Per-call options: signal to cancel, timeout to override the config one
(see CallOptions)
Promise resolving to validated asset metadata
Get a list of all metrics
Optionaloptions: CallOptions
Per-call options: signal to cancel, timeout to override the config one
(see CallOptions)
Promise resolving to validated metric metadata
Get metadata for a specific metric
Path of the metric
Query parameters for the metric (see MetricParams); numbers, booleans
and Dates are converted (a Date → unix seconds), undefined values are omitted
Optionaloptions: CallOptions
Per-call options: signal to cancel, timeout to override the config one
(see CallOptions)
Promise resolving to validated metric metadata
Get data-lag statistics for a specific metric. Returns the current data lag as aggregated percentiles over the past 30 days.
Path of the metric (e.g. /institutions/us_spot_etf_balances_all)
Optional query parameters (e.g. a to scope stats to an asset; see
MetricParams for value conversion)
Optionaloptions: CallOptions
Per-call options: signal to cancel, timeout to override the config one
(see CallOptions)
Promise resolving to validated metric stats
Glassnode API client