Interactive API reference
Expose authentication API documentation in a browser for developers and integrators.
Better Auth · Const
The openAPI plugin adds a Scalar-based OpenAPI reference for Better Auth, covering core and plugin endpoints. It also exposes the generated schema programmatically.
The openAPI plugin adds a Scalar-powered OpenAPI reference to Better Auth. Install it in the auth configuration, then browse the default reference route or call the server API to generate the schema directly.
openAPI()auth.api.generateOpenAPISchema() returns the generated Open API schema as a JSON object.
import { betterAuth } from "better-auth"
import { openAPI } from "better-auth/plugins"
export const auth = betterAuth({
plugins: [openAPI()],
})
const schema = await auth.api.generateOpenAPISchema()
console.log(schema)Registers the Open API plugin and obtains the generated schema as a JSON object.
Expose authentication API documentation in a browser for developers and integrators.
Create client libraries or feed the authentication contract into compatible API tooling.
Inspect and manually invoke Better Auth endpoints during development or troubleshooting.
The plugin is enabled by importing openAPI from better-auth/plugins and adding openAPI() to the plugins array passed to betterAuth. It exposes the reference at /api/auth/reference by default.
Follow-up: How can the route be changed? Set the plugin's path option to another path, remembering that the value is appended to the auth server base path.
The reference groups plugin endpoints by plugin name, places core endpoints in Default, and places model schemas in Models. Scalar renders the reference and provides interactive endpoint testing.
Follow-up: What powers the interactive UI? Scalar is the library used to display and test the generated reference.
Call auth.api.generateOpenAPISchema() to obtain the generated Open API schema directly as a JSON object. The schema follows the OpenAPI 3.1.1 specification.
Follow-up: What compatibility concern applies when using it for code generation? The consuming generator or tool must understand OpenAPI 3.1 semantics.
betterAuthauth.api.generateOpenAPISchemaDefaultModelsScalar