Package model/anthropic
Go module github.com/bide-ai/bide; all packages.
github.com/bide-ai/bide/model/anthropic · pkg.go.dev · Stability: core
Package anthropic adapts Anthropic's Messages API to agent.Model.
type Model
go
type Model struct {
// contains filtered or unexported fields
}Model is an Anthropic Messages API adapter implementing agent.Model.
Constructors and functions
func New(apiKey string, opts ...Option) *Model: New constructs an Anthropic model adapter.
Methods
func (m *Model) Describe() agent.ModelInfo: Describe reports the adapter's identity: provider "anthropic", the configured model ID, and no JSON-schema response format (a request that sets one fails with agent.ErrConfig).func (m Model) Format(f fmt.State, _ rune): Format writes String for every verb, so no fmt verb (%v, %+v, %#v, %s, %x, ...) prints the key.func (m *Model) RequiresToolsForRequired() bool: RequiresToolsForRequired implements agent.ToolRules: Anthropic refuses tool choice "required" with no tools declared.func (m *Model) Stream(ctx context.Context, req agent.Request) (*agent.Stream, error): Stream implements agent.Model.func (m Model) String() string: String describes the adapter by its model id.func (m *Model) ToolNameRule() *regexp.Regexp: ToolNameRule implements agent.ToolRules: the tool names Anthropic accepts,^[a-zA-Z0-9_-]{1,64}$, so agent.New refuses any other name when the agent is built.
type Option
go
type Option func(*Model)Option configures a Model in New.
Constructors and functions
func WithBaseURL(u string) Option: WithBaseURL sets the API host, for a proxy or a compatible endpoint; /v1/messages is appended to it.func WithHTTPClient(c *http.Client) Option: WithHTTPClient sets the HTTP client requests are sent with.func WithMaxResponseBytes(n int64) Option: WithMaxResponseBytes caps how many bytes of one streamed reply the adapter reads: a reply that runs longer fails with agent.ErrResponseTooLarge, which middleware.Retryable does not retry.func WithMaxTokens(n int) Option: WithMaxTokens sets the default limit on tokens in a reply; a request's Sampling.MaxTokens overrides it.func WithModel(id string) Option: WithModel sets the model ID sent with every request.func WithPromptCache() Option: WithPromptCache turns on Anthropic prompt caching: cache_control breakpoints are placed on the system prompt and the tool definitions, the large, constant prefix an agent loop resends every turn, so repeat turns are billed at the cache-read rate.func WithToolResultCodec(c provider.ToolResultCodec) Option: WithToolResultCodec encodes tool results sent to the model with c instead of raw JSON (for example GCF, to cut tokens on structured output).