anthropic

package
v0.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvAnthropicAPIKey = "ANTHROPIC_API_KEY"
)

Environment variable names for Anthropic configuration.

Variables

This section is empty.

Functions

func DefaultOptions added in v0.12.0

func DefaultOptions() []llm.Option

DefaultOptions returns the default options for Anthropic. Base URL defaults to https://api.anthropic.com. API key should be provided via WithAPIKey() or WithAPIKeyFunc().

func MaybeRegister added in v0.13.0

func MaybeRegister(reg *llm.Registry)

MaybeRegister registers available Anthropic providers:

  • Claude Code provider (via local claude CLI) if claude is in PATH
  • Anthropic API provider if ANTHROPIC_API_KEY is set

Types

type ClaudeCodeProvider

type ClaudeCodeProvider struct {
	// contains filtered or unexported fields
}

ClaudeCodeProvider implements the provider interface using the Claude Code CLI via cc-sdk-go. It wraps the oai.Client which spawns the official claude CLI as a subprocess.

func NewCCWithClient

func NewCCWithClient(client *oai.Client) *ClaudeCodeProvider

NewCCWithClient creates a Claude Code provider with a custom oai.Client. Use this when you need to customize the underlying cchat.Client configuration (e.g. CLI path, max concurrency, working directory).

func NewClaudeCodeProvider

func NewClaudeCodeProvider() *ClaudeCodeProvider

NewClaudeCodeProvider creates a new Claude Code provider with default settings. The claude CLI must be authenticated (claude setup-token) and available in PATH.

func (*ClaudeCodeProvider) CreateStream

func (p *ClaudeCodeProvider) CreateStream(ctx context.Context, opts llm.StreamOptions) (<-chan llm.StreamEvent, error)

func (*ClaudeCodeProvider) Models

func (p *ClaudeCodeProvider) Models() []llm.Model

func (*ClaudeCodeProvider) Name

func (p *ClaudeCodeProvider) Name() string

type OAuthConfig added in v0.12.0

type OAuthConfig struct {
	Access  string // Access token (sk-ant-oat-...)
	Refresh string // Refresh token
	Expires int64  // Expiry timestamp in milliseconds
}

OAuthConfig holds OAuth token information for Claude Code authentication.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider implements the Anthropic (Claude) LLM backend.

func New

func New(opts ...llm.Option) *Provider

New creates a new Anthropic provider. Options are applied on top of DefaultOptions().

Example usage:

// With API key
p := anthropic.New(llm.WithAPIKey("sk-ant-..."))

// With API key from environment
p := anthropic.New(llm.APIKeyFromEnv("ANTHROPIC_API_KEY"))

// With dynamic API key resolution
p := anthropic.New(llm.WithAPIKeyFunc(func(ctx context.Context) (string, error) {
    return secretStore.Get(ctx, "anthropic-key")
}))

func (*Provider) CreateStream

func (p *Provider) CreateStream(ctx context.Context, opts llm.StreamOptions) (<-chan llm.StreamEvent, error)

func (*Provider) Models

func (p *Provider) Models() []llm.Model

func (*Provider) Name

func (p *Provider) Name() string

func (*Provider) WithOAuth added in v0.12.0

func (p *Provider) WithOAuth(oauth *OAuthConfig) *Provider

WithOAuth configures the provider to use OAuth authentication. This enables Claude Code-style authentication with automatic token refresh.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL