anthropic

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package anthropic is the tacklr.Model for Claude models on the Claude API (the Messages API). It streams each request, replays thinking blocks unchanged, counts tokens with the API's count endpoint, and caches the stable prefix of each request.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrIncompleteStream is a stream that closed before message_stop.
	ErrIncompleteStream = provider.ErrIncompleteStream
	// ErrMalformedStream is a stream event that is not valid JSON.
	ErrMalformedStream = provider.ErrMalformedStream
)

Functions

This section is empty.

Types

type APIStatusError

type APIStatusError = provider.APIStatusError

APIStatusError is an HTTP error answer from the API. Find it in a wrapped chain with errors.As.

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model holds only model and endpoint settings. Each request carries its own prompt, so one Model is safe to share across sessions.

func New

func New(client *http.Client) *Model

New is a client over client, whose requests carry their trace context (W3C traceparent). A nil client is http.DefaultClient's settings.

func (*Model) CountTokens

func (m *Model) CountTokens(ctx context.Context, req tacklr.ModelRequest) (int, error)

CountTokens counts req's input tokens with the count endpoint. A gateway without the endpoint (HTTP 404) fails with tacklr.ErrCannotCount.

func (*Model) Invoke

func (m *Model) Invoke(ctx context.Context, req tacklr.ModelRequest) (chan tacklr.LLMResponseChunk, error)

Invoke streams one response to req.

func (*Model) MaxContextWindow

func (m *Model) MaxContextWindow() (int, error)

MaxContextWindow is the window WithContextWindow set, else the known window of the model id.

func (*Model) ModelTelemetryIdentity

func (m *Model) ModelTelemetryIdentity() telemetry.ModelIdentity

ModelTelemetryIdentity names the provider and model for model spans.

func (*Model) SupportsMIME

func (m *Model) SupportsMIME(mimeType string) bool

SupportsMIME reports the input types every Claude model accepts: text, JPEG, PNG, GIF and WebP images, and PDF documents. Any model id works, such as a Foundry deployment name: a Messages API serves Claude models.

func (*Model) WithApiKey

func (m *Model) WithApiKey(key string) *Model

WithApiKey sets the API key, sent as x-api-key.

func (*Model) WithContextWindow

func (m *Model) WithContextWindow(n int) *Model

WithContextWindow sets the model's context window in tokens, for a model id the client does not know, such as a Foundry deployment name.

func (*Model) WithEffort

func (m *Model) WithEffort(effort string) *Model

WithEffort sets output_config.effort: low, medium, high, xhigh or max. Empty sends none, so the model's default applies. Defaults differ by model: claude-opus-5-5 defaults to medium.

func (*Model) WithMaxTokens

func (m *Model) WithMaxTokens(n int) *Model

WithMaxTokens sets max_tokens, the limit on each response. The default is 64,000.

func (*Model) WithModel

func (m *Model) WithModel(model string) *Model

WithModel sets the model id, such as claude-opus-5-5.

func (*Model) WithURL

func (m *Model) WithURL(url string) *Model

WithURL sets the API's base URL: a gateway in front of the Claude API, or another Messages API, such as Microsoft Foundry's https://<resource>.services.ai.azure.com/anthropic/v1. The default is https://api.anthropic.com/v1.

Jump to

Keyboard shortcuts

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