Documentation
¶
Overview ¶
Package claude provides Anthropic Claude LLM provider integration.
Index ¶
- Variables
- type Provider
- func (p *Provider) CalculateCost(tokensIn, tokensOut, cachedTokens int) types.CostInfo
- func (p *Provider) GetMultimodalCapabilities() providers.MultimodalCapabilities
- func (p *Provider) MaxContextTokens() int
- func (p *Provider) Model() string
- func (p *Provider) Predict(ctx context.Context, req providers.PredictionRequest) (providers.PredictionResponse, error)
- func (p *Provider) PredictStream(ctx context.Context, req providers.PredictionRequest) (<-chan providers.StreamChunk, error)
- func (p *Provider) SendableMultimodalCapabilities() providers.MultimodalCapabilities
- func (p *Provider) SupportsPromptCaching() bool
- func (p *Provider) WithMediaSettings(m providers.MediaSettings) providers.Provider
- type ToolProvider
- func (p *ToolProvider) BuildTooling(descriptors []*providers.ToolDescriptor) (providers.ProviderTools, error)
- func (p *ToolProvider) PredictStreamWithTools(ctx context.Context, req providers.PredictionRequest, tools any, ...) (<-chan providers.StreamChunk, error)
- func (p *ToolProvider) PredictWithTools(ctx context.Context, req providers.PredictionRequest, ...) (providers.PredictionResponse, []types.MessageToolCall, error)
- func (p *ToolProvider) WithMediaSettings(m providers.MediaSettings) providers.Provider
Constants ¶
This section is empty.
Variables ¶
var ErrClaudeStreamError = errors.New("claude stream error")
ErrClaudeStreamError marks a failure Anthropic reported mid-stream through an error event. The wrapping error carries the error type and message.
Functions ¶
This section is empty.
Types ¶
type Provider ¶
type Provider struct {
providers.BaseProvider
// contains filtered or unexported fields
}
Provider implements the Provider interface for Anthropic Claude
func NewProvider ¶
func NewProvider(id, model, baseURL string, defaults providers.ProviderDefaults, includeRawOutput bool) *Provider
NewProvider creates a new Claude provider
func NewProviderWithCredential ¶
func NewProviderWithCredential( id, model, baseURL string, defaults providers.ProviderDefaults, includeRawOutput bool, cred providers.Credential, platform string, platformConfig *providers.PlatformConfig, ) *Provider
NewProviderWithCredential creates a new Claude provider with explicit credential.
When baseURL is empty the URL is derived from platformConfig for the platforms that support it: Vertex (`publishers/anthropic/models`) and Azure (`openai/deployments/{deployment}`). Callers that pass an explicit baseURL always win.
func (*Provider) CalculateCost ¶
CalculateCost calculates detailed cost breakdown including optional cached tokens. Thin wrapper over costFromUsage, kept for the Provider interface's legacy signature (cachedTokens here means cache READS only — callers that also have cache-write counts, e.g. wire claudeUsage, should call costFromUsage directly instead so cache writes aren't dropped).
func (*Provider) GetMultimodalCapabilities ¶
func (p *Provider) GetMultimodalCapabilities() providers.MultimodalCapabilities
GetMultimodalCapabilities returns Claude's multimodal support capabilities. When the provider config declares its capabilities, the declaration is authoritative for which modalities are enabled; otherwise Claude's built-in defaults apply (images + documents, no audio/video).
func (*Provider) MaxContextTokens ¶ added in v2.17.0
MaxContextTokens returns the model's context window in tokens: the additional_config.context_window override, else the built-in table, else 0 (unknown), which makes the compactor use its default budget.
func (*Provider) Predict ¶
func (p *Provider) Predict(ctx context.Context, req providers.PredictionRequest) (providers.PredictionResponse, error)
Predict runs predictOnce, retrying without any sampling parameter the API rejects for this model (providers.BaseProvider.RetryRejectedParams), and with the other thinking type if the model rejects the one sent.
func (*Provider) PredictStream ¶
func (p *Provider) PredictStream( ctx context.Context, req providers.PredictionRequest, ) (<-chan providers.StreamChunk, error)
PredictStream runs predictStreamOnce, retrying without any sampling parameter the API rejects for this model, and with the other thinking type if the model rejects the one sent.
func (*Provider) SendableMultimodalCapabilities ¶ added in v2.17.0
func (p *Provider) SendableMultimodalCapabilities() providers.MultimodalCapabilities
SendableMultimodalCapabilities returns what the adapter sends whatever the config declares: images (convertImagePartToClaude) and PDF documents (convertDocumentPartToClaude). Audio and video parts fail conversion.
func (*Provider) SupportsPromptCaching ¶
SupportsPromptCaching reports whether prompt caching is active for this provider (supported and not disabled by config). The pipeline uses this to decide whether a zero-cache-read tool loop is worth warning about, so providers without caching don't produce false "caching not engaging" warnings.
func (*Provider) WithMediaSettings ¶ added in v2.13.0
func (p *Provider) WithMediaSettings(m providers.MediaSettings) providers.Provider
WithMediaSettings returns a view of p that uses m's media settings and shares everything else (providers.MediaScoped).
type ToolProvider ¶
type ToolProvider struct {
*Provider
// contains filtered or unexported fields
}
ToolProvider extends ClaudeProvider with tool support
func NewToolProvider ¶
func NewToolProvider( id, model, baseURL string, defaults providers.ProviderDefaults, includeRawOutput bool, ) *ToolProvider
NewToolProvider creates a new Claude provider with tool support
func NewToolProviderWithCredential ¶
func NewToolProviderWithCredential( id, model, baseURL string, defaults providers.ProviderDefaults, includeRawOutput bool, cred providers.Credential, platform string, platformConfig *providers.PlatformConfig, ) *ToolProvider
NewToolProviderWithCredential creates a Claude tool provider with explicit credential.
func (*ToolProvider) BuildTooling ¶
func (p *ToolProvider) BuildTooling(descriptors []*providers.ToolDescriptor) (providers.ProviderTools, error)
BuildTooling converts tool descriptors to Claude format
func (*ToolProvider) PredictStreamWithTools ¶
func (p *ToolProvider) PredictStreamWithTools( ctx context.Context, req providers.PredictionRequest, tools any, toolChoice string, ) (<-chan providers.StreamChunk, error)
PredictStreamWithTools runs predictStreamWithToolsOnce, retrying without any sampling parameter the API rejects for this model, and with the other thinking type if the model rejects the one sent.
func (*ToolProvider) PredictWithTools ¶
func (p *ToolProvider) PredictWithTools( ctx context.Context, req providers.PredictionRequest, tools providers.ProviderTools, toolChoice string, ) (providers.PredictionResponse, []types.MessageToolCall, error)
PredictWithTools runs predictWithToolsOnce, retrying without any sampling parameter the API rejects for this model, and with the other thinking type if the model rejects the one sent.
func (*ToolProvider) WithMediaSettings ¶ added in v2.13.0
func (p *ToolProvider) WithMediaSettings(m providers.MediaSettings) providers.Provider
WithMediaSettings returns a view of p, and of the Provider it wraps, that uses m's media settings (providers.MediaScoped).