SDK & Export API

Client Configuration

Last updated June 4, 2026

Client Configuration

You create a client with createClient(config). It returns a RankHikerClient.

ts
import { createClient } from '@rankhiker/sdk';

const rh = createClient({ apiKey: process.env.RANKHIKER_API_KEY! });

Config options

OptionTypeDefaultNotes
apiKeystring(required)Your rh_export_... key. Throws a RankHikerError if missing or empty.
baseUrlstringhttps://rankhiker.comAPI host. Trailing slashes are stripped. The default works in the browser too; do not use the www host (it redirects and can drop the key header).
fetchtypeof fetchglobal fetchCustom fetch implementation: legacy Node, a proxy, or a caching layer.
requestInitRequestInit{}Merged into every request. Useful for Next.js cache hints.
The client exposes one public readonly property, client.baseUrl, holding the resolved host.

baseUrl override and staging

ts
// Point at a staging host
const staging = createClient({
  apiKey: process.env.RANKHIKER_API_KEY!,
  baseUrl: 'https://staging.rankhiker.com',
});

Custom fetch (proxy or cache)

Provide your own fetch to route requests through a proxy, add caching, or supply a polyfill on older Node runtimes:

ts
import { createClient } from '@rankhiker/sdk';
import nodeFetch from 'node-fetch';

const rh = createClient({ apiKey: process.env.RANKHIKER_API_KEY!, fetch: nodeFetch as unknown as typeof fetch, });

requestInit for Next.js caching

requestInit is spread into every underlying request, so you can apply Next.js fetch cache directives globally.

Incremental Static Regeneration (revalidate every 5 minutes):

ts
const rh = createClient({
  apiKey: process.env.RANKHIKER_API_KEY!,
  requestInit: { next: { revalidate: 300 } },
});

Always fetch fresh (no caching):

ts
const rh = createClient({
  apiKey: process.env.RANKHIKER_API_KEY!,
  requestInit: { cache: 'no-store' },
});

Any other RequestInit field works too (custom headers, signals, and so on). Note that the SDK always sets the request method to GET and adds the X-API-Key and Accept headers, so those are not overridable through requestInit.

Was this article helpful?