claude

package
v2.20.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 16 Imported by: 3 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package claude provides Anthropic Claude LLM provider integration.

Index

Constants

This section is empty.

Variables

View Source
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

func (p *Provider) CalculateCost(tokensIn, tokensOut, cachedTokens int) types.CostInfo

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

func (p *Provider) MaxContextTokens() int

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) Model

func (p *Provider) Model() string

Model returns the model name/identifier used by this provider.

func (*Provider) Predict

Predict runs predictOnce, retrying without any sampling parameter the API rejects for this model (providers.BaseProvider.RetryRejectedParams).

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.

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

func (p *Provider) SupportsPromptCaching() bool

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.

func (*ToolProvider) PredictWithTools

PredictWithTools runs predictWithToolsOnce, retrying without any sampling parameter the API rejects for this model.

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).

Jump to

Keyboard shortcuts

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