SDKs & Developer Experience

Go SDK Quickstart: Module Setup and First Request

Go is the language of platform teams — gateways, internal services, infrastructure glue. The official Go SDK puts Claude one go get away from all of it.

Claude 3P 101 · Updated July 2026 · Unofficial guide

If your organization routes LLM traffic through an internal gateway, builds CLI tooling, or runs high-concurrency backend services, chances are that code is written in Go. Anthropic's official Go SDK lives at github.com/anthropics/anthropic-sdk-go and follows the conventions Go engineers expect: modules, explicit error returns, and context.Context on every call.

Step 1: Add the module

The SDK requires Go 1.24 or newer. Add it to your module with a pinned version:

go get -u 'github.com/anthropics/anthropic-sdk-go@v1.56.0'

Pinning the version in go.mod is standard Go practice and doubly worthwhile here — you want SDK upgrades to be deliberate events you test, not surprises in a routine dependency refresh. The version shown is current as of this writing; check the repository's releases for the latest.

Step 2: Initialize the client

client := anthropic.NewClient(
    option.WithAPIKey("..."), // omit to fall back to ANTHROPIC_API_KEY
)

Construction follows Go's functional-options pattern. If you pass no API key option, the client defaults to reading the ANTHROPIC_API_KEY environment variable — the pattern you should prefer in real services, since it keeps the secret out of source code and lets your deployment platform inject it. Keys are created in the Claude Console (Settings → API keys), never expire on their own, and should live in a secrets manager with periodic rotation. For production workloads on cloud platforms and CI, Anthropic recommends Workload Identity Federation — short-lived tokens exchanged from your identity provider — over long-lived keys.

Step 3: Make the request, with context

Every request method takes a context.Context as its first argument:

message, err := client.Messages.New(ctx, anthropic.MessageNewParams{
    // model: e.g. anthropic.ModelClaudeOpus4_6 or a bare model ID string;
    // build content with anthropic.NewUserMessage(anthropic.NewTextBlock("..."))
})
if err != nil {
    // inspect and handle: auth errors, rate limits, transient failures
}

The ctx parameter is where Go's operational discipline pays off. Derive it from your request's context with a deadline, and a slow model response cannot pin a goroutine forever: when the deadline passes or the caller cancels, the SDK call returns promptly with an error. For services calling Claude, set timeouts generous enough for real generation lengths — model responses take longer than typical microservice hops — and prefer streaming for anything user-facing (see streaming basics).

The SDK provides helper constructors — anthropic.NewUserMessage and anthropic.NewTextBlock — for building the message list, plus model constants such as anthropic.ModelClaudeOpus4_6 so model selection is checked at compile time. For current-generation models like claude-sonnet-5 and claude-opus-4-8, check the SDK's constants list for the matching identifier or pass the ID string the models documentation gives you. The returned message carries the reply content and token-usage counts; log the usage from day one so cost attribution is possible later.

Idiomatic checklist: pinned module version, key from the environment, per-request context with a deadline, explicit error handling on every call, usage logged. That is the whole production posture in five items.

Go and the third-party platforms

The module above targets Anthropic's first-party Claude API. For Claude Platform on AWS — the Anthropic-operated service inside AWS — the same module tree provides an AWS-specific client created via anthropicaws.NewClient(ctx, anthropicaws.ClientConfig{}), which handles SigV4 signing and workspace configuration; the platform-specific clients are in beta. For Amazon Bedrock or Google Vertex AI from Go, rely on those platforms' own SDKs and documentation rather than assuming client packages exist here; the concepts in the Python-oriented setup guides (Bedrock, Vertex AI) — credential chains, regions, model ID formats — transfer directly.

Where to go next

Read SDK error handling and retry configuration before shipping, compare languages in the SDK overview, or start from the platform quickstart.

Sources