api object that mirrors every HTTP endpoint — including endpoints added by plugins. You can call these as regular TypeScript functions on the server, or hit them as HTTP endpoints from any client.
Base path
All endpoints are mounted under/api/auth by default. You can change this with the basePath option.
Plugins register additional endpoints under the same base path. All
plugin endpoints are automatically available on the
api object.Calling endpoints server-side
Import yourauth instance and call endpoints directly as functions. This skips HTTP entirely — useful in server components, API routes, and middleware.
server.ts
Body, headers, and query parameters
Unlike the browser client, the server API accepts values as a plain object:server.ts
Better Auth’s API layer is built on
better-call, a tiny web framework
that lets REST endpoints be called as regular TypeScript functions with full
type inference.
Retrieving response headers
UsereturnHeaders: true to get back the response Headers object alongside
the data. This is useful when you need Set-Cookie headers.
server.ts
Retrieving the raw Response object
PassasResponse: true to receive a standard Response instead of the
deserialised data.
server.ts
Error handling
Server-side API calls throw anAPIError on failure. Use isAPIError to
narrow the error type.
server.ts