Skip to main content

Installation

Install the autumn-js package using your preferred package manager:

Package Exports

The SDK provides multiple entry points for different use cases:
  • autumn-js - Core SDK (re-exports from @useautumn/sdk)
  • autumn-js/react - React hooks and provider
  • autumn-js/backend - Backend integration utilities
  • autumn-js/hono - Hono framework adapter
  • autumn-js/next - Next.js framework adapter
  • autumn-js/better-auth - Better Auth plugin

Quick Start

Frontend (React)

Wrap your app with the AutumnProvider to enable React hooks:

Provider Props

string
Base URL for your backend server (e.g., "https://api.example.com"). Defaults to the current origin.
string
Path prefix for Autumn routes. Defaults to "/api/autumn", or "/api/auth/autumn" if useBetterAuth is enabled.
boolean
Enable Better Auth integration. Sets pathPrefix to "/api/auth/autumn" and includeCredentials to true.
boolean
Include credentials (cookies) in cross-origin requests. Defaults to true if useBetterAuth is enabled.

Backend (Next.js)

Create an API route to handle Autumn requests:

Backend (Hono)

Add the Autumn middleware to your Hono app:

Better Auth Integration

If you’re using Better Auth, install the Autumn plugin:

Backend Setup

Frontend Setup

Customer Scope Options

'user' | 'organization' | 'user_and_organization'
default:"user"
Determines how customer identity is resolved:
  • user - Customer ID is the user’s ID
  • organization - Customer ID is the active organization’s ID
  • user_and_organization - Customer ID combines user and organization IDs

Custom Identity Resolution

For advanced use cases, provide a custom identify function:

Environment Variables

string
required
Your Autumn API secret key. Get this from your Autumn dashboard.

TypeScript Support

The SDK is written in TypeScript and provides full type definitions. All hooks, methods, and responses are fully typed:

Error Handling

All client methods throw AutumnClientError on failure:

AutumnClientError Properties

string
Human-readable error message
string
Machine-readable error code
number
HTTP status code
unknown
Additional error details if available

Next Steps

React Hooks

Learn about all available React hooks

Backend Integration

Set up backend handlers and custom routes