Repository navigation
Show and tell: a two-protocol local gateway and where its retry boundary sits (MicroGlow Relay, open source) #9771
mazda6hk-coder
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Not a feature request — posting the implementation details of a related project in case they are useful, and to note that it complements rather than competes with cc-switch.
MicroGlow Relay (https://github.com/mazda6hk-coder/MicroGlow-Relay, Apache-2.0) is a Windows desktop app that runs a local gateway on
127.0.0.1:4141so Codex and Claude Code can both reach third-party providers through one endpoint.The part that overlaps with cc-switch's local-proxy work is protocol handling, so here is how Relay does it.
Two inbound protocols on one port.
/v1/responses(OpenAI Responses, used by Codex) and/v1/messages(Anthropic Messages, used by Claude Code). An Anthropic request is folded into an internal Responses-shaped pipeline, and both share one upstream adapter chain — Chat Completions, Responses, Anthropic Messages.Retries are bounded by "before the client sees anything". A channel may be retried up to twice (three times on HTTP 500), but only while nothing has been sent downstream. The first SSE event is prefetched so response headers are not committed prematurely. Once a stream has started it is never replayed — a replay would double-charge the provider and duplicate output.
Channels are weighted with a cooldown. On failure a channel is cooled down for 60 seconds. When every channel is cooling, the one whose cooldown expires soonest is used. Failover to a different channel happens only before the response starts.
The client side is one switch. Writing
~/.codex/config.tomland~/.claude/settings.jsonis handled by the app: it backs up before writing, detects changes made outside Relay, and restores the client configuration on exit.Two implementation details that took some care:
thinkingblocks are folded into reasoning items, and their signatures are never replayed.systemblocks insidemessagesare hoisted to the top level, matching what Claude Code actually sends.There is a factual comparison page against cc-switch at https://mazda6hk-coder.github.io/MicroGlow-Relay/compare/cc-switch.html — cc-switch switches which configuration a client reads, Relay runs a service the client talks to. Different shapes, and people use them for different reasons.
Happy to answer questions about the protocol translation or the retry and failover logic.
All reactions