Hello world: Go
Ready — installs from the CloakAPI downloads page. Tested end to end on Linux x86-64.
Runs today on Linux x86-64. On macOS, Windows and ARM the on-device engine is not available yet; the SDK uses basic detection and shows a warning.
1. Get an API key
Create a key at app.cloakapi.io/api-keys. It starts with cloak_. Verify your email to unlock your trial balance.
2. Install
Set up the on-device engine and pin: Engine setup.
curl -fsSLO https://app.cloakapi.io/downloads/sdks/go/cloakapi-go-v1.2.1-src.zipunzip -q cloakapi-go-v1.2.1-src.zip -d third_partygo mod init hello && go mod edit -replace github.com/cloakapi/cloakapi-go=./third_party/gogo mod tidy3. Set your key
export CLOAKAPI_API_KEY="cloak_your_key_here"4. Run hello world
package main
import ( "bufio" "context" "fmt" "os" "strings"
"github.com/cloakapi/cloakapi-go/cloakapi")
const prompt = "Say hello to jane.doe@example.com in one short sentence."
func main() { apiKey := os.Getenv("CLOAKAPI_API_KEY") if apiKey == "" { fmt.Fprintln(os.Stderr, "CLOAKAPI_API_KEY is not set. Create a key at https://app.cloakapi.io/api-keys") os.Exit(1) }
stdin := bufio.NewReader(os.Stdin) client := cloakapi.NewClient(apiKey, &cloakapi.Config{ Review: func(req cloakapi.EgressRequest) bool { fmt.Printf("This exact request will leave your machine:\n\n%s %s\n%s\n\nSend it? [y/N] ", req.Method, req.URL, req.Body) answer, _ := stdin.ReadString('\n') return strings.EqualFold(strings.TrimSpace(answer), "y") }, })
resp, err := client.Messages.Create(context.Background(), cloakapi.MessagesRequest{ Model: "claude-sonnet-4-6", Messages: []cloakapi.Message{{Role: "user", Content: prompt}}, }) if err != nil { fmt.Fprintln(os.Stderr, "Request failed:", err) os.Exit(1) } fmt.Println("\nReply (restored on your device):") fmt.Println(resp.FirstText())}cd repo/sdk/goCGO_ENABLED=1 go run ./examples/hello5. What you should see
You’ll see the exact request before it is sent. Your email address is replaced with a token like <<CLOAK:CONTACT_EM:3f9a1c>>. Type y. The reply comes back with the real address restored on your device. The reply text varies.
If something goes wrong
See the Go SDK README for common messages and fixes.
What this does and does not do
- Detection is best-effort. Emails, phone numbers, cards and similar are matched by rules; names use an on-device list and an optional on-device model, and may be missed.
- You see the exact request before it is sent.
- CloakAPI does not refuse a request because of what it contains. Errors come from your key, balance, usage limits, request format or size, or the model provider.
- The gateway does not run detection on your content. It checks the request proof, then relays it to the model provider.