Prerequisites
Before installing the Mantlz SDK, ensure your project meets these requirements:Version 15.0.0 or higher
Version 19.0.0 or higher
Version 3.0.0 or higher
The SDK is designed for Next.js App Router. If you’re using the Pages Router, some features may not work as expected.
Install the Package
Install the SDK using your preferred package manager:Get Your API Key
- Sign up for a Mantlz account at mantlz.app
- Navigate to your dashboard
- Go to Settings → API Keys
- Copy your API key
Environment Setup
Create a.env.local file in your project root:
.env.local
MANTLZ_KEY environment variable if no API key is explicitly provided to the provider.
Configure the Provider
Wrap your application with theMantlzProvider in your root layout:
If using environment variables in client components, prefix your variable with
NEXT_PUBLIC_.Provider Props
TheMantlzProvider component accepts the following props:
Your Mantlz API key. If not provided, the SDK will attempt to use
process.env.MANTLZ_KEY.Your application components
Verify Installation
Create a test page to verify the SDK is working:app/test-form/page.tsx
"your-form-id" with an actual form ID from your Mantlz dashboard.
Client Configuration (Advanced)
For advanced use cases, you can create a custom client with additional configuration:lib/mantlz.ts
Client Configuration Options
Enable or disable toast notifications for form submissions and errors
Show toast notifications for API key errors (401 responses)
Custom API URL for self-hosted Mantlz instances
Credentials mode for fetch requests. Options:
'include', 'omit', 'same-origin'CORS mode for fetch requests. Options:
'cors', 'no-cors', 'same-origin'Enable response caching for GET requests
Cache time-to-live in milliseconds (default: 5 minutes)
Custom logging function for debugging. Receives message and additional arguments.
Custom toast notification handler (see Customization docs)
Custom Toast Adapter
If you’re using a custom toast library like Sonner, you can create an adapter:lib/mantlz.ts
Troubleshooting
API Key Not Found Error
If you see this error:Form Not Loading
If forms aren’t loading:- Check that the form ID exists in your Mantlz dashboard
- Verify your API key has access to the form
- Check the browser console for API errors
- Ensure the
MantlzProvideris wrapping your component tree
CORS Errors
If you see CORS errors:- Ensure you’re using the correct API URL
- Check that
credentials: 'include'is set in the client config - Verify your domain is whitelisted in the Mantlz dashboard
Next Steps
Basic Usage
Learn how to use the Mantlz component in your app
Form Types
Explore all available form types