Documentation
¶
Index ¶
- func IsDefinedModel(g *genkit.Genkit, id string) booldeprecated
- func Model(g *genkit.Genkit, id string) ai.Modeldeprecated
- func ModelRef(id string, config *anthropic.MessageNewParams) ai.ModelRef
- type Anthropic
- func (a *Anthropic) DefineModel(g *genkit.Genkit, id string, opts *ai.ModelOptions) (ai.Model, error)deprecated
- func (a *Anthropic) Init(ctx context.Context) []api.Action
- func (a *Anthropic) ListActions(ctx context.Context) []api.ActionDesc
- func (a *Anthropic) Name() string
- func (a *Anthropic) ResolveAction(atype api.ActionType, id string) api.Action
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsDefinedModel
deprecated
IsDefinedModel reports whether a model is already registered. The lookup deliberately does not resolve dynamically: a resolving lookup would ask the plugin to resolve the very model the caller is checking for, registering it and answering true for any ID the Anthropic API can serve.
Deprecated: this existed to guard a registration call that could panic on a duplicate. Capabilities now come from Anthropic.Models, which nothing has to register and which no ordering can defeat, leaving this a question about registry state that applications do not need to ask.
func Model
deprecated
Model returns a previously registered model.
Deprecated: Generation resolves a model from its name, so looking one up first is rarely necessary: pass ai.WithModelName("anthropic/claude-opus-4-5") or, to carry config with it, ModelRef. Use genkit.LookupModel when the action itself is what you need.
func ModelRef ¶ added in v1.12.0
func ModelRef(id string, config *anthropic.MessageNewParams) ai.ModelRef
ModelRef names a Claude model and carries the config to generate with, so the config is typed at the call site instead of an any the model checks at runtime. A nil config leaves the request's config unset.
ai.WithModel(anthropic.ModelRef("claude-opus-4-5", &sdk.MessageNewParams{
MaxTokens: 1024,
}))
id is the model ID, with or without the provider prefix: "claude-opus-4-5" and "anthropic/claude-opus-4-5" name the same model, as they do everywhere else in this package.
This package and the Anthropic SDK are both named anthropic, so one of them needs an import alias; the example above aliases the SDK to sdk.
Types ¶
type Anthropic ¶
type Anthropic struct {
// APIKey is the key requests are authenticated with. When empty, the
// ANTHROPIC_API_KEY environment variable is used, and [Anthropic.Init]
// panics unless authentication arrives another way: an auth token in
// ANTHROPIC_AUTH_TOKEN, or a non-empty Opts.
APIKey string
// BaseURL overrides the API endpoint requests are sent to. When empty, the
// ANTHROPIC_BASE_URL environment variable is used, and failing that the
// SDK's own default.
BaseURL string
// Opts are anthropic-sdk-go request options applied to every request the
// client sends. They open the SDK's full client configuration to the
// plugin: [option.WithMiddleware], [option.WithMaxRetries],
// [option.WithRequestTimeout], extra headers, and the SDK's bedrock and
// vertex packages, whose routing helpers are request options too.
//
// They are applied after the options derived from APIKey and BaseURL, and
// the SDK applies options in order, so an option here wins over those
// fields when it sets the same setting. Distinct settings do not displace
// each other: the API key rides an X-Api-Key header and an auth token an
// authorization header, so a configured key (here, in APIKey, or in
// ANTHROPIC_API_KEY, which the SDK reads on its own) is still sent
// alongside whatever Opts configure. A key-less setup such as Bedrock or
// Vertex routing therefore needs the key unset everywhere, or an
// [option.WithHeaderDel] for X-Api-Key here, which applies after the key
// options and so strips the header.
//
// Options are opaque, so a non-empty Opts is trusted to carry
// authentication when no API key is configured.
Opts []option.RequestOption
// Models overrides what the plugin knows about a Claude model, keyed by
// model ID, bare or provider-prefixed. Every Claude model already works
// without an entry here: known IDs carry curated capabilities and the rest
// take the Claude defaults. Supply an entry only to correct or extend what
// the plugin resolves, most often to describe a model released after this
// version of the plugin.
//
// &anthropic.Anthropic{Models: map[string]ai.ModelOptions{
// "claude-opus-4-5": {Supports: &ai.ModelSupports{Tools: true, Multiturn: true}},
// }}
//
// Fields left at their zero value keep what the plugin resolves, so an
// entry can pin one capability without restating the label or the config
// schema. Entries apply everywhere a model is described: the actions
// [Anthropic.ListActions] advertises and the ones
// [Anthropic.ResolveAction] builds to serve a request.
Models map[string]ai.ModelOptions
// contains filtered or unexported fields
}
Anthropic is a Genkit plugin for interacting with the Anthropic API.
func (*Anthropic) DefineModel
deprecated
func (a *Anthropic) DefineModel(g *genkit.Genkit, id string, opts *ai.ModelOptions) (ai.Model, error)
DefineModel builds a Claude model and returns it, without registering it with g.
Deprecated: describe the model through Anthropic.Models instead. This method builds the model and ignores g, so the result carries only the model's name: generation resolves a model from that name and serves the request with the capabilities the plugin resolves, not the ones passed here. An entry in Models reaches both paths.
func (*Anthropic) Init ¶
Init prepares the plugin to serve models and registers none: every Claude model arrives through Anthropic.ResolveAction on first use.
It panics when no authentication is configured (an API key in APIKey or ANTHROPIC_API_KEY, an auth token in ANTHROPIC_AUTH_TOKEN, or a non-empty Opts, which is trusted to carry its own) and when called twice, both being setup mistakes rather than conditions an application can recover from.
func (*Anthropic) ListActions ¶
func (a *Anthropic) ListActions(ctx context.Context) []api.ActionDesc
ListActions describes every model the API currently advertises. A discovery failure is reported as an empty catalog rather than an error, since the interface has nowhere to return one.
func (*Anthropic) Name ¶
Name returns the plugin's name, which is also the provider prefix on the action name of every model it serves.
func (*Anthropic) ResolveAction ¶
ResolveAction builds the model named by a request. Models are the only action type this plugin serves.
The ID is passed through to the API untouched. Anthropic resolves an alias like claude-opus-4-5 to its current dated release itself, so there is nothing to look up and nothing to validate here: the API is the authority on whether a model exists, and it answers when the request is made. Building an action is local work either way.