Documentation
¶
Index ¶
- Constants
- Variables
- type APIError
- func (e *APIError) Error() string
- func (e *APIError) IsApiErr() bool
- func (e *APIError) IsAuthenticationErr() bool
- func (e *APIError) IsInvalidRequestErr() bool
- func (e *APIError) IsNotFoundErr() bool
- func (e *APIError) IsOverloadedErr() bool
- func (e *APIError) IsPermissionErr() bool
- func (e *APIError) IsRateLimitErr() bool
- func (e *APIError) IsTooLargeErr() bool
- type APIVersion
- type ApiKeyFunc
- type BatchId
- type BatchRequest
- type BatchRespCore
- type BatchResponse
- type BatchResponseType
- type BatchResult
- type BatchResultCore
- type BetaVersion
- type CacheControlType
- type ChatRole
- type Client
- func (c *Client) CancelBatch(ctx context.Context, batchId BatchId) (*BatchResponse, error)
- func (c *Client) CountTokens(ctx context.Context, request MessagesRequest) (response CountTokensResponse, err error)
- func (c *Client) CreateBatch(ctx context.Context, request BatchRequest) (*BatchResponse, error)
- func (c *Client) CreateComplete(ctx context.Context, request CompleteRequest) (response CompleteResponse, err error)
- func (c *Client) CreateCompleteStream(ctx context.Context, request CompleteStreamRequest) (response CompleteResponse, err error)
- func (c *Client) CreateMessages(ctx context.Context, request MessagesRequest) (response MessagesResponse, err error)
- func (c *Client) CreateMessagesStream(ctx context.Context, request MessagesStreamRequest) (response MessagesResponse, err error)
- func (c *Client) ListBatches(ctx context.Context, lBatchReq ListBatchesRequest) (*ListBatchesResponse, error)
- func (c *Client) RetrieveBatch(ctx context.Context, batchId BatchId) (*BatchResponse, error)
- func (c *Client) RetrieveBatchResults(ctx context.Context, batchId BatchId) (*RetrieveBatchResultsResponse, error)
- type ClientAdapter
- type ClientConfig
- type ClientOption
- func WithAPIVersion(apiVersion APIVersion) ClientOption
- func WithApiKeyFunc(apiKeyFunc ApiKeyFunc) ClientOption
- func WithBaseURL(baseUrl string) ClientOption
- func WithBetaVersion(betaVersion ...BetaVersion) ClientOption
- func WithEmptyMessagesLimit(limit uint) ClientOption
- func WithHTTPClient(cli *http.Client) ClientOption
- func WithVertexAI(projectID string, location string) ClientOption
- type CompleteEvent
- type CompleteRequest
- type CompleteResponse
- type CompleteStreamPingData
- type CompleteStreamRequest
- type CountTokensResponse
- type DefaultAdapter
- type ErrType
- type ErrorResponse
- type InnerRequests
- type ListBatchesRequest
- type ListBatchesResponse
- type Message
- type MessageCacheControl
- type MessageContent
- func NewDocumentMessageContent(source MessageContentSource) MessageContent
- func NewImageMessageContent(source MessageContentSource) MessageContent
- func NewTextMessageContent(text string) MessageContent
- func NewToolResultMessageContent(toolUseID, content string, isError bool) MessageContent
- func NewToolUseMessageContent(toolUseID, name string, input json.RawMessage) MessageContent
- type MessageContentRedactedThinking
- type MessageContentSource
- type MessageContentThinking
- type MessageContentToolResult
- type MessageContentToolUse
- type MessageSystemPart
- type MessagesContentSourceType
- type MessagesContentType
- type MessagesEvent
- type MessagesEventContentBlockDeltaData
- type MessagesEventContentBlockStartData
- type MessagesEventContentBlockStopData
- type MessagesEventMessageDeltaData
- type MessagesEventMessageStartData
- type MessagesEventMessageStopData
- type MessagesEventPingData
- type MessagesRequest
- func (m MessagesRequest) GetModel() Model
- func (m *MessagesRequest) IsStreaming() bool
- func (m MessagesRequest) MarshalJSON() ([]byte, error)
- func (m *MessagesRequest) SetAnthropicVersion(version APIVersion)
- func (m *MessagesRequest) SetTemperature(t float32)
- func (m *MessagesRequest) SetTopK(k int)
- func (m *MessagesRequest) SetTopP(p float32)
- type MessagesResponse
- type MessagesResponseType
- type MessagesStopReason
- type MessagesStreamRequest
- type MessagesUsage
- type Model
- type ProcessingStatus
- type RateLimitHeaders
- type RequestCounts
- type RequestError
- type Response
- type ResultType
- type RetrieveBatchResultsResponse
- type Thinking
- type ThinkingType
- type ToolChoice
- type ToolDefinition
- type VertexAIErrorResponse
- type VertexAISupport
- type VertexAPIError
- type VertexAPIErrorDetails
- type VertexAdapter
Constants ¶
const (
MessagesContentSourceTypeBase64 = "base64"
)
Variables ¶
var (
ErrSteamingNotSupportTools = errors.New("streaming is not yet supported tools")
)
var (
ErrTooManyEmptyStreamMessages = errors.New("stream has sent too many empty messages")
)
Functions ¶
This section is empty.
Types ¶
type APIError ¶
APIError provides error information returned by the Anthropic API.
func (*APIError) IsAuthenticationErr ¶
func (*APIError) IsInvalidRequestErr ¶
func (*APIError) IsNotFoundErr ¶
func (*APIError) IsOverloadedErr ¶
func (*APIError) IsPermissionErr ¶
func (*APIError) IsRateLimitErr ¶
func (*APIError) IsTooLargeErr ¶ added in v2.4.1
type APIVersion ¶ added in v2.8.0
type APIVersion string
const ( APIVersion20230601 APIVersion = "2023-06-01" APIVersionVertex20231016 APIVersion = "vertex-2023-10-16" )
type ApiKeyFunc ¶ added in v2.12.0
type ApiKeyFunc func() string
type BatchRequest ¶ added in v2.9.0
type BatchRequest struct {
Requests []InnerRequests `json:"requests"`
}
While in beta, batches may contain up to 10,000 requests and be up to 32 MB in total size.
type BatchRespCore ¶ added in v2.9.0
type BatchRespCore struct { Id BatchId `json:"id"` Type BatchResponseType `json:"type"` ProcessingStatus ProcessingStatus `json:"processing_status"` RequestCounts RequestCounts `json:"request_counts"` EndedAt *time.Time `json:"ended_at"` CreatedAt time.Time `json:"created_at"` ExpiresAt time.Time `json:"expires_at"` ArchivedAt *time.Time `json:"archived_at"` CancelInitiatedAt *time.Time `json:"cancel_initiated_at"` ResultsUrl *string `json:"results_url"` }
type BatchResponse ¶ added in v2.9.0
type BatchResponse struct { BatchRespCore // contains filtered or unexported fields }
All times returned in RFC 3339
func (*BatchResponse) GetRateLimitHeaders ¶ added in v2.9.0
func (h *BatchResponse) GetRateLimitHeaders() (RateLimitHeaders, error)
type BatchResponseType ¶ added in v2.9.0
type BatchResponseType string
const (
BatchResponseTypeMessageBatch BatchResponseType = "message_batch"
)
type BatchResult ¶ added in v2.9.0
type BatchResult struct { CustomId string `json:"custom_id"` Result BatchResultCore `json:"result"` }
type BatchResultCore ¶ added in v2.9.0
type BatchResultCore struct { Type ResultType `json:"type"` Result MessagesResponse `json:"message"` }
type BetaVersion ¶ added in v2.8.0
type BetaVersion string
const ( BetaTools20240404 BetaVersion = "tools-2024-04-04" BetaTools20240516 BetaVersion = "tools-2024-05-16" BetaPromptCaching20240731 BetaVersion = "prompt-caching-2024-07-31" BetaMessageBatches20240924 BetaVersion = "message-batches-2024-09-24" BetaTokenCounting20241101 BetaVersion = "token-counting-2024-11-01" BetaMaxTokens35Sonnet20240715 BetaVersion = "max-tokens-3-5-sonnet-2024-07-15" BetaComputerUse20241022 BetaVersion = "computer-use-2024-10-22" BetaOutput128k20250219 BetaVersion = "output-128k-2025-02-19" )
type CacheControlType ¶ added in v2.6.0
type CacheControlType string
const (
CacheControlTypeEphemeral CacheControlType = "ephemeral"
)
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(apiKey string, opts ...ClientOption) *Client
NewClient create new Anthropic API client
func (*Client) CancelBatch ¶ added in v2.9.0
func (*Client) CountTokens ¶ added in v2.10.0
func (c *Client) CountTokens( ctx context.Context, request MessagesRequest, ) (response CountTokensResponse, err error)
func (*Client) CreateBatch ¶ added in v2.9.0
func (c *Client) CreateBatch( ctx context.Context, request BatchRequest, ) (*BatchResponse, error)
func (*Client) CreateComplete ¶
func (c *Client) CreateComplete( ctx context.Context, request CompleteRequest, ) (response CompleteResponse, err error)
func (*Client) CreateCompleteStream ¶
func (c *Client) CreateCompleteStream( ctx context.Context, request CompleteStreamRequest, ) (response CompleteResponse, err error)
func (*Client) CreateMessages ¶
func (c *Client) CreateMessages( ctx context.Context, request MessagesRequest, ) (response MessagesResponse, err error)
func (*Client) CreateMessagesStream ¶
func (c *Client) CreateMessagesStream( ctx context.Context, request MessagesStreamRequest, ) (response MessagesResponse, err error)
func (*Client) ListBatches ¶ added in v2.9.0
func (c *Client) ListBatches( ctx context.Context, lBatchReq ListBatchesRequest, ) (*ListBatchesResponse, error)
func (*Client) RetrieveBatch ¶ added in v2.9.0
func (*Client) RetrieveBatchResults ¶ added in v2.9.0
type ClientAdapter ¶ added in v2.12.0
type ClientAdapter interface { // Translate provider specific errors. Responds with an error and a boolean indicating if the error has been successfully parsed. TranslateError(resp *http.Response, body []byte) (error, bool) // Prepare the request for the provider and return the full URL PrepareRequest(c *Client, method, urlSuffix string, body any) (string, error) // Set the request headers for the provider SetRequestHeaders(c *Client, req *http.Request) error }
ClientAdapter is an interface that defines the methods that allow use of the anthropic API with different providers.
type ClientConfig ¶
type ClientConfig struct { BaseURL string APIVersion APIVersion BetaVersion []BetaVersion HTTPClient *http.Client EmptyMessagesLimit uint Adapter ClientAdapter // contains filtered or unexported fields }
ClientConfig is a configuration of a client.
func (*ClientConfig) GetApiKey ¶ added in v2.12.0
func (c *ClientConfig) GetApiKey() string
type ClientOption ¶
type ClientOption func(c *ClientConfig)
func WithAPIVersion ¶
func WithAPIVersion(apiVersion APIVersion) ClientOption
func WithApiKeyFunc ¶ added in v2.12.0
func WithApiKeyFunc(apiKeyFunc ApiKeyFunc) ClientOption
func WithBaseURL ¶
func WithBaseURL(baseUrl string) ClientOption
func WithBetaVersion ¶
func WithBetaVersion(betaVersion ...BetaVersion) ClientOption
func WithEmptyMessagesLimit ¶
func WithEmptyMessagesLimit(limit uint) ClientOption
func WithHTTPClient ¶
func WithHTTPClient(cli *http.Client) ClientOption
func WithVertexAI ¶ added in v2.12.0
func WithVertexAI(projectID string, location string) ClientOption
type CompleteEvent ¶
type CompleteEvent string
const ( CompleteEventError CompleteEvent = "error" CompleteEventCompletion CompleteEvent = "completion" CompleteEventPing CompleteEvent = "ping" )
type CompleteRequest ¶
type CompleteRequest struct { Model Model `json:"model"` Prompt string `json:"prompt"` MaxTokensToSample int `json:"max_tokens_to_sample"` StopSequences []string `json:"stop_sequences,omitempty"` Temperature *float32 `json:"temperature,omitempty"` TopP *float32 `json:"top_p,omitempty"` TopK *int `json:"top_k,omitempty"` MetaData map[string]any `json:"meta_data,omitempty"` Stream bool `json:"stream,omitempty"` }
func (*CompleteRequest) SetTemperature ¶
func (c *CompleteRequest) SetTemperature(t float32)
func (*CompleteRequest) SetTopK ¶
func (c *CompleteRequest) SetTopK(k int)
func (*CompleteRequest) SetTopP ¶
func (c *CompleteRequest) SetTopP(p float32)
type CompleteResponse ¶
type CompleteResponse struct { Type string `json:"type"` ID string `json:"id"` Completion string `json:"completion"` // possible values are: stop_sequence、max_tokens、null StopReason string `json:"stop_reason"` Model Model `json:"model"` // contains filtered or unexported fields }
func (*CompleteResponse) GetRateLimitHeaders ¶ added in v2.3.0
func (h *CompleteResponse) GetRateLimitHeaders() (RateLimitHeaders, error)
type CompleteStreamPingData ¶
type CompleteStreamPingData struct {
Type string `json:"type"`
}
type CompleteStreamRequest ¶
type CompleteStreamRequest struct { CompleteRequest OnCompletion func(CompleteResponse) `json:"-"` OnPing func(CompleteStreamPingData) `json:"-"` OnError func(ErrorResponse) `json:"-"` }
type CountTokensResponse ¶ added in v2.10.0
type CountTokensResponse struct { InputTokens int `json:"input_tokens"` // contains filtered or unexported fields }
func (*CountTokensResponse) GetRateLimitHeaders ¶ added in v2.10.0
func (h *CountTokensResponse) GetRateLimitHeaders() (RateLimitHeaders, error)
type DefaultAdapter ¶ added in v2.12.0
type DefaultAdapter struct { }
func (*DefaultAdapter) PrepareRequest ¶ added in v2.12.0
func (*DefaultAdapter) SetRequestHeaders ¶ added in v2.12.0
func (v *DefaultAdapter) SetRequestHeaders(c *Client, req *http.Request) error
func (*DefaultAdapter) TranslateError ¶ added in v2.12.0
type ErrType ¶
type ErrType string
const ( // ErrTypeInvalidRequest There was an issue with the format or content of your request. ErrTypeInvalidRequest ErrType = "invalid_request_error" // ErrTypeAuthentication There's an issue with your API key. ErrTypeAuthentication ErrType = "authentication_error" // ErrTypePermission Your API key does not have permission to use the specified resource. ErrTypePermission ErrType = "permission_error" // ErrTypeNotFound The requested resource was not found. ErrTypeNotFound ErrType = "not_found_error" // ErrTypeTooLarge Request exceeds the maximum allowed number of bytes. ErrTypeTooLarge ErrType = "request_too_large" // ErrTypeRateLimit Your account has hit a rate limit. ErrTypeRateLimit ErrType = "rate_limit_error" // ErrTypeApi An unexpected error has occurred internal to Anthropic's systems. ErrTypeApi ErrType = "api_error" // ErrTypeOverloaded Anthropic's API is temporarily overloaded. ErrTypeOverloaded ErrType = "overloaded_error" )
type ErrorResponse ¶
type InnerRequests ¶ added in v2.9.0
type InnerRequests struct { CustomId string `json:"custom_id"` Params MessagesRequest `json:"params"` }
type ListBatchesRequest ¶ added in v2.9.0
type ListBatchesResponse ¶ added in v2.9.0
type ListBatchesResponse struct { Data []BatchRespCore `json:"data"` HasMore bool `json:"has_more"` FirstId *BatchId `json:"first_id"` LastId *BatchId `json:"last_id"` // contains filtered or unexported fields }
func (*ListBatchesResponse) GetRateLimitHeaders ¶ added in v2.9.0
func (h *ListBatchesResponse) GetRateLimitHeaders() (RateLimitHeaders, error)
type Message ¶
type Message struct { Role ChatRole `json:"role"` Content []MessageContent `json:"content"` }
func NewAssistantTextMessage ¶
func NewToolResultsMessage ¶
func NewUserTextMessage ¶
func (Message) GetFirstContent ¶
func (m Message) GetFirstContent() MessageContent
type MessageCacheControl ¶ added in v2.6.0
type MessageCacheControl struct {
Type CacheControlType `json:"type"`
}
type MessageContent ¶
type MessageContent struct { Type MessagesContentType `json:"type"` Text *string `json:"text,omitempty"` Source *MessageContentSource `json:"source,omitempty"` *MessageContentToolResult *MessageContentToolUse PartialJson *string `json:"partial_json,omitempty"` CacheControl *MessageCacheControl `json:"cache_control,omitempty"` *MessageContentThinking *MessageContentRedactedThinking }
func NewDocumentMessageContent ¶ added in v2.11.0
func NewDocumentMessageContent(source MessageContentSource) MessageContent
func NewImageMessageContent ¶
func NewImageMessageContent(source MessageContentSource) MessageContent
func NewTextMessageContent ¶
func NewTextMessageContent(text string) MessageContent
func NewToolResultMessageContent ¶
func NewToolResultMessageContent(toolUseID, content string, isError bool) MessageContent
func NewToolUseMessageContent ¶
func NewToolUseMessageContent(toolUseID, name string, input json.RawMessage) MessageContent
func (*MessageContent) ConcatText ¶
func (m *MessageContent) ConcatText(s string)
func (*MessageContent) GetText ¶
func (m *MessageContent) GetText() string
func (*MessageContent) MergeContentDelta ¶ added in v2.2.0
func (m *MessageContent) MergeContentDelta(mc MessageContent)
func (*MessageContent) SetCacheControl ¶ added in v2.6.0
func (m *MessageContent) SetCacheControl(ts ...CacheControlType)
type MessageContentRedactedThinking ¶ added in v2.14.0
type MessageContentRedactedThinking struct {
Data string `json:"data,omitempty"`
}
type MessageContentSource ¶ added in v2.11.0
type MessageContentSource struct { Type MessagesContentSourceType `json:"type"` MediaType string `json:"media_type"` Data any `json:"data"` }
func NewMessageContentSource ¶ added in v2.11.0
func NewMessageContentSource( sourceType MessagesContentSourceType, mediaType string, data any, ) MessageContentSource
type MessageContentThinking ¶ added in v2.14.0
type MessageContentToolResult ¶
type MessageContentToolResult struct { ToolUseID *string `json:"tool_use_id,omitempty"` Content []MessageContent `json:"content,omitempty"` IsError *bool `json:"is_error,omitempty"` }
func NewMessageContentToolResult ¶
func NewMessageContentToolResult( toolUseID, content string, isError bool, ) *MessageContentToolResult
type MessageContentToolUse ¶
type MessageContentToolUse struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` Input json.RawMessage `json:"input,omitempty"` }
func NewMessageContentToolUse ¶ added in v2.7.0
func NewMessageContentToolUse( toolUseId, name string, input json.RawMessage, ) *MessageContentToolUse
func (*MessageContentToolUse) UnmarshalInput ¶ added in v2.2.0
func (c *MessageContentToolUse) UnmarshalInput(v any) error
type MessageSystemPart ¶ added in v2.6.0
type MessageSystemPart struct { Type string `json:"type"` Text string `json:"text"` CacheControl *MessageCacheControl `json:"cache_control,omitempty"` }
func NewMultiSystemMessages ¶ added in v2.7.0
func NewMultiSystemMessages(texts ...string) []MessageSystemPart
func NewSystemMessagePart ¶ added in v2.7.0
func NewSystemMessagePart(text string) MessageSystemPart
type MessagesContentSourceType ¶ added in v2.11.0
type MessagesContentSourceType string
type MessagesContentType ¶
type MessagesContentType string
const ( MessagesContentTypeText MessagesContentType = "text" MessagesContentTypeTextDelta MessagesContentType = "text_delta" MessagesContentTypeImage MessagesContentType = "image" MessagesContentTypeToolResult MessagesContentType = "tool_result" MessagesContentTypeToolUse MessagesContentType = "tool_use" MessagesContentTypeInputJsonDelta MessagesContentType = "input_json_delta" MessagesContentTypeDocument MessagesContentType = "document" MessagesContentTypeThinking MessagesContentType = "thinking" MessagesContentTypeThinkingDelta MessagesContentType = "thinking_delta" MessagesContentTypeSignatureDelta MessagesContentType = "signature_delta" MessagesContentTypeRedactedThinking MessagesContentType = "redacted_thinking" )
type MessagesEvent ¶
type MessagesEvent string
MessagesEvent docs: https://docs.anthropic.com/claude/reference/messages-streaming
const ( MessagesEventError MessagesEvent = "error" MessagesEventMessageStart MessagesEvent = "message_start" MessagesEventContentBlockStart MessagesEvent = "content_block_start" MessagesEventPing MessagesEvent = "ping" MessagesEventContentBlockDelta MessagesEvent = "content_block_delta" MessagesEventContentBlockStop MessagesEvent = "content_block_stop" MessagesEventMessageDelta MessagesEvent = "message_delta" MessagesEventMessageStop MessagesEvent = "message_stop" )
type MessagesEventContentBlockDeltaData ¶
type MessagesEventContentBlockDeltaData struct { Type string `json:"type"` Index int `json:"index"` Delta MessageContent `json:"delta"` }
type MessagesEventContentBlockStartData ¶
type MessagesEventContentBlockStartData struct { Type MessagesEvent `json:"type"` Index int `json:"index"` ContentBlock MessageContent `json:"content_block"` }
type MessagesEventMessageDeltaData ¶
type MessagesEventMessageDeltaData struct { Type string `json:"type"` Delta MessagesResponse `json:"delta"` Usage MessagesUsage `json:"usage"` }
type MessagesEventMessageStartData ¶
type MessagesEventMessageStartData struct { Type MessagesEvent `json:"type"` Message MessagesResponse `json:"message"` }
type MessagesEventMessageStopData ¶
type MessagesEventMessageStopData struct {
Type string `json:"type"`
}
type MessagesEventPingData ¶
type MessagesEventPingData struct {
Type string `json:"type"`
}
type MessagesRequest ¶
type MessagesRequest struct { Model Model `json:"model,omitempty"` AnthropicVersion string `json:"anthropic_version,omitempty"` Messages []Message `json:"messages"` MaxTokens int `json:"max_tokens,omitempty"` System string `json:"-"` MultiSystem []MessageSystemPart `json:"-"` Metadata map[string]any `json:"metadata,omitempty"` StopSequences []string `json:"stop_sequences,omitempty"` Stream bool `json:"stream,omitempty"` Temperature *float32 `json:"temperature,omitempty"` TopP *float32 `json:"top_p,omitempty"` TopK *int `json:"top_k,omitempty"` Tools []ToolDefinition `json:"tools,omitempty"` ToolChoice *ToolChoice `json:"tool_choice,omitempty"` Thinking *Thinking `json:"thinking,omitempty"` }
func (MessagesRequest) GetModel ¶ added in v2.12.0
func (m MessagesRequest) GetModel() Model
func (*MessagesRequest) IsStreaming ¶ added in v2.12.0
func (m *MessagesRequest) IsStreaming() bool
func (MessagesRequest) MarshalJSON ¶ added in v2.6.0
func (m MessagesRequest) MarshalJSON() ([]byte, error)
func (*MessagesRequest) SetAnthropicVersion ¶ added in v2.12.0
func (m *MessagesRequest) SetAnthropicVersion(version APIVersion)
func (*MessagesRequest) SetTemperature ¶
func (m *MessagesRequest) SetTemperature(t float32)
func (*MessagesRequest) SetTopK ¶
func (m *MessagesRequest) SetTopK(k int)
func (*MessagesRequest) SetTopP ¶
func (m *MessagesRequest) SetTopP(p float32)
type MessagesResponse ¶
type MessagesResponse struct { ID string `json:"id"` Type MessagesResponseType `json:"type"` Role ChatRole `json:"role"` Content []MessageContent `json:"content"` Model Model `json:"model"` StopReason MessagesStopReason `json:"stop_reason"` StopSequence string `json:"stop_sequence"` Usage MessagesUsage `json:"usage"` // contains filtered or unexported fields }
func (MessagesResponse) GetFirstContentText ¶
func (m MessagesResponse) GetFirstContentText() string
GetFirstContentText get Content[0].Text avoid panic
func (*MessagesResponse) GetRateLimitHeaders ¶ added in v2.3.0
func (h *MessagesResponse) GetRateLimitHeaders() (RateLimitHeaders, error)
type MessagesResponseType ¶
type MessagesResponseType string
const ( MessagesResponseTypeMessage MessagesResponseType = "message" MessagesResponseTypeError MessagesResponseType = "error" )
type MessagesStopReason ¶
type MessagesStopReason string
const ( MessagesStopReasonEndTurn MessagesStopReason = "end_turn" MessagesStopReasonMaxTokens MessagesStopReason = "max_tokens" MessagesStopReasonStopSequence MessagesStopReason = "stop_sequence" MessagesStopReasonToolUse MessagesStopReason = "tool_use" )
type MessagesStreamRequest ¶
type MessagesStreamRequest struct { MessagesRequest OnError func(ErrorResponse) `json:"-"` OnPing func(MessagesEventPingData) `json:"-"` OnMessageStart func(MessagesEventMessageStartData) `json:"-"` OnContentBlockStart func(MessagesEventContentBlockStartData) `json:"-"` OnContentBlockDelta func(MessagesEventContentBlockDeltaData) `json:"-"` OnContentBlockStop func(MessagesEventContentBlockStopData, MessageContent) `json:"-"` OnMessageDelta func(MessagesEventMessageDeltaData) `json:"-"` OnMessageStop func(MessagesEventMessageStopData) `json:"-"` }
type MessagesUsage ¶
type MessagesUsage struct { InputTokens int `json:"input_tokens"` OutputTokens int `json:"output_tokens"` // The number of tokens written to the cache when creating a new entry. CacheCreationInputTokens int `json:"cache_creation_input_tokens,omitempty"` // The number of tokens retrieved from the cache for associated request. CacheReadInputTokens int `json:"cache_read_input_tokens,omitempty"` }
type Model ¶ added in v2.7.0
type Model string
const ( ModelClaude2Dot0 Model = "claude-2.0" ModelClaude2Dot1 Model = "claude-2.1" ModelClaude3Opus20240229 Model = "claude-3-opus-20240229" ModelClaude3Sonnet20240229 Model = "claude-3-sonnet-20240229" ModelClaude3Dot5Sonnet20240620 Model = "claude-3-5-sonnet-20240620" ModelClaude3Dot5Sonnet20241022 Model = "claude-3-5-sonnet-20241022" ModelClaude3Dot5SonnetLatest Model = "claude-3-5-sonnet-latest" ModelClaude3Haiku20240307 Model = "claude-3-haiku-20240307" ModelClaude3Dot5HaikuLatest Model = "claude-3-5-haiku-latest" ModelClaude3Dot5Haiku20241022 Model = "claude-3-5-haiku-20241022" ModelClaude3Dot7SonnetLatest Model = "claude-3-7-sonnet-latest" ModelClaude3Dot7Sonnet20250219 Model = "claude-3-7-sonnet-20250219" )
type ProcessingStatus ¶ added in v2.9.0
type ProcessingStatus string
const ( ProcessingStatusInProgress ProcessingStatus = "in_progress" ProcessingStatusCanceling ProcessingStatus = "canceling" ProcessingStatusEnded ProcessingStatus = "ended" )
type RateLimitHeaders ¶ added in v2.3.0
type RateLimitHeaders struct { // The maximum number of requests allowed within the rate limit window. RequestsLimit int `json:"anthropic-ratelimit-requests-limit"` // The number of requests remaining within the current rate limit window. RequestsRemaining int `json:"anthropic-ratelimit-requests-remaining"` // The time when the request rate limit window will reset, provided in RFC 3339 format. RequestsReset time.Time `json:"anthropic-ratelimit-requests-reset"` // The maximum number of tokens allowed within the rate limit window. TokensLimit int `json:"anthropic-ratelimit-tokens-limit"` // The number of tokens remaining, rounded to the nearest thousand, within the current rate limit window. TokensRemaining int `json:"anthropic-ratelimit-tokens-remaining"` // The time when the token rate limit window will reset, provided in RFC 3339 format. TokensReset time.Time `json:"anthropic-ratelimit-tokens-reset"` // The maximum number of input tokens allowed within any rate limit period. InputTokensLimit int `json:"anthropic-ratelimit-input-tokens-limit"` // The number of input tokens remaining (rounded to the nearest thousand) before being rate limited. InputTokensRemaining int `json:"anthropic-ratelimit-input-tokens-remaining"` // The time when the input token rate limit will be fully replenished, provided in RFC 3339 format. InputTokensReset time.Time `json:"anthropic-ratelimit-input-tokens-reset"` // The maximum number of output tokens allowed within any rate limit period. OutputTokensLimit int `json:"anthropic-ratelimit-output-tokens-limit"` // The number of output tokens remaining (rounded to the nearest thousand) before being rate limited. OutputTokensRemaining int `json:"anthropic-ratelimit-output-tokens-remaining"` // The time when the output token rate limit will be fully replenished, provided in RFC 3339 format. OutputTokensReset time.Time `json:"anthropic-ratelimit-output-tokens-reset"` // The number of seconds until the rate limit window resets. RetryAfter int `json:"retry-after"` }
type RequestCounts ¶ added in v2.9.0
type RequestError ¶
RequestError provides information about generic request errors.
func (*RequestError) Error ¶
func (e *RequestError) Error() string
type ResultType ¶ added in v2.9.0
type ResultType string
const ( ResultTypeSucceeded ResultType = "succeeded" ResultTypeErrored ResultType = "errored" ResultTypeCanceled ResultType = "canceled" ResultTypeExpired ResultType = "expired" )
type RetrieveBatchResultsResponse ¶ added in v2.9.0
type RetrieveBatchResultsResponse struct { Responses []BatchResult RawResponse []byte // contains filtered or unexported fields }
func (*RetrieveBatchResultsResponse) GetRateLimitHeaders ¶ added in v2.9.0
func (h *RetrieveBatchResultsResponse) GetRateLimitHeaders() (RateLimitHeaders, error)
type Thinking ¶ added in v2.14.0
type Thinking struct { Type ThinkingType `json:"type"` // Determines how many tokens Claude can use for its internal reasoning process. Larger budgets can enable more thorough analysis for complex problems, improving response quality. // Must be ≥1024 and less than max_tokens. BudgetTokens int `json:"budget_tokens"` }
type ThinkingType ¶ added in v2.14.0
type ThinkingType string
const ( ThinkingTypeEnabled ThinkingType = "enabled" ThinkingTypeDisabled ThinkingType = "disabled" )
type ToolChoice ¶ added in v2.2.0
type ToolDefinition ¶
type ToolDefinition struct { Name string `json:"name"` Description string `json:"description,omitempty"` // InputSchema is an object describing the tool. // You can pass json.RawMessage to describe the schema, // or you can pass in a struct which serializes to the proper JSON schema. // The jsonschema package is provided for convenience, but you should // consider another specialized library if you require more complex schemas. InputSchema any `json:"input_schema,omitempty"` CacheControl *MessageCacheControl `json:"cache_control,omitempty"` // Type is required for Anthropic defined tools. Type string `json:"type,omitempty"` // DisplayWidthPx is a required parameter of the Computer Use tool. DisplayWidthPx int `json:"display_width_px,omitempty"` // DisplayHeightPx is a required parameter of the Computer Use tool. DisplayHeightPx int `json:"display_height_px,omitempty"` // DisplayNumber is an optional parameter of the Computer Use tool. DisplayNumber *int `json:"display_number,omitempty"` }
func NewBashToolDefinition ¶ added in v2.13.0
func NewBashToolDefinition(name string) ToolDefinition
func NewComputerUseToolDefinition ¶ added in v2.13.0
func NewComputerUseToolDefinition( name string, displayWidthPx int, displayHeightPx int, displayNumber *int, ) ToolDefinition
func NewTextEditorToolDefinition ¶ added in v2.13.0
func NewTextEditorToolDefinition(name string) ToolDefinition
type VertexAIErrorResponse ¶ added in v2.12.0
type VertexAIErrorResponse struct {
Error *VertexAPIError `json:"error,omitempty"`
}
type VertexAISupport ¶ added in v2.12.0
type VertexAISupport interface { GetModel() Model SetAnthropicVersion(APIVersion) IsStreaming() bool }
VertexAISupport is an interface that is used to configure Vertex AI requests. The changes are defined here: https://docs.anthropic.com/en/api/claude-on-vertex-ai Model needs to be in the calling URL The version of the API is defined in the request body This interface allows the vertex ai changes to be contained in the client code, and not leak to each indivdual request definition.
type VertexAPIError ¶ added in v2.12.0
type VertexAPIError struct { Code int `json:"code"` Message string `json:"message"` Status string `json:"status"` Details []VertexAPIErrorDetails `json:"details"` }
VertexAPIError provides error information returned by the Anthropic API.
func (*VertexAPIError) Error ¶ added in v2.12.0
func (e *VertexAPIError) Error() string
type VertexAPIErrorDetails ¶ added in v2.12.0
type VertexAdapter ¶ added in v2.12.0
type VertexAdapter struct { }
func (*VertexAdapter) PrepareRequest ¶ added in v2.12.0
func (*VertexAdapter) SetRequestHeaders ¶ added in v2.12.0
func (v *VertexAdapter) SetRequestHeaders(c *Client, req *http.Request) error
func (*VertexAdapter) TranslateError ¶ added in v2.12.0
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
internal
|
|
Package jsonschema provides very simple functionality for representing a JSON schema as a (nested) struct.
|
Package jsonschema provides very simple functionality for representing a JSON schema as a (nested) struct. |