claude

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package claude provides a minimal client for the Anthropic Messages API, including non-streaming and streaming text completions.

Index

Constants

View Source
const (
	// ModelHaiku is the default Claude Haiku model identifier used by this package.
	ModelHaiku = "claude-haiku-4-5"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client calls the Anthropic Messages API.

func New

func New(apiKey string) *Client

New returns a Client using apiKey for Anthropic API authentication.

func (*Client) Complete

func (c *Client) Complete(ctx context.Context, req MessageRequest) (string, error)

Complete sends a message request and returns the text response.

func (*Client) Stream

func (c *Client) Stream(ctx context.Context, req MessageRequest, onDelta func(string) error) error

Stream sends a streaming message request and invokes onDelta for each text delta. It returns when the stream ends (message_stop), the context is canceled, or an error occurs.

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

Message is a single role/content message sent to the model.

type MessageRequest

type MessageRequest struct {
	Model       string    `json:"-"`
	MaxTokens   int       `json:"-"`
	System      string    `json:"-"`
	CacheSystem bool      `json:"-"`
	Messages    []Message `json:"-"`
	Stream      bool      `json:"-"`
}

MessageRequest describes a request to the Anthropic Messages API.

func (MessageRequest) MarshalJSON

func (r MessageRequest) MarshalJSON() ([]byte, error)

MarshalJSON serializes the request, using a structured system block with cache_control when CacheSystem is true.

Jump to

Keyboard shortcuts

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