anthropic-sdk-go
Official Go SDK for Claude's Messages, Files, Skills, and Beta agent APIs, with built-in Bedrock and Vertex AI support.
Repository Health
Technical Analysis
anthropic-sdk-go is the official Go client library for Anthropic’s Claude API, generated from Anthropic’s OpenAPI spec and covering Messages, Models, Files, Skills, and Completions, plus a growing set of beta agent-session and tool-runner resources for building multi-turn tool-using agents.
Beyond a thin REST wrapper, the SDK ships dedicated subpackages for authenticating through AWS Bedrock, Google Vertex AI, or generic Google Cloud credentials, a native Model Context Protocol (MCP) client, and an explicit credential-resolution chain (API key, auth token, named profile, or environment-federated identity) so the same Client type can target the direct API or either hyperscaler platform without code changes.
What You Get
- Typed request/response structs for every Claude API resource (Messages, Models, Files, Skills, Completions, and their Beta counterparts)
- A functional-options client (option.RequestOption) for configuring auth, base URL, retries, and HTTP transport
- Drop-in subpackages for AWS Bedrock, Google Vertex AI, and generic Google Cloud auth so the same Client targets any of the three platforms
- Beta agent-session, tool-runner, and native MCP client support for building multi-turn tool-using agents
- 35+ runnable examples covering streaming, file upload, MCP tool running, and managed agents
Common Use Cases
- Calling Claude’s Messages API from a Go backend service
- Streaming message deltas into a chat UI or CLI
- Running Claude through AWS Bedrock or Google Vertex AI for compliance-driven deployments
- Building tool-calling agents with the beta session and tool-runner APIs
- Uploading files and managing Skills programmatically from CI or automation scripts
Under The Hood
Architecture
The SDK is organized as a flat top-level anthropic package where each API resource gets its own generated file (message.go, model.go, file.go, skill.go, beta*.go) paired with a matching _test.go, with the Client struct in client.go composing per-resource services (Completions, Messages, Models, Files, Skills, Beta) built by NewClient; cross-cutting request plumbing — auth headers, retries, base URL, credential resolution — lives in internal/requestconfig and internal/auth and is threaded through via the functional-options pattern in option/ (RequestOption), while cloud-specific transports for AWS Bedrock, Google Vertex, and generic Google Cloud auth are isolated into their own bedrock/, vertex/, googlecloud/, and aws/ subpackages that decorate the same Client rather than forking it. DefaultClientOptions implements an explicit credential-precedence chain (API key, then auth token, then named profile, then env-var federation, then fallback profile) that fails closed with a typed auth.NoCredentialsError when nothing resolves.
Tech Stack Written in Go 1.24 (toolchain 1.25.8) with no web framework, since it is a client library; dependencies include aws-sdk-go-v2 and smithy-go for Bedrock request signing, google.golang.org/api and golang.org/x/oauth2 for Vertex and Google Cloud auth, modelcontextprotocol/go-sdk and google/jsonschema-go for MCP tool-calling support, tidwall/gjson and tidwall/sjson for dynamic JSON patching, invopop/jsonschema and pb33f/ordered-map for schema generation, and stretchr/testify plus dnaeon/go-vcr for HTTP-cassette-based test recording. Build and test tooling is a set of shell scripts under scripts/ (bootstrap, lint, format, mock, test) driving gofmt and a local mock server generated from the OpenAPI spec.
Code Quality 62 top-level _test.go files pair almost every generated resource file with a corresponding test, using stretchr/testify assertions and go-vcr cassette recording to replay HTTP fixtures rather than hitting a live API in CI; fuller integration-style testing requires a local mock server via ./scripts/mock. Error handling is explicit and typed — the credential chain returns wrapped, typed errors (auth.NoCredentialsError, profile-load errors) instead of swallowing failures, and generated types carry dedicated unmarshal-error test coverage (paramunmarshal_test.go, schemautil_test.go). Formatting is enforced via gofmt (./scripts/format) and linting via ./scripts/lint, with GitHub Actions CI wired under .github/workflows. Because most of the SDK is generator output, naming is mechanically consistent across resources rather than hand-crafted, and CONTRIBUTING.md is explicit that manual patches to generated files can be lost or conflict on the next generation pass.
API Design What sets this apart from a plain REST wrapper is that it embeds full agent-loop plumbing directly in the client: beta session, thread, event, and tool-runner types (betasessiontoolrunner.go, betatoolrunner.go, toolrunner/) implement multi-turn tool-execution loops, a dedicated mcp/ package adds native Model Context Protocol client support, and skill/skill-version resources model Claude’s Skills feature — none of which is typical of a bare API client. It also unifies three deployment surfaces (the direct Anthropic API, AWS Bedrock, and Google Vertex AI) behind one Client type via swappable auth/transport subpackages, so switching providers is a constructor change rather than a rewrite, though the underlying generated-client-plus-functional-options pattern itself is common across all Stainless-generated SDKs.
Used by 6 apps in this directory
Coder
Devops · Developer Tools · Code Editors
Self-hosted cloud development environments and AI coding agents — defined in Terraform, connected via WireGuard, automatically shut down when idle.
hoop
Security · Monitoring
A wire-protocol gateway that enforces data masking, command blocking, approval workflows, and full session recording for engineers and AI agents accessing production infrastructure.
klaw
AI Agents · Devops
kubectl for AI Agents — manage, schedule, and scale your AI workforce with a single binary that deploys in seconds.
Notifuse
Marketing
Open-source, self-hosted alternative to Mailchimp, Brevo, and Klaviyo — send newsletters and transactional emails without per-email pricing or vendor lock-in.
open-code-review
Developer Tools · Devops
The AI code review agent born at Alibaba's scale — combining deterministic engineering with LLM intelligence for precise, token-efficient reviews.
Rill
Analytics · Data Engineering
The fastest BI tool for humans and agents — define metrics, models, and dashboards as code and query them instantly on ClickHouse or DuckDB.