Documentation
¶
Overview ¶
Package anthropicwire is the Anthropic Messages API adapter — the ONE implementation of the Messages dialect (cache_control placement, adaptive thinking, streaming decode, tool calls, native web search, usage parsing), shared by the hosted gateway (its own or the user's BYOK key) and the CLI's direct endpoint mode (api.anthropic.com). Transport encoding only — no routing policy, no metering.
Index ¶
- Constants
- type Anthropic
- func (a *Anthropic) BaseURL() string
- func (a *Anthropic) Complete(ctx context.Context, r wire.Request) (wire.Response, error)
- func (a *Anthropic) Model() string
- func (a *Anthropic) SetBaseURL(u string)
- func (a *Anthropic) Stream(ctx context.Context, r wire.Request, h wire.StreamHandler) (wire.Response, error)
- func (a *Anthropic) WebFetch(ctx context.Context, url string) (string, wire.Response, error)
- func (a *Anthropic) WebSearch(ctx context.Context, query string) (string, wire.Response, error)
Constants ¶
const EnvAnthropicKey = "ANTHROPIC_API_KEY"
EnvAnthropicKey is the environment variable holding the Anthropic API key.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Anthropic ¶
type Anthropic struct {
// contains filtered or unexported fields
}
Anthropic is a minimal ModelProvider backed by the Claude Messages API. The struct fields are kept exactly as before so tests can override baseURL.
func NewAnthropic ¶
NewAnthropic returns a client using the given credential. A normal sk-ant-api* key takes the clean x-api-key path; a Claude subscription OAuth token (cc-*/eyJ*/sk-ant-oat*) turns on the Claude Code compatibility mode (see oauth.go). baseURL is left empty so the SDK defaults to https://api.anthropic.com; tests override it via a.baseURL = srv.URL.
func (*Anthropic) Complete ¶
Complete satisfies the non-streamed contract by streaming under the hood and assembling the full Response, discarding the live deltas. Anthropic's SDK REFUSES a true non-streaming request whose estimated time exceeds 10 minutes — for a large max_tokens (e.g. an Opus turn) client.go's CalculateNonStreamingTimeout returns "streaming is required for operations that may take longer than 10 minutes", which the gateway then surfaces as a 502. Streaming sidesteps that ceiling entirely.
This is deliberately Anthropic-ONLY (it lives in this provider): Fireworks/vLLM keep their own non-streaming Complete, because streaming there breaks tool-call assembly.
func (*Anthropic) Model ¶
Model returns the default model id (for display / StrongProvider). The Anthropic provider serves whatever model resolve.go chose; this is the strong-tier default (Sonnet — the balanced tier), matching OpenAI.Model()'s Terra default.
func (*Anthropic) SetBaseURL ¶
SetBaseURL points the adapter at a different Messages-API host (tests, proxies, enterprise gateways). "" restores the SDK default.
func (*Anthropic) Stream ¶
func (a *Anthropic) Stream(ctx context.Context, r wire.Request, h wire.StreamHandler) (wire.Response, error)
Stream sends a streaming Messages request, forwarding text/usage to h as they arrive, and returns the fully assembled Response. It runs a bounded, emitted-aware retry for transient failures (429/5xx before the first token) — the same pattern the OpenAI provider uses, and the reliability the escalation paths (self_heal, plan review) most need. A stream can't resume mid-flight, so it only re-attempts when nothing was forwarded to h yet.
func (*Anthropic) WebFetch ¶
WebFetch retrieves a URL via Anthropic's server-side web_fetch tool and returns its readable content (the fetched document text, falling back to the model's text). Handles text + PDF; does NOT render JavaScript pages. No extra charge beyond tokens. The URL is in the request context, satisfying web_fetch's "URL must appear in context" rule.