Skip to main content

api

This module exposes the SDK's GMX API endpoint lookup helpers.

Functions

All three helpers accept an optional ApiEnvironment value of "production" or "test". They use "production" by default.

getApiUrl

getApiUrl(chainId: number, environment?: ApiEnvironment): string | undefined

Returns the configured GMX API base URL as a string, or undefined when that chain does not have API support.

import { getApiUrl } from "@gmx-io/sdk/configs/api";

const apiUrl = getApiUrl(chainId);

if (!apiUrl) {
throw new Error(`GMX API is not configured for chain ${chainId}`);
}

The returned value is an unversioned host. GmxApiSdk methods append paths such as /v1/markets/info or /v2/jit/liquidity_info.

getApiFallbackUrls

getApiFallbackUrls(chainId: number, environment?: ApiEnvironment): string[]

Returns the additional GMX API base URLs configured for the requested chain and environment. The returned list can be empty.

import { getApiFallbackUrls } from "@gmx-io/sdk/configs/api";

const fallbackUrls = getApiFallbackUrls(chainId);
warning

In 1.6.4 this returns an empty array for every chain in both the production and test environments. The packaged configuration currently ships no peer hosts, so peer rotation has to be supplied by your application.

GMX API production networks are deployed across separate .gmxapi.io and .gmxapi.ai hosts. If your integration requires peer rotation, pass the second host explicitly rather than relying on this helper. See GMX API peer deployments.

isApiSupported

isApiSupported(chainId: number, environment?: ApiEnvironment): boolean

Returns true when getApiUrl(chainId) resolves to a GMX API endpoint.

import { isApiSupported } from "@gmx-io/sdk/configs/api";

if (!isApiSupported(chainId)) {
throw new Error(`GMX API is not configured for chain ${chainId}`);
}
note

This helper reports package configuration; it does not check whether an endpoint is reachable or whether a deployment is still active. Verify network availability against the GMX API peer deployments page before integrating.