Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIMessage ¶
type APIMessage struct {
Role string `json:"role"`
Content []types.ContentBlock `json:"content"`
}
APIMessage is a message sent to the API.
type APIToolParam ¶
type APIToolParam struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema map[string]interface{} `json:"input_schema"`
CacheControl *CacheControl `json:"cache_control,omitempty"`
}
APIToolParam is a tool definition for the API.
func ToolToAPIParam ¶
func ToolToAPIParam(t types.Tool) APIToolParam
ToolToAPIParam converts a Tool to an API tool parameter.
func ToolToAPIParamWithCache ¶
func ToolToAPIParamWithCache(t types.Tool) APIToolParam
ToolToAPIParamWithCache creates a tool parameter with cache control.
type CacheControl ¶
type CacheControl struct {
Type string `json:"type"` // "ephemeral"
}
CacheControl configures prompt caching.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client communicates with the Messages API.
func (*Client) CreateMessage ¶
func (c *Client) CreateMessage(ctx context.Context, req MessagesRequest) (*StreamMessage, error)
CreateMessage sends a non-streaming messages request.
func (*Client) CreateMessageStream ¶
func (c *Client) CreateMessageStream(ctx context.Context, req MessagesRequest) (<-chan StreamEvent, <-chan error)
CreateMessageStream sends a streaming messages request.
type ClientConfig ¶
type ClientConfig struct {
APIKey string
BaseURL string
Model string
MaxTokens int
HTTPClient *http.Client
CustomHeaders map[string]string
ProxyURL string
TimeoutMs int
}
ClientConfig configures the API client.
type MessagesRequest ¶
type MessagesRequest struct {
Model string `json:"model"`
MaxTokens int `json:"max_tokens"`
System []SystemBlock `json:"system,omitempty"`
Messages []APIMessage `json:"messages"`
Tools []APIToolParam `json:"tools,omitempty"`
Stream bool `json:"stream"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
StopSequences []string `json:"stop_sequences,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
TopP *float64 `json:"top_p,omitempty"`
// Extended thinking
Thinking *ThinkingConfig `json:"thinking,omitempty"`
// Structured output
ToolChoice interface{} `json:"tool_choice,omitempty"`
}
MessagesRequest is the request body for the Messages API.
type ModelConfig ¶
ModelConfig holds per-model configuration.
func GetModelConfig ¶
func GetModelConfig(model string) ModelConfig
GetModelConfig returns configuration for a model.
type StreamCallback ¶
type StreamCallback func(event StreamEvent) error
StreamCallback is called for each streaming event.
type StreamEvent ¶
type StreamEvent struct {
Type string `json:"type"`
// message_start
Message *StreamMessage `json:"message,omitempty"`
// content_block_start, content_block_delta
Index int `json:"index,omitempty"`
ContentBlock *types.ContentBlock `json:"content_block,omitempty"`
Delta map[string]interface{} `json:"delta,omitempty"`
// message_delta
Usage *types.Usage `json:"usage,omitempty"`
}
StreamEvent represents a server-sent event from the streaming API.
type StreamMessage ¶
type StreamMessage struct {
ID string `json:"id"`
Type string `json:"type"`
Role string `json:"role"`
Content []types.ContentBlock `json:"content"`
Model string `json:"model"`
StopReason string `json:"stop_reason"`
Usage *types.Usage `json:"usage"`
}
StreamMessage is the message object in a message_start event.
type SystemBlock ¶
type SystemBlock struct {
Type string `json:"type"`
Text string `json:"text"`
CacheControl *CacheControl `json:"cache_control,omitempty"`
}
SystemBlock is a system prompt block.
type ThinkingConfig ¶
type ThinkingConfig struct {
Type string `json:"type"` // "enabled"
BudgetTokens int `json:"budget_tokens"` // Max thinking tokens
}
ThinkingConfig configures extended thinking.