Skip to content

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

License

Notifications You must be signed in to change notification settings

unfunco/anthropic-sdk-go

Repository files navigation

Anthropic SDK for Go

CI License: MIT

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.