API reference
createApi
Compose services into one client, cascading shared configuration.
const api = createApi(config, fetcher?);
Options
servicesRecord<string, ServiceConfig>Required
- The services to expose. Each key becomes a property on the returned client.
- Author these with
defineServiceso their literal types survive.
baseUrlstringdefaults to '' (relative requests)
- The origin for every request. Reaches the fetcher through
FetcherCallContext.baseUrlrather than being folded into the path. - Because it is not in the path, it is not in your cache keys — so keys survive a change of environment.
headersHeadersProvider | HeadersProvider[]
- Static records, or functions resolved per request. Functions receive
{ signal }. - Applied before service and endpoint headers; the last writer of a name wins.
hooksPartial<PipelineHooks>
- Lifecycle hooks applied to every endpoint in every service.
- These run first, before service and endpoint hooks.
defaultOptionsWithOptionsConfig
- Defaults merged into every endpoint —
staleTime,gcTime,timeout,queryKeyPrefix, and any TanStack option. - Endpoint-level options win over service, which win over these.
Second argument
fetcherEndpointFetcherdefaults to defaultFetcher
- The transport used by every endpoint. See
createFetcher.
Returns
ApiClient{ [service]: { queryKey } & { [endpoint]: UnifiedEndpoint } }
- One property per service. Each carries a
queryKeyof[serviceName], useful as an invalidation prefix, plus every endpoint.