> ## 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.

# WhatsApp and SMS OTP in Node.js

> Send and verify OTP codes over WhatsApp or SMS from Node.js, and create WhatsApp OTP links, with the Hypersender OTP API. Expiry and checks in TypeScript.

Use the Hypersender OTP service from Node.js to send verification codes over WhatsApp or SMS, validate the codes your users enter, and generate passwordless WhatsApp links.

## What you can do

* **Request OTP codes**: Generate a one-time code and send it from a WhatsApp or SMS instance.
* **Validate codes**: Check user-entered codes against the active OTP.
* **Generate OTP links (WhatsApp only)**: Create WhatsApp links that complete verification without typing. SMS instances can't generate links.

## Prerequisites

* Node.js app with the `hypersender-node` package installed ([Installation](https://docs.hypersender.com/v2/packages-and-sdks/node/installation.md)).
* Hypersender **API token** and **Instance UUID** from the dashboard, set as `HYPERSENDER_OTP_API_KEY` and `HYPERSENDER_OTP_INSTANCE_ID`.
* For SMS, an SMS instance with the Hypersender SMS app running on the linked Android phone. See [SMS quick start](https://docs.hypersender.com/v2/hypersender/overview/sms/sms-quick-start.md).

## Base URL and auth

```bash theme={null}
Base URL: https://app.hypersender.com/api/otp/v2/{instance}
Auth: Authorization: Bearer YOUR_API_TOKEN
```

The SDK adds the instance UUID to the URL and the token to the header for you.

## Quick start (request and validate)

```typescript theme={null}
import { Hypersender } from "hypersender-node";
import { HypersenderError } from "hypersender-node/models/errors";

const codeFromUser = "482913"; // the code the user typed

// 1) Send a code
const result = await Hypersender.otp().requestCode({
  chatId: "201001234567@c.us", // WhatsApp chat ID
  length: 6,
  useNumber: true,
  useLetter: false,
  allCapital: false,
  name: "YourApp",
  expires: 300,
});

const chatId = result.data?.chatId ?? "201001234567@c.us";

// 2) Validate the code the user typed
let isValid = false;

try {
  const validation = await Hypersender.otp().validateCode({
    chatId,
    code: codeFromUser,
  });
  isValid = validation.success === true;
} catch (error) {
  if (!(error instanceof HypersenderError)) throw error;
  // Wrong, used, or expired code: error.statusCode is 422
}
```

Both methods return the parsed, typed response body, with the OTP details under `data`. Any `4XX` or `5XX` response throws an error that extends `HypersenderError`; a wrong, used, or expired code throws with `statusCode` `422`.

## Send the code over SMS

With an SMS instance, pass the phone number in international format as `chatId`. Spaces, dashes, dots, and parentheses are removed, and `00` at the start is read as `+`. WhatsApp chat IDs are rejected for SMS.

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

const result = await Hypersender.otp().requestCode({
  chatId: "+201001234567",
  length: 6,
  useNumber: true,
  useLetter: false,
  allCapital: false,
  name: "YourApp",
  expires: 300,
});
```

The user receives a short plain-text SMS, such as:

```text theme={null}
YourApp code: 482913
```

The wording rotates between six short versions, so carriers are less likely to drop it. Validate it with the same phone number. If you want your own message text, send the code yourself with the SMS API. See the [SMS OTP guide](https://docs.hypersender.com/v2/hypersender/overview/sms/sms-otp-guide.md).

> [!WARNING]
>
> Keep tokens and OTP codes out of logs. Use HTTPS for all calls.

## Next steps

* [Request OTP Code](https://docs.hypersender.com/v2/packages-and-sdks/node/otp/request-otp-code-node-sdk.md)
* [Validate OTP Code](https://docs.hypersender.com/v2/packages-and-sdks/node/otp/validate-otp-code-node-sdk.md)
* [Generate OTP Link](https://docs.hypersender.com/v2/packages-and-sdks/node/otp/generate-whatsapp-otp-link-with-node.md)


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