anthropic

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package anthropic adapts Anthropic Messages-compatible APIs to sigma.

The provider supports streaming text, image input, tools, thinking, prompt cache markers, usage, and Anthropic-compatible endpoint variations where the upstream API exposes stable fields. Credentials resolve through sigma.Options.AuthResolver instead of direct environment reads.

Index

Constants

View Source
const (
	DefaultBaseURL = "https://api.anthropic.com/v1"
)

Variables

View Source
var Tools = struct {
	WebSearch     func(opts ...WebSearchOption) sigma.Tool
	WebFetch      func(opts ...WebFetchOption) sigma.Tool
	CodeExecution func() sigma.Tool
}{
	WebSearch:     webSearchTool,
	WebFetch:      webFetchTool,
	CodeExecution: codeExecutionTool,
}

Tools provides factories for Anthropic server-side provider-defined tools.

Functions

func Register

func Register(registry *sigma.Registry, providerID sigma.ProviderID, opts ...ProviderOption) error

Register adds an Anthropic Messages-compatible text provider to registry.

func RegisterDefault

func RegisterDefault(providerID sigma.ProviderID, opts ...ProviderOption) error

RegisterDefault adds an Anthropic Messages-compatible text provider to sigma's default registry.

Types

type MessagesCompat

type MessagesCompat struct {
	EagerToolInputStreaming bool
	LongCacheRetention      bool
	SessionAffinityHeaders  bool
	CacheControlOnTools     bool
	AdaptiveThinking        bool
}

MessagesCompat describes Anthropic Messages compatibility differences for Anthropic-compatible endpoints. Leave fields at their zero value to use provider/base-URL detection, or set them with WithMessagesCompat for tests or custom routers.

type Provider

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

Provider adapts Anthropic Messages-compatible HTTP APIs to sigma.

func NewProvider

func NewProvider(opts ...ProviderOption) *Provider

NewProvider constructs an Anthropic Messages-compatible provider.

func (*Provider) API

func (p *Provider) API() sigma.API

API reports the Anthropic Messages API surface.

func (*Provider) Stream

func (p *Provider) Stream(ctx context.Context, model sigma.Model, req sigma.Request, opts sigma.Options) *sigma.Stream

Stream sends req to a Messages-compatible endpoint and emits sigma events as SSE chunks arrive.

type ProviderOption

type ProviderOption func(*Provider)

ProviderOption configures a Provider.

func WithBaseURL

func WithBaseURL(baseURL string) ProviderOption

WithBaseURL configures the provider base URL, for example an httptest server URL ending in /v1 or an Anthropic-compatible endpoint.

func WithHTTPClient

func WithHTTPClient(client *http.Client) ProviderOption

WithHTTPClient configures the provider fallback HTTP client.

func WithHeader

func WithHeader(key, value string) ProviderOption

WithHeader configures a provider default request header.

func WithHeaders

func WithHeaders(headers map[string]string) ProviderOption

WithHeaders configures provider default request headers.

func WithMessagesCompat

func WithMessagesCompat(compat MessagesCompat) ProviderOption

WithMessagesCompat overrides detected Anthropic-compatible endpoint behavior.

type WebFetchCitations

type WebFetchCitations struct {
	Enabled bool
}

type WebFetchOption

type WebFetchOption func(*webFetchConfig)

func WithCitations

func WithCitations(enabled bool) WebFetchOption

func WithMaxContentTokens

func WithMaxContentTokens(tokens int) WebFetchOption

func WithWebFetchAllowedDomains

func WithWebFetchAllowedDomains(domains ...string) WebFetchOption

func WithWebFetchBlockedDomains

func WithWebFetchBlockedDomains(domains ...string) WebFetchOption

func WithWebFetchMaxUses

func WithWebFetchMaxUses(maxUses int) WebFetchOption

type WebSearchLocation

type WebSearchLocation struct {
	City     string
	Region   string
	Country  string
	Timezone string
}

type WebSearchOption

type WebSearchOption func(*webSearchConfig)

func WithAllowedDomains

func WithAllowedDomains(domains ...string) WebSearchOption

func WithBlockedDomains

func WithBlockedDomains(domains ...string) WebSearchOption

func WithMaxUses

func WithMaxUses(maxUses int) WebSearchOption

func WithWebSearchUserLocation

func WithWebSearchUserLocation(location WebSearchLocation) WebSearchOption

Jump to

Keyboard shortcuts

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