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
- Variables
- func NewAnthropicOAuthTokenProvider(credentials AnthropicOAuthCredentials, opts AnthropicOAuthTokenProviderOptions) sigma.OAuthTokenProvider
- func ProviderAuth(opts AnthropicOAuthTokenProviderOptions) sigma.ProviderAuth
- func Register(registry *sigma.Registry, providerID sigma.ProviderID, opts ...ProviderOption) error
- func RegisterAuth(registry *sigma.Registry, opts AnthropicOAuthTokenProviderOptions, ...) error
- func RegisterDefault(providerID sigma.ProviderID, opts ...ProviderOption) error
- func RegisterDefaultAuth(opts AnthropicOAuthTokenProviderOptions, registerOpts ...sigma.RegisterOption) error
- func RegisterVertex(registry *sigma.Registry, providerID sigma.ProviderID, ...) error
- func RegisterVertexDefault(providerID sigma.ProviderID, opts ...VertexProviderOption) error
- type AnthropicBrowserAuthInfo
- type AnthropicBrowserLoginOptions
- type AnthropicBrowserManualPrompt
- type AnthropicOAuthCredentials
- type AnthropicOAuthTokenProviderOptions
- type MessagesCompat
- type Provider
- type ProviderOption
- type VertexConfig
- type VertexCredentialMode
- type VertexProvider
- type VertexProviderOption
- func WithVertexBaseURL(baseURL string) VertexProviderOption
- func WithVertexConfig(config VertexConfig) VertexProviderOption
- func WithVertexHTTPClient(client *http.Client) VertexProviderOption
- func WithVertexHeader(key, value string) VertexProviderOption
- func WithVertexHeaders(headers map[string]string) VertexProviderOption
- func WithVertexMessagesCompat(compat MessagesCompat) VertexProviderOption
- func WithVertexTokenProvider(tokenProvider sigma.OAuthTokenProvider) VertexProviderOption
- type WebFetchCitations
- type WebFetchOption
- type WebSearchLocation
- type WebSearchOption
Constants ¶
const (
DefaultBaseURL = "https://api.anthropic.com/v1"
)
Variables ¶
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 NewAnthropicOAuthTokenProvider ¶ added in v0.5.0
func NewAnthropicOAuthTokenProvider(credentials AnthropicOAuthCredentials, opts AnthropicOAuthTokenProviderOptions) sigma.OAuthTokenProvider
NewAnthropicOAuthTokenProvider adapts caller-managed Anthropic OAuth credentials to Sigma's OAuthTokenProvider interface. Refreshed credentials are kept in memory and passed to OnRefresh for caller persistence.
func ProviderAuth ¶ added in v0.6.0
func ProviderAuth(opts AnthropicOAuthTokenProviderOptions) sigma.ProviderAuth
ProviderAuth returns Anthropic API-key and OAuth auth descriptors.
func Register ¶
func Register(registry *sigma.Registry, providerID sigma.ProviderID, opts ...ProviderOption) error
Register adds an Anthropic Messages-compatible text provider to registry.
func RegisterAuth ¶ added in v0.6.0
func RegisterAuth(registry *sigma.Registry, opts AnthropicOAuthTokenProviderOptions, registerOpts ...sigma.RegisterOption) error
RegisterAuth registers Anthropic auth descriptors on registry.
func RegisterDefault ¶
func RegisterDefault(providerID sigma.ProviderID, opts ...ProviderOption) error
RegisterDefault adds an Anthropic Messages-compatible text provider to sigma's default registry.
func RegisterDefaultAuth ¶ added in v0.6.0
func RegisterDefaultAuth(opts AnthropicOAuthTokenProviderOptions, registerOpts ...sigma.RegisterOption) error
RegisterDefaultAuth registers Anthropic auth descriptors on the default registry.
func RegisterVertex ¶ added in v0.4.0
func RegisterVertex(registry *sigma.Registry, providerID sigma.ProviderID, opts ...VertexProviderOption) error
RegisterVertex adds a Vertex Anthropic text provider to registry.
func RegisterVertexDefault ¶ added in v0.4.0
func RegisterVertexDefault(providerID sigma.ProviderID, opts ...VertexProviderOption) error
RegisterVertexDefault adds a Vertex Anthropic text provider to sigma's default registry.
Types ¶
type AnthropicBrowserAuthInfo ¶ added in v0.5.0
AnthropicBrowserAuthInfo reports the authorization URL that callers should open in a browser to complete Anthropic OAuth login.
type AnthropicBrowserLoginOptions ¶ added in v0.5.0
type AnthropicBrowserLoginOptions struct {
HTTPClient *http.Client
OnAuth func(AnthropicBrowserAuthInfo)
OnManualCode func(context.Context, AnthropicBrowserManualPrompt) (string, error)
}
AnthropicBrowserLoginOptions configures Anthropic browser callback login.
type AnthropicBrowserManualPrompt ¶ added in v0.5.0
type AnthropicBrowserManualPrompt struct {
Message string
}
AnthropicBrowserManualPrompt describes the fallback prompt for manually pasting an authorization code or redirect URL.
type AnthropicOAuthCredentials ¶ added in v0.5.0
AnthropicOAuthCredentials carries Anthropic (Claude Pro/Max) OAuth tokens. Callers own persistence; Sigma never stores these credentials.
func LoginAnthropicBrowser ¶ added in v0.5.0
func LoginAnthropicBrowser(ctx context.Context, opts AnthropicBrowserLoginOptions) (AnthropicOAuthCredentials, error)
LoginAnthropicBrowser runs the Anthropic (Claude Pro/Max) browser callback OAuth flow and returns credentials for caller-managed persistence.
func RefreshAnthropicToken ¶ added in v0.5.0
func RefreshAnthropicToken(ctx context.Context, refreshToken string, opts AnthropicOAuthTokenProviderOptions) (AnthropicOAuthCredentials, error)
RefreshAnthropicToken refreshes Anthropic OAuth credentials from a refresh token.
type AnthropicOAuthTokenProviderOptions ¶ added in v0.5.0
type AnthropicOAuthTokenProviderOptions struct {
HTTPClient *http.Client
Now func() time.Time
RefreshBefore time.Duration
OnRefresh func(context.Context, AnthropicOAuthCredentials) error
}
AnthropicOAuthTokenProviderOptions configures the OAuth token provider returned by NewAnthropicOAuthTokenProvider.
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.
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 VertexConfig ¶ added in v0.4.0
type VertexConfig struct {
ProjectID string
Location string
Publisher string
APIVersion string
CredentialMode VertexCredentialMode
}
VertexConfig carries Vertex Anthropic request configuration.
type VertexCredentialMode ¶ added in v0.4.0
type VertexCredentialMode string
VertexCredentialMode selects the Google Vertex AI authentication path.
const ( // VertexCredentialAuto resolves a sigma credential first, then falls back to // the configured token provider when no API key or token is available. VertexCredentialAuto VertexCredentialMode = VertexCredentialMode(vertexai.CredentialAuto) // VertexCredentialAPIKey requires an API-key credential. VertexCredentialAPIKey VertexCredentialMode = VertexCredentialMode(vertexai.CredentialAPIKey) // VertexCredentialToken requires an OAuth token credential. VertexCredentialToken VertexCredentialMode = VertexCredentialMode(vertexai.CredentialToken) )
type VertexProvider ¶ added in v0.4.0
type VertexProvider struct {
// contains filtered or unexported fields
}
VertexProvider adapts Anthropic Claude on Vertex AI to sigma.
func NewVertexProvider ¶ added in v0.4.0
func NewVertexProvider(opts ...VertexProviderOption) *VertexProvider
NewVertexProvider constructs a Vertex Anthropic provider.
func (*VertexProvider) API ¶ added in v0.4.0
func (p *VertexProvider) API() sigma.API
API reports the Anthropic Messages API surface.
type VertexProviderOption ¶ added in v0.4.0
type VertexProviderOption func(*VertexProvider)
VertexProviderOption configures a VertexProvider.
func WithVertexBaseURL ¶ added in v0.4.0
func WithVertexBaseURL(baseURL string) VertexProviderOption
WithVertexBaseURL configures the Vertex service base URL including API version.
func WithVertexConfig ¶ added in v0.4.0
func WithVertexConfig(config VertexConfig) VertexProviderOption
WithVertexConfig configures provider-level Vertex routing and auth defaults.
func WithVertexHTTPClient ¶ added in v0.4.0
func WithVertexHTTPClient(client *http.Client) VertexProviderOption
WithVertexHTTPClient configures the provider fallback HTTP client.
func WithVertexHeader ¶ added in v0.4.0
func WithVertexHeader(key, value string) VertexProviderOption
WithVertexHeader configures a provider default request header.
func WithVertexHeaders ¶ added in v0.4.0
func WithVertexHeaders(headers map[string]string) VertexProviderOption
WithVertexHeaders configures provider default request headers.
func WithVertexMessagesCompat ¶ added in v0.4.0
func WithVertexMessagesCompat(compat MessagesCompat) VertexProviderOption
WithVertexMessagesCompat overrides detected Anthropic-compatible endpoint behavior.
func WithVertexTokenProvider ¶ added in v0.4.0
func WithVertexTokenProvider(tokenProvider sigma.OAuthTokenProvider) VertexProviderOption
WithVertexTokenProvider configures an ADC or OAuth token provider.
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 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