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

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

Generate a one-time password and send it over WhatsApp or SMS with the Python 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 |
| - | - | - | - |
| chat\_id | str | yes | WhatsApp: a chat ID such as `201001234567@c.us`. SMS: a phone number such as `+201001234567`. |
| length | int | no | Code length, 4 to 10. |
| use\_number | bool | no | Include numbers. |
| use\_letter | bool | no | Include letters. |
| all\_capital | bool | no | Use uppercase letters when `use_letter` is `True`. |
| name | str | no | Your app or company name, shown in the message. Up to 255 characters. |
| expires | int | no | How long the code is valid, in seconds: 60 to 1800. |

## Send the request

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

hs = Hypersender()

result = hs.otp.request_code(
    "+201001234567",  # or "201001234567@c.us" on a WhatsApp instance
    length=6,
    use_number=True,
    use_letter=False,
    all_capital=False,
    name="YourApp",
    expires=600,
)

otp = result["data"]  # uuid, chat_id, code, status, otp_type, expires_at, created_at
```

* The method takes `chat_id` as the first argument and the other fields as snake\_case keyword arguments.
* On an SMS instance, `data["chat_id"]` 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`).
* `expires_at` and `created_at` are ISO 8601 strings. Parse them with `datetime.fromisoformat()` if you need `datetime` 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/python/otp/validate-otp-code-python-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.