anthropic

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 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

Overview

Package anthropic implements the Anthropic-compatible HTTP surface: POST /v1/messages, streaming and non-streaming.

The wire shapes below are the subset of the Messages API that agent2api can honour, plus the fields it must explicitly refuse. Everything an agent CLI cannot enforce is either passed along as a best-effort hint or rejected with a 400 — never silently ignored in a way that changes the answer.

Index

Constants

View Source
const MaxRequestBytes = 32 << 20 // 32 MiB

MaxRequestBytes caps the request body. A replayed conversation is the payload here, so the limit is generous, but not unbounded.

Variables

This section is empty.

Functions

func WriteError

func WriteError(w http.ResponseWriter, err error)

WriteError renders err in Anthropic's error shape with the matching status.

Types

type Handler

type Handler struct {
	Router *router.Router
	Log    *slog.Logger
	// Heartbeat is how often a silent stream emits a ping. Zero disables
	// pings; [New] starts it at [sse.DefaultHeartbeat].
	Heartbeat time.Duration
	// Now is injectable so tests get stable timestamps.
	Now func() time.Time
}

Handler serves the Anthropic-compatible endpoints.

func New

func New(r *router.Router, log *slog.Logger) *Handler

New builds a handler.

func (*Handler) Messages

func (h *Handler) Messages(w http.ResponseWriter, r *http.Request)

Messages implements POST /v1/messages.

func (*Handler) Routes

func (h *Handler) Routes(mux *http.ServeMux)

Routes registers the Anthropic endpoints on mux.

Jump to

Keyboard shortcuts

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