Documentation
¶
Overview ¶
Package anthropic implements the Anthropic Messages–compatible HTTP frontend.
v1 subset vs vendor spec (cross-check) ¶
Spec: https://docs.anthropic.com/en/api/messages
| Area | v1 status | Tests | |-------------------|------------|-------| | POST …/messages | Supported | integration_test.go, decode_test.go, encode_test.go | | system string/blocks (text) | Supported | decode_test.go | | messages user/assistant | Supported | decode_test.go | | tools, tool_choice | Supported (decode) | decode_test.go | | max_tokens, sampling | Supported | decode_test.go | | metadata | Ignored (not mapped to Call) | decode_test.go | | top_k | Ignored (not mapped to Call) | decode_test.go | | anthropic-version header | Passed via DecodeOptions (not validated; wire compatibility) | integration_test.go | | tool_use on response (stream + JSON) | Supported (encode) | encode_test.go, integration_test.go | | thinking / extended blocks | Supported (encode, thinking + signature) | encode_test.go |
Index ¶
- Constants
- func ModelFromCall(c *lipapi.Call) string
- func Mount(mux *http.ServeMux, opts lipsdk.FrontendMountOptions) error
- func RouteClaims(ownerID string) ([]httpcontract.RouteClaim, error)
- func WriteErrorJSON(w http.ResponseWriter, status int, message, errType string) error
- func WriteNonStreamJSON(ctx context.Context, w http.ResponseWriter, call *lipapi.Call, ...) error
- func WriteStreamSSE(ctx context.Context, w http.ResponseWriter, call *lipapi.Call, ...) error
- type Config
- type DecodeOptions
- type DecodedMessage
- type EncodeOptions
- type Handler
- type WireErrors
- func (WireErrors) WriteAdmissionReject(w http.ResponseWriter, d decodeqos.Decision) error
- func (WireErrors) WriteBodyTooLarge(w http.ResponseWriter) error
- func (WireErrors) WriteEncodeFailed(w http.ResponseWriter) error
- func (WireErrors) WriteExecuteError(w http.ResponseWriter, out execerr.Outcome) error
- func (WireErrors) WriteExecutorNotConfigured(w http.ResponseWriter) error
- func (WireErrors) WriteInvalidJSON(w http.ResponseWriter) error
- func (WireErrors) WriteInvalidRequest(w http.ResponseWriter) error
- func (WireErrors) WritePreflightCanceled(w http.ResponseWriter) error
- func (WireErrors) WriteReadBodyFailed(w http.ResponseWriter) error
Constants ¶
const ( HeaderRouteSelector = routeselect.HeaderRouteSelector HeaderAnthropicVersion = "anthropic-version" )
const ID = "anthropic"
ID is the reserved plugin identifier for the Anthropic frontend.
Variables ¶
This section is empty.
Functions ¶
func ModelFromCall ¶
ModelFromCall returns the wire model string stored during decode.
func Mount ¶
func Mount(mux *http.ServeMux, opts lipsdk.FrontendMountOptions) error
Mount registers the Anthropic Messages API handler on mux.
func RouteClaims ¶
func RouteClaims(ownerID string) ([]httpcontract.RouteClaim, error)
RouteClaims describes the routes Mount registers for one frontend owner.
func WriteErrorJSON ¶
func WriteErrorJSON(w http.ResponseWriter, status int, message, errType string) error
WriteErrorJSON writes an Anthropic-shaped JSON error before any streamed bytes.
func WriteNonStreamJSON ¶
func WriteNonStreamJSON(ctx context.Context, w http.ResponseWriter, call *lipapi.Call, es lipapi.EventStream, opts EncodeOptions) error
WriteNonStreamJSON encodes a completed canonical stream as a Messages API JSON body.
func WriteStreamSSE ¶
func WriteStreamSSE(ctx context.Context, w http.ResponseWriter, call *lipapi.Call, es lipapi.EventStream, opts EncodeOptions) error
Types ¶
type Config ¶
type Config = frontendconfig.Config
type DecodeOptions ¶
type DecodeOptions struct {
// RouteSelector is required (e.g. "stub:claude-3-5-haiku"); usually from X-LIP-Route header.
RouteSelector string
// AnthropicVersion is the optional anthropic-version header; empty means default for decode.
AnthropicVersion string
Headers http.Header
}
DecodeOptions configures decoding of a Messages API request.
type DecodedMessage ¶
DecodedMessage is the result of decoding POST /v1/messages JSON.
func DecodeMessageRequest ¶
func DecodeMessageRequest(body []byte, opts DecodeOptions) (*DecodedMessage, error)
DecodeMessageRequest maps Anthropic Messages JSON into a canonical call.
type EncodeOptions ¶
EncodeOptions controls wire identifiers for encoded Messages payloads.
type Handler ¶
type Handler struct {
Exec lipsdk.ExecutorView
// DefaultRouteSelector is used when HeaderRouteSelector is absent.
DefaultRouteSelector string
// RoutePrefixes are backend route-selector prefixes accepted from body model.
RoutePrefixes routeselect.PrefixSet
MaxRequestBodyBytes int64
Log *slog.Logger
TrafficPorts traffic.PortBundle
DecodeAdmission lipsdk.DecodeAdmission
PreRequestKeepalive lipsdk.FrontendKeepaliveConfig
Config Config
HTTPHeaders lipsdk.HTTPHeaders
StreamKeepaliveInterval time.Duration
// contains filtered or unexported fields
}
Handler wires HTTP POST /v1/messages to decode → executor → encode.
type WireErrors ¶
type WireErrors struct{}
WireErrors implements frontendpipe.WireErrors for Anthropic Messages API errors.
func (WireErrors) WriteAdmissionReject ¶
func (WireErrors) WriteAdmissionReject(w http.ResponseWriter, d decodeqos.Decision) error
func (WireErrors) WriteBodyTooLarge ¶
func (WireErrors) WriteBodyTooLarge(w http.ResponseWriter) error
func (WireErrors) WriteEncodeFailed ¶
func (WireErrors) WriteEncodeFailed(w http.ResponseWriter) error
func (WireErrors) WriteExecuteError ¶
func (WireErrors) WriteExecuteError(w http.ResponseWriter, out execerr.Outcome) error
func (WireErrors) WriteExecutorNotConfigured ¶
func (WireErrors) WriteExecutorNotConfigured(w http.ResponseWriter) error
func (WireErrors) WriteInvalidJSON ¶
func (WireErrors) WriteInvalidJSON(w http.ResponseWriter) error
func (WireErrors) WriteInvalidRequest ¶
func (WireErrors) WriteInvalidRequest(w http.ResponseWriter) error
func (WireErrors) WritePreflightCanceled ¶
func (WireErrors) WritePreflightCanceled(w http.ResponseWriter) error
func (WireErrors) WriteReadBodyFailed ¶
func (WireErrors) WriteReadBodyFailed(w http.ResponseWriter) error