Skip to content

createFetch

createFetch mental model

ts
import { createFetch } from 'tanstack-fetch'

const api = createFetch(options?)

For SSE, import from tanstack-fetch/sse instead.

CreateFetchOptions

OptionTypeNotes
baseUrlstringAbsolute URL required for SSR / Edge
headersHeadersInit | getterMerged into every request
getToken() => tokenSets Bearer auth
auth{ getToken, header?, scheme? }Advanced auth
onUnauthorizedstatus handlerHTTP 401
onForbiddenstatus handlerHTTP 403
onNotFoundstatus handlerHTTP 404
onServerErrorstatus handlerHTTP 5xx
onStatusstatus mapExact / 4xx / 5xx / default
pluginsPluginName[]Built-in interceptors
interceptorsHttpInterceptor[]Custom
throwOnErrorbooleanDefault true
timeoutMsnumberPer-client timeout
maxRetriesnumberRetry budget
fetchtypeof fetchCustom fetch / tests
credentialsRequestCredentialse.g. include
source'browser' | 'ssr' | …Runtime hint
incomingheaders | getterSSR forward input

Deprecated alias: createClientcreateFetch.

MIT Licensed · Created by Mohammad Garmabi · Not an official TanStack package