anthropic

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

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

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

	APIVersion = "2023-06-01"
)
View Source
const ID = "anthropic"

ID is the reserved plugin identifier for the Anthropic backend.

Variables

View Source
var (
	ErrNoCacheEvidence = anthropicmessages.ErrNoCacheEvidence
	ErrTargetNotFound  = anthropicmessages.ErrTargetNotFound
)

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 (*TokenCounter) CountText

func (*TokenCounter) SupportsCount

func (c *TokenCounter) SupportsCount(ctx context.Context, input app.ProviderCountInput) app.ProviderSupport

Jump to

Keyboard shortcuts

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