anthropic

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AnthropicVersion        = "2023-06-01"
	BetaInterleavedThinking = "interleaved-thinking-2025-05-14"
)
View Source
const (
	// Claude 4.6 (current).
	ModelOpus   = "claude-opus-4-6"
	ModelSonnet = "claude-sonnet-4-6"

	// Claude 4.5 (Haiku latest).
	ModelHaiku = "claude-haiku-4-5-20251001"
)

Model ID constants for programmatic use.

Variables

View Source
var ModelAliases = map[string]string{
	"opus":   ModelOpus,
	"sonnet": ModelSonnet,
	"haiku":  ModelHaiku,
}

ModelAliases maps short alias names to full model IDs. These are used by the auto package for provider-prefixed resolution (e.g., "claude/sonnet").

Functions

func CoerceAnthropicThinkingTemperature added in v0.40.0

func CoerceAnthropicThinkingTemperature(msgReq *providercore2.MessagesRequest)

func DefaultOptions added in v0.12.0

func DefaultOptions() []llm.Option

func DoCountTokensAPI added in v0.40.0

func DoCountTokensAPI(
	ctx context.Context,
	client *http.Client,
	baseURL, apiKey string,
	extraHeaders map[string]string,
	apiReq *providercore.MessagesRequest,
) (int, error)

DoCountTokensAPI is the shared implementation for the Anthropic count_tokens endpoint, usable by both the direct Anthropic provider and the Claude OAuth provider. extraHeaders are appended to the request (e.g. OAuth Authorization).

Types

type Provider

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

func New

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

func (*Provider) CountTokensAPI added in v0.40.0

func (p *Provider) CountTokensAPI(ctx context.Context, apiReq *providercore.MessagesRequest) (int, error)

CountTokensAPI calls the Anthropic /v1/messages/count_tokens endpoint to get an exact token count for the given request. This is free and does not consume message rate limits, but adds one HTTP round-trip.

The returned count is exact (not a heuristic approximation). It includes tool definitions, system prompts, images, PDFs, and thinking blocks.

func (*Provider) CreateStream

func (p *Provider) CreateStream(ctx context.Context, src llm.Buildable) (llm.Stream, error)

func (*Provider) Models

func (p *Provider) Models() llm.Models

func (*Provider) Name

func (p *Provider) Name() string

Directories

Path Synopsis
Package claude provides an Anthropic provider using Claude OAuth tokens.
Package claude provides an Anthropic provider using Claude OAuth tokens.

Jump to

Keyboard shortcuts

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