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

> Send a one-time password over WhatsApp or SMS from Golang 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 Go 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`. |
| opts.Length | int | no | Code length, 4 to 10. |
| opts.UseNumber | \*bool | no | Include numbers. |
| opts.UseLetter | \*bool | no | Include letters. |
| opts.AllCapital | \*bool | no | Use uppercase letters when `UseLetter` is `true`. |
| opts.Name | string | no | Your app or company name, shown in the message. Up to 255 characters. |
| opts.Expires | int | no | How long the code is valid, in seconds: 60 to 1800. |

## Send the request

```go theme={null}
client := hypersender.NewClient()

res, err := client.OTP.RequestCode(ctx,
    "+201001234567", // or "201001234567@c.us" on a WhatsApp instance
    &hypersender.RequestCodeOptions{
        Length:     6,
        UseNumber:  hypersender.Bool(true),
        UseLetter:  hypersender.Bool(false),
        AllCapital: hypersender.Bool(false),
        Name:       "YourApp",
        Expires:    600,
    })
if err != nil {
    log.Fatal(err)
}

otp, _ := res["data"].(map[string]any) // uuid, chat_id, code, status, otp_type, expires_at, created_at

fmt.Println(otp["uuid"], otp["status"])
```

* The method takes `ctx` and `chatID` as the first arguments and the other fields in a `*hypersender.RequestCodeOptions` (or `nil` for the defaults). Set the `*bool` fields with `hypersender.Bool`.
* On an SMS instance, `otp["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 `time.Parse(time.RFC3339, ...)` if you need `time.Time` values.

![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/go/otp/validate-otp-code-go-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.