Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Anthropic Package for Go
    Anthropic package Go library Claude API go-anthropic completions streaming messages vision Go SDK


Anthropic Package for Go


The Anthropic package for Go provides a convenient way to interact with the Anthropic Claude API. Here are the key points:

The go-anthropic library[1][2] is an unofficial Anthropic Claude API wrapper for Go. It supports the following features:

- Completions
- Streaming Completions
- Messages
- Streaming Messages
- Vision
- Tool use

To use the library, you can install it via `go get`:


go get github.com/liushuangls/go-anthropic/v2

The library requires Go version 1.21 or greater. It provides example usage for the Messages and Vision APIs[1][2]:

go
client := anthropic.NewClient("your anthropic apikey")
resp, err := client.CreateMessages(context.Background(), anthropic.MessagesRequest{
    Model: anthropic.ModelClaude3Opus20240229,
    Messages: []anthropic.Message{
        {
            Role: anthropic.RoleUser,
            Content: []anthropic.MessageContent{
                anthropic.NewImageMessageContent(anthropic.MessageContentImageSource{
                    Type: "base64",
                    MediaType: "image/jpeg",
                    Data: imageData,
                }),
                anthropic.NewTextMessageContent("Describe this image."),
            },
        },
    },
    MaxTokens: 1000,
})

The library also has a few other Go SDK options, such as the anthropic-sdk-go[3] and go-anthropic[4] packages, which provide similar functionality. The official Anthropic documentation also mentions Python and TypeScript SDKs[5].

Citations:
[1] https://pkg.go.dev/github.com/liushuangls/go-anthropic
[2] https://github.com/liushuangls/go-anthropic
[3] https://github.com/3JoB/anthropic-sdk-go
[4] https://pkg.go.dev/github.com/staropshq/go-anthropic
[5] https://docs.anthropic.com/en/api/client-sdks