Documentation
¶
Index ¶
- type APIError
- type BaseContent
- type Client
- func (c *Client) Complete(req *Request) (*SuccessfulResponse, error)
- func (c *Client) CountTokens(ctx context.Context, req *MessageCountTokensRequest) (*MessageCountTokensResponse, error)
- func (c *Client) SendMessage(ctx context.Context, req *MessageRequest) (*MessageResponse, error)
- func (c *Client) SetBearerAuthorization(value string)
- func (c *Client) SetHTTPClient(httpClient *http.Client)
- func (c *Client) SetOAuthBearerAuthorization(value string)
- func (c *Client) SetOutboundURLOptions(opts security.OutboundURLOptions)
- func (c *Client) StreamComplete(req *Request) (<-chan Event, error)
- func (c *Client) StreamMessage(ctx context.Context, req *MessageRequest) (<-chan StreamingEvent, error)
- type Content
- func NewImageContent(mediaType, base64Data string) Content
- func NewTextContent(text string) Content
- func NewThinkingContent(thinking, signature string) Content
- func NewToolResultContent(toolUseID, content string) Content
- func NewToolUseContent(toolID, toolName string, toolInput string) Content
- func UnmarshalContent(data []byte) (Content, error)
- type ContentBlock
- type ContentType
- type Delta
- type Error
- type ErrorDetail
- type ErrorResponse
- type Event
- type ImageContent
- type ImageSource
- type Message
- type MessageCountTokensRequest
- type MessageCountTokensResponse
- type MessageRequest
- type MessageResponse
- type Metadata
- type OutputFormat
- type Request
- type StreamingDeltaType
- type StreamingEvent
- type StreamingEventType
- type SuccessfulResponse
- type TextContent
- type ThinkingContent
- type ThinkingParam
- type Tool
- type ToolResultContent
- type ToolUseContent
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶ added in v0.13.11
APIError is a non-success response returned by the Claude API.
Callers can use errors.As to inspect the HTTP status and Anthropic error type without parsing the human-readable message.
type BaseContent ¶
type BaseContent struct {
Type_ ContentType `json:"type"`
}
func (BaseContent) MarshalZerologObject ¶
func (bc BaseContent) MarshalZerologObject(e *zerolog.Event)
type Client ¶
Client represents the Claude API client.
func (*Client) Complete ¶
func (c *Client) Complete(req *Request) (*SuccessfulResponse, error)
Complete sends a completion request and returns the response.
func (*Client) CountTokens ¶ added in v0.10.9
func (c *Client) CountTokens(ctx context.Context, req *MessageCountTokensRequest) (*MessageCountTokensResponse, error)
func (*Client) SendMessage ¶
func (c *Client) SendMessage(ctx context.Context, req *MessageRequest) (*MessageResponse, error)
SendMessage sends a message request and returns the response.
func (*Client) SetBearerAuthorization ¶ added in v0.13.7
SetBearerAuthorization adds the verified bearer form for gateways which require it in addition to the Anthropic x-api-key header. It is a Go-only runtime option and is never read from inference settings.
func (*Client) SetHTTPClient ¶ added in v0.10.9
func (*Client) SetOAuthBearerAuthorization ¶ added in v0.13.7
SetOAuthBearerAuthorization configures Anthropic subscription OAuth mode: bearer authorization plus the Claude Code identity/beta headers observed in the provider implementation. It deliberately does not send x-api-key.
func (*Client) SetOutboundURLOptions ¶ added in v0.13.4
func (c *Client) SetOutboundURLOptions(opts security.OutboundURLOptions)
func (*Client) StreamMessage ¶
func (c *Client) StreamMessage(ctx context.Context, req *MessageRequest) (<-chan StreamingEvent, error)
StreamMessage sends a message request and returns a channel of Events for streaming responses.
type Content ¶
type Content interface {
Type() ContentType
}
func NewImageContent ¶
func NewTextContent ¶
func NewThinkingContent ¶ added in v0.13.3
func NewToolResultContent ¶
func NewToolUseContent ¶
func UnmarshalContent ¶ added in v0.4.40
type ContentBlock ¶
type ContentBlock struct {
Type ContentType `json:"type"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Input interface{} `json:"input,omitempty"` // Can be string for text or object for tool_use
Text string `json:"text,omitempty"`
Thinking string `json:"thinking,omitempty"`
Signature string `json:"signature,omitempty"`
}
func (ContentBlock) MarshalZerologObject ¶
func (cb ContentBlock) MarshalZerologObject(e *zerolog.Event)
type ContentType ¶
type ContentType string
const ( ContentTypeText ContentType = "text" ContentTypeImage ContentType = "image" ContentTypeToolUse ContentType = "tool_use" ContentTypeToolResult ContentType = "tool_result" ContentTypeThinking ContentType = "thinking" )
type Delta ¶
type Delta struct {
Type StreamingDeltaType `json:"type"`
Text string `json:"text,omitempty"`
PartialJSON string `json:"partial_json"`
Thinking string `json:"thinking,omitempty"`
Signature string `json:"signature,omitempty"`
StopReason string `json:"stop_reason,omitempty"`
StopSequence string `json:"stop_sequence,omitempty"`
}
func (Delta) MarshalZerologObject ¶
type Error ¶
func (Error) MarshalZerologObject ¶
type ErrorDetail ¶
ErrorDetail contains error details.
type ErrorResponse ¶
type ErrorResponse struct {
Error ErrorDetail `json:"error"`
}
ErrorResponse represents the API's error response.
type ImageContent ¶
type ImageContent struct {
BaseContent
Source ImageSource `json:"source"`
}
func (ImageContent) MarshalZerologObject ¶
func (ic ImageContent) MarshalZerologObject(e *zerolog.Event)
func (ImageContent) Type ¶
func (i ImageContent) Type() ContentType
type ImageSource ¶
type ImageSource struct {
BaseContent
Type string `json:"type"`
MediaType string `json:"media_type"`
Data string `json:"data"`
}
func (ImageSource) MarshalZerologObject ¶
func (is ImageSource) MarshalZerologObject(e *zerolog.Event)
type Message ¶
type Message struct {
Role string `json:"role"`
Content []Content `json:"content"` // Can be a string or an array of content blocks
}
Message represents a single message in the conversation.
func (*Message) UnmarshalJSON ¶
type MessageCountTokensRequest ¶ added in v0.10.9
type MessageCountTokensResponse ¶ added in v0.10.9
type MessageCountTokensResponse struct {
InputTokens int `json:"input_tokens"`
}
type MessageRequest ¶
type MessageRequest struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
MaxTokens int `json:"max_tokens"`
Metadata *Metadata `json:"metadata,omitempty"`
StopSequences []string `json:"stop_sequences,omitempty"`
Stream bool `json:"stream"`
System string `json:"system,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
Thinking *ThinkingParam `json:"thinking,omitempty"`
Tools []Tool `json:"tools,omitempty"`
TopK *int `json:"top_k,omitempty"`
TopP *float64 `json:"top_p,omitempty"`
OutputFormat *OutputFormat `json:"output_format,omitempty"`
}
MessageRequest represents the Messages API request payload.
type MessageResponse ¶
type MessageResponse struct {
ID string `json:"id"`
Type string `json:"type"`
Role string `json:"role"`
Content []Content `json:"content"`
Model string `json:"model"`
StopReason string `json:"stop_reason,omitempty"`
StopSequence string `json:"stop_sequence,omitempty"`
Usage Usage `json:"usage"`
}
MessageResponse represents the Messages API response payload.
func (MessageResponse) FullText ¶
func (m MessageResponse) FullText() string
FullText is a way to quickly get the entire text of the message response, for our current streaming system which only deals with full strings.
func (MessageResponse) MarshalZerologObject ¶
func (s MessageResponse) MarshalZerologObject(e *zerolog.Event)
func (*MessageResponse) UnmarshalJSON ¶ added in v0.4.40
func (m *MessageResponse) UnmarshalJSON(data []byte) error
type Metadata ¶
type Metadata struct {
UserID string `json:"user_id,omitempty"`
}
Metadata represents the metadata object for Claude API requests.
type OutputFormat ¶ added in v0.8.2
type Request ¶
type Request struct {
Model string `json:"model"`
Prompt string `json:"prompt"`
MaxTokensToSample int `json:"max_tokens_to_sample"`
StopSequences []string `json:"stop_sequences,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
TopP *float64 `json:"top_p,omitempty"`
TopK *int `json:"top_k,omitempty"`
Metadata *Metadata `json:"metadata,omitempty"`
Stream bool `json:"stream"`
}
Request represents the completion request payload.
type StreamingDeltaType ¶
type StreamingDeltaType string
const ( TextDeltaType StreamingDeltaType = "text_delta" InputJSONDeltaType StreamingDeltaType = "input_json_delta" ThinkingDeltaType StreamingDeltaType = "thinking_delta" SignatureDeltaType StreamingDeltaType = "signature_delta" )
type StreamingEvent ¶
type StreamingEvent struct {
Type StreamingEventType `json:"type"`
Message *MessageResponse `json:"message,omitempty"`
Delta *Delta `json:"delta,omitempty"`
Error *Error `json:"error,omitempty"`
Index int `json:"index,omitempty"`
Usage *Usage `json:"usage,omitempty"`
ContentBlock *ContentBlock `json:"content_block,omitempty"`
}
func (StreamingEvent) MarshalZerologObject ¶
func (s StreamingEvent) MarshalZerologObject(e *zerolog.Event)
type StreamingEventType ¶
type StreamingEventType string
const ( PingType StreamingEventType = "ping" MessageStartType StreamingEventType = "message_start" ContentBlockStartType StreamingEventType = "content_block_start" ContentBlockDeltaType StreamingEventType = "content_block_delta" ContentBlockStopType StreamingEventType = "content_block_stop" MessageDeltaType StreamingEventType = "message_delta" MessageStopType StreamingEventType = "message_stop" ErrorType StreamingEventType = "error" )
type SuccessfulResponse ¶
type SuccessfulResponse struct {
Completion string `json:"completion"`
StopReason string `json:"stop_reason"`
Model string `json:"model"`
}
SuccessfulResponse represents the API's successful response.
type TextContent ¶
type TextContent struct {
BaseContent
Text string `json:"text"`
}
func (TextContent) MarshalZerologObject ¶
func (tc TextContent) MarshalZerologObject(e *zerolog.Event)
func (TextContent) Type ¶
func (t TextContent) Type() ContentType
type ThinkingContent ¶ added in v0.13.3
type ThinkingContent struct {
BaseContent
Thinking string `json:"thinking,omitempty"`
Signature string `json:"signature,omitempty"`
}
func (ThinkingContent) MarshalZerologObject ¶ added in v0.13.3
func (tc ThinkingContent) MarshalZerologObject(e *zerolog.Event)
func (ThinkingContent) Type ¶ added in v0.13.3
func (t ThinkingContent) Type() ContentType
type ThinkingParam ¶ added in v0.9.0
ThinkingParam configures extended thinking for Claude models.
type Tool ¶
type Tool struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
InputSchema interface{} `json:"input_schema"` // JSON schema for the tool input
}
Tool represents a tool that the model can use.
type ToolResultContent ¶
type ToolResultContent struct {
BaseContent
ToolUseID string `json:"tool_use_id"`
Content string `json:"content"`
}
func (ToolResultContent) MarshalZerologObject ¶
func (trc ToolResultContent) MarshalZerologObject(e *zerolog.Event)
func (ToolResultContent) Type ¶
func (t ToolResultContent) Type() ContentType
type ToolUseContent ¶
type ToolUseContent struct {
BaseContent
ID string `json:"id"`
Name string `json:"name"`
Input json.RawMessage `json:"input"`
}
func (ToolUseContent) MarshalZerologObject ¶
func (tuc ToolUseContent) MarshalZerologObject(e *zerolog.Event)
func (ToolUseContent) Type ¶
func (t ToolUseContent) Type() ContentType
type Usage ¶
type Usage struct {
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
CacheCreationInputTokens int `json:"cache_creation_input_tokens"`
CacheReadInputTokens int `json:"cache_read_input_tokens"`
}
Usage represents the billing and rate-limit usage information.