SDKs & examples
Node.js SDK, NestJS, Next.js, PHP, Laravel and cURL.
Node.js SDK
@sms21/node has no runtime dependencies (Node.js 20.3+), full TypeScript types, typed errors, safe automatic retries with idempotency keys, and webhook verification.
Terminal
npm install @sms21/nodeTypeScript
import { Sms21, RateLimitError } from '@sms21/node';
const sms21 = new Sms21({ apiKey: process.env.SMS21_API_KEY });
const { requestId } = await sms21.otp.send({ mobile: '919876543210', purpose: 'login' });
await sms21.otp.verify({ requestId, otp });
await sms21.sms.send({ to: '919876543210', templateId: 'tmpl_…', variables: { order: '1042' } });
await sms21.whatsapp.sendTemplate({ to: '919876543210', templateId: 'wtpl_…' });
const message = await sms21.messages.get('msg_…');
const wallet = await sms21.wallet.get();| Option | Default |
|---|---|
apiKey | SMS21_API_KEY |
baseUrl | SMS21_BASE_URL or https://api.sms21.in/v1 |
timeoutMs | 30000 per attempt |
maxRetries | 2 (only failures that cannot cause a second send) |
appInfo | Appended to the User-Agent, e.g. auth-pay2all/2.3.0 |
Framework examples
Complete, tested examples live in the SMS21 repository under examples/:
| Stack | Path | Includes |
|---|---|---|
| cURL | examples/curl | Every endpoint; an OTP flow script; OpenSSL signature check |
| Node.js | examples/node | OTP login CLI, SMS with status tracking, webhook server |
| NestJS | examples/nestjs | Global client module, OTP login controller, raw-body webhook controller |
| Next.js | examples/nextjs | Server-only client, OTP route handlers and form, webhook route |
| PHP | examples/php | Dependency-free cURL client with safe retries, webhook verification |
| Laravel | examples/laravel | Service provider, OTP login controller, signature middleware, queued webhook job |
Other languages
- Generate a client from the OpenAPI 3.1 document (for example with openapi-generator), or call the REST API directly.
- Whatever you use, follow the same rules as the SDK: send idempotency keys, retry only failures that cannot send twice, never retry OTP verification, and verify webhook signatures on the raw body.