> ## 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 OTP Link with Python

> Create a WhatsApp OTP link from Python: the user taps it, sends the prefilled code from WhatsApp, and is verified with no code to type. Built on the OTP API.

Use the Hypersender Python SDK to create a WhatsApp OTP link from your application. Your backend receives the generated link and can deliver it through email, SMS, or an in-app message.

> [!NOTE]
>
> Install and configure the [Hypersender Python SDK](https://docs.hypersender.com/v2/packages-and-sdks/python/installation.md) first. You need an active WhatsApp instance and the OTP API credentials in your environment.

## Generate and deliver a link

The SDK returns the parsed JSON response as a `dict`. The generated WhatsApp URL is at `result["data"]["whatsapp_link"]`.

```python theme={null}
from hypersender import Hypersender, HypersenderError

hs = Hypersender()

try:
    result = hs.otp.generate_link(
        "20123456789@c.us",
        expires=1800,
        name="YourApp",
        message={
            "prompt": "Send me my YourApp link",
            "success": "Here is your link: {link}",
            "failed": "Login failed, please try again later.",
            "expired": "This link has expired. Please request another one.",
        },
        callback={
            "success": "https://yourdomain.com/api/otp/success",
            "failed": "https://yourdomain.com/api/otp/failed",
        },
    )
except HypersenderError as error:
    # Handle the failed API request; do not treat the user as verified.
    print(f"OTP link request failed with status {error.status_code}")
    raise

whatsapp_link = (result.get("data") or {}).get("whatsapp_link")

if not whatsapp_link:
    raise RuntimeError("The OTP API response did not include data.whatsapp_link.")

# Return or deliver this URL through your application.
```

`chat_id` is the recipient's WhatsApp chat ID. The `expires` parameter accepts a lifetime from 60 to 3600 seconds. Keep API credentials in server-side configuration and avoid logging the returned link or OTP code.

## What happens after generation

1. Deliver the returned `data.whatsapp_link` to the user.
2. The user opens WhatsApp and sends the prefilled message.
3. Your application handles the success or failure callback URL if you configured one.
4. Continue the login or verification flow only after your server has confirmed the verification result.

The API documentation does not define callback payload fields or a signing scheme. Confirm the callback contract for your account before using callbacks to authorize access. For the endpoint request and response examples, see [Generate WhatsApp OTP Link](https://docs.hypersender.com/v2/api-reference/otp/otp-service/generate-a-whatsapp-otp-link.md).

## Next steps

* [Install the Python SDK](https://docs.hypersender.com/v2/packages-and-sdks/python/installation.md)
* [Review the OTP API overview](https://docs.hypersender.com/v2/api-reference/otp/otp-api-introduction.md)
* [Try link generation in Postman](https://docs.hypersender.com/v2/api-reference/otp/how-to-generate-a-whatsapp-otp-link-in-postman.md)
* [Create a Hypersender account](https://app.hypersender.com/register)


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