← 开源
anthropics

anthropic-sdk-go

Access to Anthropic's safety-first language model APIs via Go

AI EngineeringAccess modelsGo
在 GitHub 打开
增长势头
+124 小时新增 Star+0.1%
1.21k
Star
214
Fork
+5
本周
37
贡献者
创建于 2024-07-30 · 更新于 2026-10-06 · 今日第 5055 名
主要开发者
README

Claude SDK for Go

Go Reference

The Claude SDK for Go provides access to the Claude API from Go applications.

Documentation

Full documentation is available at platform.claude.com/docs/en/api/sdks/go.

Installation

import (
	"github.com/anthropics/anthropic-sdk-go" // imported as anthropic
)

Or explicitly add the dependency:

go get -u 'github.com/anthropics/[email protected]'

Getting started

package main

import (
	"context"
	"fmt"

	"github.com/anthropics/anthropic-sdk-go"
	"github.com/anthropics/anthropic-sdk-go/option"
)

func main() {
	client := anthropic.NewClient(
		option.WithAPIKey("my-anthropic-api-key"), // defaults to os.LookupEnv("ANTHROPIC_API_KEY")
	)
	message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
		MaxTokens: 1024,
		Messages: []anthropic.MessageParam{
			anthropic.NewUserMessage(anthropic.NewTextBlock("What is a quaternion?")),
		},
		Model: anthropic.ModelClaudeOpus5_5,
	})
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("%+v\n", message.Content)
}

Requirements

Go 1.24+

Contributing

See CONTRIBUTING.md.

License

This project is licensed under the MIT License. See the LICENSE file for details.