API reference

createEndpoint

Build a single endpoint without a service or an API object.

const endpoint = createEndpoint(config, fetcher?);

Use this for a one-off endpoint. Inside a createApi tree you never call it — createApi does, after cascading configuration down.

Config

endpointstringRequired

  • Name of the endpoint. Appears in cache keys and error messages.

method'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'Required

  • Gates capabilities at compile time: a non-GET endpoint has useQuery typed never.
  • GET and DELETE send parameters as a query string; the rest send a JSON body.

pathstringRequired

  • Relative to the origin. :name is a required segment, :name? an optional one.
  • Never put the origin here — that is baseUrl.

servicestringdefaults to ''

  • Leading segment of the cache key. Set for you by createApi.

baseUrlstring

  • Origin for this endpoint. Passed to the fetcher on every call.

requestSchemaAnyValidator<TReq>

  • Validates the request body or query parameters, and gives the request its type.
  • Must be synchronous.

responseSchemaAnyValidator<TResp> | { schema, mode: 'async' }

  • Validates the response and gives the result its type.
  • Declare mode: 'async' to resolve data immediately and validate in a detached promise.

pathParamsSchemaAnyValidator<TPath>

  • Validates bound path parameters before the URL is built, and types withPathParams.
  • A failure raises a path-validation error and reaches onRequestValidationError with source: 'path'.

getNextPageParam(lastPage, allPages) => Partial<TReq> | null | undefined

  • Declaring this unlocks useInfiniteQuery and the suspense variant.
  • Return null or undefined when there are no more pages.

maxPagesnumber

  • Caps how many pages are retained, passed to TanStack unchanged.