Installation
Install the EasyOTP SDK using npm or your preferred package manager:Quick Start
Initialization
Create a new EasyOTP client instance with your API key:Configuration Options
string
Base URL for the API. Defaults to
https://app.easyotp.dev/api/v1.Methods
send()
Send a verification code via SMS, Email, or Voice.Parameters
string
required
Communication channel. Must be one of:
sms, email, or voicestring
required
Recipient address:
- For SMS/Voice: E.164 formatted phone number (e.g.,
+1234567890) - For Email: Valid email address (e.g.,
[email protected])
string
Custom message template. Use
{code} as a placeholder for the verification code.Default: "Your verification code is: {code}"string
Email subject line (only used when
channel is email)Default: "Your Verification Code"number
Code expiration time in seconds. Must be between 60 and 3600.Default:
300 (5 minutes)string
Custom verification code. Must be a numeric string between 4-10 digits.If not provided, a code will be automatically generated.
Returns
boolean
Always
true for successful requestsstring
Unique identifier for this verification. Use this when calling
verify().string
ISO 8601 timestamp when the code expires
string
Unique request identifier for debugging
verify()
Verify a code that was previously sent.Parameters
string
required
The verification ID returned from the
send() methodstring
required
The verification code to check. Must be a numeric string between 4-10 digits.
Returns
boolean
Always
true for successful requests (even if the code is invalid)boolean
true if the code was correct and not expired, false otherwisestring
Human-readable result message. Possible values:
"Code verified successfully""Invalid code""Code expired""Code already used"
string
Unique request identifier for debugging
Examples
Complete Verification Flow
Sending via Different Channels
Error Handling
The SDK throws errors for failed requests. Always wrap API calls in try-catch blocks:Express.js Integration Example
Error Handling
The SDK throws errors for failed API requests. Error objects include:message: Human-readable error messagestatus: HTTP status coderequest_id: Unique request identifier for debuggingretry_after: Seconds to wait before retrying (for rate limit errors)
Common Error Codes
TypeScript Support
The SDK includes full TypeScript definitions. Import types as needed:Best Practices
Rate limiting: The SDK automatically handles rate limit responses. Check for
retry_after in error responses to inform users when they can retry.Additional Resources
API Reference
Complete REST API documentation
Quickstart Guide
Get started in 5 minutes
NPM Package
View on npm
Support
Get help from our team