# api

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

# 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`

```typescript
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.

```typescript

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`

```typescript
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.

```typescript

const fallbackUrls = getApiFallbackUrls(chainId);
```

:::warning
In `2.4.0` this returns an empty array for every chain in both the `production` and `test` environments. The packaged configuration 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](../../../../api/rest-api/fallback-urls.mdx#gmx-api-peer-deployments).

### `isApiSupported`

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

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

```typescript

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](../../../../api/rest-api/fallback-urls.mdx#gmx-api-peer-deployments) page before integrating.
:::
