Go SDK
The official Go SDK provides a context-aware, dependency-light client for SMS, Voice, WhatsApp, and Email — with automatic retries and Bearer-token authentication built in.
Installation
go get afriroute.ai/sdk-go
Then import the package:
import "afriroute.ai/sdk-go/afriroute"
Authentication
Create a client with your API key. It is sent as Authorization: Bearer $AFRIROUTE_API_KEY against https://api.afriroute.ai.
client := afriroute.NewClient("$AFRIROUTE_API_KEY")
Target the sandbox or tune behavior with functional options:
import "time"
client := afriroute.NewClient("$AFRIROUTE_API_KEY",
afriroute.WithBaseURL("https://api.afriroute.ai"),
afriroute.WithTimeout(60*time.Second),
afriroute.WithMaxRetries(5),
)
tip
Read the key from the environment: afriroute.NewClient(os.Getenv("AFRIROUTE_API_KEY")).
Send an SMS
resp, err := client.SMS.Send(&afriroute.SMSRequest{
To: "+251900000000",
Message: "Hello from AfriRoute",
SenderID: "AfriRoute",
})
if err != nil {
log.Fatal(err)
}
fmt.Println(resp.MessageID)
Send a WhatsApp Message
wa, err := client.WhatsApp.Send(&afriroute.WhatsAppRequest{
To: "+251900000000",
Message: "Hello via WhatsApp",
})
if err != nil {
log.Fatal(err)
}
fmt.Println(wa.MessageID)
Make a Voice Call
call, err := client.Voice.Call(&afriroute.VoiceCallRequest{
To: "+251900000000",
From: "+1234567890",
TTSMessage: "Welcome to AfriRoute",
})
if err != nil {
log.Fatal(err)
}
fmt.Println(call.CallID)
Send an Email
email, err := client.Email.Send(&afriroute.EmailRequest{
To: "[email protected]",
Subject: "Welcome",
Body: "<h1>Hello</h1>",
})
if err != nil {
log.Fatal(err)
}
fmt.Println(email.MessageID)
Error Handling
Errors implement *afriroute.APIError, exposing Code, Message, and StatusCode. Use errors.As to inspect them:
import "errors"
resp, err := client.SMS.Send(&afriroute.SMSRequest{
To: "+251900000000",
Message: "Hello",
SenderID: "AfriRoute",
})
if err != nil {
var apiErr *afriroute.APIError
if errors.As(err, &apiErr) {
switch apiErr.Code {
case "INVALID_PHONE_NUMBER":
log.Println("Use E.164 format, e.g. +251911234567")
case "INSUFFICIENT_BALANCE":
log.Println("Top up your account")
case "RATE_LIMIT_EXCEEDED":
log.Println("Slow down — retried automatically")
default:
log.Printf("%s: %s", apiErr.Code, apiErr.Message)
}
}
return
}
Transient failures (429, 5xx) are retried automatically up to the configured max retries with exponential back-off.
Features
- Idiomatic Go with explicit error returns
- Functional options for configuration
- Automatic retries with exponential back-off
- Built-in rate-limit (
429) handling - Minimal external dependencies
Related Resources
Last Updated: May 2026 · Need help? Contact Support →