What the difference?

What's the difference between these? You can use both anywhere, but which one and why should I prefer? If I'd have a seperate Rest API, then I wouldn't be able to use the first one at all, so would I lose out on anything?

  const response = await auth.api.getSession({
    headers: await headers(),
  });

and

   const response = await authClient.getSession({
    fetchOptions: { headers: await headers() },
  });
Solution
auth.api is for server-side usage. it calls the Better Auth API endpoints.

authClient.getSession is for client-side usage.

if you’re using a separate API, you’d typically lose access to the direct server-side method since it isn’t exposed over HTTP in the same way. auth.api provides a bit more performance efficiency on the server by avoiding extra HTTP overhead, while the client method is optimized for browser or external API calls.
Was this page helpful?