> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hypersender.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Send an OTP Code with Node.js

> Send a one-time password over WhatsApp or SMS from Node.js with the Hypersender OTP API. Set the code length, characters, app name, and expiry in TypeScript.

Generate a one-time password and send it over WhatsApp or SMS with the Node SDK. The channel follows your OTP instance: a WhatsApp instance sends a WhatsApp message, an SMS instance sends a plain-text SMS. The response includes the OTP `uuid`, generated `code`, status, and expiry time so you can track validation.

## Parameters

| Field | Type | Required | Description |
| - | - | - | - |
| chatId | string | yes | WhatsApp: a chat ID such as `201001234567@c.us`. SMS: a phone number such as `+201001234567`. |
| length | number | no | Code length, 4 to 10. |
| useNumber | boolean | no | Include numbers. |
| useLetter | boolean | no | Include letters. |
| allCapital | boolean | no | Use uppercase letters when `useLetter` is true. |
| name | string | no | Your app or company name, shown in the message. Up to 255 characters. |
| expires | number | no | How long the code is valid, in seconds: 60 to 1800. |

## Send the request

```typescript theme={null}
import { Hypersender } from "hypersender-node";

const result = await Hypersender.otp().requestCode({
  chatId: "+201001234567", // or "201001234567@c.us" on a WhatsApp instance
  length: 6,
  useNumber: true,
  useLetter: false,
  allCapital: false,
  name: "YourApp",
  expires: 600,
});

const otp = result.data; // uuid, chatId, code, status, otpType, expiresAt, createdAt
```

* The method takes a single request object with camelCase fields.
* On an SMS instance, `data.chatId` is the phone number in international format, `+201001234567`.
* Store `uuid` if you plan to track or audit the request.
* Use `status` to monitor the send/validation lifecycle (`pending`, `sent`, `validated`, `expired`).
* `expiresAt` and `createdAt` are parsed into `Date` objects.

![Request OTP Code](https://mintcdn.com/hypersender/heaRhbtv5g__uNmh/images/docs/whatsapp/img/otp-code.png?fit=max\&auto=format\&n=heaRhbtv5g__uNmh\&q=85\&s=866ee46af326e16a3f01a5d9e3c4d572)

## Next

Validate the code the user enters with [Validate OTP Code](https://docs.hypersender.com/v2/packages-and-sdks/node/otp/validate-otp-code-node-sdk.md).

> [!WARNING]
>
> OTP codes are short-lived and single-use. Prompt users to request a new code after expiry or repeated failures.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.