anthropic

package
v0.25.2 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 15 Imported by: 0

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

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

func NewAnthropic(apiKey string) *Anthropic

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

func (a *Anthropic) BaseURL() string

BaseURL reports the configured override ("" = the SDK default).

func (*Anthropic) Complete

func (a *Anthropic) Complete(ctx context.Context, r wire.Request) (wire.Response, error)

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

func (a *Anthropic) Model() string

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

func (a *Anthropic) SetBaseURL(u string)

SetBaseURL points the adapter at a different Messages-API host (tests, proxies, enterprise gateways). "" restores the SDK default.

func (*Anthropic) Stream

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

func (a *Anthropic) WebFetch(ctx context.Context, url string) (string, wire.Response, error)

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.

func (*Anthropic) WebSearch

func (a *Anthropic) WebSearch(ctx context.Context, query string) (string, wire.Response, error)

WebSearch answers a query (or "read this URL: …" request) using Anthropic's server-side web_search tool, returning the synthesized text. The API runs the searches within the single turn; we just return the assistant's text blocks.

Jump to

Keyboard shortcuts

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