anthropic

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Overview

anthropic implements an API client for the Anthropic Messages API. https://docs.anthropic.com/en/api/getting-started

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRequest

func GenerateRequest(model string, session *schema.Conversation, opts ...opt.Opt) (any, error)

GenerateRequest builds a generate request from options without sending it. Useful for testing and debugging.

func WithAfterId

func WithAfterId(id string) opt.Opt

WithAfterId sets the cursor for forward pagination

func WithBeforeId

func WithBeforeId(id string) opt.Opt

WithBeforeId sets the cursor for backward pagination

func WithCachedSystemPrompt

func WithCachedSystemPrompt(value string) opt.Opt

WithCachedSystemPrompt sets the system prompt with caching enabled

func WithJSONOutput

func WithJSONOutput(schema *jsonschema.Schema) opt.Opt

WithJSONOutput sets the output format to JSON with the given schema

func WithLimit

func WithLimit(limit uint) opt.Opt

WithLimit sets the page size for pagination

func WithMaxTokens

func WithMaxTokens(value uint) opt.Opt

WithMaxTokens sets the maximum number of tokens to generate (minimum 1)

func WithOutputConfig

func WithOutputConfig(value string) opt.Opt

WithOutputConfig sets the output effort ("low", "medium", or "high")

func WithServiceTier

func WithServiceTier(value string) opt.Opt

WithServiceTier sets the service tier for the request ("auto" or "standard_only")

func WithStopSequences

func WithStopSequences(values ...string) opt.Opt

WithStopSequences sets custom stop sequences for the request

func WithSystemPrompt

func WithSystemPrompt(value string) opt.Opt

WithSystemPrompt sets the system prompt for the request

func WithTemperature

func WithTemperature(value float64) opt.Opt

WithTemperature sets the temperature for the request (0.0 to 1.0)

func WithThinking

func WithThinking(budgetTokens uint) opt.Opt

WithThinking enables extended thinking with the specified token budget (minimum 1024)

func WithToolChoice

func WithToolChoice(name string) opt.Opt

WithToolChoice forces the model to use a specific tool by name

func WithToolChoiceAny

func WithToolChoiceAny() opt.Opt

WithToolChoiceAny forces the model to use one of the available tools

func WithToolChoiceAuto

func WithToolChoiceAuto() opt.Opt

WithToolChoiceAuto lets the model decide whether to use tools

func WithToolChoiceNone

func WithToolChoiceNone() opt.Opt

WithToolChoiceNone prevents the model from using any tools

func WithTopK

func WithTopK(value uint) opt.Opt

WithTopK sets the top K sampling parameter (minimum 1)

func WithTopP

func WithTopP(value float64) opt.Opt

WithTopP sets the nucleus sampling parameter (0.0 to 1.0)

func WithUser

func WithUser(value string) opt.Opt

WithUser sets the metadata.user_id for the request

Types

type Client

type Client struct {
	*client.Client
	*modelcache.ModelCache
}

func New

func New(apiKey string, opts ...client.ClientOpt) (*Client, error)

New creates a new Anthropic API client with the given API key

func (*Client) GetModel

func (c *Client) GetModel(ctx context.Context, name string, opts ...opt.Opt) (*schema.Model, error)

GetModel returns a specific model by name or ID

func (*Client) ListModels

func (c *Client) ListModels(ctx context.Context, opts ...opt.Opt) ([]schema.Model, error)

ListModels returns all available models from the Anthropic API

func (*Client) Name

func (*Client) Name() string

Name returns the provider name

func (*Client) WithSession

func (c *Client) WithSession(ctx context.Context, model schema.Model, session *schema.Conversation, message *schema.Message, opts ...opt.Opt) (*schema.Message, *schema.Usage, error)

WithSession sends a message within a session and returns the response (stateful)

func (*Client) WithoutSession

func (c *Client) WithoutSession(ctx context.Context, model schema.Model, message *schema.Message, opts ...opt.Opt) (*schema.Message, *schema.Usage, error)

WithoutSession sends a single message and returns the response (stateless)

Jump to

Keyboard shortcuts

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