provider/anthropic
import "github.com/barevoidco/zelk/core/provider/anthropic"Package anthropic implements the Anthropic Messages provider port. It translates wire formats without changing zelk’s shared harness behavior. Open tool schemas retain their server contract with non-strict rendering; canonical tools retain the adapter’s existing schema dialect.
Client
Section titled “Client”type Client struct { // contains filtered or unexported fields}Client calls Anthropic Messages. It is safe for concurrent use.
func New(baseURL string, opts ...Option) (*Client, error)New creates a client for baseURL, normally https://api.anthropic.com/v1. It performs no I/O and reads no process configuration.
Example
c, err := anthropic.New("https://api.anthropic.com/v1", anthropic.WithAPIKey("host-supplied-key"))if err != nil { fmt.Println(err) return}defer c.Close()fmt.Println(c.Family())// Output: anthropicOutput:
anthropicClient.Capabilities
Section titled “Client.Capabilities”func (c *Client) Capabilities(ctx context.Context, model string) (provider.Caps, error)Capabilities returns the injected capability snapshot without network I/O.
Client.Close
Section titled “Client.Close”func (c *Client) Close() errorClose releases idle connections owned by this client. Injected clients are left to their owners; active calls retain their original contexts.
Client.Family
Section titled “Client.Family”func (c *Client) Family() history.FamilyFamily identifies the Anthropic Messages wire format.
Client.Models
Section titled “Client.Models”func (c *Client) Models(ctx context.Context) ([]provider.Model, error)Models returns the models declared with WithModels.
Client.Reservation
Section titled “Client.Reservation”func (c *Client) Reservation(req *provider.Request, caps provider.Caps) event.TokensReservation conservatively bounds the exact rendered body when the host has recorded a byte input bound. Otherwise it reserves the whole context window.
Client.SearchBackend
Section titled “Client.SearchBackend”func (c *Client) SearchBackend(model string) (*Search, error)SearchBackend returns a backend using model and this client’s credentials. The caller must keep the client open until all searches finish. The endpoint and model must support web_search_20250305 with thinking disabled; no request is made here.
Example
c, err := anthropic.New("https://api.anthropic.com/v1", anthropic.WithAPIKey("host-supplied-key"))if err != nil { panic(err)}defer c.Close()backend, err := c.SearchBackend("claude-haiku-5-5")if err != nil { panic(err)}// Inject backend with zelk.WithSearch; this example makes no requests.fmt.Printf("%T\n", backend)// Output: *anthropic.SearchOutput:
*anthropic.SearchClient.Stream
Section titled “Client.Stream”func (c *Client) Stream(ctx context.Context, req *provider.Request) (provider.Stream, error)Stream prepares a lazy single-use stream. Iteration owns and closes its HTTP response; breaking iteration or cancelling ctx stops the call.
Option
Section titled “Option”type Option func(*Client)Option configures a Client.
WithAPIKey
Section titled “WithAPIKey”func WithAPIKey(key string) OptionWithAPIKey sets the credential sent only to the provider.
WithCache
Section titled “WithCache”func WithCache(enabled bool) OptionWithCache enables or disables explicit and automatic prompt cache breakpoints. Caching is enabled by default.
WithCapabilities
Section titled “WithCapabilities”func WithCapabilities(caps provider.Caps) OptionWithCapabilities sets the model capabilities supplied by the host.
WithHTTPClient
Section titled “WithHTTPClient”func WithHTTPClient(hc *http.Client) OptionWithHTTPClient injects the caller-owned HTTP client. It must be safe for concurrent use.
WithModels
Section titled “WithModels”func WithModels(models ...provider.Model) OptionWithModels declares the models the client offers, each with its own capabilities, for Capabilities and WithModels to report. Capabilities remain those of any model not declared.
WithStreamIdleTimeout
Section titled “WithStreamIdleTimeout”func WithStreamIdleTimeout(d time.Duration) OptionWithStreamIdleTimeout sets the maximum interval without response bytes on a stream, including with an injected HTTP client. It must be positive and defaults to five minutes. Expiry closes the body and returns ErrorTransient.
Example
client, err := anthropic.New("https://example.test/v1", anthropic.WithStreamIdleTimeout(2*time.Minute))if err != nil { panic(err)}defer client.Close()fmt.Println("client configured")// Output: client configuredOutput:
client configuredWithToolLoading
Section titled “WithToolLoading”func WithToolLoading(loads func(model string) bool) OptionWithToolLoading says which models load deferred tools natively, through tool_reference blocks (docs/design/tools.md, deferred tools): Anthropic documents it for Claude Haiku 4.5, Sonnet 4.5, Opus 4.5 and later. A gateway may reject the fields, so a host sets it only for an endpoint known to accept them. A model declared with DeferredTools loads them regardless.
Search
Section titled “Search”type Search struct { // contains filtered or unexported fields}Search is a native Messages web search backend. It borrows its client’s transport and credentials, and is safe for concurrent use.
Search.Limit
Section titled “Search.Limit”func (s *Search) Limit() event.TokensLimit bounds the entire native request, including server-supplied search context. Unknown model limits are zero and cannot support hard token budgets.
Example
c, err := anthropic.New("https://unused.test/v1", anthropic.WithCapabilities(provider.Caps{ContextWindow: 200000}))if err != nil { panic(err)}defer c.Close()backend, err := c.SearchBackend("fast")if err != nil { panic(err)}limit := backend.Limit()fmt.Println(limit.Input, limit.Output)// Output: 200000 2048Output:
200000 2048Search.Search
Section titled “Search.Search”func (s *Search) Search(ctx context.Context, q search.Query) (search.Response, error)Search makes one bounded request with at most one native search. When both domain lists are set, allowed domains go to the server and blocked domains are applied locally, because Messages rejects both lists in one request.