AI Decision System
Replayable, offline-verifiable records for AI-assisted go/no-go decisions: experiment promotions, typed model answers and human-approved actions.
翻譯準備中
Access to Anthropic's safety-first language model APIs via Go
翻譯準備中
開發工具Go · ShellGitHub @anthropics自行安裝營運者未確認
試用過了嗎? 點一下就好,不需要登入。
正在載入完整 README。 以下為已儲存的摘錄。
The Claude SDK for Go provides access to the Claude API from Go applications.
Full documentation is available at platform.claude.com/docs/en/api/sdks/go.
See CONTRIBUTING.md.
This project is licensed under the MIT License. See the LICENSE file for details.檢視完整 README ↗The Claude SDK for Go provides access to the Claude API from Go applications.
Full documentation is available at platform.claude.com/docs/en/api/sdks/go.
import (
"github.com/anthropics/anthropic-sdk-go/v2" // imported as anthropic
)
Or explicitly add the dependency:
go get -u 'github.com/anthropics/anthropic-sdk-go/[email protected]'
package main
import (
"context"
"fmt"
"github.com/anthropics/anthropic-sdk-go/v2"
"github.com/anthropics/anthropic-sdk-go/v2/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)
}
The SDK reports each API call as an OpenTelemetry span when your application has registered a tracer provider.
No client option is needed for that.
The spans carry no content of requests or responses unless you set option.WithOpenTelemetryTracesContentMode(option.OpenTelemetryContentModeContent) or ANTHROPIC_OPEN_TELEMETRY_TRACES_CONTENT_MODE=content.
A span then holds at most 750,000 bytes of content, and has anthropic.content.truncated when content was cut or left out to fit; option.WithOpenTelemetryTracesMaxContentBytes(n) or ANTHROPIC_OPEN_TELEMETRY_TRACES_MAX_CONTENT_BYTES=n sets another maximum.
Each request carries the trace context of its span in the headers of your registered propagator; option.WithOpenTelemetryPropagation(false) or ANTHROPIC_OPEN_TELEMETRY_PROPAGATION=false leaves them out, for an application whose HTTP client instrumentation already sends them.
client := anthropic.NewClient(option.WithTracerProvider(provider)) // a provider other than the registered one
quiet := anthropic.NewClient(option.WithoutOpenTelemetry()) // no spans; ANTHROPIC_OPEN_TELEMETRY=false does the same
client.Messages.New(ctx, params, option.WithOpenTelemetryConversationID(conversationID)) // sets gen_ai.conversation.id
WithTracerProvider, WithOpenTelemetryPropagation, WithoutOpenTelemetry, WithOpenTelemetryTraces, WithOpenTelemetryTracesContentMode, and WithOpenTelemetryTracesMaxContentBytes are client options.
Go has one request option type, so a method call accepts them too; passed that way, they apply to that call only.
Go 1.25+
See CONTRIBUTING.md.
This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details. Versions released before the change from the MIT License, and third-party contributions merged before it, remain under the MIT License. See LICENSE-MIT.