Documentation
¶
Index ¶
- Constants
- func Bool(value bool) param.Field[bool]
- func F[T any](value T) param.Field[T]
- func FileParam(reader io.Reader, filename string, contentType string) param.Field[io.Reader]
- func Float(value float64) param.Field[float64]
- func Int(value int64) param.Field[int64]
- func Null[T any]() param.Field[T]
- func Raw[T any](value any) param.Field[T]
- func String(value string) param.Field[string]
- type APIErrorObject
- type APIErrorObjectType
- type AnthropicBeta
- type AuthenticationError
- type AuthenticationErrorType
- type Base64PDFSourceMediaType
- type Base64PDFSourceParam
- type Base64PDFSourceType
- type BetaAPIError
- type BetaAPIErrorType
- type BetaAuthenticationError
- type BetaAuthenticationErrorType
- type BetaBase64PDFBlockParam
- type BetaBase64PDFBlockType
- type BetaBase64PDFSourceMediaType
- type BetaBase64PDFSourceParam
- type BetaBase64PDFSourceType
- type BetaBillingError
- type BetaBillingErrorType
- type BetaCacheControlEphemeralParam
- type BetaCacheControlEphemeralType
- type BetaContentBlock
- type BetaContentBlockParam
- type BetaContentBlockParamType
- type BetaContentBlockParamUnion
- type BetaContentBlockType
- type BetaContentBlockUnion
- type BetaError
- type BetaErrorResponse
- type BetaErrorResponseType
- type BetaErrorType
- type BetaErrorUnion
- type BetaGatewayTimeoutError
- type BetaGatewayTimeoutErrorType
- type BetaImageBlockParam
- type BetaImageBlockParamSource
- type BetaImageBlockParamSourceMediaType
- type BetaImageBlockParamSourceType
- type BetaImageBlockParamType
- type BetaInputJSONDelta
- type BetaInputJSONDeltaType
- type BetaInvalidRequestError
- type BetaInvalidRequestErrorType
- type BetaMessage
- type BetaMessageBatch
- type BetaMessageBatchCancelParams
- type BetaMessageBatchCanceledResult
- type BetaMessageBatchCanceledResultType
- type BetaMessageBatchErroredResult
- type BetaMessageBatchErroredResultType
- type BetaMessageBatchExpiredResult
- type BetaMessageBatchExpiredResultType
- type BetaMessageBatchGetParams
- type BetaMessageBatchIndividualResponse
- type BetaMessageBatchListParams
- type BetaMessageBatchNewParams
- type BetaMessageBatchNewParamsRequest
- type BetaMessageBatchNewParamsRequestsParams
- type BetaMessageBatchProcessingStatus
- type BetaMessageBatchRequestCounts
- type BetaMessageBatchResult
- type BetaMessageBatchResultType
- type BetaMessageBatchResultUnion
- type BetaMessageBatchResultsParams
- type BetaMessageBatchService
- func (r *BetaMessageBatchService) Cancel(ctx context.Context, messageBatchID string, body BetaMessageBatchCancelParams, ...) (res *BetaMessageBatch, err error)
- func (r *BetaMessageBatchService) Get(ctx context.Context, messageBatchID string, query BetaMessageBatchGetParams, ...) (res *BetaMessageBatch, err error)
- func (r *BetaMessageBatchService) List(ctx context.Context, params BetaMessageBatchListParams, ...) (res *pagination.Page[BetaMessageBatch], err error)
- func (r *BetaMessageBatchService) ListAutoPaging(ctx context.Context, params BetaMessageBatchListParams, ...) *pagination.PageAutoPager[BetaMessageBatch]
- func (r *BetaMessageBatchService) New(ctx context.Context, params BetaMessageBatchNewParams, ...) (res *BetaMessageBatch, err error)
- func (r *BetaMessageBatchService) Results(ctx context.Context, messageBatchID string, ...) (res *http.Response, err error)
- type BetaMessageBatchSucceededResult
- type BetaMessageBatchSucceededResultType
- type BetaMessageBatchType
- type BetaMessageCountTokensParams
- type BetaMessageCountTokensParamsSystemArray
- type BetaMessageCountTokensParamsSystemUnion
- type BetaMessageCountTokensParamsTool
- type BetaMessageCountTokensParamsToolUnion
- type BetaMessageCountTokensParamsToolsType
- type BetaMessageDeltaUsage
- type BetaMessageNewParams
- type BetaMessageParam
- type BetaMessageParamRole
- type BetaMessageRole
- type BetaMessageService
- func (r *BetaMessageService) CountTokens(ctx context.Context, params BetaMessageCountTokensParams, ...) (res *BetaMessageTokensCount, err error)
- func (r *BetaMessageService) New(ctx context.Context, params BetaMessageNewParams, opts ...option.RequestOption) (res *BetaMessage, err error)
- func (r *BetaMessageService) NewStreaming(ctx context.Context, params BetaMessageNewParams, opts ...option.RequestOption) (stream *ssestream.Stream[BetaRawMessageStreamEvent])
- type BetaMessageStopReason
- type BetaMessageTokensCount
- type BetaMessageType
- type BetaMetadataParam
- type BetaModelInfo
- type BetaModelInfoType
- type BetaModelListParams
- type BetaModelService
- func (r *BetaModelService) Get(ctx context.Context, modelID string, opts ...option.RequestOption) (res *BetaModelInfo, err error)
- func (r *BetaModelService) List(ctx context.Context, query BetaModelListParams, opts ...option.RequestOption) (res *pagination.Page[BetaModelInfo], err error)
- func (r *BetaModelService) ListAutoPaging(ctx context.Context, query BetaModelListParams, opts ...option.RequestOption) *pagination.PageAutoPager[BetaModelInfo]
- type BetaNotFoundError
- type BetaNotFoundErrorType
- type BetaOverloadedError
- type BetaOverloadedErrorType
- type BetaPermissionError
- type BetaPermissionErrorType
- type BetaRateLimitError
- type BetaRateLimitErrorType
- type BetaRawContentBlockDeltaEvent
- type BetaRawContentBlockDeltaEventDelta
- type BetaRawContentBlockDeltaEventDeltaType
- type BetaRawContentBlockDeltaEventDeltaUnion
- type BetaRawContentBlockDeltaEventType
- type BetaRawContentBlockStartEvent
- type BetaRawContentBlockStartEventContentBlock
- type BetaRawContentBlockStartEventContentBlockType
- type BetaRawContentBlockStartEventContentBlockUnion
- type BetaRawContentBlockStartEventType
- type BetaRawContentBlockStopEvent
- type BetaRawContentBlockStopEventType
- type BetaRawMessageDeltaEvent
- type BetaRawMessageDeltaEventDelta
- type BetaRawMessageDeltaEventDeltaStopReason
- type BetaRawMessageDeltaEventType
- type BetaRawMessageStartEvent
- type BetaRawMessageStartEventType
- type BetaRawMessageStopEvent
- type BetaRawMessageStopEventType
- type BetaRawMessageStreamEvent
- type BetaRawMessageStreamEventType
- type BetaRawMessageStreamEventUnion
- type BetaService
- type BetaTextBlock
- type BetaTextBlockParam
- type BetaTextBlockParamType
- type BetaTextBlockType
- type BetaTextDelta
- type BetaTextDeltaType
- type BetaToolBash20241022Name
- type BetaToolBash20241022Param
- type BetaToolBash20241022Type
- type BetaToolChoiceAnyParam
- type BetaToolChoiceAnyType
- type BetaToolChoiceAutoParam
- type BetaToolChoiceAutoType
- type BetaToolChoiceParam
- type BetaToolChoiceToolParam
- type BetaToolChoiceToolType
- type BetaToolChoiceType
- type BetaToolChoiceUnionParam
- type BetaToolComputerUse20241022Name
- type BetaToolComputerUse20241022Param
- type BetaToolComputerUse20241022Type
- type BetaToolInputSchemaParam
- type BetaToolInputSchemaType
- type BetaToolParam
- type BetaToolResultBlockParam
- type BetaToolResultBlockParamContent
- type BetaToolResultBlockParamContentType
- type BetaToolResultBlockParamContentUnion
- type BetaToolResultBlockParamType
- type BetaToolTextEditor20241022Name
- type BetaToolTextEditor20241022Param
- type BetaToolTextEditor20241022Type
- type BetaToolType
- type BetaToolUnionParam
- type BetaToolUnionType
- type BetaToolUnionUnionParam
- type BetaToolUseBlock
- type BetaToolUseBlockParam
- type BetaToolUseBlockParamType
- type BetaToolUseBlockType
- type BetaUsage
- type BillingError
- type BillingErrorType
- type CacheControlEphemeralParam
- type CacheControlEphemeralType
- type Client
- func (r *Client) Delete(ctx context.Context, path string, params interface{}, res interface{}, ...) error
- func (r *Client) Execute(ctx context.Context, method string, path string, params interface{}, ...) error
- func (r *Client) Get(ctx context.Context, path string, params interface{}, res interface{}, ...) error
- func (r *Client) Patch(ctx context.Context, path string, params interface{}, res interface{}, ...) error
- func (r *Client) Post(ctx context.Context, path string, params interface{}, res interface{}, ...) error
- func (r *Client) Put(ctx context.Context, path string, params interface{}, res interface{}, ...) error
- type Completion
- type CompletionNewParams
- type CompletionService
- type CompletionType
- type ContentBlock
- type ContentBlockDeltaEvent
- type ContentBlockDeltaEventDelta
- type ContentBlockDeltaEventDeltaType
- type ContentBlockDeltaEventDeltaUnion
- type ContentBlockDeltaEventType
- type ContentBlockParam
- type ContentBlockParamType
- type ContentBlockParamUnion
- type ContentBlockStartEvent
- type ContentBlockStartEventContentBlock
- type ContentBlockStartEventContentBlockType
- type ContentBlockStartEventContentBlockUnion
- type ContentBlockStartEventType
- type ContentBlockStopEvent
- type ContentBlockStopEventType
- type ContentBlockType
- type ContentBlockUnion
- type DocumentBlockParam
- type DocumentBlockParamType
- type Error
- type ErrorObject
- type ErrorObjectType
- type ErrorResponse
- type ErrorResponseType
- type GatewayTimeoutError
- type GatewayTimeoutErrorType
- type ImageBlockParam
- type ImageBlockParamSource
- type ImageBlockParamSourceMediaType
- type ImageBlockParamSourceType
- type ImageBlockParamType
- type InputJSONDelta
- type InputJSONDeltaType
- type InvalidRequestError
- type InvalidRequestErrorType
- type Message
- type MessageBatch
- type MessageBatchCanceledResult
- type MessageBatchCanceledResultType
- type MessageBatchErroredResult
- type MessageBatchErroredResultType
- type MessageBatchExpiredResult
- type MessageBatchExpiredResultType
- type MessageBatchIndividualResponse
- type MessageBatchListParams
- type MessageBatchNewParams
- type MessageBatchNewParamsRequest
- type MessageBatchProcessingStatus
- type MessageBatchRequestCounts
- type MessageBatchResult
- type MessageBatchResultType
- type MessageBatchResultUnion
- type MessageBatchService
- func (r *MessageBatchService) Cancel(ctx context.Context, messageBatchID string, opts ...option.RequestOption) (res *MessageBatch, err error)
- func (r *MessageBatchService) Get(ctx context.Context, messageBatchID string, opts ...option.RequestOption) (res *MessageBatch, err error)
- func (r *MessageBatchService) List(ctx context.Context, query MessageBatchListParams, ...) (res *pagination.Page[MessageBatch], err error)
- func (r *MessageBatchService) ListAutoPaging(ctx context.Context, query MessageBatchListParams, ...) *pagination.PageAutoPager[MessageBatch]
- func (r *MessageBatchService) New(ctx context.Context, body MessageBatchNewParams, opts ...option.RequestOption) (res *MessageBatch, err error)
- func (r *MessageBatchService) Results(ctx context.Context, messageBatchID string, opts ...option.RequestOption) (res *http.Response, err error)
- type MessageBatchSucceededResult
- type MessageBatchSucceededResultType
- type MessageBatchType
- type MessageCountTokensParams
- type MessageCountTokensParamsSystemArray
- type MessageCountTokensParamsSystemUnion
- type MessageDeltaEvent
- type MessageDeltaEventDelta
- type MessageDeltaEventDeltaStopReason
- type MessageDeltaEventType
- type MessageDeltaUsage
- type MessageNewParams
- type MessageParam
- type MessageParamRole
- type MessageRole
- type MessageService
- func (r *MessageService) CountTokens(ctx context.Context, body MessageCountTokensParams, ...) (res *MessageTokensCount, err error)
- func (r *MessageService) New(ctx context.Context, body MessageNewParams, opts ...option.RequestOption) (res *Message, err error)
- func (r *MessageService) NewStreaming(ctx context.Context, body MessageNewParams, opts ...option.RequestOption) (stream *ssestream.Stream[MessageStreamEvent])
- type MessageStartEvent
- type MessageStartEventType
- type MessageStopEvent
- type MessageStopEventType
- type MessageStopReason
- type MessageStreamEvent
- type MessageStreamEventType
- type MessageStreamEventUnion
- type MessageTokensCount
- type MessageType
- type MetadataParam
- type Model
- type ModelInfo
- type ModelInfoType
- type ModelListParams
- type ModelService
- func (r *ModelService) Get(ctx context.Context, modelID string, opts ...option.RequestOption) (res *ModelInfo, err error)
- func (r *ModelService) List(ctx context.Context, query ModelListParams, opts ...option.RequestOption) (res *pagination.Page[ModelInfo], err error)
- func (r *ModelService) ListAutoPaging(ctx context.Context, query ModelListParams, opts ...option.RequestOption) *pagination.PageAutoPager[ModelInfo]
- type NotFoundError
- type NotFoundErrorType
- type OverloadedError
- type OverloadedErrorType
- type PermissionError
- type PermissionErrorType
- type RateLimitError
- type RateLimitErrorType
- type TextBlock
- type TextBlockParam
- type TextBlockParamType
- type TextBlockType
- type TextDelta
- type TextDeltaType
- type ToolChoiceAnyParam
- type ToolChoiceAnyType
- type ToolChoiceAutoParam
- type ToolChoiceAutoType
- type ToolChoiceParam
- type ToolChoiceToolParam
- type ToolChoiceToolType
- type ToolChoiceType
- type ToolChoiceUnionParam
- type ToolInputSchemaParam
- type ToolInputSchemaType
- type ToolParam
- type ToolResultBlockParam
- type ToolResultBlockParamContent
- type ToolResultBlockParamContentType
- type ToolResultBlockParamContentUnion
- type ToolResultBlockParamType
- type ToolUseBlock
- type ToolUseBlockParam
- type ToolUseBlockParamType
- type ToolUseBlockType
- type Usage
Constants ¶
const APIErrorObjectTypeAPIError = shared.APIErrorObjectTypeAPIError
This is an alias to an internal value.
const AuthenticationErrorTypeAuthenticationError = shared.AuthenticationErrorTypeAuthenticationError
This is an alias to an internal value.
const BillingErrorTypeBillingError = shared.BillingErrorTypeBillingError
This is an alias to an internal value.
const ErrorObjectTypeAPIError = shared.ErrorObjectTypeAPIError
This is an alias to an internal value.
const ErrorObjectTypeAuthenticationError = shared.ErrorObjectTypeAuthenticationError
This is an alias to an internal value.
const ErrorObjectTypeBillingError = shared.ErrorObjectTypeBillingError
This is an alias to an internal value.
const ErrorObjectTypeInvalidRequestError = shared.ErrorObjectTypeInvalidRequestError
This is an alias to an internal value.
const ErrorObjectTypeNotFoundError = shared.ErrorObjectTypeNotFoundError
This is an alias to an internal value.
const ErrorObjectTypeOverloadedError = shared.ErrorObjectTypeOverloadedError
This is an alias to an internal value.
const ErrorObjectTypePermissionError = shared.ErrorObjectTypePermissionError
This is an alias to an internal value.
const ErrorObjectTypeRateLimitError = shared.ErrorObjectTypeRateLimitError
This is an alias to an internal value.
const ErrorObjectTypeTimeoutError = shared.ErrorObjectTypeTimeoutError
This is an alias to an internal value.
const ErrorResponseTypeError = shared.ErrorResponseTypeError
This is an alias to an internal value.
const GatewayTimeoutErrorTypeTimeoutError = shared.GatewayTimeoutErrorTypeTimeoutError
This is an alias to an internal value.
const InvalidRequestErrorTypeInvalidRequestError = shared.InvalidRequestErrorTypeInvalidRequestError
This is an alias to an internal value.
const NotFoundErrorTypeNotFoundError = shared.NotFoundErrorTypeNotFoundError
This is an alias to an internal value.
const OverloadedErrorTypeOverloadedError = shared.OverloadedErrorTypeOverloadedError
This is an alias to an internal value.
const PermissionErrorTypePermissionError = shared.PermissionErrorTypePermissionError
This is an alias to an internal value.
const RateLimitErrorTypeRateLimitError = shared.RateLimitErrorTypeRateLimitError
This is an alias to an internal value.
Variables ¶
This section is empty.
Functions ¶
func F ¶
F is a param field helper used to initialize a param.Field generic struct. This helps specify null, zero values, and overrides, as well as normal values. You can read more about this in our README.
func Int ¶
Int is a param field helper which helps specify integers. This is particularly helpful when specifying integer constants for fields.
func Raw ¶
Raw is a param field helper for specifying values for fields when the type you are looking to send is different from the type that is specified in the SDK. For example, if the type of the field is an integer, but you want to send a float, you could do that by setting the corresponding field with Raw[int](0.5).
Types ¶
type APIErrorObject ¶
type APIErrorObject = shared.APIErrorObject
This is an alias to an internal type.
type APIErrorObjectType ¶
type APIErrorObjectType = shared.APIErrorObjectType
This is an alias to an internal type.
type AnthropicBeta ¶
type AnthropicBeta = string
const ( AnthropicBetaMessageBatches2024_09_24 AnthropicBeta = "message-batches-2024-09-24" AnthropicBetaPromptCaching2024_07_31 AnthropicBeta = "prompt-caching-2024-07-31" AnthropicBetaComputerUse2024_10_22 AnthropicBeta = "computer-use-2024-10-22" AnthropicBetaPDFs2024_09_25 AnthropicBeta = "pdfs-2024-09-25" AnthropicBetaTokenCounting2024_11_01 AnthropicBeta = "token-counting-2024-11-01" )
type AuthenticationError ¶
type AuthenticationError = shared.AuthenticationError
This is an alias to an internal type.
type AuthenticationErrorType ¶
type AuthenticationErrorType = shared.AuthenticationErrorType
This is an alias to an internal type.
type Base64PDFSourceMediaType ¶
type Base64PDFSourceMediaType string
const (
Base64PDFSourceMediaTypeApplicationPDF Base64PDFSourceMediaType = "application/pdf"
)
func (Base64PDFSourceMediaType) IsKnown ¶
func (r Base64PDFSourceMediaType) IsKnown() bool
type Base64PDFSourceParam ¶
type Base64PDFSourceParam struct {
Data param.Field[string] `json:"data,required" format:"byte"`
MediaType param.Field[Base64PDFSourceMediaType] `json:"media_type,required"`
Type param.Field[Base64PDFSourceType] `json:"type,required"`
}
func (Base64PDFSourceParam) MarshalJSON ¶
func (r Base64PDFSourceParam) MarshalJSON() (data []byte, err error)
type Base64PDFSourceType ¶
type Base64PDFSourceType string
const (
Base64PDFSourceTypeBase64 Base64PDFSourceType = "base64"
)
func (Base64PDFSourceType) IsKnown ¶
func (r Base64PDFSourceType) IsKnown() bool
type BetaAPIError ¶
type BetaAPIError struct {
Message string `json:"message,required"`
Type BetaAPIErrorType `json:"type,required"`
JSON betaAPIErrorJSON `json:"-"`
}
func (*BetaAPIError) UnmarshalJSON ¶
func (r *BetaAPIError) UnmarshalJSON(data []byte) (err error)
type BetaAPIErrorType ¶
type BetaAPIErrorType string
const (
BetaAPIErrorTypeAPIError BetaAPIErrorType = "api_error"
)
func (BetaAPIErrorType) IsKnown ¶
func (r BetaAPIErrorType) IsKnown() bool
type BetaAuthenticationError ¶
type BetaAuthenticationError struct {
Message string `json:"message,required"`
Type BetaAuthenticationErrorType `json:"type,required"`
JSON betaAuthenticationErrorJSON `json:"-"`
}
func (*BetaAuthenticationError) UnmarshalJSON ¶
func (r *BetaAuthenticationError) UnmarshalJSON(data []byte) (err error)
type BetaAuthenticationErrorType ¶
type BetaAuthenticationErrorType string
const (
BetaAuthenticationErrorTypeAuthenticationError BetaAuthenticationErrorType = "authentication_error"
)
func (BetaAuthenticationErrorType) IsKnown ¶
func (r BetaAuthenticationErrorType) IsKnown() bool
type BetaBase64PDFBlockParam ¶
type BetaBase64PDFBlockParam struct {
Source param.Field[BetaBase64PDFSourceParam] `json:"source,required"`
Type param.Field[BetaBase64PDFBlockType] `json:"type,required"`
CacheControl param.Field[BetaCacheControlEphemeralParam] `json:"cache_control"`
}
func (BetaBase64PDFBlockParam) MarshalJSON ¶
func (r BetaBase64PDFBlockParam) MarshalJSON() (data []byte, err error)
type BetaBase64PDFBlockType ¶
type BetaBase64PDFBlockType string
const (
BetaBase64PDFBlockTypeDocument BetaBase64PDFBlockType = "document"
)
func (BetaBase64PDFBlockType) IsKnown ¶
func (r BetaBase64PDFBlockType) IsKnown() bool
type BetaBase64PDFSourceMediaType ¶
type BetaBase64PDFSourceMediaType string
const (
BetaBase64PDFSourceMediaTypeApplicationPDF BetaBase64PDFSourceMediaType = "application/pdf"
)
func (BetaBase64PDFSourceMediaType) IsKnown ¶
func (r BetaBase64PDFSourceMediaType) IsKnown() bool
type BetaBase64PDFSourceParam ¶
type BetaBase64PDFSourceParam struct {
Data param.Field[string] `json:"data,required" format:"byte"`
MediaType param.Field[BetaBase64PDFSourceMediaType] `json:"media_type,required"`
Type param.Field[BetaBase64PDFSourceType] `json:"type,required"`
}
func (BetaBase64PDFSourceParam) MarshalJSON ¶
func (r BetaBase64PDFSourceParam) MarshalJSON() (data []byte, err error)
type BetaBase64PDFSourceType ¶
type BetaBase64PDFSourceType string
const (
BetaBase64PDFSourceTypeBase64 BetaBase64PDFSourceType = "base64"
)
func (BetaBase64PDFSourceType) IsKnown ¶
func (r BetaBase64PDFSourceType) IsKnown() bool
type BetaBillingError ¶
type BetaBillingError struct {
Message string `json:"message,required"`
Type BetaBillingErrorType `json:"type,required"`
JSON betaBillingErrorJSON `json:"-"`
}
func (*BetaBillingError) UnmarshalJSON ¶
func (r *BetaBillingError) UnmarshalJSON(data []byte) (err error)
type BetaBillingErrorType ¶
type BetaBillingErrorType string
const (
BetaBillingErrorTypeBillingError BetaBillingErrorType = "billing_error"
)
func (BetaBillingErrorType) IsKnown ¶
func (r BetaBillingErrorType) IsKnown() bool
type BetaCacheControlEphemeralParam ¶
type BetaCacheControlEphemeralParam struct {
Type param.Field[BetaCacheControlEphemeralType] `json:"type,required"`
}
func (BetaCacheControlEphemeralParam) MarshalJSON ¶
func (r BetaCacheControlEphemeralParam) MarshalJSON() (data []byte, err error)
type BetaCacheControlEphemeralType ¶
type BetaCacheControlEphemeralType string
const (
BetaCacheControlEphemeralTypeEphemeral BetaCacheControlEphemeralType = "ephemeral"
)
func (BetaCacheControlEphemeralType) IsKnown ¶
func (r BetaCacheControlEphemeralType) IsKnown() bool
type BetaContentBlock ¶
type BetaContentBlock struct {
Type BetaContentBlockType `json:"type,required"`
ID string `json:"id"`
// This field can have the runtime type of [interface{}].
Input interface{} `json:"input"`
Name string `json:"name"`
Text string `json:"text"`
JSON betaContentBlockJSON `json:"-"`
// contains filtered or unexported fields
}
func (BetaContentBlock) AsUnion ¶
func (r BetaContentBlock) AsUnion() BetaContentBlockUnion
AsUnion returns a BetaContentBlockUnion interface which you can cast to the specific types for more type safety.
Possible runtime types of the union are BetaTextBlock, BetaToolUseBlock.
func (*BetaContentBlock) UnmarshalJSON ¶
func (r *BetaContentBlock) UnmarshalJSON(data []byte) (err error)
type BetaContentBlockParam ¶
type BetaContentBlockParam struct {
Type param.Field[BetaContentBlockParamType] `json:"type,required"`
ID param.Field[string] `json:"id"`
CacheControl param.Field[BetaCacheControlEphemeralParam] `json:"cache_control"`
Content param.Field[interface{}] `json:"content"`
Input param.Field[interface{}] `json:"input"`
IsError param.Field[bool] `json:"is_error"`
Name param.Field[string] `json:"name"`
Source param.Field[interface{}] `json:"source"`
Text param.Field[string] `json:"text"`
ToolUseID param.Field[string] `json:"tool_use_id"`
}
func (BetaContentBlockParam) MarshalJSON ¶
func (r BetaContentBlockParam) MarshalJSON() (data []byte, err error)
type BetaContentBlockParamType ¶
type BetaContentBlockParamType string
const ( BetaContentBlockParamTypeText BetaContentBlockParamType = "text" BetaContentBlockParamTypeImage BetaContentBlockParamType = "image" BetaContentBlockParamTypeToolUse BetaContentBlockParamType = "tool_use" BetaContentBlockParamTypeToolResult BetaContentBlockParamType = "tool_result" BetaContentBlockParamTypeDocument BetaContentBlockParamType = "document" )
func (BetaContentBlockParamType) IsKnown ¶
func (r BetaContentBlockParamType) IsKnown() bool
type BetaContentBlockParamUnion ¶
type BetaContentBlockParamUnion interface {
// contains filtered or unexported methods
}
Satisfied by BetaTextBlockParam, BetaImageBlockParam, BetaToolUseBlockParam, BetaToolResultBlockParam, BetaBase64PDFBlockParam, BetaContentBlockParam.
type BetaContentBlockType ¶
type BetaContentBlockType string
const ( BetaContentBlockTypeText BetaContentBlockType = "text" BetaContentBlockTypeToolUse BetaContentBlockType = "tool_use" )
func (BetaContentBlockType) IsKnown ¶
func (r BetaContentBlockType) IsKnown() bool
type BetaContentBlockUnion ¶
type BetaContentBlockUnion interface {
// contains filtered or unexported methods
}
Union satisfied by BetaTextBlock or BetaToolUseBlock.
type BetaError ¶
type BetaError struct {
Message string `json:"message,required"`
Type BetaErrorType `json:"type,required"`
JSON betaErrorJSON `json:"-"`
// contains filtered or unexported fields
}
func (BetaError) AsUnion ¶
func (r BetaError) AsUnion() BetaErrorUnion
AsUnion returns a BetaErrorUnion interface which you can cast to the specific types for more type safety.
Possible runtime types of the union are BetaInvalidRequestError, BetaAuthenticationError, BetaBillingError, BetaPermissionError, BetaNotFoundError, BetaRateLimitError, BetaGatewayTimeoutError, BetaAPIError, BetaOverloadedError.
func (*BetaError) UnmarshalJSON ¶
type BetaErrorResponse ¶
type BetaErrorResponse struct {
Error BetaError `json:"error,required"`
Type BetaErrorResponseType `json:"type,required"`
JSON betaErrorResponseJSON `json:"-"`
}
func (*BetaErrorResponse) UnmarshalJSON ¶
func (r *BetaErrorResponse) UnmarshalJSON(data []byte) (err error)
type BetaErrorResponseType ¶
type BetaErrorResponseType string
const (
BetaErrorResponseTypeError BetaErrorResponseType = "error"
)
func (BetaErrorResponseType) IsKnown ¶
func (r BetaErrorResponseType) IsKnown() bool
type BetaErrorType ¶
type BetaErrorType string
const ( BetaErrorTypeInvalidRequestError BetaErrorType = "invalid_request_error" BetaErrorTypeAuthenticationError BetaErrorType = "authentication_error" BetaErrorTypeBillingError BetaErrorType = "billing_error" BetaErrorTypePermissionError BetaErrorType = "permission_error" BetaErrorTypeNotFoundError BetaErrorType = "not_found_error" BetaErrorTypeRateLimitError BetaErrorType = "rate_limit_error" BetaErrorTypeTimeoutError BetaErrorType = "timeout_error" BetaErrorTypeAPIError BetaErrorType = "api_error" BetaErrorTypeOverloadedError BetaErrorType = "overloaded_error" )
func (BetaErrorType) IsKnown ¶
func (r BetaErrorType) IsKnown() bool
type BetaErrorUnion ¶
type BetaErrorUnion interface {
// contains filtered or unexported methods
}
Union satisfied by BetaInvalidRequestError, BetaAuthenticationError, BetaBillingError, BetaPermissionError, BetaNotFoundError, BetaRateLimitError, BetaGatewayTimeoutError, BetaAPIError or BetaOverloadedError.
type BetaGatewayTimeoutError ¶
type BetaGatewayTimeoutError struct {
Message string `json:"message,required"`
Type BetaGatewayTimeoutErrorType `json:"type,required"`
JSON betaGatewayTimeoutErrorJSON `json:"-"`
}
func (*BetaGatewayTimeoutError) UnmarshalJSON ¶
func (r *BetaGatewayTimeoutError) UnmarshalJSON(data []byte) (err error)
type BetaGatewayTimeoutErrorType ¶
type BetaGatewayTimeoutErrorType string
const (
BetaGatewayTimeoutErrorTypeTimeoutError BetaGatewayTimeoutErrorType = "timeout_error"
)
func (BetaGatewayTimeoutErrorType) IsKnown ¶
func (r BetaGatewayTimeoutErrorType) IsKnown() bool
type BetaImageBlockParam ¶
type BetaImageBlockParam struct {
Source param.Field[BetaImageBlockParamSource] `json:"source,required"`
Type param.Field[BetaImageBlockParamType] `json:"type,required"`
CacheControl param.Field[BetaCacheControlEphemeralParam] `json:"cache_control"`
}
func (BetaImageBlockParam) MarshalJSON ¶
func (r BetaImageBlockParam) MarshalJSON() (data []byte, err error)
type BetaImageBlockParamSource ¶
type BetaImageBlockParamSource struct {
Data param.Field[string] `json:"data,required" format:"byte"`
MediaType param.Field[BetaImageBlockParamSourceMediaType] `json:"media_type,required"`
Type param.Field[BetaImageBlockParamSourceType] `json:"type,required"`
}
func (BetaImageBlockParamSource) MarshalJSON ¶
func (r BetaImageBlockParamSource) MarshalJSON() (data []byte, err error)
type BetaImageBlockParamSourceMediaType ¶
type BetaImageBlockParamSourceMediaType string
const ( BetaImageBlockParamSourceMediaTypeImageJPEG BetaImageBlockParamSourceMediaType = "image/jpeg" BetaImageBlockParamSourceMediaTypeImagePNG BetaImageBlockParamSourceMediaType = "image/png" BetaImageBlockParamSourceMediaTypeImageGIF BetaImageBlockParamSourceMediaType = "image/gif" BetaImageBlockParamSourceMediaTypeImageWebP BetaImageBlockParamSourceMediaType = "image/webp" )
func (BetaImageBlockParamSourceMediaType) IsKnown ¶
func (r BetaImageBlockParamSourceMediaType) IsKnown() bool
type BetaImageBlockParamSourceType ¶
type BetaImageBlockParamSourceType string
const (
BetaImageBlockParamSourceTypeBase64 BetaImageBlockParamSourceType = "base64"
)
func (BetaImageBlockParamSourceType) IsKnown ¶
func (r BetaImageBlockParamSourceType) IsKnown() bool
type BetaImageBlockParamType ¶
type BetaImageBlockParamType string
const (
BetaImageBlockParamTypeImage BetaImageBlockParamType = "image"
)
func (BetaImageBlockParamType) IsKnown ¶
func (r BetaImageBlockParamType) IsKnown() bool
type BetaInputJSONDelta ¶
type BetaInputJSONDelta struct {
PartialJSON string `json:"partial_json,required"`
Type BetaInputJSONDeltaType `json:"type,required"`
JSON betaInputJSONDeltaJSON `json:"-"`
}
func (*BetaInputJSONDelta) UnmarshalJSON ¶
func (r *BetaInputJSONDelta) UnmarshalJSON(data []byte) (err error)
type BetaInputJSONDeltaType ¶
type BetaInputJSONDeltaType string
const (
BetaInputJSONDeltaTypeInputJSONDelta BetaInputJSONDeltaType = "input_json_delta"
)
func (BetaInputJSONDeltaType) IsKnown ¶
func (r BetaInputJSONDeltaType) IsKnown() bool
type BetaInvalidRequestError ¶
type BetaInvalidRequestError struct {
Message string `json:"message,required"`
Type BetaInvalidRequestErrorType `json:"type,required"`
JSON betaInvalidRequestErrorJSON `json:"-"`
}
func (*BetaInvalidRequestError) UnmarshalJSON ¶
func (r *BetaInvalidRequestError) UnmarshalJSON(data []byte) (err error)
type BetaInvalidRequestErrorType ¶
type BetaInvalidRequestErrorType string
const (
BetaInvalidRequestErrorTypeInvalidRequestError BetaInvalidRequestErrorType = "invalid_request_error"
)
func (BetaInvalidRequestErrorType) IsKnown ¶
func (r BetaInvalidRequestErrorType) IsKnown() bool
type BetaMessage ¶
type BetaMessage struct {
// Unique object identifier.
//
// The format and length of IDs may change over time.
ID string `json:"id,required"`
// Content generated by the model.
//
// This is an array of content blocks, each of which has a `type` that determines
// its shape.
//
// Example:
//
// “`json
// [{ "type": "text", "text": "Hi, I'm Claude." }]
// “`
//
// If the request input `messages` ended with an `assistant` turn, then the
// response `content` will continue directly from that last turn. You can use this
// to constrain the model's output.
//
// For example, if the input `messages` were:
//
// “`json
// [
//
// {
// "role": "user",
// "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
// },
// { "role": "assistant", "content": "The best answer is (" }
//
// ]
// “`
//
// Then the response `content` might be:
//
// “`json
// [{ "type": "text", "text": "B)" }]
// “`
Content []BetaContentBlock `json:"content,required"`
// The model that will complete your prompt.\n\nSee
// [models](https://docs.anthropic.com/en/docs/models-overview) for additional
// details and options.
Model Model `json:"model,required"`
// Conversational role of the generated message.
//
// This will always be `"assistant"`.
Role BetaMessageRole `json:"role,required"`
// The reason that we stopped.
//
// This may be one the following values:
//
// - `"end_turn"`: the model reached a natural stopping point
// - `"max_tokens"`: we exceeded the requested `max_tokens` or the model's maximum
// - `"stop_sequence"`: one of your provided custom `stop_sequences` was generated
// - `"tool_use"`: the model invoked one or more tools
//
// In non-streaming mode this value is always non-null. In streaming mode, it is
// null in the `message_start` event and non-null otherwise.
StopReason BetaMessageStopReason `json:"stop_reason,required,nullable"`
// Which custom stop sequence was generated, if any.
//
// This value will be a non-null string if one of your custom stop sequences was
// generated.
StopSequence string `json:"stop_sequence,required,nullable"`
// Object type.
//
// For Messages, this is always `"message"`.
Type BetaMessageType `json:"type,required"`
// Billing and rate-limit usage.
//
// Anthropic's API bills and rate-limits by token counts, as tokens represent the
// underlying cost to our systems.
//
// Under the hood, the API transforms requests into a format suitable for the
// model. The model's output then goes through a parsing stage before becoming an
// API response. As a result, the token counts in `usage` will not match one-to-one
// with the exact visible content of an API request or response.
//
// For example, `output_tokens` will be non-zero, even for an empty string response
// from Claude.
Usage BetaUsage `json:"usage,required"`
JSON betaMessageJSON `json:"-"`
}
func (*BetaMessage) UnmarshalJSON ¶
func (r *BetaMessage) UnmarshalJSON(data []byte) (err error)
type BetaMessageBatch ¶
type BetaMessageBatch struct {
// Unique object identifier.
//
// The format and length of IDs may change over time.
ID string `json:"id,required"`
// RFC 3339 datetime string representing the time at which the Message Batch was
// archived and its results became unavailable.
ArchivedAt time.Time `json:"archived_at,required,nullable" format:"date-time"`
// RFC 3339 datetime string representing the time at which cancellation was
// initiated for the Message Batch. Specified only if cancellation was initiated.
CancelInitiatedAt time.Time `json:"cancel_initiated_at,required,nullable" format:"date-time"`
// RFC 3339 datetime string representing the time at which the Message Batch was
// created.
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
// RFC 3339 datetime string representing the time at which processing for the
// Message Batch ended. Specified only once processing ends.
//
// Processing ends when every request in a Message Batch has either succeeded,
// errored, canceled, or expired.
EndedAt time.Time `json:"ended_at,required,nullable" format:"date-time"`
// RFC 3339 datetime string representing the time at which the Message Batch will
// expire and end processing, which is 24 hours after creation.
ExpiresAt time.Time `json:"expires_at,required" format:"date-time"`
// Processing status of the Message Batch.
ProcessingStatus BetaMessageBatchProcessingStatus `json:"processing_status,required"`
// Tallies requests within the Message Batch, categorized by their status.
//
// Requests start as `processing` and move to one of the other statuses only once
// processing of the entire batch ends. The sum of all values always matches the
// total number of requests in the batch.
RequestCounts BetaMessageBatchRequestCounts `json:"request_counts,required"`
// URL to a `.jsonl` file containing the results of the Message Batch requests.
// Specified only once processing ends.
//
// Results in the file are not guaranteed to be in the same order as requests. Use
// the `custom_id` field to match results to requests.
ResultsURL string `json:"results_url,required,nullable"`
// Object type.
//
// For Message Batches, this is always `"message_batch"`.
Type BetaMessageBatchType `json:"type,required"`
JSON betaMessageBatchJSON `json:"-"`
}
func (*BetaMessageBatch) UnmarshalJSON ¶
func (r *BetaMessageBatch) UnmarshalJSON(data []byte) (err error)
type BetaMessageBatchCancelParams ¶
type BetaMessageBatchCancelParams struct {
// Optional header to specify the beta version(s) you want to use.
Betas param.Field[[]AnthropicBeta] `header:"anthropic-beta"`
}
type BetaMessageBatchCanceledResult ¶
type BetaMessageBatchCanceledResult struct {
Type BetaMessageBatchCanceledResultType `json:"type,required"`
JSON betaMessageBatchCanceledResultJSON `json:"-"`
}
func (*BetaMessageBatchCanceledResult) UnmarshalJSON ¶
func (r *BetaMessageBatchCanceledResult) UnmarshalJSON(data []byte) (err error)
type BetaMessageBatchCanceledResultType ¶
type BetaMessageBatchCanceledResultType string
const (
BetaMessageBatchCanceledResultTypeCanceled BetaMessageBatchCanceledResultType = "canceled"
)
func (BetaMessageBatchCanceledResultType) IsKnown ¶
func (r BetaMessageBatchCanceledResultType) IsKnown() bool
type BetaMessageBatchErroredResult ¶
type BetaMessageBatchErroredResult struct {
Error BetaErrorResponse `json:"error,required"`
Type BetaMessageBatchErroredResultType `json:"type,required"`
JSON betaMessageBatchErroredResultJSON `json:"-"`
}
func (*BetaMessageBatchErroredResult) UnmarshalJSON ¶
func (r *BetaMessageBatchErroredResult) UnmarshalJSON(data []byte) (err error)
type BetaMessageBatchErroredResultType ¶
type BetaMessageBatchErroredResultType string
const (
BetaMessageBatchErroredResultTypeErrored BetaMessageBatchErroredResultType = "errored"
)
func (BetaMessageBatchErroredResultType) IsKnown ¶
func (r BetaMessageBatchErroredResultType) IsKnown() bool
type BetaMessageBatchExpiredResult ¶
type BetaMessageBatchExpiredResult struct {
Type BetaMessageBatchExpiredResultType `json:"type,required"`
JSON betaMessageBatchExpiredResultJSON `json:"-"`
}
func (*BetaMessageBatchExpiredResult) UnmarshalJSON ¶
func (r *BetaMessageBatchExpiredResult) UnmarshalJSON(data []byte) (err error)
type BetaMessageBatchExpiredResultType ¶
type BetaMessageBatchExpiredResultType string
const (
BetaMessageBatchExpiredResultTypeExpired BetaMessageBatchExpiredResultType = "expired"
)
func (BetaMessageBatchExpiredResultType) IsKnown ¶
func (r BetaMessageBatchExpiredResultType) IsKnown() bool
type BetaMessageBatchGetParams ¶
type BetaMessageBatchGetParams struct {
// Optional header to specify the beta version(s) you want to use.
Betas param.Field[[]AnthropicBeta] `header:"anthropic-beta"`
}
type BetaMessageBatchIndividualResponse ¶
type BetaMessageBatchIndividualResponse struct {
// Developer-provided ID created for each request in a Message Batch. Useful for
// matching results to requests, as results may be given out of request order.
//
// Must be unique for each request within the Message Batch.
CustomID string `json:"custom_id,required"`
// Processing result for this request.
//
// Contains a Message output if processing was successful, an error response if
// processing failed, or the reason why processing was not attempted, such as
// cancellation or expiration.
Result BetaMessageBatchResult `json:"result,required"`
JSON betaMessageBatchIndividualResponseJSON `json:"-"`
}
func (*BetaMessageBatchIndividualResponse) UnmarshalJSON ¶
func (r *BetaMessageBatchIndividualResponse) UnmarshalJSON(data []byte) (err error)
type BetaMessageBatchListParams ¶
type BetaMessageBatchListParams struct {
// ID of the object to use as a cursor for pagination. When provided, returns the
// page of results immediately after this object.
AfterID param.Field[string] `query:"after_id"`
// ID of the object to use as a cursor for pagination. When provided, returns the
// page of results immediately before this object.
BeforeID param.Field[string] `query:"before_id"`
// Number of items to return per page.
//
// Defaults to `20`. Ranges from `1` to `1000`.
Limit param.Field[int64] `query:"limit"`
// Optional header to specify the beta version(s) you want to use.
Betas param.Field[[]AnthropicBeta] `header:"anthropic-beta"`
}
func (BetaMessageBatchListParams) URLQuery ¶
func (r BetaMessageBatchListParams) URLQuery() (v url.Values)
URLQuery serializes BetaMessageBatchListParams's query parameters as `url.Values`.
type BetaMessageBatchNewParams ¶
type BetaMessageBatchNewParams struct {
// List of requests for prompt completion. Each is an individual request to create
// a Message.
Requests param.Field[[]BetaMessageBatchNewParamsRequest] `json:"requests,required"`
// Optional header to specify the beta version(s) you want to use.
Betas param.Field[[]AnthropicBeta] `header:"anthropic-beta"`
}
func (BetaMessageBatchNewParams) MarshalJSON ¶
func (r BetaMessageBatchNewParams) MarshalJSON() (data []byte, err error)
type BetaMessageBatchNewParamsRequest ¶
type BetaMessageBatchNewParamsRequest struct {
// Developer-provided ID created for each request in a Message Batch. Useful for
// matching results to requests, as results may be given out of request order.
//
// Must be unique for each request within the Message Batch.
CustomID param.Field[string] `json:"custom_id,required"`
// Messages API creation parameters for the individual request.
//
// See the [Messages API reference](/en/api/messages) for full documentation on
// available parameters.
Params param.Field[BetaMessageBatchNewParamsRequestsParams] `json:"params,required"`
}
func (BetaMessageBatchNewParamsRequest) MarshalJSON ¶
func (r BetaMessageBatchNewParamsRequest) MarshalJSON() (data []byte, err error)
type BetaMessageBatchNewParamsRequestsParams ¶
type BetaMessageBatchNewParamsRequestsParams struct {
// The maximum number of tokens to generate before stopping.
//
// Note that our models may stop _before_ reaching this maximum. This parameter
// only specifies the absolute maximum number of tokens to generate.
//
// Different models have different maximum values for this parameter. See
// [models](https://docs.anthropic.com/en/docs/models-overview) for details.
MaxTokens param.Field[int64] `json:"max_tokens,required"`
// Input messages.
//
// Our models are trained to operate on alternating `user` and `assistant`
// conversational turns. When creating a new `Message`, you specify the prior
// conversational turns with the `messages` parameter, and the model then generates
// the next `Message` in the conversation. Consecutive `user` or `assistant` turns
// in your request will be combined into a single turn.
//
// Each input message must be an object with a `role` and `content`. You can
// specify a single `user`-role message, or you can include multiple `user` and
// `assistant` messages.
//
// If the final message uses the `assistant` role, the response content will
// continue immediately from the content in that message. This can be used to
// constrain part of the model's response.
//
// Example with a single `user` message:
//
// “`json
// [{ "role": "user", "content": "Hello, Claude" }]
// “`
//
// Example with multiple conversational turns:
//
// “`json
// [
//
// { "role": "user", "content": "Hello there." },
// { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
// { "role": "user", "content": "Can you explain LLMs in plain English?" }
//
// ]
// “`
//
// Example with a partially-filled response from Claude:
//
// “`json
// [
//
// {
// "role": "user",
// "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
// },
// { "role": "assistant", "content": "The best answer is (" }
//
// ]
// “`
//
// Each input message `content` may be either a single `string` or an array of
// content blocks, where each block has a specific `type`. Using a `string` for
// `content` is shorthand for an array of one content block of type `"text"`. The
// following input messages are equivalent:
//
// “`json
// { "role": "user", "content": "Hello, Claude" }
// “`
//
// “`json
// { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
// “`
//
// Starting with Claude 3 models, you can also send image content blocks:
//
// “`json
//
// {
// "role": "user",
// "content": [
// {
// "type": "image",
// "source": {
// "type": "base64",
// "media_type": "image/jpeg",
// "data": "/9j/4AAQSkZJRg..."
// }
// },
// { "type": "text", "text": "What is in this image?" }
// ]
// }
//
// “`
//
// We currently support the `base64` source type for images, and the `image/jpeg`,
// `image/png`, `image/gif`, and `image/webp` media types.
//
// See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
// more input examples.
//
// Note that if you want to include a
// [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
// the top-level `system` parameter — there is no `"system"` role for input
// messages in the Messages API.
Messages param.Field[[]BetaMessageParam] `json:"messages,required"`
// The model that will complete your prompt.\n\nSee
// [models](https://docs.anthropic.com/en/docs/models-overview) for additional
// details and options.
Model param.Field[Model] `json:"model,required"`
// An object describing metadata about the request.
Metadata param.Field[BetaMetadataParam] `json:"metadata"`
// Custom text sequences that will cause the model to stop generating.
//
// Our models will normally stop when they have naturally completed their turn,
// which will result in a response `stop_reason` of `"end_turn"`.
//
// If you want the model to stop generating when it encounters custom strings of
// text, you can use the `stop_sequences` parameter. If the model encounters one of
// the custom sequences, the response `stop_reason` value will be `"stop_sequence"`
// and the response `stop_sequence` value will contain the matched stop sequence.
StopSequences param.Field[[]string] `json:"stop_sequences"`
// Whether to incrementally stream the response using server-sent events.
//
// See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
// details.
Stream param.Field[bool] `json:"stream"`
// System prompt.
//
// A system prompt is a way of providing context and instructions to Claude, such
// as specifying a particular goal or role. See our
// [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
System param.Field[[]BetaTextBlockParam] `json:"system"`
// Amount of randomness injected into the response.
//
// Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
// for analytical / multiple choice, and closer to `1.0` for creative and
// generative tasks.
//
// Note that even with `temperature` of `0.0`, the results will not be fully
// deterministic.
Temperature param.Field[float64] `json:"temperature"`
// How the model should use the provided tools. The model can use a specific tool,
// any available tool, or decide by itself.
ToolChoice param.Field[BetaToolChoiceUnionParam] `json:"tool_choice"`
// Definitions of tools that the model may use.
//
// If you include `tools` in your API request, the model may return `tool_use`
// content blocks that represent the model's use of those tools. You can then run
// those tools using the tool input generated by the model and then optionally
// return results back to the model using `tool_result` content blocks.
//
// Each tool definition includes:
//
// - `name`: Name of the tool.
// - `description`: Optional, but strongly-recommended description of the tool.
// - `input_schema`: [JSON schema](https://json-schema.org/) for the tool `input`
// shape that the model will produce in `tool_use` output content blocks.
//
// For example, if you defined `tools` as:
//
// “`json
// [
//
// {
// "name": "get_stock_price",
// "description": "Get the current stock price for a given ticker symbol.",
// "input_schema": {
// "type": "object",
// "properties": {
// "ticker": {
// "type": "string",
// "description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
// }
// },
// "required": ["ticker"]
// }
// }
//
// ]
// “`
//
// And then asked the model "What's the S&P 500 at today?", the model might produce
// `tool_use` content blocks in the response like this:
//
// “`json
// [
//
// {
// "type": "tool_use",
// "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
// "name": "get_stock_price",
// "input": { "ticker": "^GSPC" }
// }
//
// ]
// “`
//
// You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an
// input, and return the following back to the model in a subsequent `user`
// message:
//
// “`json
// [
//
// {
// "type": "tool_result",
// "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
// "content": "259.75 USD"
// }
//
// ]
// “`
//
// Tools can be used for workflows that include running client-side tools and
// functions, or more generally whenever you want the model to produce a particular
// JSON structure of output.
//
// See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
Tools param.Field[[]BetaToolUnionUnionParam] `json:"tools"`
// Only sample from the top K options for each subsequent token.
//
// Used to remove "long tail" low probability responses.
// [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
//
// Recommended for advanced use cases only. You usually only need to use
// `temperature`.
TopK param.Field[int64] `json:"top_k"`
// Use nucleus sampling.
//
// In nucleus sampling, we compute the cumulative distribution over all the options
// for each subsequent token in decreasing probability order and cut it off once it
// reaches a particular probability specified by `top_p`. You should either alter
// `temperature` or `top_p`, but not both.
//
// Recommended for advanced use cases only. You usually only need to use
// `temperature`.
TopP param.Field[float64] `json:"top_p"`
}
Messages API creation parameters for the individual request.
See the [Messages API reference](/en/api/messages) for full documentation on available parameters.
func (BetaMessageBatchNewParamsRequestsParams) MarshalJSON ¶
func (r BetaMessageBatchNewParamsRequestsParams) MarshalJSON() (data []byte, err error)
type BetaMessageBatchProcessingStatus ¶
type BetaMessageBatchProcessingStatus string
Processing status of the Message Batch.
const ( BetaMessageBatchProcessingStatusInProgress BetaMessageBatchProcessingStatus = "in_progress" BetaMessageBatchProcessingStatusCanceling BetaMessageBatchProcessingStatus = "canceling" BetaMessageBatchProcessingStatusEnded BetaMessageBatchProcessingStatus = "ended" )
func (BetaMessageBatchProcessingStatus) IsKnown ¶
func (r BetaMessageBatchProcessingStatus) IsKnown() bool
type BetaMessageBatchRequestCounts ¶
type BetaMessageBatchRequestCounts struct {
// Number of requests in the Message Batch that have been canceled.
//
// This is zero until processing of the entire Message Batch has ended.
Canceled int64 `json:"canceled,required"`
// Number of requests in the Message Batch that encountered an error.
//
// This is zero until processing of the entire Message Batch has ended.
Errored int64 `json:"errored,required"`
// Number of requests in the Message Batch that have expired.
//
// This is zero until processing of the entire Message Batch has ended.
Expired int64 `json:"expired,required"`
// Number of requests in the Message Batch that are processing.
Processing int64 `json:"processing,required"`
// Number of requests in the Message Batch that have completed successfully.
//
// This is zero until processing of the entire Message Batch has ended.
Succeeded int64 `json:"succeeded,required"`
JSON betaMessageBatchRequestCountsJSON `json:"-"`
}
func (*BetaMessageBatchRequestCounts) UnmarshalJSON ¶
func (r *BetaMessageBatchRequestCounts) UnmarshalJSON(data []byte) (err error)
type BetaMessageBatchResult ¶
type BetaMessageBatchResult struct {
Type BetaMessageBatchResultType `json:"type,required"`
Error BetaErrorResponse `json:"error"`
Message BetaMessage `json:"message"`
JSON betaMessageBatchResultJSON `json:"-"`
// contains filtered or unexported fields
}
Processing result for this request.
Contains a Message output if processing was successful, an error response if processing failed, or the reason why processing was not attempted, such as cancellation or expiration.
func (BetaMessageBatchResult) AsUnion ¶
func (r BetaMessageBatchResult) AsUnion() BetaMessageBatchResultUnion
AsUnion returns a BetaMessageBatchResultUnion interface which you can cast to the specific types for more type safety.
Possible runtime types of the union are BetaMessageBatchSucceededResult, BetaMessageBatchErroredResult, BetaMessageBatchCanceledResult, BetaMessageBatchExpiredResult.
func (*BetaMessageBatchResult) UnmarshalJSON ¶
func (r *BetaMessageBatchResult) UnmarshalJSON(data []byte) (err error)
type BetaMessageBatchResultType ¶
type BetaMessageBatchResultType string
const ( BetaMessageBatchResultTypeSucceeded BetaMessageBatchResultType = "succeeded" BetaMessageBatchResultTypeErrored BetaMessageBatchResultType = "errored" BetaMessageBatchResultTypeCanceled BetaMessageBatchResultType = "canceled" BetaMessageBatchResultTypeExpired BetaMessageBatchResultType = "expired" )
func (BetaMessageBatchResultType) IsKnown ¶
func (r BetaMessageBatchResultType) IsKnown() bool
type BetaMessageBatchResultUnion ¶
type BetaMessageBatchResultUnion interface {
// contains filtered or unexported methods
}
Processing result for this request.
Contains a Message output if processing was successful, an error response if processing failed, or the reason why processing was not attempted, such as cancellation or expiration.
Union satisfied by BetaMessageBatchSucceededResult, BetaMessageBatchErroredResult, BetaMessageBatchCanceledResult or BetaMessageBatchExpiredResult.
type BetaMessageBatchResultsParams ¶
type BetaMessageBatchResultsParams struct {
// Optional header to specify the beta version(s) you want to use.
Betas param.Field[[]AnthropicBeta] `header:"anthropic-beta"`
}
type BetaMessageBatchService ¶
type BetaMessageBatchService struct {
Options []option.RequestOption
}
BetaMessageBatchService contains methods and other services that help with interacting with the anthropic API.
Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewBetaMessageBatchService method instead.
func NewBetaMessageBatchService ¶
func NewBetaMessageBatchService(opts ...option.RequestOption) (r *BetaMessageBatchService)
NewBetaMessageBatchService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.
func (*BetaMessageBatchService) Cancel ¶
func (r *BetaMessageBatchService) Cancel(ctx context.Context, messageBatchID string, body BetaMessageBatchCancelParams, opts ...option.RequestOption) (res *BetaMessageBatch, err error)
Batches may be canceled any time before processing ends. Once cancellation is initiated, the batch enters a `canceling` state, at which time the system may complete any in-progress, non-interruptible requests before finalizing cancellation.
The number of canceled requests is specified in `request_counts`. To determine which requests were canceled, check the individual results within the batch. Note that cancellation may not result in any canceled requests if they were non-interruptible.
func (*BetaMessageBatchService) Get ¶
func (r *BetaMessageBatchService) Get(ctx context.Context, messageBatchID string, query BetaMessageBatchGetParams, opts ...option.RequestOption) (res *BetaMessageBatch, err error)
This endpoint is idempotent and can be used to poll for Message Batch completion. To access the results of a Message Batch, make a request to the `results_url` field in the response.
func (*BetaMessageBatchService) List ¶
func (r *BetaMessageBatchService) List(ctx context.Context, params BetaMessageBatchListParams, opts ...option.RequestOption) (res *pagination.Page[BetaMessageBatch], err error)
List all Message Batches within a Workspace. Most recently created batches are returned first.
func (*BetaMessageBatchService) ListAutoPaging ¶
func (r *BetaMessageBatchService) ListAutoPaging(ctx context.Context, params BetaMessageBatchListParams, opts ...option.RequestOption) *pagination.PageAutoPager[BetaMessageBatch]
List all Message Batches within a Workspace. Most recently created batches are returned first.
func (*BetaMessageBatchService) New ¶
func (r *BetaMessageBatchService) New(ctx context.Context, params BetaMessageBatchNewParams, opts ...option.RequestOption) (res *BetaMessageBatch, err error)
Send a batch of Message creation requests.
The Message Batches API can be used to process multiple Messages API requests at once. Once a Message Batch is created, it begins processing immediately. Batches can take up to 24 hours to complete.
func (*BetaMessageBatchService) Results ¶
func (r *BetaMessageBatchService) Results(ctx context.Context, messageBatchID string, query BetaMessageBatchResultsParams, opts ...option.RequestOption) (res *http.Response, err error)
Streams the results of a Message Batch as a `.jsonl` file.
Each line in the file is a JSON object containing the result of a single request in the Message Batch. Results are not guaranteed to be in the same order as requests. Use the `custom_id` field to match results to requests.
type BetaMessageBatchSucceededResult ¶
type BetaMessageBatchSucceededResult struct {
Message BetaMessage `json:"message,required"`
Type BetaMessageBatchSucceededResultType `json:"type,required"`
JSON betaMessageBatchSucceededResultJSON `json:"-"`
}
func (*BetaMessageBatchSucceededResult) UnmarshalJSON ¶
func (r *BetaMessageBatchSucceededResult) UnmarshalJSON(data []byte) (err error)
type BetaMessageBatchSucceededResultType ¶
type BetaMessageBatchSucceededResultType string
const (
BetaMessageBatchSucceededResultTypeSucceeded BetaMessageBatchSucceededResultType = "succeeded"
)
func (BetaMessageBatchSucceededResultType) IsKnown ¶
func (r BetaMessageBatchSucceededResultType) IsKnown() bool
type BetaMessageBatchType ¶
type BetaMessageBatchType string
Object type.
For Message Batches, this is always `"message_batch"`.
const (
BetaMessageBatchTypeMessageBatch BetaMessageBatchType = "message_batch"
)
func (BetaMessageBatchType) IsKnown ¶
func (r BetaMessageBatchType) IsKnown() bool
type BetaMessageCountTokensParams ¶
type BetaMessageCountTokensParams struct {
// Input messages.
//
// Our models are trained to operate on alternating `user` and `assistant`
// conversational turns. When creating a new `Message`, you specify the prior
// conversational turns with the `messages` parameter, and the model then generates
// the next `Message` in the conversation. Consecutive `user` or `assistant` turns
// in your request will be combined into a single turn.
//
// Each input message must be an object with a `role` and `content`. You can
// specify a single `user`-role message, or you can include multiple `user` and
// `assistant` messages.
//
// If the final message uses the `assistant` role, the response content will
// continue immediately from the content in that message. This can be used to
// constrain part of the model's response.
//
// Example with a single `user` message:
//
// “`json
// [{ "role": "user", "content": "Hello, Claude" }]
// “`
//
// Example with multiple conversational turns:
//
// “`json
// [
//
// { "role": "user", "content": "Hello there." },
// { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
// { "role": "user", "content": "Can you explain LLMs in plain English?" }
//
// ]
// “`
//
// Example with a partially-filled response from Claude:
//
// “`json
// [
//
// {
// "role": "user",
// "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
// },
// { "role": "assistant", "content": "The best answer is (" }
//
// ]
// “`
//
// Each input message `content` may be either a single `string` or an array of
// content blocks, where each block has a specific `type`. Using a `string` for
// `content` is shorthand for an array of one content block of type `"text"`. The
// following input messages are equivalent:
//
// “`json
// { "role": "user", "content": "Hello, Claude" }
// “`
//
// “`json
// { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
// “`
//
// Starting with Claude 3 models, you can also send image content blocks:
//
// “`json
//
// {
// "role": "user",
// "content": [
// {
// "type": "image",
// "source": {
// "type": "base64",
// "media_type": "image/jpeg",
// "data": "/9j/4AAQSkZJRg..."
// }
// },
// { "type": "text", "text": "What is in this image?" }
// ]
// }
//
// “`
//
// We currently support the `base64` source type for images, and the `image/jpeg`,
// `image/png`, `image/gif`, and `image/webp` media types.
//
// See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
// more input examples.
//
// Note that if you want to include a
// [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
// the top-level `system` parameter — there is no `"system"` role for input
// messages in the Messages API.
Messages param.Field[[]BetaMessageParam] `json:"messages,required"`
// The model that will complete your prompt.\n\nSee
// [models](https://docs.anthropic.com/en/docs/models-overview) for additional
// details and options.
Model param.Field[Model] `json:"model,required"`
// System prompt.
//
// A system prompt is a way of providing context and instructions to Claude, such
// as specifying a particular goal or role. See our
// [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
System param.Field[BetaMessageCountTokensParamsSystemUnion] `json:"system"`
// How the model should use the provided tools. The model can use a specific tool,
// any available tool, or decide by itself.
ToolChoice param.Field[BetaToolChoiceUnionParam] `json:"tool_choice"`
// Definitions of tools that the model may use.
//
// If you include `tools` in your API request, the model may return `tool_use`
// content blocks that represent the model's use of those tools. You can then run
// those tools using the tool input generated by the model and then optionally
// return results back to the model using `tool_result` content blocks.
//
// Each tool definition includes:
//
// - `name`: Name of the tool.
// - `description`: Optional, but strongly-recommended description of the tool.
// - `input_schema`: [JSON schema](https://json-schema.org/) for the tool `input`
// shape that the model will produce in `tool_use` output content blocks.
//
// For example, if you defined `tools` as:
//
// “`json
// [
//
// {
// "name": "get_stock_price",
// "description": "Get the current stock price for a given ticker symbol.",
// "input_schema": {
// "type": "object",
// "properties": {
// "ticker": {
// "type": "string",
// "description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
// }
// },
// "required": ["ticker"]
// }
// }
//
// ]
// “`
//
// And then asked the model "What's the S&P 500 at today?", the model might produce
// `tool_use` content blocks in the response like this:
//
// “`json
// [
//
// {
// "type": "tool_use",
// "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
// "name": "get_stock_price",
// "input": { "ticker": "^GSPC" }
// }
//
// ]
// “`
//
// You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an
// input, and return the following back to the model in a subsequent `user`
// message:
//
// “`json
// [
//
// {
// "type": "tool_result",
// "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
// "content": "259.75 USD"
// }
//
// ]
// “`
//
// Tools can be used for workflows that include running client-side tools and
// functions, or more generally whenever you want the model to produce a particular
// JSON structure of output.
//
// See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
Tools param.Field[[]BetaMessageCountTokensParamsToolUnion] `json:"tools"`
// Optional header to specify the beta version(s) you want to use.
Betas param.Field[[]AnthropicBeta] `header:"anthropic-beta"`
}
func (BetaMessageCountTokensParams) MarshalJSON ¶
func (r BetaMessageCountTokensParams) MarshalJSON() (data []byte, err error)
type BetaMessageCountTokensParamsSystemArray ¶
type BetaMessageCountTokensParamsSystemArray []BetaTextBlockParam
func (BetaMessageCountTokensParamsSystemArray) ImplementsBetaMessageCountTokensParamsSystemUnion ¶
func (r BetaMessageCountTokensParamsSystemArray) ImplementsBetaMessageCountTokensParamsSystemUnion()
type BetaMessageCountTokensParamsSystemUnion ¶
type BetaMessageCountTokensParamsSystemUnion interface {
ImplementsBetaMessageCountTokensParamsSystemUnion()
}
System prompt.
A system prompt is a way of providing context and instructions to Claude, such as specifying a particular goal or role. See our [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
Satisfied by shared.UnionString, BetaMessageCountTokensParamsSystemArray.
type BetaMessageCountTokensParamsTool ¶
type BetaMessageCountTokensParamsTool struct {
// Name of the tool.
//
// This is how the tool will be called by the model and in tool_use blocks.
Name param.Field[string] `json:"name,required"`
CacheControl param.Field[BetaCacheControlEphemeralParam] `json:"cache_control"`
// Description of what this tool does.
//
// Tool descriptions should be as detailed as possible. The more information that
// the model has about what the tool is and how to use it, the better it will
// perform. You can use natural language descriptions to reinforce important
// aspects of the tool input JSON schema.
Description param.Field[string] `json:"description"`
// The height of the display in pixels.
DisplayHeightPx param.Field[int64] `json:"display_height_px"`
// The X11 display number (e.g. 0, 1) for the display.
DisplayNumber param.Field[int64] `json:"display_number"`
// The width of the display in pixels.
DisplayWidthPx param.Field[int64] `json:"display_width_px"`
InputSchema param.Field[interface{}] `json:"input_schema"`
Type param.Field[BetaMessageCountTokensParamsToolsType] `json:"type"`
}
func (BetaMessageCountTokensParamsTool) MarshalJSON ¶
func (r BetaMessageCountTokensParamsTool) MarshalJSON() (data []byte, err error)
type BetaMessageCountTokensParamsToolUnion ¶
type BetaMessageCountTokensParamsToolUnion interface {
// contains filtered or unexported methods
}
Satisfied by BetaToolParam, BetaToolComputerUse20241022Param, BetaToolBash20241022Param, BetaToolTextEditor20241022Param, BetaMessageCountTokensParamsTool.
type BetaMessageCountTokensParamsToolsType ¶
type BetaMessageCountTokensParamsToolsType string
const ( BetaMessageCountTokensParamsToolsTypeCustom BetaMessageCountTokensParamsToolsType = "custom" BetaMessageCountTokensParamsToolsTypeComputer20241022 BetaMessageCountTokensParamsToolsType = "computer_20241022" BetaMessageCountTokensParamsToolsTypeBash20241022 BetaMessageCountTokensParamsToolsType = "bash_20241022" BetaMessageCountTokensParamsToolsTypeTextEditor20241022 BetaMessageCountTokensParamsToolsType = "text_editor_20241022" )
func (BetaMessageCountTokensParamsToolsType) IsKnown ¶
func (r BetaMessageCountTokensParamsToolsType) IsKnown() bool
type BetaMessageDeltaUsage ¶
type BetaMessageDeltaUsage struct {
// The cumulative number of output tokens which were used.
OutputTokens int64 `json:"output_tokens,required"`
JSON betaMessageDeltaUsageJSON `json:"-"`
}
func (*BetaMessageDeltaUsage) UnmarshalJSON ¶
func (r *BetaMessageDeltaUsage) UnmarshalJSON(data []byte) (err error)
type BetaMessageNewParams ¶
type BetaMessageNewParams struct {
// The maximum number of tokens to generate before stopping.
//
// Note that our models may stop _before_ reaching this maximum. This parameter
// only specifies the absolute maximum number of tokens to generate.
//
// Different models have different maximum values for this parameter. See
// [models](https://docs.anthropic.com/en/docs/models-overview) for details.
MaxTokens param.Field[int64] `json:"max_tokens,required"`
// Input messages.
//
// Our models are trained to operate on alternating `user` and `assistant`
// conversational turns. When creating a new `Message`, you specify the prior
// conversational turns with the `messages` parameter, and the model then generates
// the next `Message` in the conversation. Consecutive `user` or `assistant` turns
// in your request will be combined into a single turn.
//
// Each input message must be an object with a `role` and `content`. You can
// specify a single `user`-role message, or you can include multiple `user` and
// `assistant` messages.
//
// If the final message uses the `assistant` role, the response content will
// continue immediately from the content in that message. This can be used to
// constrain part of the model's response.
//
// Example with a single `user` message:
//
// “`json
// [{ "role": "user", "content": "Hello, Claude" }]
// “`
//
// Example with multiple conversational turns:
//
// “`json
// [
//
// { "role": "user", "content": "Hello there." },
// { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
// { "role": "user", "content": "Can you explain LLMs in plain English?" }
//
// ]
// “`
//
// Example with a partially-filled response from Claude:
//
// “`json
// [
//
// {
// "role": "user",
// "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
// },
// { "role": "assistant", "content": "The best answer is (" }
//
// ]
// “`
//
// Each input message `content` may be either a single `string` or an array of
// content blocks, where each block has a specific `type`. Using a `string` for
// `content` is shorthand for an array of one content block of type `"text"`. The
// following input messages are equivalent:
//
// “`json
// { "role": "user", "content": "Hello, Claude" }
// “`
//
// “`json
// { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
// “`
//
// Starting with Claude 3 models, you can also send image content blocks:
//
// “`json
//
// {
// "role": "user",
// "content": [
// {
// "type": "image",
// "source": {
// "type": "base64",
// "media_type": "image/jpeg",
// "data": "/9j/4AAQSkZJRg..."
// }
// },
// { "type": "text", "text": "What is in this image?" }
// ]
// }
//
// “`
//
// We currently support the `base64` source type for images, and the `image/jpeg`,
// `image/png`, `image/gif`, and `image/webp` media types.
//
// See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
// more input examples.
//
// Note that if you want to include a
// [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
// the top-level `system` parameter — there is no `"system"` role for input
// messages in the Messages API.
Messages param.Field[[]BetaMessageParam] `json:"messages,required"`
// The model that will complete your prompt.\n\nSee
// [models](https://docs.anthropic.com/en/docs/models-overview) for additional
// details and options.
Model param.Field[Model] `json:"model,required"`
// An object describing metadata about the request.
Metadata param.Field[BetaMetadataParam] `json:"metadata"`
// Custom text sequences that will cause the model to stop generating.
//
// Our models will normally stop when they have naturally completed their turn,
// which will result in a response `stop_reason` of `"end_turn"`.
//
// If you want the model to stop generating when it encounters custom strings of
// text, you can use the `stop_sequences` parameter. If the model encounters one of
// the custom sequences, the response `stop_reason` value will be `"stop_sequence"`
// and the response `stop_sequence` value will contain the matched stop sequence.
StopSequences param.Field[[]string] `json:"stop_sequences"`
// System prompt.
//
// A system prompt is a way of providing context and instructions to Claude, such
// as specifying a particular goal or role. See our
// [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
System param.Field[[]BetaTextBlockParam] `json:"system"`
// Amount of randomness injected into the response.
//
// Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
// for analytical / multiple choice, and closer to `1.0` for creative and
// generative tasks.
//
// Note that even with `temperature` of `0.0`, the results will not be fully
// deterministic.
Temperature param.Field[float64] `json:"temperature"`
// How the model should use the provided tools. The model can use a specific tool,
// any available tool, or decide by itself.
ToolChoice param.Field[BetaToolChoiceUnionParam] `json:"tool_choice"`
// Definitions of tools that the model may use.
//
// If you include `tools` in your API request, the model may return `tool_use`
// content blocks that represent the model's use of those tools. You can then run
// those tools using the tool input generated by the model and then optionally
// return results back to the model using `tool_result` content blocks.
//
// Each tool definition includes:
//
// - `name`: Name of the tool.
// - `description`: Optional, but strongly-recommended description of the tool.
// - `input_schema`: [JSON schema](https://json-schema.org/) for the tool `input`
// shape that the model will produce in `tool_use` output content blocks.
//
// For example, if you defined `tools` as:
//
// “`json
// [
//
// {
// "name": "get_stock_price",
// "description": "Get the current stock price for a given ticker symbol.",
// "input_schema": {
// "type": "object",
// "properties": {
// "ticker": {
// "type": "string",
// "description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
// }
// },
// "required": ["ticker"]
// }
// }
//
// ]
// “`
//
// And then asked the model "What's the S&P 500 at today?", the model might produce
// `tool_use` content blocks in the response like this:
//
// “`json
// [
//
// {
// "type": "tool_use",
// "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
// "name": "get_stock_price",
// "input": { "ticker": "^GSPC" }
// }
//
// ]
// “`
//
// You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an
// input, and return the following back to the model in a subsequent `user`
// message:
//
// “`json
// [
//
// {
// "type": "tool_result",
// "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
// "content": "259.75 USD"
// }
//
// ]
// “`
//
// Tools can be used for workflows that include running client-side tools and
// functions, or more generally whenever you want the model to produce a particular
// JSON structure of output.
//
// See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
Tools param.Field[[]BetaToolUnionUnionParam] `json:"tools"`
// Only sample from the top K options for each subsequent token.
//
// Used to remove "long tail" low probability responses.
// [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
//
// Recommended for advanced use cases only. You usually only need to use
// `temperature`.
TopK param.Field[int64] `json:"top_k"`
// Use nucleus sampling.
//
// In nucleus sampling, we compute the cumulative distribution over all the options
// for each subsequent token in decreasing probability order and cut it off once it
// reaches a particular probability specified by `top_p`. You should either alter
// `temperature` or `top_p`, but not both.
//
// Recommended for advanced use cases only. You usually only need to use
// `temperature`.
TopP param.Field[float64] `json:"top_p"`
// Optional header to specify the beta version(s) you want to use.
Betas param.Field[[]AnthropicBeta] `header:"anthropic-beta"`
}
func (BetaMessageNewParams) MarshalJSON ¶
func (r BetaMessageNewParams) MarshalJSON() (data []byte, err error)
type BetaMessageParam ¶
type BetaMessageParam struct {
Content param.Field[[]BetaContentBlockParamUnion] `json:"content,required"`
Role param.Field[BetaMessageParamRole] `json:"role,required"`
}
func (BetaMessageParam) MarshalJSON ¶
func (r BetaMessageParam) MarshalJSON() (data []byte, err error)
type BetaMessageParamRole ¶
type BetaMessageParamRole string
const ( BetaMessageParamRoleUser BetaMessageParamRole = "user" BetaMessageParamRoleAssistant BetaMessageParamRole = "assistant" )
func (BetaMessageParamRole) IsKnown ¶
func (r BetaMessageParamRole) IsKnown() bool
type BetaMessageRole ¶
type BetaMessageRole string
Conversational role of the generated message.
This will always be `"assistant"`.
const (
BetaMessageRoleAssistant BetaMessageRole = "assistant"
)
func (BetaMessageRole) IsKnown ¶
func (r BetaMessageRole) IsKnown() bool
type BetaMessageService ¶
type BetaMessageService struct {
Options []option.RequestOption
Batches *BetaMessageBatchService
}
BetaMessageService contains methods and other services that help with interacting with the anthropic API.
Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewBetaMessageService method instead.
func NewBetaMessageService ¶
func NewBetaMessageService(opts ...option.RequestOption) (r *BetaMessageService)
NewBetaMessageService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.
func (*BetaMessageService) CountTokens ¶
func (r *BetaMessageService) CountTokens(ctx context.Context, params BetaMessageCountTokensParams, opts ...option.RequestOption) (res *BetaMessageTokensCount, err error)
Count the number of tokens in a Message.
The Token Count API can be used to count the number of tokens in a Message, including tools, images, and documents, without creating it.
func (*BetaMessageService) New ¶
func (r *BetaMessageService) New(ctx context.Context, params BetaMessageNewParams, opts ...option.RequestOption) (res *BetaMessage, err error)
Send a structured list of input messages with text and/or image content, and the model will generate the next message in the conversation.
The Messages API can be used for either single queries or stateless multi-turn conversations.
Note: If you choose to set a timeout for this request, we recommend 10 minutes.
func (*BetaMessageService) NewStreaming ¶
func (r *BetaMessageService) NewStreaming(ctx context.Context, params BetaMessageNewParams, opts ...option.RequestOption) (stream *ssestream.Stream[BetaRawMessageStreamEvent])
Send a structured list of input messages with text and/or image content, and the model will generate the next message in the conversation.
The Messages API can be used for either single queries or stateless multi-turn conversations.
Note: If you choose to set a timeout for this request, we recommend 10 minutes.
type BetaMessageStopReason ¶
type BetaMessageStopReason string
The reason that we stopped.
This may be one the following values:
- `"end_turn"`: the model reached a natural stopping point - `"max_tokens"`: we exceeded the requested `max_tokens` or the model's maximum - `"stop_sequence"`: one of your provided custom `stop_sequences` was generated - `"tool_use"`: the model invoked one or more tools
In non-streaming mode this value is always non-null. In streaming mode, it is null in the `message_start` event and non-null otherwise.
const ( BetaMessageStopReasonEndTurn BetaMessageStopReason = "end_turn" BetaMessageStopReasonMaxTokens BetaMessageStopReason = "max_tokens" BetaMessageStopReasonStopSequence BetaMessageStopReason = "stop_sequence" BetaMessageStopReasonToolUse BetaMessageStopReason = "tool_use" )
func (BetaMessageStopReason) IsKnown ¶
func (r BetaMessageStopReason) IsKnown() bool
type BetaMessageTokensCount ¶
type BetaMessageTokensCount struct {
// The total number of tokens across the provided list of messages, system prompt,
// and tools.
InputTokens int64 `json:"input_tokens,required"`
JSON betaMessageTokensCountJSON `json:"-"`
}
func (*BetaMessageTokensCount) UnmarshalJSON ¶
func (r *BetaMessageTokensCount) UnmarshalJSON(data []byte) (err error)
type BetaMessageType ¶
type BetaMessageType string
Object type.
For Messages, this is always `"message"`.
const (
BetaMessageTypeMessage BetaMessageType = "message"
)
func (BetaMessageType) IsKnown ¶
func (r BetaMessageType) IsKnown() bool
type BetaMetadataParam ¶
type BetaMetadataParam struct {
// An external identifier for the user who is associated with the request.
//
// This should be a uuid, hash value, or other opaque identifier. Anthropic may use
// this id to help detect abuse. Do not include any identifying information such as
// name, email address, or phone number.
UserID param.Field[string] `json:"user_id"`
}
func (BetaMetadataParam) MarshalJSON ¶
func (r BetaMetadataParam) MarshalJSON() (data []byte, err error)
type BetaModelInfo ¶
type BetaModelInfo struct {
// Unique model identifier.
ID string `json:"id,required"`
// RFC 3339 datetime string representing the time at which the model was released.
// May be set to an epoch value if the release date is unknown.
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
// A human-readable name for the model.
DisplayName string `json:"display_name,required"`
// Object type.
//
// For Models, this is always `"model"`.
Type BetaModelInfoType `json:"type,required"`
JSON betaModelInfoJSON `json:"-"`
}
func (*BetaModelInfo) UnmarshalJSON ¶
func (r *BetaModelInfo) UnmarshalJSON(data []byte) (err error)
type BetaModelInfoType ¶
type BetaModelInfoType string
Object type.
For Models, this is always `"model"`.
const (
BetaModelInfoTypeModel BetaModelInfoType = "model"
)
func (BetaModelInfoType) IsKnown ¶
func (r BetaModelInfoType) IsKnown() bool
type BetaModelListParams ¶
type BetaModelListParams struct {
// ID of the object to use as a cursor for pagination. When provided, returns the
// page of results immediately after this object.
AfterID param.Field[string] `query:"after_id"`
// ID of the object to use as a cursor for pagination. When provided, returns the
// page of results immediately before this object.
BeforeID param.Field[string] `query:"before_id"`
// Number of items to return per page.
//
// Defaults to `20`. Ranges from `1` to `1000`.
Limit param.Field[int64] `query:"limit"`
}
func (BetaModelListParams) URLQuery ¶
func (r BetaModelListParams) URLQuery() (v url.Values)
URLQuery serializes BetaModelListParams's query parameters as `url.Values`.
type BetaModelService ¶
type BetaModelService struct {
Options []option.RequestOption
}
BetaModelService contains methods and other services that help with interacting with the anthropic API.
Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewBetaModelService method instead.
func NewBetaModelService ¶
func NewBetaModelService(opts ...option.RequestOption) (r *BetaModelService)
NewBetaModelService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.
func (*BetaModelService) Get ¶
func (r *BetaModelService) Get(ctx context.Context, modelID string, opts ...option.RequestOption) (res *BetaModelInfo, err error)
Get a specific model.
The Models API response can be used to determine information about a specific model or resolve a model alias to a model ID.
func (*BetaModelService) List ¶
func (r *BetaModelService) List(ctx context.Context, query BetaModelListParams, opts ...option.RequestOption) (res *pagination.Page[BetaModelInfo], err error)
List available models.
The Models API response can be used to determine which models are available for use in the API. More recently released models are listed first.
func (*BetaModelService) ListAutoPaging ¶
func (r *BetaModelService) ListAutoPaging(ctx context.Context, query BetaModelListParams, opts ...option.RequestOption) *pagination.PageAutoPager[BetaModelInfo]
List available models.
The Models API response can be used to determine which models are available for use in the API. More recently released models are listed first.
type BetaNotFoundError ¶
type BetaNotFoundError struct {
Message string `json:"message,required"`
Type BetaNotFoundErrorType `json:"type,required"`
JSON betaNotFoundErrorJSON `json:"-"`
}
func (*BetaNotFoundError) UnmarshalJSON ¶
func (r *BetaNotFoundError) UnmarshalJSON(data []byte) (err error)
type BetaNotFoundErrorType ¶
type BetaNotFoundErrorType string
const (
BetaNotFoundErrorTypeNotFoundError BetaNotFoundErrorType = "not_found_error"
)
func (BetaNotFoundErrorType) IsKnown ¶
func (r BetaNotFoundErrorType) IsKnown() bool
type BetaOverloadedError ¶
type BetaOverloadedError struct {
Message string `json:"message,required"`
Type BetaOverloadedErrorType `json:"type,required"`
JSON betaOverloadedErrorJSON `json:"-"`
}
func (*BetaOverloadedError) UnmarshalJSON ¶
func (r *BetaOverloadedError) UnmarshalJSON(data []byte) (err error)
type BetaOverloadedErrorType ¶
type BetaOverloadedErrorType string
const (
BetaOverloadedErrorTypeOverloadedError BetaOverloadedErrorType = "overloaded_error"
)
func (BetaOverloadedErrorType) IsKnown ¶
func (r BetaOverloadedErrorType) IsKnown() bool
type BetaPermissionError ¶
type BetaPermissionError struct {
Message string `json:"message,required"`
Type BetaPermissionErrorType `json:"type,required"`
JSON betaPermissionErrorJSON `json:"-"`
}
func (*BetaPermissionError) UnmarshalJSON ¶
func (r *BetaPermissionError) UnmarshalJSON(data []byte) (err error)
type BetaPermissionErrorType ¶
type BetaPermissionErrorType string
const (
BetaPermissionErrorTypePermissionError BetaPermissionErrorType = "permission_error"
)
func (BetaPermissionErrorType) IsKnown ¶
func (r BetaPermissionErrorType) IsKnown() bool
type BetaRateLimitError ¶
type BetaRateLimitError struct {
Message string `json:"message,required"`
Type BetaRateLimitErrorType `json:"type,required"`
JSON betaRateLimitErrorJSON `json:"-"`
}
func (*BetaRateLimitError) UnmarshalJSON ¶
func (r *BetaRateLimitError) UnmarshalJSON(data []byte) (err error)
type BetaRateLimitErrorType ¶
type BetaRateLimitErrorType string
const (
BetaRateLimitErrorTypeRateLimitError BetaRateLimitErrorType = "rate_limit_error"
)
func (BetaRateLimitErrorType) IsKnown ¶
func (r BetaRateLimitErrorType) IsKnown() bool
type BetaRawContentBlockDeltaEvent ¶
type BetaRawContentBlockDeltaEvent struct {
Delta BetaRawContentBlockDeltaEventDelta `json:"delta,required"`
Index int64 `json:"index,required"`
Type BetaRawContentBlockDeltaEventType `json:"type,required"`
JSON betaRawContentBlockDeltaEventJSON `json:"-"`
}
func (*BetaRawContentBlockDeltaEvent) UnmarshalJSON ¶
func (r *BetaRawContentBlockDeltaEvent) UnmarshalJSON(data []byte) (err error)
type BetaRawContentBlockDeltaEventDelta ¶
type BetaRawContentBlockDeltaEventDelta struct {
Type BetaRawContentBlockDeltaEventDeltaType `json:"type,required"`
PartialJSON string `json:"partial_json"`
Text string `json:"text"`
JSON betaRawContentBlockDeltaEventDeltaJSON `json:"-"`
// contains filtered or unexported fields
}
func (BetaRawContentBlockDeltaEventDelta) AsUnion ¶
func (r BetaRawContentBlockDeltaEventDelta) AsUnion() BetaRawContentBlockDeltaEventDeltaUnion
AsUnion returns a BetaRawContentBlockDeltaEventDeltaUnion interface which you can cast to the specific types for more type safety.
Possible runtime types of the union are BetaTextDelta, BetaInputJSONDelta.
func (*BetaRawContentBlockDeltaEventDelta) UnmarshalJSON ¶
func (r *BetaRawContentBlockDeltaEventDelta) UnmarshalJSON(data []byte) (err error)
type BetaRawContentBlockDeltaEventDeltaType ¶
type BetaRawContentBlockDeltaEventDeltaType string
const ( BetaRawContentBlockDeltaEventDeltaTypeTextDelta BetaRawContentBlockDeltaEventDeltaType = "text_delta" BetaRawContentBlockDeltaEventDeltaTypeInputJSONDelta BetaRawContentBlockDeltaEventDeltaType = "input_json_delta" )
func (BetaRawContentBlockDeltaEventDeltaType) IsKnown ¶
func (r BetaRawContentBlockDeltaEventDeltaType) IsKnown() bool
type BetaRawContentBlockDeltaEventDeltaUnion ¶
type BetaRawContentBlockDeltaEventDeltaUnion interface {
// contains filtered or unexported methods
}
Union satisfied by BetaTextDelta or BetaInputJSONDelta.
type BetaRawContentBlockDeltaEventType ¶
type BetaRawContentBlockDeltaEventType string
const (
BetaRawContentBlockDeltaEventTypeContentBlockDelta BetaRawContentBlockDeltaEventType = "content_block_delta"
)
func (BetaRawContentBlockDeltaEventType) IsKnown ¶
func (r BetaRawContentBlockDeltaEventType) IsKnown() bool
type BetaRawContentBlockStartEvent ¶
type BetaRawContentBlockStartEvent struct {
ContentBlock BetaRawContentBlockStartEventContentBlock `json:"content_block,required"`
Index int64 `json:"index,required"`
Type BetaRawContentBlockStartEventType `json:"type,required"`
JSON betaRawContentBlockStartEventJSON `json:"-"`
}
func (*BetaRawContentBlockStartEvent) UnmarshalJSON ¶
func (r *BetaRawContentBlockStartEvent) UnmarshalJSON(data []byte) (err error)
type BetaRawContentBlockStartEventContentBlock ¶
type BetaRawContentBlockStartEventContentBlock struct {
Type BetaRawContentBlockStartEventContentBlockType `json:"type,required"`
ID string `json:"id"`
// This field can have the runtime type of [interface{}].
Input interface{} `json:"input"`
Name string `json:"name"`
Text string `json:"text"`
JSON betaRawContentBlockStartEventContentBlockJSON `json:"-"`
// contains filtered or unexported fields
}
func (BetaRawContentBlockStartEventContentBlock) AsUnion ¶
func (r BetaRawContentBlockStartEventContentBlock) AsUnion() BetaRawContentBlockStartEventContentBlockUnion
AsUnion returns a BetaRawContentBlockStartEventContentBlockUnion interface which you can cast to the specific types for more type safety.
Possible runtime types of the union are BetaTextBlock, BetaToolUseBlock.
func (*BetaRawContentBlockStartEventContentBlock) UnmarshalJSON ¶
func (r *BetaRawContentBlockStartEventContentBlock) UnmarshalJSON(data []byte) (err error)
type BetaRawContentBlockStartEventContentBlockType ¶
type BetaRawContentBlockStartEventContentBlockType string
const ( BetaRawContentBlockStartEventContentBlockTypeText BetaRawContentBlockStartEventContentBlockType = "text" BetaRawContentBlockStartEventContentBlockTypeToolUse BetaRawContentBlockStartEventContentBlockType = "tool_use" )
func (BetaRawContentBlockStartEventContentBlockType) IsKnown ¶
func (r BetaRawContentBlockStartEventContentBlockType) IsKnown() bool
type BetaRawContentBlockStartEventContentBlockUnion ¶
type BetaRawContentBlockStartEventContentBlockUnion interface {
// contains filtered or unexported methods
}
Union satisfied by BetaTextBlock or BetaToolUseBlock.
type BetaRawContentBlockStartEventType ¶
type BetaRawContentBlockStartEventType string
const (
BetaRawContentBlockStartEventTypeContentBlockStart BetaRawContentBlockStartEventType = "content_block_start"
)
func (BetaRawContentBlockStartEventType) IsKnown ¶
func (r BetaRawContentBlockStartEventType) IsKnown() bool
type BetaRawContentBlockStopEvent ¶
type BetaRawContentBlockStopEvent struct {
Index int64 `json:"index,required"`
Type BetaRawContentBlockStopEventType `json:"type,required"`
JSON betaRawContentBlockStopEventJSON `json:"-"`
}
func (*BetaRawContentBlockStopEvent) UnmarshalJSON ¶
func (r *BetaRawContentBlockStopEvent) UnmarshalJSON(data []byte) (err error)
type BetaRawContentBlockStopEventType ¶
type BetaRawContentBlockStopEventType string
const (
BetaRawContentBlockStopEventTypeContentBlockStop BetaRawContentBlockStopEventType = "content_block_stop"
)
func (BetaRawContentBlockStopEventType) IsKnown ¶
func (r BetaRawContentBlockStopEventType) IsKnown() bool
type BetaRawMessageDeltaEvent ¶
type BetaRawMessageDeltaEvent struct {
Delta BetaRawMessageDeltaEventDelta `json:"delta,required"`
Type BetaRawMessageDeltaEventType `json:"type,required"`
// Billing and rate-limit usage.
//
// Anthropic's API bills and rate-limits by token counts, as tokens represent the
// underlying cost to our systems.
//
// Under the hood, the API transforms requests into a format suitable for the
// model. The model's output then goes through a parsing stage before becoming an
// API response. As a result, the token counts in `usage` will not match one-to-one
// with the exact visible content of an API request or response.
//
// For example, `output_tokens` will be non-zero, even for an empty string response
// from Claude.
Usage BetaMessageDeltaUsage `json:"usage,required"`
JSON betaRawMessageDeltaEventJSON `json:"-"`
}
func (*BetaRawMessageDeltaEvent) UnmarshalJSON ¶
func (r *BetaRawMessageDeltaEvent) UnmarshalJSON(data []byte) (err error)
type BetaRawMessageDeltaEventDelta ¶
type BetaRawMessageDeltaEventDelta struct {
StopReason BetaRawMessageDeltaEventDeltaStopReason `json:"stop_reason,required,nullable"`
StopSequence string `json:"stop_sequence,required,nullable"`
JSON betaRawMessageDeltaEventDeltaJSON `json:"-"`
}
func (*BetaRawMessageDeltaEventDelta) UnmarshalJSON ¶
func (r *BetaRawMessageDeltaEventDelta) UnmarshalJSON(data []byte) (err error)
type BetaRawMessageDeltaEventDeltaStopReason ¶
type BetaRawMessageDeltaEventDeltaStopReason string
const ( BetaRawMessageDeltaEventDeltaStopReasonEndTurn BetaRawMessageDeltaEventDeltaStopReason = "end_turn" BetaRawMessageDeltaEventDeltaStopReasonMaxTokens BetaRawMessageDeltaEventDeltaStopReason = "max_tokens" BetaRawMessageDeltaEventDeltaStopReasonStopSequence BetaRawMessageDeltaEventDeltaStopReason = "stop_sequence" BetaRawMessageDeltaEventDeltaStopReasonToolUse BetaRawMessageDeltaEventDeltaStopReason = "tool_use" )
func (BetaRawMessageDeltaEventDeltaStopReason) IsKnown ¶
func (r BetaRawMessageDeltaEventDeltaStopReason) IsKnown() bool
type BetaRawMessageDeltaEventType ¶
type BetaRawMessageDeltaEventType string
const (
BetaRawMessageDeltaEventTypeMessageDelta BetaRawMessageDeltaEventType = "message_delta"
)
func (BetaRawMessageDeltaEventType) IsKnown ¶
func (r BetaRawMessageDeltaEventType) IsKnown() bool
type BetaRawMessageStartEvent ¶
type BetaRawMessageStartEvent struct {
Message BetaMessage `json:"message,required"`
Type BetaRawMessageStartEventType `json:"type,required"`
JSON betaRawMessageStartEventJSON `json:"-"`
}
func (*BetaRawMessageStartEvent) UnmarshalJSON ¶
func (r *BetaRawMessageStartEvent) UnmarshalJSON(data []byte) (err error)
type BetaRawMessageStartEventType ¶
type BetaRawMessageStartEventType string
const (
BetaRawMessageStartEventTypeMessageStart BetaRawMessageStartEventType = "message_start"
)
func (BetaRawMessageStartEventType) IsKnown ¶
func (r BetaRawMessageStartEventType) IsKnown() bool
type BetaRawMessageStopEvent ¶
type BetaRawMessageStopEvent struct {
Type BetaRawMessageStopEventType `json:"type,required"`
JSON betaRawMessageStopEventJSON `json:"-"`
}
func (*BetaRawMessageStopEvent) UnmarshalJSON ¶
func (r *BetaRawMessageStopEvent) UnmarshalJSON(data []byte) (err error)
type BetaRawMessageStopEventType ¶
type BetaRawMessageStopEventType string
const (
BetaRawMessageStopEventTypeMessageStop BetaRawMessageStopEventType = "message_stop"
)
func (BetaRawMessageStopEventType) IsKnown ¶
func (r BetaRawMessageStopEventType) IsKnown() bool
type BetaRawMessageStreamEvent ¶
type BetaRawMessageStreamEvent struct {
Type BetaRawMessageStreamEventType `json:"type,required"`
// This field can have the runtime type of
// [BetaRawContentBlockStartEventContentBlock].
ContentBlock interface{} `json:"content_block"`
// This field can have the runtime type of [BetaRawMessageDeltaEventDelta],
// [BetaRawContentBlockDeltaEventDelta].
Delta interface{} `json:"delta"`
Index int64 `json:"index"`
Message BetaMessage `json:"message"`
// Billing and rate-limit usage.
//
// Anthropic's API bills and rate-limits by token counts, as tokens represent the
// underlying cost to our systems.
//
// Under the hood, the API transforms requests into a format suitable for the
// model. The model's output then goes through a parsing stage before becoming an
// API response. As a result, the token counts in `usage` will not match one-to-one
// with the exact visible content of an API request or response.
//
// For example, `output_tokens` will be non-zero, even for an empty string response
// from Claude.
Usage BetaMessageDeltaUsage `json:"usage"`
JSON betaRawMessageStreamEventJSON `json:"-"`
// contains filtered or unexported fields
}
func (BetaRawMessageStreamEvent) AsUnion ¶
func (r BetaRawMessageStreamEvent) AsUnion() BetaRawMessageStreamEventUnion
AsUnion returns a BetaRawMessageStreamEventUnion interface which you can cast to the specific types for more type safety.
Possible runtime types of the union are BetaRawMessageStartEvent, BetaRawMessageDeltaEvent, BetaRawMessageStopEvent, BetaRawContentBlockStartEvent, BetaRawContentBlockDeltaEvent, BetaRawContentBlockStopEvent.
func (*BetaRawMessageStreamEvent) UnmarshalJSON ¶
func (r *BetaRawMessageStreamEvent) UnmarshalJSON(data []byte) (err error)
type BetaRawMessageStreamEventType ¶
type BetaRawMessageStreamEventType string
const ( BetaRawMessageStreamEventTypeMessageStart BetaRawMessageStreamEventType = "message_start" BetaRawMessageStreamEventTypeMessageDelta BetaRawMessageStreamEventType = "message_delta" BetaRawMessageStreamEventTypeMessageStop BetaRawMessageStreamEventType = "message_stop" BetaRawMessageStreamEventTypeContentBlockStart BetaRawMessageStreamEventType = "content_block_start" BetaRawMessageStreamEventTypeContentBlockDelta BetaRawMessageStreamEventType = "content_block_delta" BetaRawMessageStreamEventTypeContentBlockStop BetaRawMessageStreamEventType = "content_block_stop" )
func (BetaRawMessageStreamEventType) IsKnown ¶
func (r BetaRawMessageStreamEventType) IsKnown() bool
type BetaRawMessageStreamEventUnion ¶
type BetaRawMessageStreamEventUnion interface {
// contains filtered or unexported methods
}
Union satisfied by BetaRawMessageStartEvent, BetaRawMessageDeltaEvent, BetaRawMessageStopEvent, BetaRawContentBlockStartEvent, BetaRawContentBlockDeltaEvent or BetaRawContentBlockStopEvent.
type BetaService ¶
type BetaService struct {
Options []option.RequestOption
Models *BetaModelService
Messages *BetaMessageService
}
BetaService contains methods and other services that help with interacting with the anthropic API.
Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewBetaService method instead.
func NewBetaService ¶
func NewBetaService(opts ...option.RequestOption) (r *BetaService)
NewBetaService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.
type BetaTextBlock ¶
type BetaTextBlock struct {
Text string `json:"text,required"`
Type BetaTextBlockType `json:"type,required"`
JSON betaTextBlockJSON `json:"-"`
}
func (*BetaTextBlock) UnmarshalJSON ¶
func (r *BetaTextBlock) UnmarshalJSON(data []byte) (err error)
type BetaTextBlockParam ¶
type BetaTextBlockParam struct {
Text param.Field[string] `json:"text,required"`
Type param.Field[BetaTextBlockParamType] `json:"type,required"`
CacheControl param.Field[BetaCacheControlEphemeralParam] `json:"cache_control"`
}
func (BetaTextBlockParam) MarshalJSON ¶
func (r BetaTextBlockParam) MarshalJSON() (data []byte, err error)
type BetaTextBlockParamType ¶
type BetaTextBlockParamType string
const (
BetaTextBlockParamTypeText BetaTextBlockParamType = "text"
)
func (BetaTextBlockParamType) IsKnown ¶
func (r BetaTextBlockParamType) IsKnown() bool
type BetaTextBlockType ¶
type BetaTextBlockType string
const (
BetaTextBlockTypeText BetaTextBlockType = "text"
)
func (BetaTextBlockType) IsKnown ¶
func (r BetaTextBlockType) IsKnown() bool
type BetaTextDelta ¶
type BetaTextDelta struct {
Text string `json:"text,required"`
Type BetaTextDeltaType `json:"type,required"`
JSON betaTextDeltaJSON `json:"-"`
}
func (*BetaTextDelta) UnmarshalJSON ¶
func (r *BetaTextDelta) UnmarshalJSON(data []byte) (err error)
type BetaTextDeltaType ¶
type BetaTextDeltaType string
const (
BetaTextDeltaTypeTextDelta BetaTextDeltaType = "text_delta"
)
func (BetaTextDeltaType) IsKnown ¶
func (r BetaTextDeltaType) IsKnown() bool
type BetaToolBash20241022Name ¶
type BetaToolBash20241022Name string
Name of the tool.
This is how the tool will be called by the model and in tool_use blocks.
const (
BetaToolBash20241022NameBash BetaToolBash20241022Name = "bash"
)
func (BetaToolBash20241022Name) IsKnown ¶
func (r BetaToolBash20241022Name) IsKnown() bool
type BetaToolBash20241022Param ¶
type BetaToolBash20241022Param struct {
// Name of the tool.
//
// This is how the tool will be called by the model and in tool_use blocks.
Name param.Field[BetaToolBash20241022Name] `json:"name,required"`
Type param.Field[BetaToolBash20241022Type] `json:"type,required"`
CacheControl param.Field[BetaCacheControlEphemeralParam] `json:"cache_control"`
}
func (BetaToolBash20241022Param) MarshalJSON ¶
func (r BetaToolBash20241022Param) MarshalJSON() (data []byte, err error)
type BetaToolBash20241022Type ¶
type BetaToolBash20241022Type string
const (
BetaToolBash20241022TypeBash20241022 BetaToolBash20241022Type = "bash_20241022"
)
func (BetaToolBash20241022Type) IsKnown ¶
func (r BetaToolBash20241022Type) IsKnown() bool
type BetaToolChoiceAnyParam ¶
type BetaToolChoiceAnyParam struct {
Type param.Field[BetaToolChoiceAnyType] `json:"type,required"`
// Whether to disable parallel tool use.
//
// Defaults to `false`. If set to `true`, the model will output exactly one tool
// use.
DisableParallelToolUse param.Field[bool] `json:"disable_parallel_tool_use"`
}
The model will use any available tools.
func (BetaToolChoiceAnyParam) MarshalJSON ¶
func (r BetaToolChoiceAnyParam) MarshalJSON() (data []byte, err error)
type BetaToolChoiceAnyType ¶
type BetaToolChoiceAnyType string
const (
BetaToolChoiceAnyTypeAny BetaToolChoiceAnyType = "any"
)
func (BetaToolChoiceAnyType) IsKnown ¶
func (r BetaToolChoiceAnyType) IsKnown() bool
type BetaToolChoiceAutoParam ¶
type BetaToolChoiceAutoParam struct {
Type param.Field[BetaToolChoiceAutoType] `json:"type,required"`
// Whether to disable parallel tool use.
//
// Defaults to `false`. If set to `true`, the model will output at most one tool
// use.
DisableParallelToolUse param.Field[bool] `json:"disable_parallel_tool_use"`
}
The model will automatically decide whether to use tools.
func (BetaToolChoiceAutoParam) MarshalJSON ¶
func (r BetaToolChoiceAutoParam) MarshalJSON() (data []byte, err error)
type BetaToolChoiceAutoType ¶
type BetaToolChoiceAutoType string
const (
BetaToolChoiceAutoTypeAuto BetaToolChoiceAutoType = "auto"
)
func (BetaToolChoiceAutoType) IsKnown ¶
func (r BetaToolChoiceAutoType) IsKnown() bool
type BetaToolChoiceParam ¶
type BetaToolChoiceParam struct {
Type param.Field[BetaToolChoiceType] `json:"type,required"`
// Whether to disable parallel tool use.
//
// Defaults to `false`. If set to `true`, the model will output at most one tool
// use.
DisableParallelToolUse param.Field[bool] `json:"disable_parallel_tool_use"`
// The name of the tool to use.
Name param.Field[string] `json:"name"`
}
How the model should use the provided tools. The model can use a specific tool, any available tool, or decide by itself.
func (BetaToolChoiceParam) MarshalJSON ¶
func (r BetaToolChoiceParam) MarshalJSON() (data []byte, err error)
type BetaToolChoiceToolParam ¶
type BetaToolChoiceToolParam struct {
// The name of the tool to use.
Name param.Field[string] `json:"name,required"`
Type param.Field[BetaToolChoiceToolType] `json:"type,required"`
// Whether to disable parallel tool use.
//
// Defaults to `false`. If set to `true`, the model will output exactly one tool
// use.
DisableParallelToolUse param.Field[bool] `json:"disable_parallel_tool_use"`
}
The model will use the specified tool with `tool_choice.name`.
func (BetaToolChoiceToolParam) MarshalJSON ¶
func (r BetaToolChoiceToolParam) MarshalJSON() (data []byte, err error)
type BetaToolChoiceToolType ¶
type BetaToolChoiceToolType string
const (
BetaToolChoiceToolTypeTool BetaToolChoiceToolType = "tool"
)
func (BetaToolChoiceToolType) IsKnown ¶
func (r BetaToolChoiceToolType) IsKnown() bool
type BetaToolChoiceType ¶
type BetaToolChoiceType string
const ( BetaToolChoiceTypeAuto BetaToolChoiceType = "auto" BetaToolChoiceTypeAny BetaToolChoiceType = "any" BetaToolChoiceTypeTool BetaToolChoiceType = "tool" )
func (BetaToolChoiceType) IsKnown ¶
func (r BetaToolChoiceType) IsKnown() bool
type BetaToolChoiceUnionParam ¶
type BetaToolChoiceUnionParam interface {
// contains filtered or unexported methods
}
How the model should use the provided tools. The model can use a specific tool, any available tool, or decide by itself.
Satisfied by BetaToolChoiceAutoParam, BetaToolChoiceAnyParam, BetaToolChoiceToolParam, BetaToolChoiceParam.
type BetaToolComputerUse20241022Name ¶
type BetaToolComputerUse20241022Name string
Name of the tool.
This is how the tool will be called by the model and in tool_use blocks.
const (
BetaToolComputerUse20241022NameComputer BetaToolComputerUse20241022Name = "computer"
)
func (BetaToolComputerUse20241022Name) IsKnown ¶
func (r BetaToolComputerUse20241022Name) IsKnown() bool
type BetaToolComputerUse20241022Param ¶
type BetaToolComputerUse20241022Param struct {
// The height of the display in pixels.
DisplayHeightPx param.Field[int64] `json:"display_height_px,required"`
// The width of the display in pixels.
DisplayWidthPx param.Field[int64] `json:"display_width_px,required"`
// Name of the tool.
//
// This is how the tool will be called by the model and in tool_use blocks.
Name param.Field[BetaToolComputerUse20241022Name] `json:"name,required"`
Type param.Field[BetaToolComputerUse20241022Type] `json:"type,required"`
CacheControl param.Field[BetaCacheControlEphemeralParam] `json:"cache_control"`
// The X11 display number (e.g. 0, 1) for the display.
DisplayNumber param.Field[int64] `json:"display_number"`
}
func (BetaToolComputerUse20241022Param) MarshalJSON ¶
func (r BetaToolComputerUse20241022Param) MarshalJSON() (data []byte, err error)
type BetaToolComputerUse20241022Type ¶
type BetaToolComputerUse20241022Type string
const (
BetaToolComputerUse20241022TypeComputer20241022 BetaToolComputerUse20241022Type = "computer_20241022"
)
func (BetaToolComputerUse20241022Type) IsKnown ¶
func (r BetaToolComputerUse20241022Type) IsKnown() bool
type BetaToolInputSchemaParam ¶
type BetaToolInputSchemaParam struct {
Type param.Field[BetaToolInputSchemaType] `json:"type,required"`
Properties param.Field[interface{}] `json:"properties"`
ExtraFields map[string]interface{} `json:"-,extras"`
}
[JSON schema](https://json-schema.org/) for this tool's input.
This defines the shape of the `input` that your tool accepts and that the model will produce.
func (BetaToolInputSchemaParam) MarshalJSON ¶
func (r BetaToolInputSchemaParam) MarshalJSON() (data []byte, err error)
type BetaToolInputSchemaType ¶
type BetaToolInputSchemaType string
const (
BetaToolInputSchemaTypeObject BetaToolInputSchemaType = "object"
)
func (BetaToolInputSchemaType) IsKnown ¶
func (r BetaToolInputSchemaType) IsKnown() bool
type BetaToolParam ¶
type BetaToolParam struct {
// [JSON schema](https://json-schema.org/) for this tool's input.
//
// This defines the shape of the `input` that your tool accepts and that the model
// will produce.
InputSchema param.Field[BetaToolInputSchemaParam] `json:"input_schema,required"`
// Name of the tool.
//
// This is how the tool will be called by the model and in tool_use blocks.
Name param.Field[string] `json:"name,required"`
CacheControl param.Field[BetaCacheControlEphemeralParam] `json:"cache_control"`
// Description of what this tool does.
//
// Tool descriptions should be as detailed as possible. The more information that
// the model has about what the tool is and how to use it, the better it will
// perform. You can use natural language descriptions to reinforce important
// aspects of the tool input JSON schema.
Description param.Field[string] `json:"description"`
Type param.Field[BetaToolType] `json:"type"`
}
func (BetaToolParam) MarshalJSON ¶
func (r BetaToolParam) MarshalJSON() (data []byte, err error)
type BetaToolResultBlockParam ¶
type BetaToolResultBlockParam struct {
ToolUseID param.Field[string] `json:"tool_use_id,required"`
Type param.Field[BetaToolResultBlockParamType] `json:"type,required"`
CacheControl param.Field[BetaCacheControlEphemeralParam] `json:"cache_control"`
Content param.Field[[]BetaToolResultBlockParamContentUnion] `json:"content"`
IsError param.Field[bool] `json:"is_error"`
}
func (BetaToolResultBlockParam) MarshalJSON ¶
func (r BetaToolResultBlockParam) MarshalJSON() (data []byte, err error)
type BetaToolResultBlockParamContent ¶
type BetaToolResultBlockParamContent struct {
Type param.Field[BetaToolResultBlockParamContentType] `json:"type,required"`
CacheControl param.Field[BetaCacheControlEphemeralParam] `json:"cache_control"`
Source param.Field[interface{}] `json:"source"`
Text param.Field[string] `json:"text"`
}
func (BetaToolResultBlockParamContent) MarshalJSON ¶
func (r BetaToolResultBlockParamContent) MarshalJSON() (data []byte, err error)
type BetaToolResultBlockParamContentType ¶
type BetaToolResultBlockParamContentType string
const ( BetaToolResultBlockParamContentTypeText BetaToolResultBlockParamContentType = "text" BetaToolResultBlockParamContentTypeImage BetaToolResultBlockParamContentType = "image" )
func (BetaToolResultBlockParamContentType) IsKnown ¶
func (r BetaToolResultBlockParamContentType) IsKnown() bool
type BetaToolResultBlockParamContentUnion ¶
type BetaToolResultBlockParamContentUnion interface {
// contains filtered or unexported methods
}
Satisfied by BetaTextBlockParam, BetaImageBlockParam, BetaToolResultBlockParamContent.
type BetaToolResultBlockParamType ¶
type BetaToolResultBlockParamType string
const (
BetaToolResultBlockParamTypeToolResult BetaToolResultBlockParamType = "tool_result"
)
func (BetaToolResultBlockParamType) IsKnown ¶
func (r BetaToolResultBlockParamType) IsKnown() bool
type BetaToolTextEditor20241022Name ¶
type BetaToolTextEditor20241022Name string
Name of the tool.
This is how the tool will be called by the model and in tool_use blocks.
const (
BetaToolTextEditor20241022NameStrReplaceEditor BetaToolTextEditor20241022Name = "str_replace_editor"
)
func (BetaToolTextEditor20241022Name) IsKnown ¶
func (r BetaToolTextEditor20241022Name) IsKnown() bool
type BetaToolTextEditor20241022Param ¶
type BetaToolTextEditor20241022Param struct {
// Name of the tool.
//
// This is how the tool will be called by the model and in tool_use blocks.
Name param.Field[BetaToolTextEditor20241022Name] `json:"name,required"`
Type param.Field[BetaToolTextEditor20241022Type] `json:"type,required"`
CacheControl param.Field[BetaCacheControlEphemeralParam] `json:"cache_control"`
}
func (BetaToolTextEditor20241022Param) MarshalJSON ¶
func (r BetaToolTextEditor20241022Param) MarshalJSON() (data []byte, err error)
type BetaToolTextEditor20241022Type ¶
type BetaToolTextEditor20241022Type string
const (
BetaToolTextEditor20241022TypeTextEditor20241022 BetaToolTextEditor20241022Type = "text_editor_20241022"
)
func (BetaToolTextEditor20241022Type) IsKnown ¶
func (r BetaToolTextEditor20241022Type) IsKnown() bool
type BetaToolType ¶
type BetaToolType string
const (
BetaToolTypeCustom BetaToolType = "custom"
)
func (BetaToolType) IsKnown ¶
func (r BetaToolType) IsKnown() bool
type BetaToolUnionParam ¶
type BetaToolUnionParam struct {
// Name of the tool.
//
// This is how the tool will be called by the model and in tool_use blocks.
Name param.Field[string] `json:"name,required"`
CacheControl param.Field[BetaCacheControlEphemeralParam] `json:"cache_control"`
// Description of what this tool does.
//
// Tool descriptions should be as detailed as possible. The more information that
// the model has about what the tool is and how to use it, the better it will
// perform. You can use natural language descriptions to reinforce important
// aspects of the tool input JSON schema.
Description param.Field[string] `json:"description"`
// The height of the display in pixels.
DisplayHeightPx param.Field[int64] `json:"display_height_px"`
// The X11 display number (e.g. 0, 1) for the display.
DisplayNumber param.Field[int64] `json:"display_number"`
// The width of the display in pixels.
DisplayWidthPx param.Field[int64] `json:"display_width_px"`
InputSchema param.Field[interface{}] `json:"input_schema"`
Type param.Field[BetaToolUnionType] `json:"type"`
}
func (BetaToolUnionParam) MarshalJSON ¶
func (r BetaToolUnionParam) MarshalJSON() (data []byte, err error)
type BetaToolUnionType ¶
type BetaToolUnionType string
const ( BetaToolUnionTypeCustom BetaToolUnionType = "custom" BetaToolUnionTypeComputer20241022 BetaToolUnionType = "computer_20241022" BetaToolUnionTypeBash20241022 BetaToolUnionType = "bash_20241022" BetaToolUnionTypeTextEditor20241022 BetaToolUnionType = "text_editor_20241022" )
func (BetaToolUnionType) IsKnown ¶
func (r BetaToolUnionType) IsKnown() bool
type BetaToolUnionUnionParam ¶
type BetaToolUnionUnionParam interface {
// contains filtered or unexported methods
}
Satisfied by BetaToolParam, BetaToolComputerUse20241022Param, BetaToolBash20241022Param, BetaToolTextEditor20241022Param, BetaToolUnionParam.
type BetaToolUseBlock ¶
type BetaToolUseBlock struct {
ID string `json:"id,required"`
Input interface{} `json:"input,required"`
Name string `json:"name,required"`
Type BetaToolUseBlockType `json:"type,required"`
JSON betaToolUseBlockJSON `json:"-"`
}
func (*BetaToolUseBlock) UnmarshalJSON ¶
func (r *BetaToolUseBlock) UnmarshalJSON(data []byte) (err error)
type BetaToolUseBlockParam ¶
type BetaToolUseBlockParam struct {
ID param.Field[string] `json:"id,required"`
Input param.Field[interface{}] `json:"input,required"`
Name param.Field[string] `json:"name,required"`
Type param.Field[BetaToolUseBlockParamType] `json:"type,required"`
CacheControl param.Field[BetaCacheControlEphemeralParam] `json:"cache_control"`
}
func (BetaToolUseBlockParam) MarshalJSON ¶
func (r BetaToolUseBlockParam) MarshalJSON() (data []byte, err error)
type BetaToolUseBlockParamType ¶
type BetaToolUseBlockParamType string
const (
BetaToolUseBlockParamTypeToolUse BetaToolUseBlockParamType = "tool_use"
)
func (BetaToolUseBlockParamType) IsKnown ¶
func (r BetaToolUseBlockParamType) IsKnown() bool
type BetaToolUseBlockType ¶
type BetaToolUseBlockType string
const (
BetaToolUseBlockTypeToolUse BetaToolUseBlockType = "tool_use"
)
func (BetaToolUseBlockType) IsKnown ¶
func (r BetaToolUseBlockType) IsKnown() bool
type BetaUsage ¶
type BetaUsage struct {
// The number of input tokens used to create the cache entry.
CacheCreationInputTokens int64 `json:"cache_creation_input_tokens,required,nullable"`
// The number of input tokens read from the cache.
CacheReadInputTokens int64 `json:"cache_read_input_tokens,required,nullable"`
// The number of input tokens which were used.
InputTokens int64 `json:"input_tokens,required"`
// The number of output tokens which were used.
OutputTokens int64 `json:"output_tokens,required"`
JSON betaUsageJSON `json:"-"`
}
func (*BetaUsage) UnmarshalJSON ¶
type BillingErrorType ¶
type BillingErrorType = shared.BillingErrorType
This is an alias to an internal type.
type CacheControlEphemeralParam ¶
type CacheControlEphemeralParam struct {
Type param.Field[CacheControlEphemeralType] `json:"type,required"`
}
func (CacheControlEphemeralParam) MarshalJSON ¶
func (r CacheControlEphemeralParam) MarshalJSON() (data []byte, err error)
type CacheControlEphemeralType ¶
type CacheControlEphemeralType string
const (
CacheControlEphemeralTypeEphemeral CacheControlEphemeralType = "ephemeral"
)
func (CacheControlEphemeralType) IsKnown ¶
func (r CacheControlEphemeralType) IsKnown() bool
type Client ¶
type Client struct {
Options []option.RequestOption
Completions *CompletionService
Messages *MessageService
Models *ModelService
Beta *BetaService
}
Client creates a struct with services and top level methods that help with interacting with the anthropic API. You should not instantiate this client directly, and instead use the NewClient method instead.
func NewClient ¶
func NewClient(opts ...option.RequestOption) (r *Client)
NewClient generates a new client with the default option read from the environment (ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN). The option passed in as arguments are applied after these default arguments, and all option will be passed down to the services and requests that this client makes.
func (*Client) Delete ¶
func (r *Client) Delete(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error
Delete makes a DELETE request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.
func (*Client) Execute ¶
func (r *Client) Execute(ctx context.Context, method string, path string, params interface{}, res interface{}, opts ...option.RequestOption) error
Execute makes a request with the given context, method, URL, request params, response, and request options. This is useful for hitting undocumented endpoints while retaining the base URL, auth, retries, and other options from the client.
If a byte slice or an io.Reader is supplied to params, it will be used as-is for the request body.
The params is by default serialized into the body using encoding/json. If your type implements a MarshalJSON function, it will be used instead to serialize the request. If a URLQuery method is implemented, the returned url.Values will be used as query strings to the url.
If your params struct uses param.Field, you must provide either [MarshalJSON], [URLQuery], and/or [MarshalForm] functions. It is undefined behavior to use a struct uses param.Field without specifying how it is serialized.
Any "…Params" object defined in this library can be used as the request argument. Note that 'path' arguments will not be forwarded into the url.
The response body will be deserialized into the res variable, depending on its type:
- A pointer to a *http.Response is populated by the raw response.
- A pointer to a byte array will be populated with the contents of the request body.
- A pointer to any other type uses this library's default JSON decoding, which respects UnmarshalJSON if it is defined on the type.
- A nil value will not read the response body.
For even greater flexibility, see option.WithResponseInto and option.WithResponseBodyInto.
func (*Client) Get ¶
func (r *Client) Get(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error
Get makes a GET request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.
func (*Client) Patch ¶
func (r *Client) Patch(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error
Patch makes a PATCH request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.
func (*Client) Post ¶
func (r *Client) Post(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error
Post makes a POST request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.
type Completion ¶
type Completion struct {
// Unique object identifier.
//
// The format and length of IDs may change over time.
ID string `json:"id,required"`
// The resulting completion up to and excluding the stop sequences.
Completion string `json:"completion,required"`
// The model that will complete your prompt.\n\nSee
// [models](https://docs.anthropic.com/en/docs/models-overview) for additional
// details and options.
Model Model `json:"model,required"`
// The reason that we stopped.
//
// This may be one the following values:
//
// - `"stop_sequence"`: we reached a stop sequence — either provided by you via the
// `stop_sequences` parameter, or a stop sequence built into the model
// - `"max_tokens"`: we exceeded `max_tokens_to_sample` or the model's maximum
StopReason string `json:"stop_reason,required,nullable"`
// Object type.
//
// For Text Completions, this is always `"completion"`.
Type CompletionType `json:"type,required"`
JSON completionJSON `json:"-"`
}
func (*Completion) UnmarshalJSON ¶
func (r *Completion) UnmarshalJSON(data []byte) (err error)
type CompletionNewParams ¶
type CompletionNewParams struct {
// The maximum number of tokens to generate before stopping.
//
// Note that our models may stop _before_ reaching this maximum. This parameter
// only specifies the absolute maximum number of tokens to generate.
MaxTokensToSample param.Field[int64] `json:"max_tokens_to_sample,required"`
// The model that will complete your prompt.\n\nSee
// [models](https://docs.anthropic.com/en/docs/models-overview) for additional
// details and options.
Model param.Field[Model] `json:"model,required"`
// The prompt that you want Claude to complete.
//
// For proper response generation you will need to format your prompt using
// alternating `\n\nHuman:` and `\n\nAssistant:` conversational turns. For example:
//
// “`
// "\n\nHuman: {userQuestion}\n\nAssistant:"
// “`
//
// See [prompt validation](https://docs.anthropic.com/en/api/prompt-validation) and
// our guide to
// [prompt design](https://docs.anthropic.com/en/docs/intro-to-prompting) for more
// details.
Prompt param.Field[string] `json:"prompt,required"`
// An object describing metadata about the request.
Metadata param.Field[MetadataParam] `json:"metadata"`
// Sequences that will cause the model to stop generating.
//
// Our models stop on `"\n\nHuman:"`, and may include additional built-in stop
// sequences in the future. By providing the stop_sequences parameter, you may
// include additional strings that will cause the model to stop generating.
StopSequences param.Field[[]string] `json:"stop_sequences"`
// Amount of randomness injected into the response.
//
// Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
// for analytical / multiple choice, and closer to `1.0` for creative and
// generative tasks.
//
// Note that even with `temperature` of `0.0`, the results will not be fully
// deterministic.
Temperature param.Field[float64] `json:"temperature"`
// Only sample from the top K options for each subsequent token.
//
// Used to remove "long tail" low probability responses.
// [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
//
// Recommended for advanced use cases only. You usually only need to use
// `temperature`.
TopK param.Field[int64] `json:"top_k"`
// Use nucleus sampling.
//
// In nucleus sampling, we compute the cumulative distribution over all the options
// for each subsequent token in decreasing probability order and cut it off once it
// reaches a particular probability specified by `top_p`. You should either alter
// `temperature` or `top_p`, but not both.
//
// Recommended for advanced use cases only. You usually only need to use
// `temperature`.
TopP param.Field[float64] `json:"top_p"`
}
func (CompletionNewParams) MarshalJSON ¶
func (r CompletionNewParams) MarshalJSON() (data []byte, err error)
type CompletionService ¶
type CompletionService struct {
Options []option.RequestOption
}
CompletionService contains methods and other services that help with interacting with the anthropic API.
Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewCompletionService method instead.
func NewCompletionService ¶
func NewCompletionService(opts ...option.RequestOption) (r *CompletionService)
NewCompletionService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.
func (*CompletionService) New ¶
func (r *CompletionService) New(ctx context.Context, body CompletionNewParams, opts ...option.RequestOption) (res *Completion, err error)
[Legacy] Create a Text Completion.
The Text Completions API is a legacy API. We recommend using the [Messages API](https://docs.anthropic.com/en/api/messages) going forward.
Future models and features will not be compatible with Text Completions. See our [migration guide](https://docs.anthropic.com/en/api/migrating-from-text-completions-to-messages) for guidance in migrating from Text Completions to Messages.
Note: If you choose to set a timeout for this request, we recommend 10 minutes.
func (*CompletionService) NewStreaming ¶
func (r *CompletionService) NewStreaming(ctx context.Context, body CompletionNewParams, opts ...option.RequestOption) (stream *ssestream.Stream[Completion])
[Legacy] Create a Text Completion.
The Text Completions API is a legacy API. We recommend using the [Messages API](https://docs.anthropic.com/en/api/messages) going forward.
Future models and features will not be compatible with Text Completions. See our [migration guide](https://docs.anthropic.com/en/api/migrating-from-text-completions-to-messages) for guidance in migrating from Text Completions to Messages.
Note: If you choose to set a timeout for this request, we recommend 10 minutes.
type CompletionType ¶
type CompletionType string
Object type.
For Text Completions, this is always `"completion"`.
const (
CompletionTypeCompletion CompletionType = "completion"
)
func (CompletionType) IsKnown ¶
func (r CompletionType) IsKnown() bool
type ContentBlock ¶
type ContentBlock struct {
Type ContentBlockType `json:"type,required"`
Text string `json:"text"`
ID string `json:"id"`
Name string `json:"name"`
Input json.RawMessage `json:"input,required"`
JSON contentBlockJSON `json:"-"`
// contains filtered or unexported fields
}
func (ContentBlock) AsUnion ¶
func (r ContentBlock) AsUnion() ContentBlockUnion
AsUnion returns a ContentBlockUnion interface which you can cast to the specific types for more type safety.
Possible runtime types of the union are TextBlock, ToolUseBlock.
func (*ContentBlock) UnmarshalJSON ¶
func (r *ContentBlock) UnmarshalJSON(data []byte) (err error)
type ContentBlockDeltaEvent ¶
type ContentBlockDeltaEvent struct {
Delta ContentBlockDeltaEventDelta `json:"delta,required"`
Index int64 `json:"index,required"`
Type ContentBlockDeltaEventType `json:"type,required"`
JSON contentBlockDeltaEventJSON `json:"-"`
}
func (*ContentBlockDeltaEvent) UnmarshalJSON ¶
func (r *ContentBlockDeltaEvent) UnmarshalJSON(data []byte) (err error)
type ContentBlockDeltaEventDelta ¶
type ContentBlockDeltaEventDelta struct {
Type ContentBlockDeltaEventDeltaType `json:"type,required"`
PartialJSON string `json:"partial_json"`
Text string `json:"text"`
JSON contentBlockDeltaEventDeltaJSON `json:"-"`
// contains filtered or unexported fields
}
func (ContentBlockDeltaEventDelta) AsUnion ¶
func (r ContentBlockDeltaEventDelta) AsUnion() ContentBlockDeltaEventDeltaUnion
AsUnion returns a ContentBlockDeltaEventDeltaUnion interface which you can cast to the specific types for more type safety.
Possible runtime types of the union are TextDelta, InputJSONDelta.
func (*ContentBlockDeltaEventDelta) UnmarshalJSON ¶
func (r *ContentBlockDeltaEventDelta) UnmarshalJSON(data []byte) (err error)
type ContentBlockDeltaEventDeltaType ¶
type ContentBlockDeltaEventDeltaType string
const ( ContentBlockDeltaEventDeltaTypeTextDelta ContentBlockDeltaEventDeltaType = "text_delta" ContentBlockDeltaEventDeltaTypeInputJSONDelta ContentBlockDeltaEventDeltaType = "input_json_delta" )
func (ContentBlockDeltaEventDeltaType) IsKnown ¶
func (r ContentBlockDeltaEventDeltaType) IsKnown() bool
type ContentBlockDeltaEventDeltaUnion ¶
type ContentBlockDeltaEventDeltaUnion interface {
// contains filtered or unexported methods
}
Union satisfied by TextDelta or InputJSONDelta.
type ContentBlockDeltaEventType ¶
type ContentBlockDeltaEventType string
const (
ContentBlockDeltaEventTypeContentBlockDelta ContentBlockDeltaEventType = "content_block_delta"
)
func (ContentBlockDeltaEventType) IsKnown ¶
func (r ContentBlockDeltaEventType) IsKnown() bool
type ContentBlockParam ¶
type ContentBlockParam struct {
Type param.Field[ContentBlockParamType] `json:"type,required"`
ID param.Field[string] `json:"id"`
CacheControl param.Field[CacheControlEphemeralParam] `json:"cache_control"`
Content param.Field[interface{}] `json:"content"`
Input param.Field[interface{}] `json:"input"`
IsError param.Field[bool] `json:"is_error"`
Name param.Field[string] `json:"name"`
Source param.Field[interface{}] `json:"source"`
Text param.Field[string] `json:"text"`
ToolUseID param.Field[string] `json:"tool_use_id"`
}
func (ContentBlockParam) MarshalJSON ¶
func (r ContentBlockParam) MarshalJSON() (data []byte, err error)
type ContentBlockParamType ¶
type ContentBlockParamType string
const ( ContentBlockParamTypeText ContentBlockParamType = "text" ContentBlockParamTypeImage ContentBlockParamType = "image" ContentBlockParamTypeToolUse ContentBlockParamType = "tool_use" ContentBlockParamTypeToolResult ContentBlockParamType = "tool_result" ContentBlockParamTypeDocument ContentBlockParamType = "document" )
func (ContentBlockParamType) IsKnown ¶
func (r ContentBlockParamType) IsKnown() bool
type ContentBlockParamUnion ¶
type ContentBlockParamUnion interface {
// contains filtered or unexported methods
}
Satisfied by TextBlockParam, ImageBlockParam, ToolUseBlockParam, ToolResultBlockParam, DocumentBlockParam, ContentBlockParam.
type ContentBlockStartEvent ¶
type ContentBlockStartEvent struct {
ContentBlock ContentBlockStartEventContentBlock `json:"content_block,required"`
Index int64 `json:"index,required"`
Type ContentBlockStartEventType `json:"type,required"`
JSON contentBlockStartEventJSON `json:"-"`
}
func (*ContentBlockStartEvent) UnmarshalJSON ¶
func (r *ContentBlockStartEvent) UnmarshalJSON(data []byte) (err error)
type ContentBlockStartEventContentBlock ¶
type ContentBlockStartEventContentBlock struct {
Type ContentBlockStartEventContentBlockType `json:"type,required"`
Text string `json:"text"`
ID string `json:"id"`
Name string `json:"name"`
Input json.RawMessage `json:"input,required"`
JSON contentBlockStartEventContentBlockJSON `json:"-"`
// contains filtered or unexported fields
}
func (ContentBlockStartEventContentBlock) AsUnion ¶
func (r ContentBlockStartEventContentBlock) AsUnion() ContentBlockStartEventContentBlockUnion
AsUnion returns a ContentBlockStartEventContentBlockUnion interface which you can cast to the specific types for more type safety.
Possible runtime types of the union are TextBlock, ToolUseBlock.
func (*ContentBlockStartEventContentBlock) UnmarshalJSON ¶
func (r *ContentBlockStartEventContentBlock) UnmarshalJSON(data []byte) (err error)
type ContentBlockStartEventContentBlockType ¶
type ContentBlockStartEventContentBlockType string
const ( ContentBlockStartEventContentBlockTypeText ContentBlockStartEventContentBlockType = "text" ContentBlockStartEventContentBlockTypeToolUse ContentBlockStartEventContentBlockType = "tool_use" )
func (ContentBlockStartEventContentBlockType) IsKnown ¶
func (r ContentBlockStartEventContentBlockType) IsKnown() bool
type ContentBlockStartEventContentBlockUnion ¶
type ContentBlockStartEventContentBlockUnion interface {
// contains filtered or unexported methods
}
Union satisfied by TextBlock or ToolUseBlock.
type ContentBlockStartEventType ¶
type ContentBlockStartEventType string
const (
ContentBlockStartEventTypeContentBlockStart ContentBlockStartEventType = "content_block_start"
)
func (ContentBlockStartEventType) IsKnown ¶
func (r ContentBlockStartEventType) IsKnown() bool
type ContentBlockStopEvent ¶
type ContentBlockStopEvent struct {
Index int64 `json:"index,required"`
Type ContentBlockStopEventType `json:"type,required"`
JSON contentBlockStopEventJSON `json:"-"`
}
func (*ContentBlockStopEvent) UnmarshalJSON ¶
func (r *ContentBlockStopEvent) UnmarshalJSON(data []byte) (err error)
type ContentBlockStopEventType ¶
type ContentBlockStopEventType string
const (
ContentBlockStopEventTypeContentBlockStop ContentBlockStopEventType = "content_block_stop"
)
func (ContentBlockStopEventType) IsKnown ¶
func (r ContentBlockStopEventType) IsKnown() bool
type ContentBlockType ¶
type ContentBlockType string
const ( ContentBlockTypeText ContentBlockType = "text" ContentBlockTypeToolUse ContentBlockType = "tool_use" )
func (ContentBlockType) IsKnown ¶
func (r ContentBlockType) IsKnown() bool
type ContentBlockUnion ¶
type ContentBlockUnion interface {
// contains filtered or unexported methods
}
Union satisfied by TextBlock or ToolUseBlock.
type DocumentBlockParam ¶
type DocumentBlockParam struct {
Source param.Field[Base64PDFSourceParam] `json:"source,required"`
Type param.Field[DocumentBlockParamType] `json:"type,required"`
CacheControl param.Field[CacheControlEphemeralParam] `json:"cache_control"`
}
func (DocumentBlockParam) MarshalJSON ¶
func (r DocumentBlockParam) MarshalJSON() (data []byte, err error)
type DocumentBlockParamType ¶
type DocumentBlockParamType string
const (
DocumentBlockParamTypeDocument DocumentBlockParamType = "document"
)
func (DocumentBlockParamType) IsKnown ¶
func (r DocumentBlockParamType) IsKnown() bool
type ErrorObjectType ¶
type ErrorObjectType = shared.ErrorObjectType
This is an alias to an internal type.
type ErrorResponse ¶
type ErrorResponse = shared.ErrorResponse
This is an alias to an internal type.
type ErrorResponseType ¶
type ErrorResponseType = shared.ErrorResponseType
This is an alias to an internal type.
type GatewayTimeoutError ¶
type GatewayTimeoutError = shared.GatewayTimeoutError
This is an alias to an internal type.
type GatewayTimeoutErrorType ¶
type GatewayTimeoutErrorType = shared.GatewayTimeoutErrorType
This is an alias to an internal type.
type ImageBlockParam ¶
type ImageBlockParam struct {
Source param.Field[ImageBlockParamSource] `json:"source,required"`
Type param.Field[ImageBlockParamType] `json:"type,required"`
CacheControl param.Field[CacheControlEphemeralParam] `json:"cache_control"`
}
func NewImageBlockBase64 ¶
func NewImageBlockBase64(mediaType string, encodedData string) ImageBlockParam
func (ImageBlockParam) MarshalJSON ¶
func (r ImageBlockParam) MarshalJSON() (data []byte, err error)
type ImageBlockParamSource ¶
type ImageBlockParamSource struct {
Data param.Field[string] `json:"data,required" format:"byte"`
MediaType param.Field[ImageBlockParamSourceMediaType] `json:"media_type,required"`
Type param.Field[ImageBlockParamSourceType] `json:"type,required"`
}
func (ImageBlockParamSource) MarshalJSON ¶
func (r ImageBlockParamSource) MarshalJSON() (data []byte, err error)
type ImageBlockParamSourceMediaType ¶
type ImageBlockParamSourceMediaType string
const ( ImageBlockParamSourceMediaTypeImageJPEG ImageBlockParamSourceMediaType = "image/jpeg" ImageBlockParamSourceMediaTypeImagePNG ImageBlockParamSourceMediaType = "image/png" ImageBlockParamSourceMediaTypeImageGIF ImageBlockParamSourceMediaType = "image/gif" ImageBlockParamSourceMediaTypeImageWebP ImageBlockParamSourceMediaType = "image/webp" )
func (ImageBlockParamSourceMediaType) IsKnown ¶
func (r ImageBlockParamSourceMediaType) IsKnown() bool
type ImageBlockParamSourceType ¶
type ImageBlockParamSourceType string
const (
ImageBlockParamSourceTypeBase64 ImageBlockParamSourceType = "base64"
)
func (ImageBlockParamSourceType) IsKnown ¶
func (r ImageBlockParamSourceType) IsKnown() bool
type ImageBlockParamType ¶
type ImageBlockParamType string
const (
ImageBlockParamTypeImage ImageBlockParamType = "image"
)
func (ImageBlockParamType) IsKnown ¶
func (r ImageBlockParamType) IsKnown() bool
type InputJSONDelta ¶
type InputJSONDelta struct {
PartialJSON string `json:"partial_json,required"`
Type InputJSONDeltaType `json:"type,required"`
JSON inputJSONDeltaJSON `json:"-"`
}
func (*InputJSONDelta) UnmarshalJSON ¶
func (r *InputJSONDelta) UnmarshalJSON(data []byte) (err error)
type InputJSONDeltaType ¶
type InputJSONDeltaType string
const (
InputJSONDeltaTypeInputJSONDelta InputJSONDeltaType = "input_json_delta"
)
func (InputJSONDeltaType) IsKnown ¶
func (r InputJSONDeltaType) IsKnown() bool
type InvalidRequestError ¶
type InvalidRequestError = shared.InvalidRequestError
This is an alias to an internal type.
type InvalidRequestErrorType ¶
type InvalidRequestErrorType = shared.InvalidRequestErrorType
This is an alias to an internal type.
type Message ¶
type Message struct {
// Unique object identifier.
//
// The format and length of IDs may change over time.
ID string `json:"id,required"`
// Content generated by the model.
//
// This is an array of content blocks, each of which has a `type` that determines
// its shape.
//
// Example:
//
// “`json
// [{ "type": "text", "text": "Hi, I'm Claude." }]
// “`
//
// If the request input `messages` ended with an `assistant` turn, then the
// response `content` will continue directly from that last turn. You can use this
// to constrain the model's output.
//
// For example, if the input `messages` were:
//
// “`json
// [
//
// {
// "role": "user",
// "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
// },
// { "role": "assistant", "content": "The best answer is (" }
//
// ]
// “`
//
// Then the response `content` might be:
//
// “`json
// [{ "type": "text", "text": "B)" }]
// “`
Content []ContentBlock `json:"content,required"`
// The model that will complete your prompt.\n\nSee
// [models](https://docs.anthropic.com/en/docs/models-overview) for additional
// details and options.
Model Model `json:"model,required"`
// Conversational role of the generated message.
//
// This will always be `"assistant"`.
Role MessageRole `json:"role,required"`
// The reason that we stopped.
//
// This may be one the following values:
//
// - `"end_turn"`: the model reached a natural stopping point
// - `"max_tokens"`: we exceeded the requested `max_tokens` or the model's maximum
// - `"stop_sequence"`: one of your provided custom `stop_sequences` was generated
// - `"tool_use"`: the model invoked one or more tools
//
// In non-streaming mode this value is always non-null. In streaming mode, it is
// null in the `message_start` event and non-null otherwise.
StopReason MessageStopReason `json:"stop_reason,required,nullable"`
// Which custom stop sequence was generated, if any.
//
// This value will be a non-null string if one of your custom stop sequences was
// generated.
StopSequence string `json:"stop_sequence,required,nullable"`
// Object type.
//
// For Messages, this is always `"message"`.
Type MessageType `json:"type,required"`
// Billing and rate-limit usage.
//
// Anthropic's API bills and rate-limits by token counts, as tokens represent the
// underlying cost to our systems.
//
// Under the hood, the API transforms requests into a format suitable for the
// model. The model's output then goes through a parsing stage before becoming an
// API response. As a result, the token counts in `usage` will not match one-to-one
// with the exact visible content of an API request or response.
//
// For example, `output_tokens` will be non-zero, even for an empty string response
// from Claude.
Usage Usage `json:"usage,required"`
JSON messageJSON `json:"-"`
}
ToParam converts a Message to a MessageParam, which can be used when constructing a new Create
func (*Message) Accumulate ¶
func (a *Message) Accumulate(event MessageStreamEvent) error
Accumulate builds up the Message incrementally from a MessageStreamEvent. The Message then can be used as any other Message, except with the caveat that the Message.JSON field which normally can be used to inspect the JSON sent over the network may not be populated fully.
message := anthropic.Message{}
for stream.Next() {
event := stream.Current()
message.Accumulate(event)
}
func (*Message) ToParam ¶
func (r *Message) ToParam() MessageParam
ToParam converts a Message to a MessageParam which can be used when making another network request. This is useful when interacting with Claude conversationally or when tool calling.
messages := []anthropic.MessageParam{
anthropic.NewUserMessage(anthropic.NewTextBlock("What is my first name?")),
}
message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F(messages),
Model: anthropic.F(anthropic.ModelClaude_3_5_Sonnet_20240620),
})
messages = append(messages, message.ToParam())
messages = append(messages, anthropic.NewUserMessage(
anthropic.NewTextBlock("My full name is John Doe"),
))
message, err = client.Messages.New(context.TODO(), anthropic.MessageNewParams{
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F(messages),
Model: anthropic.F(anthropic.ModelClaude_3_5_Sonnet_20240620),
})
func (*Message) UnmarshalJSON ¶
type MessageBatch ¶
type MessageBatch struct {
// Unique object identifier.
//
// The format and length of IDs may change over time.
ID string `json:"id,required"`
// RFC 3339 datetime string representing the time at which the Message Batch was
// archived and its results became unavailable.
ArchivedAt time.Time `json:"archived_at,required,nullable" format:"date-time"`
// RFC 3339 datetime string representing the time at which cancellation was
// initiated for the Message Batch. Specified only if cancellation was initiated.
CancelInitiatedAt time.Time `json:"cancel_initiated_at,required,nullable" format:"date-time"`
// RFC 3339 datetime string representing the time at which the Message Batch was
// created.
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
// RFC 3339 datetime string representing the time at which processing for the
// Message Batch ended. Specified only once processing ends.
//
// Processing ends when every request in a Message Batch has either succeeded,
// errored, canceled, or expired.
EndedAt time.Time `json:"ended_at,required,nullable" format:"date-time"`
// RFC 3339 datetime string representing the time at which the Message Batch will
// expire and end processing, which is 24 hours after creation.
ExpiresAt time.Time `json:"expires_at,required" format:"date-time"`
// Processing status of the Message Batch.
ProcessingStatus MessageBatchProcessingStatus `json:"processing_status,required"`
// Tallies requests within the Message Batch, categorized by their status.
//
// Requests start as `processing` and move to one of the other statuses only once
// processing of the entire batch ends. The sum of all values always matches the
// total number of requests in the batch.
RequestCounts MessageBatchRequestCounts `json:"request_counts,required"`
// URL to a `.jsonl` file containing the results of the Message Batch requests.
// Specified only once processing ends.
//
// Results in the file are not guaranteed to be in the same order as requests. Use
// the `custom_id` field to match results to requests.
ResultsURL string `json:"results_url,required,nullable"`
// Object type.
//
// For Message Batches, this is always `"message_batch"`.
Type MessageBatchType `json:"type,required"`
JSON messageBatchJSON `json:"-"`
}
func (*MessageBatch) UnmarshalJSON ¶
func (r *MessageBatch) UnmarshalJSON(data []byte) (err error)
type MessageBatchCanceledResult ¶
type MessageBatchCanceledResult struct {
Type MessageBatchCanceledResultType `json:"type,required"`
JSON messageBatchCanceledResultJSON `json:"-"`
}
func (*MessageBatchCanceledResult) UnmarshalJSON ¶
func (r *MessageBatchCanceledResult) UnmarshalJSON(data []byte) (err error)
type MessageBatchCanceledResultType ¶
type MessageBatchCanceledResultType string
const (
MessageBatchCanceledResultTypeCanceled MessageBatchCanceledResultType = "canceled"
)
func (MessageBatchCanceledResultType) IsKnown ¶
func (r MessageBatchCanceledResultType) IsKnown() bool
type MessageBatchErroredResult ¶
type MessageBatchErroredResult struct {
Error shared.ErrorResponse `json:"error,required"`
Type MessageBatchErroredResultType `json:"type,required"`
JSON messageBatchErroredResultJSON `json:"-"`
}
func (*MessageBatchErroredResult) UnmarshalJSON ¶
func (r *MessageBatchErroredResult) UnmarshalJSON(data []byte) (err error)
type MessageBatchErroredResultType ¶
type MessageBatchErroredResultType string
const (
MessageBatchErroredResultTypeErrored MessageBatchErroredResultType = "errored"
)
func (MessageBatchErroredResultType) IsKnown ¶
func (r MessageBatchErroredResultType) IsKnown() bool
type MessageBatchExpiredResult ¶
type MessageBatchExpiredResult struct {
Type MessageBatchExpiredResultType `json:"type,required"`
JSON messageBatchExpiredResultJSON `json:"-"`
}
func (*MessageBatchExpiredResult) UnmarshalJSON ¶
func (r *MessageBatchExpiredResult) UnmarshalJSON(data []byte) (err error)
type MessageBatchExpiredResultType ¶
type MessageBatchExpiredResultType string
const (
MessageBatchExpiredResultTypeExpired MessageBatchExpiredResultType = "expired"
)
func (MessageBatchExpiredResultType) IsKnown ¶
func (r MessageBatchExpiredResultType) IsKnown() bool
type MessageBatchIndividualResponse ¶
type MessageBatchIndividualResponse struct {
// Developer-provided ID created for each request in a Message Batch. Useful for
// matching results to requests, as results may be given out of request order.
//
// Must be unique for each request within the Message Batch.
CustomID string `json:"custom_id,required"`
// Processing result for this request.
//
// Contains a Message output if processing was successful, an error response if
// processing failed, or the reason why processing was not attempted, such as
// cancellation or expiration.
Result MessageBatchResult `json:"result,required"`
JSON messageBatchIndividualResponseJSON `json:"-"`
}
func (*MessageBatchIndividualResponse) UnmarshalJSON ¶
func (r *MessageBatchIndividualResponse) UnmarshalJSON(data []byte) (err error)
type MessageBatchListParams ¶
type MessageBatchListParams struct {
// ID of the object to use as a cursor for pagination. When provided, returns the
// page of results immediately after this object.
AfterID param.Field[string] `query:"after_id"`
// ID of the object to use as a cursor for pagination. When provided, returns the
// page of results immediately before this object.
BeforeID param.Field[string] `query:"before_id"`
// Number of items to return per page.
//
// Defaults to `20`. Ranges from `1` to `1000`.
Limit param.Field[int64] `query:"limit"`
}
func (MessageBatchListParams) URLQuery ¶
func (r MessageBatchListParams) URLQuery() (v url.Values)
URLQuery serializes MessageBatchListParams's query parameters as `url.Values`.
type MessageBatchNewParams ¶
type MessageBatchNewParams struct {
// List of requests for prompt completion. Each is an individual request to create
// a Message.
Requests param.Field[[]MessageBatchNewParamsRequest] `json:"requests,required"`
}
func (MessageBatchNewParams) MarshalJSON ¶
func (r MessageBatchNewParams) MarshalJSON() (data []byte, err error)
type MessageBatchNewParamsRequest ¶
type MessageBatchNewParamsRequest struct {
// Developer-provided ID created for each request in a Message Batch. Useful for
// matching results to requests, as results may be given out of request order.
//
// Must be unique for each request within the Message Batch.
CustomID param.Field[string] `json:"custom_id,required"`
// Messages API creation parameters for the individual request.
//
// See the [Messages API reference](/en/api/messages) for full documentation on
// available parameters.
Params param.Field[MessageNewParams] `json:"params,required"`
}
func (MessageBatchNewParamsRequest) MarshalJSON ¶
func (r MessageBatchNewParamsRequest) MarshalJSON() (data []byte, err error)
type MessageBatchProcessingStatus ¶
type MessageBatchProcessingStatus string
Processing status of the Message Batch.
const ( MessageBatchProcessingStatusInProgress MessageBatchProcessingStatus = "in_progress" MessageBatchProcessingStatusCanceling MessageBatchProcessingStatus = "canceling" MessageBatchProcessingStatusEnded MessageBatchProcessingStatus = "ended" )
func (MessageBatchProcessingStatus) IsKnown ¶
func (r MessageBatchProcessingStatus) IsKnown() bool
type MessageBatchRequestCounts ¶
type MessageBatchRequestCounts struct {
// Number of requests in the Message Batch that have been canceled.
//
// This is zero until processing of the entire Message Batch has ended.
Canceled int64 `json:"canceled,required"`
// Number of requests in the Message Batch that encountered an error.
//
// This is zero until processing of the entire Message Batch has ended.
Errored int64 `json:"errored,required"`
// Number of requests in the Message Batch that have expired.
//
// This is zero until processing of the entire Message Batch has ended.
Expired int64 `json:"expired,required"`
// Number of requests in the Message Batch that are processing.
Processing int64 `json:"processing,required"`
// Number of requests in the Message Batch that have completed successfully.
//
// This is zero until processing of the entire Message Batch has ended.
Succeeded int64 `json:"succeeded,required"`
JSON messageBatchRequestCountsJSON `json:"-"`
}
func (*MessageBatchRequestCounts) UnmarshalJSON ¶
func (r *MessageBatchRequestCounts) UnmarshalJSON(data []byte) (err error)
type MessageBatchResult ¶
type MessageBatchResult struct {
Type MessageBatchResultType `json:"type,required"`
Error shared.ErrorResponse `json:"error"`
Message Message `json:"message"`
JSON messageBatchResultJSON `json:"-"`
// contains filtered or unexported fields
}
Processing result for this request.
Contains a Message output if processing was successful, an error response if processing failed, or the reason why processing was not attempted, such as cancellation or expiration.
func (MessageBatchResult) AsUnion ¶
func (r MessageBatchResult) AsUnion() MessageBatchResultUnion
AsUnion returns a MessageBatchResultUnion interface which you can cast to the specific types for more type safety.
Possible runtime types of the union are MessageBatchSucceededResult, MessageBatchErroredResult, MessageBatchCanceledResult, MessageBatchExpiredResult.
func (*MessageBatchResult) UnmarshalJSON ¶
func (r *MessageBatchResult) UnmarshalJSON(data []byte) (err error)
type MessageBatchResultType ¶
type MessageBatchResultType string
const ( MessageBatchResultTypeSucceeded MessageBatchResultType = "succeeded" MessageBatchResultTypeErrored MessageBatchResultType = "errored" MessageBatchResultTypeCanceled MessageBatchResultType = "canceled" MessageBatchResultTypeExpired MessageBatchResultType = "expired" )
func (MessageBatchResultType) IsKnown ¶
func (r MessageBatchResultType) IsKnown() bool
type MessageBatchResultUnion ¶
type MessageBatchResultUnion interface {
// contains filtered or unexported methods
}
Processing result for this request.
Contains a Message output if processing was successful, an error response if processing failed, or the reason why processing was not attempted, such as cancellation or expiration.
Union satisfied by MessageBatchSucceededResult, MessageBatchErroredResult, MessageBatchCanceledResult or MessageBatchExpiredResult.
type MessageBatchService ¶
type MessageBatchService struct {
Options []option.RequestOption
}
MessageBatchService contains methods and other services that help with interacting with the anthropic API.
Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewMessageBatchService method instead.
func NewMessageBatchService ¶
func NewMessageBatchService(opts ...option.RequestOption) (r *MessageBatchService)
NewMessageBatchService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.
func (*MessageBatchService) Cancel ¶
func (r *MessageBatchService) Cancel(ctx context.Context, messageBatchID string, opts ...option.RequestOption) (res *MessageBatch, err error)
Batches may be canceled any time before processing ends. Once cancellation is initiated, the batch enters a `canceling` state, at which time the system may complete any in-progress, non-interruptible requests before finalizing cancellation.
The number of canceled requests is specified in `request_counts`. To determine which requests were canceled, check the individual results within the batch. Note that cancellation may not result in any canceled requests if they were non-interruptible.
func (*MessageBatchService) Get ¶
func (r *MessageBatchService) Get(ctx context.Context, messageBatchID string, opts ...option.RequestOption) (res *MessageBatch, err error)
This endpoint is idempotent and can be used to poll for Message Batch completion. To access the results of a Message Batch, make a request to the `results_url` field in the response.
func (*MessageBatchService) List ¶
func (r *MessageBatchService) List(ctx context.Context, query MessageBatchListParams, opts ...option.RequestOption) (res *pagination.Page[MessageBatch], err error)
List all Message Batches within a Workspace. Most recently created batches are returned first.
func (*MessageBatchService) ListAutoPaging ¶
func (r *MessageBatchService) ListAutoPaging(ctx context.Context, query MessageBatchListParams, opts ...option.RequestOption) *pagination.PageAutoPager[MessageBatch]
List all Message Batches within a Workspace. Most recently created batches are returned first.
func (*MessageBatchService) New ¶
func (r *MessageBatchService) New(ctx context.Context, body MessageBatchNewParams, opts ...option.RequestOption) (res *MessageBatch, err error)
Send a batch of Message creation requests.
The Message Batches API can be used to process multiple Messages API requests at once. Once a Message Batch is created, it begins processing immediately. Batches can take up to 24 hours to complete.
func (*MessageBatchService) Results ¶
func (r *MessageBatchService) Results(ctx context.Context, messageBatchID string, opts ...option.RequestOption) (res *http.Response, err error)
Streams the results of a Message Batch as a `.jsonl` file.
Each line in the file is a JSON object containing the result of a single request in the Message Batch. Results are not guaranteed to be in the same order as requests. Use the `custom_id` field to match results to requests.
type MessageBatchSucceededResult ¶
type MessageBatchSucceededResult struct {
Message Message `json:"message,required"`
Type MessageBatchSucceededResultType `json:"type,required"`
JSON messageBatchSucceededResultJSON `json:"-"`
}
func (*MessageBatchSucceededResult) UnmarshalJSON ¶
func (r *MessageBatchSucceededResult) UnmarshalJSON(data []byte) (err error)
type MessageBatchSucceededResultType ¶
type MessageBatchSucceededResultType string
const (
MessageBatchSucceededResultTypeSucceeded MessageBatchSucceededResultType = "succeeded"
)
func (MessageBatchSucceededResultType) IsKnown ¶
func (r MessageBatchSucceededResultType) IsKnown() bool
type MessageBatchType ¶
type MessageBatchType string
Object type.
For Message Batches, this is always `"message_batch"`.
const (
MessageBatchTypeMessageBatch MessageBatchType = "message_batch"
)
func (MessageBatchType) IsKnown ¶
func (r MessageBatchType) IsKnown() bool
type MessageCountTokensParams ¶
type MessageCountTokensParams struct {
// Input messages.
//
// Our models are trained to operate on alternating `user` and `assistant`
// conversational turns. When creating a new `Message`, you specify the prior
// conversational turns with the `messages` parameter, and the model then generates
// the next `Message` in the conversation. Consecutive `user` or `assistant` turns
// in your request will be combined into a single turn.
//
// Each input message must be an object with a `role` and `content`. You can
// specify a single `user`-role message, or you can include multiple `user` and
// `assistant` messages.
//
// If the final message uses the `assistant` role, the response content will
// continue immediately from the content in that message. This can be used to
// constrain part of the model's response.
//
// Example with a single `user` message:
//
// “`json
// [{ "role": "user", "content": "Hello, Claude" }]
// “`
//
// Example with multiple conversational turns:
//
// “`json
// [
//
// { "role": "user", "content": "Hello there." },
// { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
// { "role": "user", "content": "Can you explain LLMs in plain English?" }
//
// ]
// “`
//
// Example with a partially-filled response from Claude:
//
// “`json
// [
//
// {
// "role": "user",
// "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
// },
// { "role": "assistant", "content": "The best answer is (" }
//
// ]
// “`
//
// Each input message `content` may be either a single `string` or an array of
// content blocks, where each block has a specific `type`. Using a `string` for
// `content` is shorthand for an array of one content block of type `"text"`. The
// following input messages are equivalent:
//
// “`json
// { "role": "user", "content": "Hello, Claude" }
// “`
//
// “`json
// { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
// “`
//
// Starting with Claude 3 models, you can also send image content blocks:
//
// “`json
//
// {
// "role": "user",
// "content": [
// {
// "type": "image",
// "source": {
// "type": "base64",
// "media_type": "image/jpeg",
// "data": "/9j/4AAQSkZJRg..."
// }
// },
// { "type": "text", "text": "What is in this image?" }
// ]
// }
//
// “`
//
// We currently support the `base64` source type for images, and the `image/jpeg`,
// `image/png`, `image/gif`, and `image/webp` media types.
//
// See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
// more input examples.
//
// Note that if you want to include a
// [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
// the top-level `system` parameter — there is no `"system"` role for input
// messages in the Messages API.
Messages param.Field[[]MessageParam] `json:"messages,required"`
// The model that will complete your prompt.\n\nSee
// [models](https://docs.anthropic.com/en/docs/models-overview) for additional
// details and options.
Model param.Field[Model] `json:"model,required"`
// System prompt.
//
// A system prompt is a way of providing context and instructions to Claude, such
// as specifying a particular goal or role. See our
// [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
System param.Field[MessageCountTokensParamsSystemUnion] `json:"system"`
// How the model should use the provided tools. The model can use a specific tool,
// any available tool, or decide by itself.
ToolChoice param.Field[ToolChoiceUnionParam] `json:"tool_choice"`
// Definitions of tools that the model may use.
//
// If you include `tools` in your API request, the model may return `tool_use`
// content blocks that represent the model's use of those tools. You can then run
// those tools using the tool input generated by the model and then optionally
// return results back to the model using `tool_result` content blocks.
//
// Each tool definition includes:
//
// - `name`: Name of the tool.
// - `description`: Optional, but strongly-recommended description of the tool.
// - `input_schema`: [JSON schema](https://json-schema.org/) for the tool `input`
// shape that the model will produce in `tool_use` output content blocks.
//
// For example, if you defined `tools` as:
//
// “`json
// [
//
// {
// "name": "get_stock_price",
// "description": "Get the current stock price for a given ticker symbol.",
// "input_schema": {
// "type": "object",
// "properties": {
// "ticker": {
// "type": "string",
// "description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
// }
// },
// "required": ["ticker"]
// }
// }
//
// ]
// “`
//
// And then asked the model "What's the S&P 500 at today?", the model might produce
// `tool_use` content blocks in the response like this:
//
// “`json
// [
//
// {
// "type": "tool_use",
// "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
// "name": "get_stock_price",
// "input": { "ticker": "^GSPC" }
// }
//
// ]
// “`
//
// You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an
// input, and return the following back to the model in a subsequent `user`
// message:
//
// “`json
// [
//
// {
// "type": "tool_result",
// "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
// "content": "259.75 USD"
// }
//
// ]
// “`
//
// Tools can be used for workflows that include running client-side tools and
// functions, or more generally whenever you want the model to produce a particular
// JSON structure of output.
//
// See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
Tools param.Field[[]ToolParam] `json:"tools"`
}
func (MessageCountTokensParams) MarshalJSON ¶
func (r MessageCountTokensParams) MarshalJSON() (data []byte, err error)
type MessageCountTokensParamsSystemArray ¶
type MessageCountTokensParamsSystemArray []TextBlockParam
func (MessageCountTokensParamsSystemArray) ImplementsMessageCountTokensParamsSystemUnion ¶
func (r MessageCountTokensParamsSystemArray) ImplementsMessageCountTokensParamsSystemUnion()
type MessageCountTokensParamsSystemUnion ¶
type MessageCountTokensParamsSystemUnion interface {
ImplementsMessageCountTokensParamsSystemUnion()
}
System prompt.
A system prompt is a way of providing context and instructions to Claude, such as specifying a particular goal or role. See our [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
Satisfied by shared.UnionString, MessageCountTokensParamsSystemArray.
type MessageDeltaEvent ¶
type MessageDeltaEvent struct {
Delta MessageDeltaEventDelta `json:"delta,required"`
Type MessageDeltaEventType `json:"type,required"`
// Billing and rate-limit usage.
//
// Anthropic's API bills and rate-limits by token counts, as tokens represent the
// underlying cost to our systems.
//
// Under the hood, the API transforms requests into a format suitable for the
// model. The model's output then goes through a parsing stage before becoming an
// API response. As a result, the token counts in `usage` will not match one-to-one
// with the exact visible content of an API request or response.
//
// For example, `output_tokens` will be non-zero, even for an empty string response
// from Claude.
Usage MessageDeltaUsage `json:"usage,required"`
JSON messageDeltaEventJSON `json:"-"`
}
func (*MessageDeltaEvent) UnmarshalJSON ¶
func (r *MessageDeltaEvent) UnmarshalJSON(data []byte) (err error)
type MessageDeltaEventDelta ¶
type MessageDeltaEventDelta struct {
StopReason MessageDeltaEventDeltaStopReason `json:"stop_reason,required,nullable"`
StopSequence string `json:"stop_sequence,required,nullable"`
JSON messageDeltaEventDeltaJSON `json:"-"`
}
func (*MessageDeltaEventDelta) UnmarshalJSON ¶
func (r *MessageDeltaEventDelta) UnmarshalJSON(data []byte) (err error)
type MessageDeltaEventDeltaStopReason ¶
type MessageDeltaEventDeltaStopReason string
const ( MessageDeltaEventDeltaStopReasonEndTurn MessageDeltaEventDeltaStopReason = "end_turn" MessageDeltaEventDeltaStopReasonMaxTokens MessageDeltaEventDeltaStopReason = "max_tokens" MessageDeltaEventDeltaStopReasonStopSequence MessageDeltaEventDeltaStopReason = "stop_sequence" MessageDeltaEventDeltaStopReasonToolUse MessageDeltaEventDeltaStopReason = "tool_use" )
func (MessageDeltaEventDeltaStopReason) IsKnown ¶
func (r MessageDeltaEventDeltaStopReason) IsKnown() bool
type MessageDeltaEventType ¶
type MessageDeltaEventType string
const (
MessageDeltaEventTypeMessageDelta MessageDeltaEventType = "message_delta"
)
func (MessageDeltaEventType) IsKnown ¶
func (r MessageDeltaEventType) IsKnown() bool
type MessageDeltaUsage ¶
type MessageDeltaUsage struct {
// The cumulative number of output tokens which were used.
OutputTokens int64 `json:"output_tokens,required"`
JSON messageDeltaUsageJSON `json:"-"`
}
func (*MessageDeltaUsage) UnmarshalJSON ¶
func (r *MessageDeltaUsage) UnmarshalJSON(data []byte) (err error)
type MessageNewParams ¶
type MessageNewParams struct {
// The maximum number of tokens to generate before stopping.
//
// Note that our models may stop _before_ reaching this maximum. This parameter
// only specifies the absolute maximum number of tokens to generate.
//
// Different models have different maximum values for this parameter. See
// [models](https://docs.anthropic.com/en/docs/models-overview) for details.
MaxTokens param.Field[int64] `json:"max_tokens,required"`
// Input messages.
//
// Our models are trained to operate on alternating `user` and `assistant`
// conversational turns. When creating a new `Message`, you specify the prior
// conversational turns with the `messages` parameter, and the model then generates
// the next `Message` in the conversation. Consecutive `user` or `assistant` turns
// in your request will be combined into a single turn.
//
// Each input message must be an object with a `role` and `content`. You can
// specify a single `user`-role message, or you can include multiple `user` and
// `assistant` messages.
//
// If the final message uses the `assistant` role, the response content will
// continue immediately from the content in that message. This can be used to
// constrain part of the model's response.
//
// Example with a single `user` message:
//
// “`json
// [{ "role": "user", "content": "Hello, Claude" }]
// “`
//
// Example with multiple conversational turns:
//
// “`json
// [
//
// { "role": "user", "content": "Hello there." },
// { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
// { "role": "user", "content": "Can you explain LLMs in plain English?" }
//
// ]
// “`
//
// Example with a partially-filled response from Claude:
//
// “`json
// [
//
// {
// "role": "user",
// "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
// },
// { "role": "assistant", "content": "The best answer is (" }
//
// ]
// “`
//
// Each input message `content` may be either a single `string` or an array of
// content blocks, where each block has a specific `type`. Using a `string` for
// `content` is shorthand for an array of one content block of type `"text"`. The
// following input messages are equivalent:
//
// “`json
// { "role": "user", "content": "Hello, Claude" }
// “`
//
// “`json
// { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
// “`
//
// Starting with Claude 3 models, you can also send image content blocks:
//
// “`json
//
// {
// "role": "user",
// "content": [
// {
// "type": "image",
// "source": {
// "type": "base64",
// "media_type": "image/jpeg",
// "data": "/9j/4AAQSkZJRg..."
// }
// },
// { "type": "text", "text": "What is in this image?" }
// ]
// }
//
// “`
//
// We currently support the `base64` source type for images, and the `image/jpeg`,
// `image/png`, `image/gif`, and `image/webp` media types.
//
// See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
// more input examples.
//
// Note that if you want to include a
// [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
// the top-level `system` parameter — there is no `"system"` role for input
// messages in the Messages API.
Messages param.Field[[]MessageParam] `json:"messages,required"`
// The model that will complete your prompt.\n\nSee
// [models](https://docs.anthropic.com/en/docs/models-overview) for additional
// details and options.
Model param.Field[Model] `json:"model,required"`
// An object describing metadata about the request.
Metadata param.Field[MetadataParam] `json:"metadata"`
// Custom text sequences that will cause the model to stop generating.
//
// Our models will normally stop when they have naturally completed their turn,
// which will result in a response `stop_reason` of `"end_turn"`.
//
// If you want the model to stop generating when it encounters custom strings of
// text, you can use the `stop_sequences` parameter. If the model encounters one of
// the custom sequences, the response `stop_reason` value will be `"stop_sequence"`
// and the response `stop_sequence` value will contain the matched stop sequence.
StopSequences param.Field[[]string] `json:"stop_sequences"`
// System prompt.
//
// A system prompt is a way of providing context and instructions to Claude, such
// as specifying a particular goal or role. See our
// [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
System param.Field[[]TextBlockParam] `json:"system"`
// Amount of randomness injected into the response.
//
// Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
// for analytical / multiple choice, and closer to `1.0` for creative and
// generative tasks.
//
// Note that even with `temperature` of `0.0`, the results will not be fully
// deterministic.
Temperature param.Field[float64] `json:"temperature"`
// How the model should use the provided tools. The model can use a specific tool,
// any available tool, or decide by itself.
ToolChoice param.Field[ToolChoiceUnionParam] `json:"tool_choice"`
// Definitions of tools that the model may use.
//
// If you include `tools` in your API request, the model may return `tool_use`
// content blocks that represent the model's use of those tools. You can then run
// those tools using the tool input generated by the model and then optionally
// return results back to the model using `tool_result` content blocks.
//
// Each tool definition includes:
//
// - `name`: Name of the tool.
// - `description`: Optional, but strongly-recommended description of the tool.
// - `input_schema`: [JSON schema](https://json-schema.org/) for the tool `input`
// shape that the model will produce in `tool_use` output content blocks.
//
// For example, if you defined `tools` as:
//
// “`json
// [
//
// {
// "name": "get_stock_price",
// "description": "Get the current stock price for a given ticker symbol.",
// "input_schema": {
// "type": "object",
// "properties": {
// "ticker": {
// "type": "string",
// "description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
// }
// },
// "required": ["ticker"]
// }
// }
//
// ]
// “`
//
// And then asked the model "What's the S&P 500 at today?", the model might produce
// `tool_use` content blocks in the response like this:
//
// “`json
// [
//
// {
// "type": "tool_use",
// "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
// "name": "get_stock_price",
// "input": { "ticker": "^GSPC" }
// }
//
// ]
// “`
//
// You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an
// input, and return the following back to the model in a subsequent `user`
// message:
//
// “`json
// [
//
// {
// "type": "tool_result",
// "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
// "content": "259.75 USD"
// }
//
// ]
// “`
//
// Tools can be used for workflows that include running client-side tools and
// functions, or more generally whenever you want the model to produce a particular
// JSON structure of output.
//
// See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
Tools param.Field[[]ToolParam] `json:"tools"`
// Only sample from the top K options for each subsequent token.
//
// Used to remove "long tail" low probability responses.
// [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
//
// Recommended for advanced use cases only. You usually only need to use
// `temperature`.
TopK param.Field[int64] `json:"top_k"`
// Use nucleus sampling.
//
// In nucleus sampling, we compute the cumulative distribution over all the options
// for each subsequent token in decreasing probability order and cut it off once it
// reaches a particular probability specified by `top_p`. You should either alter
// `temperature` or `top_p`, but not both.
//
// Recommended for advanced use cases only. You usually only need to use
// `temperature`.
TopP param.Field[float64] `json:"top_p"`
}
func (MessageNewParams) MarshalJSON ¶
func (r MessageNewParams) MarshalJSON() (data []byte, err error)
type MessageParam ¶
type MessageParam struct {
Content param.Field[[]ContentBlockParamUnion] `json:"content,required"`
Role param.Field[MessageParamRole] `json:"role,required"`
}
func NewAssistantMessage ¶
func NewAssistantMessage(blocks ...ContentBlockParamUnion) MessageParam
func NewUserMessage ¶
func NewUserMessage(blocks ...ContentBlockParamUnion) MessageParam
func (MessageParam) MarshalJSON ¶
func (r MessageParam) MarshalJSON() (data []byte, err error)
type MessageParamRole ¶
type MessageParamRole string
const ( MessageParamRoleUser MessageParamRole = "user" MessageParamRoleAssistant MessageParamRole = "assistant" )
func (MessageParamRole) IsKnown ¶
func (r MessageParamRole) IsKnown() bool
type MessageRole ¶
type MessageRole string
Conversational role of the generated message.
This will always be `"assistant"`.
const (
MessageRoleAssistant MessageRole = "assistant"
)
func (MessageRole) IsKnown ¶
func (r MessageRole) IsKnown() bool
type MessageService ¶
type MessageService struct {
Options []option.RequestOption
Batches *MessageBatchService
}
MessageService contains methods and other services that help with interacting with the anthropic API.
Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewMessageService method instead.
func NewMessageService ¶
func NewMessageService(opts ...option.RequestOption) (r *MessageService)
NewMessageService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.
func (*MessageService) CountTokens ¶
func (r *MessageService) CountTokens(ctx context.Context, body MessageCountTokensParams, opts ...option.RequestOption) (res *MessageTokensCount, err error)
Count the number of tokens in a Message.
The Token Count API can be used to count the number of tokens in a Message, including tools, images, and documents, without creating it.
func (*MessageService) New ¶
func (r *MessageService) New(ctx context.Context, body MessageNewParams, opts ...option.RequestOption) (res *Message, err error)
Send a structured list of input messages with text and/or image content, and the model will generate the next message in the conversation.
The Messages API can be used for either single queries or stateless multi-turn conversations.
Note: If you choose to set a timeout for this request, we recommend 10 minutes.
func (*MessageService) NewStreaming ¶
func (r *MessageService) NewStreaming(ctx context.Context, body MessageNewParams, opts ...option.RequestOption) (stream *ssestream.Stream[MessageStreamEvent])
Send a structured list of input messages with text and/or image content, and the model will generate the next message in the conversation.
The Messages API can be used for either single queries or stateless multi-turn conversations.
Note: If you choose to set a timeout for this request, we recommend 10 minutes.
type MessageStartEvent ¶
type MessageStartEvent struct {
Message Message `json:"message,required"`
Type MessageStartEventType `json:"type,required"`
JSON messageStartEventJSON `json:"-"`
}
func (*MessageStartEvent) UnmarshalJSON ¶
func (r *MessageStartEvent) UnmarshalJSON(data []byte) (err error)
type MessageStartEventType ¶
type MessageStartEventType string
const (
MessageStartEventTypeMessageStart MessageStartEventType = "message_start"
)
func (MessageStartEventType) IsKnown ¶
func (r MessageStartEventType) IsKnown() bool
type MessageStopEvent ¶
type MessageStopEvent struct {
Type MessageStopEventType `json:"type,required"`
JSON messageStopEventJSON `json:"-"`
}
func (*MessageStopEvent) UnmarshalJSON ¶
func (r *MessageStopEvent) UnmarshalJSON(data []byte) (err error)
type MessageStopEventType ¶
type MessageStopEventType string
const (
MessageStopEventTypeMessageStop MessageStopEventType = "message_stop"
)
func (MessageStopEventType) IsKnown ¶
func (r MessageStopEventType) IsKnown() bool
type MessageStopReason ¶
type MessageStopReason string
The reason that we stopped.
This may be one the following values:
- `"end_turn"`: the model reached a natural stopping point - `"max_tokens"`: we exceeded the requested `max_tokens` or the model's maximum - `"stop_sequence"`: one of your provided custom `stop_sequences` was generated - `"tool_use"`: the model invoked one or more tools
In non-streaming mode this value is always non-null. In streaming mode, it is null in the `message_start` event and non-null otherwise.
const ( MessageStopReasonEndTurn MessageStopReason = "end_turn" MessageStopReasonMaxTokens MessageStopReason = "max_tokens" MessageStopReasonStopSequence MessageStopReason = "stop_sequence" MessageStopReasonToolUse MessageStopReason = "tool_use" )
func (MessageStopReason) IsKnown ¶
func (r MessageStopReason) IsKnown() bool
type MessageStreamEvent ¶
type MessageStreamEvent struct {
Type MessageStreamEventType `json:"type,required"`
// This field can have the runtime type of [ContentBlockStartEventContentBlock].
ContentBlock interface{} `json:"content_block"`
// This field can have the runtime type of [MessageDeltaEventDelta],
// [ContentBlockDeltaEventDelta].
Delta interface{} `json:"delta"`
Index int64 `json:"index"`
Message Message `json:"message"`
// Billing and rate-limit usage.
//
// Anthropic's API bills and rate-limits by token counts, as tokens represent the
// underlying cost to our systems.
//
// Under the hood, the API transforms requests into a format suitable for the
// model. The model's output then goes through a parsing stage before becoming an
// API response. As a result, the token counts in `usage` will not match one-to-one
// with the exact visible content of an API request or response.
//
// For example, `output_tokens` will be non-zero, even for an empty string response
// from Claude.
Usage MessageDeltaUsage `json:"usage"`
JSON messageStreamEventJSON `json:"-"`
// contains filtered or unexported fields
}
func (MessageStreamEvent) AsUnion ¶
func (r MessageStreamEvent) AsUnion() MessageStreamEventUnion
AsUnion returns a MessageStreamEventUnion interface which you can cast to the specific types for more type safety.
Possible runtime types of the union are MessageStartEvent, MessageDeltaEvent, MessageStopEvent, ContentBlockStartEvent, ContentBlockDeltaEvent, ContentBlockStopEvent.
func (*MessageStreamEvent) UnmarshalJSON ¶
func (r *MessageStreamEvent) UnmarshalJSON(data []byte) (err error)
type MessageStreamEventType ¶
type MessageStreamEventType string
const ( MessageStreamEventTypeMessageStart MessageStreamEventType = "message_start" MessageStreamEventTypeMessageDelta MessageStreamEventType = "message_delta" MessageStreamEventTypeMessageStop MessageStreamEventType = "message_stop" MessageStreamEventTypeContentBlockStart MessageStreamEventType = "content_block_start" MessageStreamEventTypeContentBlockDelta MessageStreamEventType = "content_block_delta" MessageStreamEventTypeContentBlockStop MessageStreamEventType = "content_block_stop" )
func (MessageStreamEventType) IsKnown ¶
func (r MessageStreamEventType) IsKnown() bool
type MessageStreamEventUnion ¶
type MessageStreamEventUnion interface {
// contains filtered or unexported methods
}
Union satisfied by MessageStartEvent, MessageDeltaEvent, MessageStopEvent, ContentBlockStartEvent, ContentBlockDeltaEvent or ContentBlockStopEvent.
type MessageTokensCount ¶
type MessageTokensCount struct {
// The total number of tokens across the provided list of messages, system prompt,
// and tools.
InputTokens int64 `json:"input_tokens,required"`
JSON messageTokensCountJSON `json:"-"`
}
func (*MessageTokensCount) UnmarshalJSON ¶
func (r *MessageTokensCount) UnmarshalJSON(data []byte) (err error)
type MessageType ¶
type MessageType string
Object type.
For Messages, this is always `"message"`.
const (
MessageTypeMessage MessageType = "message"
)
func (MessageType) IsKnown ¶
func (r MessageType) IsKnown() bool
type MetadataParam ¶
type MetadataParam struct {
// An external identifier for the user who is associated with the request.
//
// This should be a uuid, hash value, or other opaque identifier. Anthropic may use
// this id to help detect abuse. Do not include any identifying information such as
// name, email address, or phone number.
UserID param.Field[string] `json:"user_id"`
}
func (MetadataParam) MarshalJSON ¶
func (r MetadataParam) MarshalJSON() (data []byte, err error)
type Model ¶
type Model = string
The model that will complete your prompt.\n\nSee [models](https://docs.anthropic.com/en/docs/models-overview) for additional details and options.
const ( // Fast and cost-effective model ModelClaude3_5HaikuLatest Model = "claude-3-5-haiku-latest" // Fast and cost-effective model ModelClaude3_5Haiku20241022 Model = "claude-3-5-haiku-20241022" // Our most intelligent model ModelClaude3_5SonnetLatest Model = "claude-3-5-sonnet-latest" // Our most intelligent model ModelClaude3_5Sonnet20241022 Model = "claude-3-5-sonnet-20241022" // Our previous most intelligent model ModelClaude_3_5_Sonnet_20240620 Model = "claude-3-5-sonnet-20240620" // Excels at writing and complex tasks ModelClaude3OpusLatest Model = "claude-3-opus-latest" // Excels at writing and complex tasks ModelClaude_3_Opus_20240229 Model = "claude-3-opus-20240229" // Balance of speed and intelligence ModelClaude_3_Sonnet_20240229 Model = "claude-3-sonnet-20240229" // Our previous fast and cost-effective ModelClaude_3_Haiku_20240307 Model = "claude-3-haiku-20240307" ModelClaude_2_1 Model = "claude-2.1" ModelClaude_2_0 Model = "claude-2.0" )
type ModelInfo ¶
type ModelInfo struct {
// Unique model identifier.
ID string `json:"id,required"`
// RFC 3339 datetime string representing the time at which the model was released.
// May be set to an epoch value if the release date is unknown.
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
// A human-readable name for the model.
DisplayName string `json:"display_name,required"`
// Object type.
//
// For Models, this is always `"model"`.
Type ModelInfoType `json:"type,required"`
JSON modelInfoJSON `json:"-"`
}
func (*ModelInfo) UnmarshalJSON ¶
type ModelInfoType ¶
type ModelInfoType string
Object type.
For Models, this is always `"model"`.
const (
ModelInfoTypeModel ModelInfoType = "model"
)
func (ModelInfoType) IsKnown ¶
func (r ModelInfoType) IsKnown() bool
type ModelListParams ¶
type ModelListParams struct {
// ID of the object to use as a cursor for pagination. When provided, returns the
// page of results immediately after this object.
AfterID param.Field[string] `query:"after_id"`
// ID of the object to use as a cursor for pagination. When provided, returns the
// page of results immediately before this object.
BeforeID param.Field[string] `query:"before_id"`
// Number of items to return per page.
//
// Defaults to `20`. Ranges from `1` to `1000`.
Limit param.Field[int64] `query:"limit"`
}
func (ModelListParams) URLQuery ¶
func (r ModelListParams) URLQuery() (v url.Values)
URLQuery serializes ModelListParams's query parameters as `url.Values`.
type ModelService ¶
type ModelService struct {
Options []option.RequestOption
}
ModelService contains methods and other services that help with interacting with the anthropic API.
Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewModelService method instead.
func NewModelService ¶
func NewModelService(opts ...option.RequestOption) (r *ModelService)
NewModelService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.
func (*ModelService) Get ¶
func (r *ModelService) Get(ctx context.Context, modelID string, opts ...option.RequestOption) (res *ModelInfo, err error)
Get a specific model.
The Models API response can be used to determine information about a specific model or resolve a model alias to a model ID.
func (*ModelService) List ¶
func (r *ModelService) List(ctx context.Context, query ModelListParams, opts ...option.RequestOption) (res *pagination.Page[ModelInfo], err error)
List available models.
The Models API response can be used to determine which models are available for use in the API. More recently released models are listed first.
func (*ModelService) ListAutoPaging ¶
func (r *ModelService) ListAutoPaging(ctx context.Context, query ModelListParams, opts ...option.RequestOption) *pagination.PageAutoPager[ModelInfo]
List available models.
The Models API response can be used to determine which models are available for use in the API. More recently released models are listed first.
type NotFoundError ¶
type NotFoundError = shared.NotFoundError
This is an alias to an internal type.
type NotFoundErrorType ¶
type NotFoundErrorType = shared.NotFoundErrorType
This is an alias to an internal type.
type OverloadedError ¶
type OverloadedError = shared.OverloadedError
This is an alias to an internal type.
type OverloadedErrorType ¶
type OverloadedErrorType = shared.OverloadedErrorType
This is an alias to an internal type.
type PermissionError ¶
type PermissionError = shared.PermissionError
This is an alias to an internal type.
type PermissionErrorType ¶
type PermissionErrorType = shared.PermissionErrorType
This is an alias to an internal type.
type RateLimitError ¶
type RateLimitError = shared.RateLimitError
This is an alias to an internal type.
type RateLimitErrorType ¶
type RateLimitErrorType = shared.RateLimitErrorType
This is an alias to an internal type.
type TextBlock ¶
type TextBlock struct {
Text string `json:"text,required"`
Type TextBlockType `json:"type,required"`
JSON textBlockJSON `json:"-"`
}
func (*TextBlock) UnmarshalJSON ¶
type TextBlockParam ¶
type TextBlockParam struct {
Text param.Field[string] `json:"text,required"`
Type param.Field[TextBlockParamType] `json:"type,required"`
CacheControl param.Field[CacheControlEphemeralParam] `json:"cache_control"`
}
func NewTextBlock ¶
func NewTextBlock(text string) TextBlockParam
func (TextBlockParam) MarshalJSON ¶
func (r TextBlockParam) MarshalJSON() (data []byte, err error)
type TextBlockParamType ¶
type TextBlockParamType string
const (
TextBlockParamTypeText TextBlockParamType = "text"
)
func (TextBlockParamType) IsKnown ¶
func (r TextBlockParamType) IsKnown() bool
type TextBlockType ¶
type TextBlockType string
const (
TextBlockTypeText TextBlockType = "text"
)
func (TextBlockType) IsKnown ¶
func (r TextBlockType) IsKnown() bool
type TextDelta ¶
type TextDelta struct {
Text string `json:"text,required"`
Type TextDeltaType `json:"type,required"`
JSON textDeltaJSON `json:"-"`
}
func (*TextDelta) UnmarshalJSON ¶
type TextDeltaType ¶
type TextDeltaType string
const (
TextDeltaTypeTextDelta TextDeltaType = "text_delta"
)
func (TextDeltaType) IsKnown ¶
func (r TextDeltaType) IsKnown() bool
type ToolChoiceAnyParam ¶
type ToolChoiceAnyParam struct {
Type param.Field[ToolChoiceAnyType] `json:"type,required"`
// Whether to disable parallel tool use.
//
// Defaults to `false`. If set to `true`, the model will output exactly one tool
// use.
DisableParallelToolUse param.Field[bool] `json:"disable_parallel_tool_use"`
}
The model will use any available tools.
func (ToolChoiceAnyParam) MarshalJSON ¶
func (r ToolChoiceAnyParam) MarshalJSON() (data []byte, err error)
type ToolChoiceAnyType ¶
type ToolChoiceAnyType string
const (
ToolChoiceAnyTypeAny ToolChoiceAnyType = "any"
)
func (ToolChoiceAnyType) IsKnown ¶
func (r ToolChoiceAnyType) IsKnown() bool
type ToolChoiceAutoParam ¶
type ToolChoiceAutoParam struct {
Type param.Field[ToolChoiceAutoType] `json:"type,required"`
// Whether to disable parallel tool use.
//
// Defaults to `false`. If set to `true`, the model will output at most one tool
// use.
DisableParallelToolUse param.Field[bool] `json:"disable_parallel_tool_use"`
}
The model will automatically decide whether to use tools.
func (ToolChoiceAutoParam) MarshalJSON ¶
func (r ToolChoiceAutoParam) MarshalJSON() (data []byte, err error)
type ToolChoiceAutoType ¶
type ToolChoiceAutoType string
const (
ToolChoiceAutoTypeAuto ToolChoiceAutoType = "auto"
)
func (ToolChoiceAutoType) IsKnown ¶
func (r ToolChoiceAutoType) IsKnown() bool
type ToolChoiceParam ¶
type ToolChoiceParam struct {
Type param.Field[ToolChoiceType] `json:"type,required"`
// Whether to disable parallel tool use.
//
// Defaults to `false`. If set to `true`, the model will output at most one tool
// use.
DisableParallelToolUse param.Field[bool] `json:"disable_parallel_tool_use"`
// The name of the tool to use.
Name param.Field[string] `json:"name"`
}
How the model should use the provided tools. The model can use a specific tool, any available tool, or decide by itself.
func (ToolChoiceParam) MarshalJSON ¶
func (r ToolChoiceParam) MarshalJSON() (data []byte, err error)
type ToolChoiceToolParam ¶
type ToolChoiceToolParam struct {
// The name of the tool to use.
Name param.Field[string] `json:"name,required"`
Type param.Field[ToolChoiceToolType] `json:"type,required"`
// Whether to disable parallel tool use.
//
// Defaults to `false`. If set to `true`, the model will output exactly one tool
// use.
DisableParallelToolUse param.Field[bool] `json:"disable_parallel_tool_use"`
}
The model will use the specified tool with `tool_choice.name`.
func (ToolChoiceToolParam) MarshalJSON ¶
func (r ToolChoiceToolParam) MarshalJSON() (data []byte, err error)
type ToolChoiceToolType ¶
type ToolChoiceToolType string
const (
ToolChoiceToolTypeTool ToolChoiceToolType = "tool"
)
func (ToolChoiceToolType) IsKnown ¶
func (r ToolChoiceToolType) IsKnown() bool
type ToolChoiceType ¶
type ToolChoiceType string
const ( ToolChoiceTypeAuto ToolChoiceType = "auto" ToolChoiceTypeAny ToolChoiceType = "any" ToolChoiceTypeTool ToolChoiceType = "tool" )
func (ToolChoiceType) IsKnown ¶
func (r ToolChoiceType) IsKnown() bool
type ToolChoiceUnionParam ¶
type ToolChoiceUnionParam interface {
// contains filtered or unexported methods
}
How the model should use the provided tools. The model can use a specific tool, any available tool, or decide by itself.
Satisfied by ToolChoiceAutoParam, ToolChoiceAnyParam, ToolChoiceToolParam, ToolChoiceParam.
type ToolInputSchemaParam ¶
type ToolInputSchemaParam struct {
Type param.Field[ToolInputSchemaType] `json:"type,required"`
Properties param.Field[interface{}] `json:"properties"`
ExtraFields map[string]interface{} `json:"-,extras"`
}
[JSON schema](https://json-schema.org/) for this tool's input.
This defines the shape of the `input` that your tool accepts and that the model will produce.
func (ToolInputSchemaParam) MarshalJSON ¶
func (r ToolInputSchemaParam) MarshalJSON() (data []byte, err error)
type ToolInputSchemaType ¶
type ToolInputSchemaType string
const (
ToolInputSchemaTypeObject ToolInputSchemaType = "object"
)
func (ToolInputSchemaType) IsKnown ¶
func (r ToolInputSchemaType) IsKnown() bool
type ToolParam ¶
type ToolParam struct {
// [JSON schema](https://json-schema.org/) for this tool's input.
//
// This defines the shape of the `input` that your tool accepts and that the model
// will produce.
InputSchema param.Field[interface{}] `json:"input_schema,required"`
// Name of the tool.
//
// This is how the tool will be called by the model and in tool_use blocks.
Name param.Field[string] `json:"name,required"`
CacheControl param.Field[CacheControlEphemeralParam] `json:"cache_control"`
// Description of what this tool does.
//
// Tool descriptions should be as detailed as possible. The more information that
// the model has about what the tool is and how to use it, the better it will
// perform. You can use natural language descriptions to reinforce important
// aspects of the tool input JSON schema.
Description param.Field[string] `json:"description"`
}
func (ToolParam) MarshalJSON ¶
type ToolResultBlockParam ¶
type ToolResultBlockParam struct {
ToolUseID param.Field[string] `json:"tool_use_id,required"`
Type param.Field[ToolResultBlockParamType] `json:"type,required"`
CacheControl param.Field[CacheControlEphemeralParam] `json:"cache_control"`
Content param.Field[[]ToolResultBlockParamContentUnion] `json:"content"`
IsError param.Field[bool] `json:"is_error"`
}
func NewToolResultBlock ¶
func NewToolResultBlock(toolUseID string, content string, isError bool) ToolResultBlockParam
func (ToolResultBlockParam) MarshalJSON ¶
func (r ToolResultBlockParam) MarshalJSON() (data []byte, err error)
type ToolResultBlockParamContent ¶
type ToolResultBlockParamContent struct {
Type param.Field[ToolResultBlockParamContentType] `json:"type,required"`
CacheControl param.Field[CacheControlEphemeralParam] `json:"cache_control"`
Source param.Field[interface{}] `json:"source"`
Text param.Field[string] `json:"text"`
}
func (ToolResultBlockParamContent) MarshalJSON ¶
func (r ToolResultBlockParamContent) MarshalJSON() (data []byte, err error)
type ToolResultBlockParamContentType ¶
type ToolResultBlockParamContentType string
const ( ToolResultBlockParamContentTypeText ToolResultBlockParamContentType = "text" ToolResultBlockParamContentTypeImage ToolResultBlockParamContentType = "image" )
func (ToolResultBlockParamContentType) IsKnown ¶
func (r ToolResultBlockParamContentType) IsKnown() bool
type ToolResultBlockParamContentUnion ¶
type ToolResultBlockParamContentUnion interface {
// contains filtered or unexported methods
}
Satisfied by TextBlockParam, ImageBlockParam, ToolResultBlockParamContent.
type ToolResultBlockParamType ¶
type ToolResultBlockParamType string
const (
ToolResultBlockParamTypeToolResult ToolResultBlockParamType = "tool_result"
)
func (ToolResultBlockParamType) IsKnown ¶
func (r ToolResultBlockParamType) IsKnown() bool
type ToolUseBlock ¶
type ToolUseBlock struct {
ID string `json:"id,required"`
Input json.RawMessage `json:"input,required"`
Name string `json:"name,required"`
Type ToolUseBlockType `json:"type,required"`
JSON toolUseBlockJSON `json:"-"`
}
func (*ToolUseBlock) UnmarshalJSON ¶
func (r *ToolUseBlock) UnmarshalJSON(data []byte) (err error)
type ToolUseBlockParam ¶
type ToolUseBlockParam struct {
ID param.Field[string] `json:"id,required"`
Input param.Field[interface{}] `json:"input,required"`
Name param.Field[string] `json:"name,required"`
Type param.Field[ToolUseBlockParamType] `json:"type,required"`
CacheControl param.Field[CacheControlEphemeralParam] `json:"cache_control"`
}
func NewToolUseBlockParam ¶
func NewToolUseBlockParam(id string, name string, input interface{}) ToolUseBlockParam
func (ToolUseBlockParam) MarshalJSON ¶
func (r ToolUseBlockParam) MarshalJSON() (data []byte, err error)
type ToolUseBlockParamType ¶
type ToolUseBlockParamType string
const (
ToolUseBlockParamTypeToolUse ToolUseBlockParamType = "tool_use"
)
func (ToolUseBlockParamType) IsKnown ¶
func (r ToolUseBlockParamType) IsKnown() bool
type ToolUseBlockType ¶
type ToolUseBlockType string
const (
ToolUseBlockTypeToolUse ToolUseBlockType = "tool_use"
)
func (ToolUseBlockType) IsKnown ¶
func (r ToolUseBlockType) IsKnown() bool
type Usage ¶
type Usage struct {
// The number of input tokens used to create the cache entry.
CacheCreationInputTokens int64 `json:"cache_creation_input_tokens,required,nullable"`
// The number of input tokens read from the cache.
CacheReadInputTokens int64 `json:"cache_read_input_tokens,required,nullable"`
// The number of input tokens which were used.
InputTokens int64 `json:"input_tokens,required"`
// The number of output tokens which were used.
OutputTokens int64 `json:"output_tokens,required"`
JSON usageJSON `json:"-"`
}