api

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 NewClient

func NewClient(config ClientConfig) *Client

NewClient creates an API client.

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

type ModelConfig struct {
	MaxOutputTokens int
	ContextWindow   int
}

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.

Jump to

Keyboard shortcuts

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