Skip to main content
This page shows how to set up the Razorpay client plugin, how endpoint paths map to client methods, and how to call endpoints from both the browser and the server.

Add the client plugin

Import razorpayClient from the client entry point and pass it to createAuthClient. Set subscription: true when your server has subscriptions enabled so the client registers subscription methods.
client.ts
razorpayClient is also exported as razorpayClientPlugin. The plugin id is "razorpay-client".

How endpoints map to client methods

Better Auth converts endpoint paths to camelCase methods on authClient. Here are common examples:

POST vs GET calls

POST calls pass the body object directly:
GET calls pass a query object:

Response shape and error handling

Every client call returns { data, error } following the Better Auth convention. On success, data contains the endpoint response. On failure, error includes error.code and error.message.
The client entry point re-exports RAZORPAY_ERROR_CODES so you can compare against known codes:

Calling endpoints from the server

On the server, use auth.api.<name> with the request headers so Better Auth can resolve the session. Pass body for POST endpoints or query for GET endpoints.
The server API names match the endpoint definitions. For example, POST /razorpay/create-order is auth.api.createRazorpayOrder, and GET /razorpay/order is auth.api.getRazorpayOrder.