Skip to content
This repository was archived by the owner on Sep 26, 2026. It is now read-only.

Repository files navigation

Anthropic SDK for Go

CI License: MIT

Note

This project predates Anthropic's official Go SDK. Use Anthropic's official Go SDK instead; this repository will no longer be developed.

Note

This is not an official SDK, and I am not affiliated with Anthropic.
Official SDKs from Anthropic are available for Python, and TypeScript/JavaScript.

Client library for interacting with the Anthropic safety-first language model REST APIs.
Documentation for the REST API can be found at docs.anthropic.com.

Getting started

Requirements

Installation and usage

Import the module and run the go get command without any arguments to resolve and add the SDK to your dependencies.

import "github.com/unfunco/anthropic-sdk-go"

Construct a new REST API client with a http.Client derived from a Transport containing your Claude API key. The derived HTTP client will automatically add the API key as a header to each request sent to the API.

transport := anthropic.NewTransport(os.Getenv("ANTHROPIC_API_KEY"))
claude := anthropic.NewClient(transport.Client())

Once constructed, you can use the client to interact with the REST API.

data, _, err := claude.Messages.Create(
    context.Background(),
    &anthropic.CreateMessageInput{
        MaxTokens: 1024,
        Messages: []anthropic.Message{
            {
                Content: "Hello, Claude!",
                Role:    "user",
            },
        },
        Model: anthropic.Claude3Opus20240229,
    },
)

Development and testing

Clone the repository and change into the anthropic-sdk-go directory.

git clone git@github.com:unfunco/anthropic-sdk-go.git
cd anthropic-sdk-go

Run the unit tests with coverage to ensure everything is working as expected.

go test -cover -v ./...

References

License

© 2024 Daniel Morris
Made available under the terms of the MIT License.

About

Go client library for interacting with the Anthropic safety-first language model REST APIs.

Topics

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages