Skip to main content
createCorsairClient({ baseURL }) returns a typed client that mirrors every route on the handler. Use it from a Node script, a CLI, a worker, or a non-React frontend.
client.ts
For React, prefer createCorsairReactClient — it wraps this one and adds hooks.

Reading

reads.ts
Every method is typed against the route’s response. Hovering client.tenants.list() in your editor shows Promise<Tenant[]>, and so on. connectionStatus.get returns a Record<string, 'connected' | 'missing_credentials' | 'not_connected'> keyed by plugin id:

Writing

writes.ts
Connect/OAuth methods are documented on the Connect page.

Options

baseURL is the origin + base path the handler is mounted at, e.g. https://app.example.com/api/corsair. A trailing slash is tolerated. fetch is optional — see Custom fetch below. Need auth headers, custom retry, or interceptors? Pass a wrapped fetch:

Error handling

Failed requests throw CorsairClientError:
Network failures (DNS, abort, no response) throw a plain ErrorCorsairClientError is only used when the server responded with a non-2xx body.

Custom fetch

When you call createCorsairClient, the client picks its fetch function once — either the one you pass in, or globalThis.fetch at that moment. Every later call (client.tenants.list(), etc.) uses that same function; it does not re-read globalThis.fetch on each request. In a normal browser or Node 18+ app, this makes no practical difference. fetch is already available when you create the client, and it stays the same. It only matters in two cases:
  • Tests — your test runner or jsdom may install or replace fetch after your client module is imported. Pass an explicit fetch so the client uses the right one.
  • Custom behavior — auth headers, retries, or routing requests to an in-process handler instead of over HTTP.
If you create the client at module scope and later replace globalThis.fetch, the client will not pick up the change. Create the client after your environment is ready, or pass fetch explicitly.