Documentation Index
Fetch the complete documentation index at: https://mintlify.com/useautumn/autumn/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The Hono adapter provides seamless integration between Autumn and the Hono web framework. It automatically handles routing, request parsing, and customer identification for all Autumn endpoints.Installation
Install the Autumn JS SDK which includes the Hono adapter:Quick Start
Set up the Autumn handler as middleware in your Hono application:Configuration
ThehonoAutumnHandler accepts the following options:
Options
Function to identify the customer from the Hono context. Return
null for unauthenticated requests.Returns: { customerId: string; customerData?: { name?: string; email?: string; ... } } or nullYour Autumn API secret key. Defaults to the
AUTUMN_SECRET_KEY environment variable.The Autumn API base URL. Only change this if you’re self-hosting Autumn.
The path prefix for all Autumn routes. Routes will be registered under this prefix.
Integration with Authentication
Using Hono Context Variables
If your auth middleware sets user data on the Hono context, you can access it in the identify function:Using JWT Authentication
Cookie-based Sessions
Available Routes
Once configured, the following routes are automatically available:Customer Routes
POST /api/autumn/getOrCreateCustomer- Get or create customer
Billing Routes
POST /api/autumn/attach- Attach a plan to customerPOST /api/autumn/previewAttach- Preview plan attachmentPOST /api/autumn/updateSubscription- Update subscriptionPOST /api/autumn/previewUpdateSubscription- Preview subscription updatePOST /api/autumn/openCustomerPortal- Open customer billing portalPOST /api/autumn/multiAttach- Attach multiple plansPOST /api/autumn/previewMultiAttach- Preview multiple plan attachmentsPOST /api/autumn/setupPayment- Setup payment method
Plan Routes
POST /api/autumn/listPlans- List available plans
Event Routes
POST /api/autumn/listEvents- List customer eventsPOST /api/autumn/aggregateEvents- Aggregate event data
Referral Routes
POST /api/autumn/createReferralCode- Create referral codePOST /api/autumn/redeemReferralCode- Redeem referral code
How It Works
The adapter:- Intercepts requests to the configured path prefix (default:
/api/autumn/*) - Parses the request body and method
- Calls your identify function to get customer identity
- Routes to the appropriate handler based on the endpoint path
- Returns JSON responses with appropriate HTTP status codes
- Passes through 404s to your next middleware if the route doesn’t match
TypeScript Support
The adapter provides full TypeScript support with proper type inference:Error Handling
The adapter automatically handles errors and returns appropriate responses:- 401 Unauthorized - When
identifyreturnsnullfor protected routes - 404 Not Found - When the route doesn’t match (passed to next middleware)
- 400 Bad Request - For invalid request bodies
- 500 Internal Server Error - For SDK errors
Custom Path Prefix
You can customize where Autumn routes are mounted:Environment Variables
The adapter uses the following environment variables:Complete Example
Here’s a complete example with authentication and custom routes:Next Steps
Better Auth Integration
Use Autumn with Better Auth for authentication
React Hooks
Call Autumn endpoints from your React frontend
API Reference
Explore all available API endpoints
Billing Integration
Learn about attaching plans and billing