Documentation
¶
Overview ¶
Package anthropic implements the Anthropic Messages API backend connector using github.com/anthropics/anthropic-sdk-go. It maps lipapi.Call to POST /v1/messages and emits canonical events from the official SSE stream.
BaseURL must be the API origin only (for example https://api.anthropic.com), without a /v1 suffix; the SDK appends /v1/messages. This differs from OpenAI-style backends where BaseURL often includes /v1.
Model resolution uses the route candidate when present, otherwise the JSON string stored under the anthropic.model extension key (same key as the Anthropic frontend decoder).
Index ¶
- Constants
- Variables
- func BuildCompatible(instanceID, factoryKind string, n yaml.Node, upstream *http.Client) (execbackend.Backend, error)
- func BuildCompatibleWithModelsPath(instanceID, factoryKind string, n yaml.Node, upstream *http.Client, ...) (execbackend.Backend, error)
- func LifecycleAnthropicCompatible(instanceID string, n yaml.Node, upstream *http.Client, ...) (pluginreg.BackendBuildResult, error)
- func ModelCapabilities(model string) lipapi.BackendCaps
- func New(cfg Config) execbackend.Backend
- func ValidateCacheConfig(mode CacheEnrollmentMode, ttl string) error
- type CacheController
- type CacheControllerConfig
- type CacheEnrollmentMode
- type CacheTarget
- type Config
- type RenewalCacheControl
- type RenewalMessage
- type RenewalSnapshot
- type RenewalSystemBlock
- type TokenCounter
- func (c *TokenCounter) CountCall(ctx context.Context, input app.CountCallInput) (app.CountResult, error)
- func (c *TokenCounter) CountOutput(context.Context, app.CountOutputInput) (app.CountResult, error)
- func (c *TokenCounter) CountText(context.Context, app.CountTextInput) (app.CountResult, error)
- func (c *TokenCounter) SupportsCount(ctx context.Context, input app.ProviderCountInput) app.ProviderSupport
Constants ¶
const ( DefaultBaseURL = "https://api.anthropic.com" APIVersion = "2023-06-01" )
const ID = "anthropic"
ID is the reserved plugin identifier for the Anthropic backend.
Variables ¶
var ( ErrNoCacheEvidence = anthropicmessages.ErrNoCacheEvidence ErrTargetNotFound = anthropicmessages.ErrTargetNotFound )
var NewCacheController = anthropicmessages.NewCacheController
Functions ¶
func BuildCompatible ¶
func BuildCompatible(instanceID, factoryKind string, n yaml.Node, upstream *http.Client) (execbackend.Backend, error)
BuildCompatible constructs a built-in Anthropic-compatible backend from strict compatible-mode YAML for one configured runtime instance.
func BuildCompatibleWithModelsPath ¶
func BuildCompatibleWithModelsPath(instanceID, factoryKind string, n yaml.Node, upstream *http.Client, modelsPath string) (execbackend.Backend, error)
BuildCompatibleWithModelsPath constructs an Anthropic-compatible backend with an explicit model-list path. The path is a bounded family quirk seam; an empty path retains the family default (/v1/models).
func LifecycleAnthropicCompatible ¶
func LifecycleAnthropicCompatible(instanceID string, n yaml.Node, upstream *http.Client, _ pluginreg.BackendFactoryDeps) (pluginreg.BackendBuildResult, error)
LifecycleAnthropicCompatible is the standardplugins lifecycle entrypoint.
func ModelCapabilities ¶
func ModelCapabilities(model string) lipapi.BackendCaps
ModelCapabilities returns negotiated backend caps for a resolved Anthropic model id. Rules are intentionally small; expand as catalog data grows.
func New ¶
func New(cfg Config) execbackend.Backend
New returns a runtime backend that invokes the Anthropic Messages API using anthropic-sdk-go.
func ValidateCacheConfig ¶
func ValidateCacheConfig(mode CacheEnrollmentMode, ttl string) error
Types ¶
type CacheController ¶
type CacheController = anthropicmessages.CacheController
Re-export the protocol-layer controller so the direct-Anthropic plugin surface and its tests keep compiling. The production controller lives in the shared anthropicmessages protocol adapter where the backend is built.
type CacheControllerConfig ¶
type CacheControllerConfig = anthropicmessages.CacheControllerConfig
Re-export the protocol-layer controller so the direct-Anthropic plugin surface and its tests keep compiling. The production controller lives in the shared anthropicmessages protocol adapter where the backend is built.
type CacheEnrollmentMode ¶
type CacheEnrollmentMode string
const ( CacheEnrollmentDisabled CacheEnrollmentMode = "disabled" CacheEnrollmentAutomatic CacheEnrollmentMode = "automatic" )
type CacheTarget ¶
type CacheTarget = anthropicmessages.CacheTarget
Re-export the protocol-layer controller so the direct-Anthropic plugin surface and its tests keep compiling. The production controller lives in the shared anthropicmessages protocol adapter where the backend is built.
type Config ¶
type Config struct {
BaseURL string
APIKey string
// BackendPrefix overrides the backend/model-inventory prefix. Empty uses the bundled Anthropic ID.
BackendPrefix string
// APIKeys is the ordered credential list for this backend instance.
// When non-empty, APIKey should match APIKeys[0] for SDK compatibility.
APIKeys []string
// Credentials is the structured credential list. When set, it takes precedence
// over APIKey/APIKeys and preserves non-secret credential IDs for diagnostics.
Credentials []credpool.Credential
// HTTPClient is optional; when nil the SDK default is used.
HTTPClient *http.Client
// SDKMaxRetries optionally sets the official SDK MaxRetries (nil = SDK default).
// Integration tests that assert a single upstream attempt on 429/401 should use a pointer to 0.
SDKMaxRetries *int
// CompatibleModeAuth enables optional credentials for custom-anthropic-compatible.
CompatibleModeAuth bool
// ModelsEndpoint, when set, is the absolute inventory URL from the shared
// endpoint descriptor join table. Empty uses BaseURL+"/v1/models".
ModelsEndpoint string
// CacheEnrollment is independent from keep-warm orchestration. The default
// disabled value preserves existing foreground request behavior.
CacheEnrollment CacheEnrollmentMode
// CacheTTL is valid only for automatic enrollment and must be 5m or 1h.
CacheTTL string
}
Config configures the Anthropic Messages API backend connector (official SDK). BaseURL is the API origin only (e.g. https://api.anthropic.com), without a /v1 suffix; the SDK posts to /v1/messages relative to it.
type RenewalCacheControl ¶
type RenewalCacheControl = anthropicmessages.RenewalCacheControl
Re-export the protocol-layer controller so the direct-Anthropic plugin surface and its tests keep compiling. The production controller lives in the shared anthropicmessages protocol adapter where the backend is built.
type RenewalMessage ¶
type RenewalMessage = anthropicmessages.RenewalMessage
Re-export the protocol-layer controller so the direct-Anthropic plugin surface and its tests keep compiling. The production controller lives in the shared anthropicmessages protocol adapter where the backend is built.
type RenewalSnapshot ¶
type RenewalSnapshot = anthropicmessages.RenewalSnapshot
Re-export the protocol-layer controller so the direct-Anthropic plugin surface and its tests keep compiling. The production controller lives in the shared anthropicmessages protocol adapter where the backend is built.
type RenewalSystemBlock ¶
type RenewalSystemBlock = anthropicmessages.RenewalSystemBlock
Re-export the protocol-layer controller so the direct-Anthropic plugin surface and its tests keep compiling. The production controller lives in the shared anthropicmessages protocol adapter where the backend is built.
type TokenCounter ¶
type TokenCounter struct {
// contains filtered or unexported fields
}
TokenCounter counts Anthropic Messages input tokens through /v1/messages/count_tokens.
func NewTokenCounter ¶
func NewTokenCounter(cfg Config) *TokenCounter
NewTokenCounter returns an Anthropic provider-count adapter.
func (*TokenCounter) CountCall ¶
func (c *TokenCounter) CountCall(ctx context.Context, input app.CountCallInput) (app.CountResult, error)
func (*TokenCounter) CountOutput ¶
func (c *TokenCounter) CountOutput(context.Context, app.CountOutputInput) (app.CountResult, error)
func (*TokenCounter) CountText ¶
func (c *TokenCounter) CountText(context.Context, app.CountTextInput) (app.CountResult, error)
func (*TokenCounter) SupportsCount ¶
func (c *TokenCounter) SupportsCount(ctx context.Context, input app.ProviderCountInput) app.ProviderSupport