anthropic

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ToolNameRegex = `^[a-zA-Z0-9_-]{1,64}$`

	// DefaultMaxOutputTokens is used when the request config does not set
	// MaxTokens, which the Anthropic API requires. It matches the JS plugin's
	// DEFAULT_MAX_OUTPUT_TOKENS and is low enough for every Claude model.
	DefaultMaxOutputTokens = 4096
)

Variables

This section is empty.

Functions

func DisplayName added in v1.12.0

func DisplayName(provider string) string

DisplayName is how a provider is spelled in a model's dev UI label. Plugins that curate their own labels join it with internal.ProviderLabel, so every Claude model names its provider the same way whichever plugin serves it.

func Generate

func Generate(
	ctx context.Context,
	client anthropic.Client,
	provider string,
	model string,
	input *ai.ModelRequest,
	config anthropic.MessageNewParams,
	cb func(context.Context, *ai.ModelResponseChunk) error,
) (*ai.ModelResponse, error)

Generate function defines how a generate request is done in Anthropic models. config is the request's config, already deserialized by the framework, and is the base the request is built on.

func NewModel added in v1.12.0

func NewModel(client anthropic.Client, provider, name string, opts ai.ModelOptions) *ai.ModelAction

NewModel creates a Claude model action without registering it. name is both the Genkit action name and the model ID requests are sent to: Anthropic resolves an alias like claude-opus-4-5 to its current dated release itself.

opts is used as given, except that a nil ConfigSchema defaults to the reflected anthropic.MessageNewParams schema and an empty Label is derived from the provider and the name. The framework validates the request's config against that schema and deserializes it into anthropic.MessageNewParams before the model function runs.

func WrapAPIError added in v1.12.0

func WrapAPIError(err error) error

WrapAPIError wraps an error the Anthropic SDK returned for an HTTP response in a status.Error carrying the status the server reported, so status-aware middleware (retry, fallback, ...) can tell a rate limit from a malformed request. Without it every API failure is unclassified, which the retry middleware treats as retryable: a 400 would be reissued unchanged until the attempts ran out.

Values that are not an SDK API error pass through untouched. Those are transport failures the SDK does not wrap, and leaving them unclassified is the right answer: a connection reset really is worth retrying.

Types

This section is empty.

Jump to

Keyboard shortcuts

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