To send a text from Go, make an HTTPS POST to your SMS provider's REST endpoint with the standard library's net/http, put your API key in a header, and send the recipient and message as JSON. You don't need an SDK, and you don't need a third-party module. A handful of lines and a timeout is the whole job; retries and error handling are where the care goes.

We make Ready, so the worked example uses the Ready REST API and only the request shape we document. The patterns carry over to any provider: one shared http.Client, a context deadline on every call, and a stable idempotency key so a retry never texts someone twice. The code assumes Go 1.21 or later.

What you need before the first request

Four things stand between you and a delivered text.

  1. An API key. Ready authenticates with an X-API-Key header. Load it from an environment variable or a secrets manager. Never commit it.
  2. A card and a number. A card on file and a number of your own are required to send. The number is $2 a month. To build and test first, create a test key (Settings, Developers, Environment: Test): it simulates every send, with no card, number or charge. Add the card and number before you go live.
  3. Consent. Each request carries consent_attested: true, your promise that the recipient agreed to receive texts. It's a statement you're making, so only set it when it's true.
  4. A plan for registration. An account can send up to 500 texts a month before it registers for 10DLC, at its normal per-text rate. After that it has to register, and most approvals take 2 to 7 days. Our 10DLC explainer covers why carriers require it.

Every text is charged from the first one: each segment costs $0.0075 plus a $0.0045 carrier fee, passed through at cost. Screening, the optional scrub and validation checks, is extra when you switch it on.

Send a text with net/http

The endpoint is POST https://api.tryready.com/v1/messages. The body takes to in E.164 format (a 10-digit US number is treated as +1), body, and consent_attested. Here's a complete program:

package main

import (
	"bytes"
	"context"
	"crypto/rand"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
	"os"
	"time"
)

const baseURL = "https://api.tryready.com"

type sendRequest struct {
	To              string `json:"to"`
	Body            string `json:"body"`
	ConsentAttested bool   `json:"consent_attested"`
}

var client = &http.Client{Timeout: 20 * time.Second}

func newUUID() string {
	b := make([]byte, 16)
	if _, err := rand.Read(b); err != nil {
		panic(err)
	}
	b[6] = (b[6] & 0x0f) | 0x40
	b[8] = (b[8] & 0x3f) | 0x80
	return fmt.Sprintf("%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:])
}

func send(ctx context.Context, to, body, key string) (int, []byte, error) {
	payload, err := json.Marshal(sendRequest{To: to, Body: body, ConsentAttested: true})
	if err != nil {
		return 0, nil, err
	}
	req, err := http.NewRequestWithContext(ctx, http.MethodPost,
		baseURL+"/v1/messages", bytes.NewReader(payload))
	if err != nil {
		return 0, nil, err
	}
	req.Header.Set("X-API-Key", os.Getenv("READY_API_KEY"))
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Idempotency-Key", key)

	resp, err := client.Do(req)
	if err != nil {
		return 0, nil, err
	}
	defer resp.Body.Close()
	out, err := io.ReadAll(resp.Body)
	return resp.StatusCode, out, err
}

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
	defer cancel()

	status, out, err := send(ctx, "+12125550199", "Your order #1042 has shipped.", newUUID())
	if err != nil {
		fmt.Println("request failed:", err)
		os.Exit(1)
	}
	fmt.Println(status, string(out))
}

Three choices in there are worth explaining. json.Marshal builds the payload, so a customer name with a quote or a newline can't produce broken JSON. The http.Client is created once and reused, because it pools connections. And the request carries a context, so a stalled network call gives up on a deadline rather than hanging a goroutine forever.

The example prints the status and the raw body. For the exact response fields and error bodies, use the messages API reference instead of a blog post's summary.

Optional fields

Two optional fields are worth knowing. from picks one of your own numbers, and media_url sends a picture as MMS. If you leave from out, Ready picks the number: the one this contact already texts with, otherwise your number closest to their area code. That keeps a conversation on one thread on the contact's phone. Add them as From string and MediaURL string fields on the struct with omitempty tags so they drop out when empty.

Retries without double-sending

Networks fail. If your request times out, you don't know whether the text went out, and retrying blindly can text a customer twice. Duplicate texts are a reliable way to collect opt-outs.

The fix is the Idempotency-Key header. Generate one UUID per logical message, store it with the message record, and send the same key on every attempt. A retried request with the same key doesn't send twice. This wrapper retries only when it's safe:

func sendWithRetry(ctx context.Context, to, body, key string) (int, []byte, error) {
	backoff := 500 * time.Millisecond
	var status int
	var out []byte
	var err error
	for attempt := 1; attempt <= 4; attempt++ {
		status, out, err = send(ctx, to, body, key)
		retryable := err != nil || status == 429 ||
			(status == 409 && bytes.Contains(out, []byte("idempotency_in_progress")))
		if !retryable || attempt == 4 {
			return status, out, err
		}
		select {
		case <-time.After(backoff):
		case <-ctx.Done():
			return status, out, ctx.Err()
		}
		backoff *= 2
	}
	return status, out, err
}

The rules behind it:

  • Retry with the same key on connection errors and timeouts, on HTTP 429, and on a 409 idempotency_in_progress.
  • Don't replay a 503 with the same key. The text wasn't sent and wasn't charged, and the same key returns the stored error. Send it again with a new key.
  • After a 504, or a code ending in OUTCOME_UNKNOWN, check GET /v1/messages first. The message may have gone out.
  • Don't retry other 4xx responses. A malformed number or a bad key fails the same way on attempt four.
  • Keep the key constant across attempts. A fresh UUID each time defeats the purpose.

Ready also refuses some sends up front without charging you: opted-out numbers, numbers on your Ban list and known landlines. Treat those as final. Our posts on idempotency keys and retries and failure handling go deeper.

Sending to many numbers

For the same message to many recipients, POST /v1/messages/bulk takes to as an array, with at most 100 recipients per call. Split a bigger list into batches and give each batch its own persisted idempotency key, so a crash and restart reuses the key instead of resending. The bulk messages docs have the details.

In Go, a worker pool fits well. Feed batches through a channel to a small number of goroutines, and keep the pool small so you stay inside rate limits. A 429 means slow down, so back off rather than adding workers.

Receiving replies and delivery reports

Sending is half the story. To learn whether a text was delivered, and to receive replies, run an HTTP handler that the provider calls. In Go that's a few lines with http.HandleFunc. Read the raw body with io.ReadAll, verify the signature over those exact bytes, put the payload on a queue, and return a 200 quickly. Don't do database work in the handler.

Exact payload fields and the signature header are in the docs, so follow them there. Two guides cover the pattern: inbound webhooks and testing webhooks locally with a tunnel.

A worked cost example

Assume a Go service sends 3,000 single-segment order updates in a month, with screening off. That's 3,000 segments. At $0.0075 each plus the $0.0045 carrier fee, you pay for 3,000 times the sum of the two, plus $2 for the number. Accounts opened before November 12, 2026 keep the prices they signed up with, shown under Billing. The pricing page lists every rate.

Segments are what's metered, not messages. An emoji drops a segment to 70 characters, so a 140-character text with one emoji is 3 segments instead of 1. Count segments before you budget.

Wrapping up

Sending an SMS from Go is a small amount of code: marshal JSON, set three headers, use a context deadline, and reuse one client. The real work is the stable idempotency key, retrying only what's safe, and a webhook handler that acknowledges fast.

If you're comparing languages, the Node.js and Python guides use the same request. When you're ready to try it, sign up and follow the API quickstart.