Skip to main content

Overview

Autumn’s backend integration creates API routes that proxy requests to the Autumn API while injecting customer identity from your auth system. This ensures customers can only access their own data.

Framework Adapters

Next.js

For Next.js App Router, use the autumn-js/next adapter:

Handler Options

(request: Request) => AuthResult
required
Function to extract customer identity from the request. Must return an object with customerId or null for unauthenticated requests.
string
Autumn API secret key. Defaults to AUTUMN_SECRET_KEY environment variable.
string
Autumn API base URL. Defaults to https://api.useautumn.com/v1.
string
default:"/api/autumn"
Path prefix for routes. Must match the route file location.

Hono

For Hono applications, use the autumn-js/hono adapter:

Handler Options

(c: Context) => AuthResult
required
Function to extract customer identity from the Hono context.
string
Autumn API secret key.
string
Autumn API base URL.
string
default:"/api/autumn"
Path prefix for routes.

Framework-Agnostic

For custom frameworks, use the generic autumnHandler:

Handler Options

object
required
Request object with url, method, and body.
string
Customer ID to inject into the request.
CustomerData
Additional customer data (email, name, etc.).
object
Client configuration with secretKey and optional baseURL.
string
default:"/api/autumn"
Path prefix for routes.
RouteDefinition[]
Custom route definitions (for advanced use cases).

Identity Resolution

The identify function is called for every request and must return customer identity:

Return Type

Examples

Basic User ID

With Customer Data

Organization-Based

User + Organization Composite

Better Auth Plugin

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

Customer Scope

'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 both (format: user_{userId}_org_{orgId})

Custom Identity Function

Override the default behavior with a custom identify function:

Identify Function Parameters

BetterAuthSession | null
Better Auth session object with user and session data.
BetterAuthOrganization | null
Active organization object (if using Better Auth organizations).

Advanced: Custom Routes

For advanced use cases, define custom routes:

Available Route Configs

  • getOrCreateCustomer
  • attach
  • previewAttach
  • updateSubscription
  • previewUpdateSubscription
  • multiAttach
  • previewMultiAttach
  • setupPayment
  • openCustomerPortal
  • createReferralCode
  • redeemReferralCode
  • listPlans
  • listEvents
  • aggregateEvents

Core Handler

For maximum flexibility, use the core handler directly:

Core Handler Options

(raw: unknown) => AuthResult
required
Function to extract customer identity. Receives the raw request object.
string
Autumn API secret key.
string
Autumn API base URL.
string
default:"/api/autumn"
Path prefix for routes.
RouteDefinition[]
Custom route definitions.

Core Handler Request

string
required
HTTP method (GET, POST, DELETE).
string
required
Request path (e.g., /api/autumn/attach).
unknown
Request body (parsed JSON).
unknown
Original framework request object (passed to identify).

Error Handling

The handler automatically transforms errors into appropriate HTTP responses:

Utilities

secretKeyCheck

Validate that the secret key is configured:

sanitizeBody

Sanitize request body before sending to Autumn API:

backendSuccess / backendError

Create standardized backend responses:

Type Exports

All backend types are exported for TypeScript users: