Skip to main content
When you create a Better Auth instance it exposes an 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 your auth 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

Use returnHeaders: 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

Pass asResponse: true to receive a standard Response instead of the deserialised data.
server.ts

Error handling

Server-side API calls throw an APIError on failure. Use isAPIError to narrow the error type.
server.ts

Calling endpoints via HTTP

You can also call Better Auth endpoints with any HTTP client.

Response format

All endpoints return JSON. Successful responses use HTTP 2xx status codes. Error responses follow this shape: