# Plexum-anthropic-compat-client Shared HTTP+SSE Anthropic Messages API client + canonical ↔ Anthropic translator. Used by Plexum provider plugins that talk to any "Anthropic-compatible" endpoint (the one Anthropic itself, MiniMax, Kimi, Qwen, etc. all expose at `/v1/messages`). Each provider plugin imports these two packages and adds: - its own `cmd/plexum--provider-plugin/main.go` entry - a list of supported model ids in the manifest - an endpoint URL + auth key + optional User-Agent override ## Packages ### `anthropic/` Minimal HTTP+SSE client. Single entry point: ```go client := anthropic.New(baseURL, apiKey) client.UserAgent = "claude-code/0.1.0" // optional events, err := client.StreamMessages(ctx, anthropic.MessagesRequest{ Model: "MiniMax-M2.7", MaxTokens: 4096, Messages: []anthropic.Message{...}, }) for ev := range events { /* anthropic.Event */ } ``` Features: - POST `/v1/messages` with `stream: true` - Parses standard SSE frames (`event:` + `data:` + blank line) - Surfaces non-2xx as HTTP error (before channel opens) - Surfaces mid-stream errors as `Event{Type:"error"}` final entry - `UserAgent` + `ExtraHeaders` fields for per-backend customization - 5min per-call timeout ### `translate/` Bidirectional canonical-types ↔ Anthropic-types adapter: - `CanonicalToAnthropic(req canonical.TurnRequest, modelID, defaultMaxTokens) → anthropic.MessagesRequest` - `Translator` state machine consumes `<-chan anthropic.Event`, emits `[]canonical.TurnEvent` per event (handles text / thinking / tool_use / signature deltas + per-block close) ## Usage In a provider plugin's `go.mod`: ``` require git.hangman-lab.top/hzhang/Plexum-anthropic-compat-client v0.0.0 replace git.hangman-lab.top/hzhang/Plexum-anthropic-compat-client => ../Plexum-anthropic-compat-client ``` In code: ```go import ( "git.hangman-lab.top/hzhang/Plexum-anthropic-compat-client/anthropic" "git.hangman-lab.top/hzhang/Plexum-anthropic-compat-client/translate" ) ``` ## History Extracted from `Plexum-minimax-provider` and `Plexum-kimi-provider` — both had a near-identical copy. New providers (Qwen, Doubao, …) drop in without re-implementing the protocol. ## License Same as Plexum.