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

# Go WhatsApp and SMS API SDK: Installation

> Install the Hypersender Go SDK with go get to use the WhatsApp API, SMS API, and OTP API from Golang, with keys read from environment variables.

## Getting Started with Hypersender SDK

This guide will walk you through the process of installing and configuring the Hypersender Go SDK for your Golang application, whether it is a `net/http` service, a Gin or Echo app, or a simple command-line tool.

## Prerequisites

Before you begin, ensure you have the following:

* **Go 1.24 or higher:** The SDK uses only the Go standard library, with no third-party dependencies.
* **Go modules:** For package management and dependency resolution
* **Hypersender account:** Sign up at [Hypersender](https://app.hypersender.com) to obtain your API key and Instance ID.

> [!TIP]
>
> You can find your API key and Instance ID in the Hypersender dashboard

![Hypersender Dashboard API Key](https://mintcdn.com/hypersender/oXq9uVgBJOXaL1p2/images/docs/whatsapp/img/api-key-and-instance-id.jpeg?fit=max\&auto=format\&n=oXq9uVgBJOXaL1p2\&q=85\&s=addd172bddcb335eeb1eb029473bac71)

## Installation

**1. Install the SDK with go get**

Run the following command in your module's directory to install the Hypersender Go SDK:

```bash theme={null}
go get github.com/hypersender/hypersender-go
```

> [!TIP]
>
> After installation, you can verify the package is in your module with `go list -m github.com/hypersender/hypersender-go`.

**2. Configure Environment Variables**

The SDK reads its credentials from environment variables, using the same names as the Laravel package. Set the variables for the APIs you use: WhatsApp, SMS, OTP, or any mix of them.

**`For WhatsApp API, set the following environment variables in your .env file:`**

```bash theme={null}
# API key from Hypersender dashboard
HYPERSENDER_WHATSAPP_API_KEY=
# Instance ID from Hypersender dashboard
HYPERSENDER_WHATSAPP_INSTANCE_ID=
```

> [!TIP]
>
> Learn how to get the Hypersender whatsapp `API token` and `Instance ID` from Dashboard: [Demo Link](https://docs.hypersender.com/v2/api-reference/whatsapp/how-to-send-a-whatsapp-message-in-postman.md).

**`For SMS API, set the following environment variables in your .env file:`**

```bash theme={null}
# API key from Hypersender dashboard
HYPERSENDER_SMS_API_KEY=
# Instance ID from Hypersender dashboard
HYPERSENDER_SMS_INSTANCE_ID=
```

> [!TIP]
>
> Learn how to get the Hypersender SMS `API token` and `Instance ID` from the dashboard: [Demo Link](https://docs.hypersender.com/v2/api-reference/sms/how-to-send-an-sms-message-in-postman.md).

**`For OTP API, set the following environment variables in your .env file:`**

```bash theme={null}
# API key from Hypersender dashboard
HYPERSENDER_OTP_API_KEY=
# Instance ID from Hypersender dashboard
HYPERSENDER_OTP_INSTANCE_ID=
```

**`For Enterprise instance management (Enterprise accounts only), set:`**

```bash theme={null}
# Enterprise API key from Hypersender dashboard
HYPERSENDER_ENTERPRISE_API_KEY=
```

> [!NOTE]
>
> Go does not read `.env` files on its own. Export the variables in your shell or hosting platform, or install a package such as [godotenv](https://github.com/joho/godotenv) (`go get github.com/joho/godotenv`) and load the file before you create the client.
>
> ```go theme={null}
> import _ "github.com/joho/godotenv/autoload"
> ```

**3. Send your first message**

Import `github.com/hypersender/hypersender-go`, create a client, and call the API you need. The client picks up the environment variables when you create it.

```go theme={null}
package main

import (
    "context"
    "fmt"
    "log"

    "github.com/hypersender/hypersender-go"
)

func main() {
    client := hypersender.NewClient()

    res, err := client.WhatsApp.SendText(context.Background(), "20123456789@c.us", "Hello from Hypersender!", nil)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(res["queued_request_uuid"])
}
```

## Reading responses and errors

Every method takes a `context.Context` first, then its required arguments, then an optional options struct (pass `nil` when you don't need it). It returns the API's JSON as a `hypersender.Result`, which is a `map[string]any`, so the fields keep the API's names. Nested objects are `map[string]any` too, and lists are `[]any`, so read them with type assertions:

```go theme={null}
res, err := client.OTP.RequestCode(ctx, "201001234567@c.us", nil)
if err != nil {
    log.Fatal(err)
}

data, _ := res["data"].(map[string]any)
status, _ := data["status"].(string)

fmt.Println(status)
```

When the API answers with a `4XX` or `5XX` status, the method returns a `*hypersender.Error` with the `StatusCode`, `Message`, and raw `Body` of the response. Check for it with `errors.As`:

```go theme={null}
_, err := client.WhatsApp.SendText(ctx, "20123456789@c.us", "Hello!", nil)

var apiErr *hypersender.Error
if errors.As(err, &apiErr) {
    fmt.Println(apiErr.StatusCode, apiErr.Message)
} else if err != nil {
    log.Fatal(err) // network error, or a missing HYPERSENDER_* variable
}
```

If a credential is missing, the method returns a plain error that names the environment variable to set.

## Configure in code instead of environment variables

If you can't use environment variables, pass the credentials when you create the client:

```go theme={null}
client := hypersender.NewClient(
    hypersender.WithWhatsApp("your-whatsapp-api-key", "your-whatsapp-instance-id"),
    hypersender.WithSMS("your-sms-api-key", "your-sms-instance-id"),
    hypersender.WithOTP("your-otp-api-key", "your-otp-instance-id"),
)
```

Options override environment variables. Use `hypersender.WithEnterprise(apiKey)` for the Enterprise API key and `hypersender.WithHTTPClient(httpClient)` to use your own `*http.Client` (the default has a 30 second timeout).

The client is safe for concurrent use, so create it once and share it. To work with more than one account at the same time, create a `hypersender.NewClient(...)` client for each one. Each client has the same `WhatsApp`, `SMS`, `OTP`, and `Enterprise` fields.

## You're all set!

You have successfully installed and configured the Hypersender Go SDK in your application. You can now start using the SDK to send messages and manage your communications.

* **WhatsApp:** [Usage Guide](https://docs.hypersender.com/v2/packages-and-sdks/go/whatsapp/send-messages.md)
* **WhatsApp webhooks:** [Receive WhatsApp webhooks in Go](https://docs.hypersender.com/v2/packages-and-sdks/go/whatsapp/whatsapp-webhooks.md)
* **SMS:** [Usage Guide](https://docs.hypersender.com/v2/packages-and-sdks/go/sms/send-and-manage-sms-messages.md)
* **OTP codes (WhatsApp or SMS):** [OTP with Go](https://docs.hypersender.com/v2/packages-and-sdks/go/otp/otp-with-go.md)
* **WhatsApp OTP links:** [Generate a link with Go](https://docs.hypersender.com/v2/packages-and-sdks/go/otp/generate-whatsapp-otp-link-with-go.md)


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