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

# Verify an OTP Code with Go

> Verify the OTP code a user typed from Golang with the Hypersender OTP API. Handle wrong, used, and expired codes for WhatsApp and SMS OTP verification flows.

Check whether an OTP code is correct, unexpired, and unused using the Go SDK. Use this after the user submits the code they received via WhatsApp.

## Parameters

| Field | Type | Required | Description |
| - | - | - | - |
| chatID | string | yes | The chat ID or, for SMS, the phone number that received the code. |
| code | string | yes | The OTP code entered by the user. |

## Validate the code

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

res, err := client.OTP.ValidateCode(ctx, "+201001234567", "439713")

var apiErr *hypersender.Error
switch {
case err == nil:
    data, _ := res["data"].(map[string]any)
    if data["status"] == "validated" {
        // proceed with login or protected action
    }
case errors.As(err, &apiErr):
    // Validation failed (apiErr.StatusCode is 422); do not treat the user as verified
default:
    log.Fatal(err) // network error or missing credentials
}
```

The method returns the parsed response on success and a `*hypersender.Error` on any `4XX` or `5XX` response.

### Common failure reasons

* Code does not match the active OTP
* Code expired based on `expires` value
* Code already used (single-use)
* No active OTP found for the `chatID`

> [!WARNING]
>
> Implement rate limits on validation attempts (e.g., max 3-5 tries) to block brute-force guessing.

## Next

For passwordless login flows, try [Generate OTP Link](https://docs.hypersender.com/v2/packages-and-sdks/go/otp/generate-whatsapp-otp-link-with-go.md) to avoid manual code entry.


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