Documentation
¶
Overview ¶
Package anthropic provides a native Anthropic Messages API client. It keeps Anthropic's top-level system prompt, typed content blocks, tool_result/tool_use turns, thinking controls, and SSE lifecycle intact by delegating wire semantics to inference/codec/anthropicapi.
Index ¶
- func New(selected model.Model, key auth.APIKey, options ...Option) (inference.Client, error)
- func NewCounter(key auth.APIKey) (contextcount.ContextCounter, error)
- type CacheControlOptions
- type Counter
- type CounterEndpointError
- type CounterEndpointReason
- type CounterRequestError
- type CounterRequestReason
- type CounterResponseError
- type CounterResponseField
- type CounterResponseFieldError
- type CounterResponseFieldReason
- type CounterResponseReason
- type CounterStateError
- type CounterStateReason
- type Option
- type OptionError
- type ThinkingOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New constructs an Anthropic native Messages API client. The selected model must identify Anthropic and model.APIFormatAnthropic. An empty model base URL uses Anthropic's canonical API root.
func NewCounter ¶
func NewCounter(key auth.APIKey) (contextcount.ContextCounter, error)
NewCounter constructs an exact Anthropic Messages input-token counter.
Types ¶
type CacheControlOptions ¶
CacheControlOptions selects Anthropic's prompt-cache boundary.
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter is a separately constructed exact Anthropic Messages count_tokens client. It is not embedded in the inference client.
func (*Counter) CountContext ¶
func (c *Counter) CountContext(ctx context.Context, req inference.Request) (contextcount.ContextCount, error)
func (*Counter) CounterCapability ¶
func (c *Counter) CounterCapability() contextcount.CounterCapability
type CounterEndpointError ¶
type CounterEndpointError struct{ Reason CounterEndpointReason }
func (*CounterEndpointError) Error ¶
func (e *CounterEndpointError) Error() string
type CounterEndpointReason ¶
type CounterEndpointReason string
const ( CounterEndpointMalformed CounterEndpointReason = "malformed endpoint" CounterEndpointMissingHost CounterEndpointReason = "missing endpoint host" CounterEndpointCredentials CounterEndpointReason = "endpoint contains credentials" CounterEndpointUnsupportedScheme CounterEndpointReason = "unsupported endpoint scheme" CounterEndpointInsecureTransport CounterEndpointReason = "plaintext endpoint is not loopback" )
type CounterRequestError ¶
type CounterRequestError struct {
Reason CounterRequestReason
Err error
}
func (*CounterRequestError) Error ¶
func (e *CounterRequestError) Error() string
func (*CounterRequestError) Unwrap ¶
func (e *CounterRequestError) Unwrap() error
type CounterRequestReason ¶
type CounterRequestReason string
const ( CounterRequestEncodeFailed CounterRequestReason = "Messages request encoding failed" CounterRequestMalformed CounterRequestReason = "encoded request is not one JSON object" )
type CounterResponseError ¶
type CounterResponseError struct {
Reason CounterResponseReason
Err error
}
func (*CounterResponseError) Error ¶
func (e *CounterResponseError) Error() string
func (*CounterResponseError) Unwrap ¶
func (e *CounterResponseError) Unwrap() error
type CounterResponseField ¶
type CounterResponseField string
const CounterResponseFieldInputTokens CounterResponseField = "input_tokens"
type CounterResponseFieldError ¶
type CounterResponseFieldError struct {
Field CounterResponseField
Reason CounterResponseFieldReason
}
func (*CounterResponseFieldError) Error ¶
func (e *CounterResponseFieldError) Error() string
type CounterResponseFieldReason ¶
type CounterResponseFieldReason string
const CounterResponseFieldDuplicate CounterResponseFieldReason = "duplicate"
type CounterResponseReason ¶
type CounterResponseReason string
const ( CounterResponseMalformed CounterResponseReason = "malformed response" CounterResponseMissingCount CounterResponseReason = "missing input_tokens" CounterResponseInvalidCount CounterResponseReason = "invalid input_tokens" CounterResponseDuplicateField CounterResponseReason = "duplicate response field" CounterResponseBodyTooLarge CounterResponseReason = "response body too large" )
type CounterStateError ¶
type CounterStateError struct{ Reason CounterStateReason }
func (*CounterStateError) Error ¶
func (e *CounterStateError) Error() string
type CounterStateReason ¶
type CounterStateReason string
const ( CounterStateNilReceiver CounterStateReason = "nil counter" CounterStateNilContext CounterStateReason = "nil context" CounterStateMissingEndpoint CounterStateReason = "missing endpoint" CounterStateMissingAuthenticator CounterStateReason = "missing authenticator" CounterStateMissingHTTPDoer CounterStateReason = "missing HTTP doer" CounterStateInvalidTimeout CounterStateReason = "invalid timeout" )
type Option ¶
type Option func(*config)
Option customizes an Anthropic Messages client at construction time.
func WithBetaHeaders ¶
WithBetaHeaders replaces the Anthropic beta feature header values. The default matches the currently documented OpenCode Anthropic integration.
func WithMetadataUserID ¶
WithMetadataUserID sets Anthropic's supported metadata.user_id field.
func WithPromptCacheControl ¶
func WithPromptCacheControl(options CacheControlOptions) Option
WithPromptCacheControl marks the system prompt's cache boundary. The request codec turns Anthropic's string system prompt into its native text content-block form so cache_control remains a first-class block field.
func WithThinking ¶
func WithThinking(options ThinkingOptions) Option
WithThinking sets Anthropic's native thinking configuration. It is encoded as `thinking` and, when Effort is set, `output_config.effort`.
type OptionError ¶
OptionError reports a local provider-option encoding failure.
func (*OptionError) Error ¶
func (e *OptionError) Error() string
func (*OptionError) Unwrap ¶
func (e *OptionError) Unwrap() error
type ThinkingOptions ¶
type ThinkingOptions struct {
Type string `json:"type"`
Effort string `json:"effort,omitempty"`
BudgetTokens *int `json:"budget_tokens,omitempty"`
}
ThinkingOptions controls Anthropic's native thinking request fields. Type is normally "adaptive" for current Claude models; BudgetTokens is retained for providers/models that still expose the manual thinking mode.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package subscription exposes the Anthropic subscription registration policy boundary.
|
Package subscription exposes the Anthropic subscription registration policy boundary. |