Repository navigation
feat(gateway): P3-A three-protocol conversion — OpenAI Chat / Responses / Anthropic interop + /v1/responses (v0.4.0) - #83
Merged
Conversation
added 2 commits
August 18, 2026 16:41
…es / Anthropic interop + /v1/responses (v0.4.0)
Host rant 2026-08-18T16:15:42: support calling any listed model via
OpenAI Chat / OpenAI Responses / Anthropic APIs with automatic protocol
conversion (previously same-protocol passthrough only; openai request
hitting an anthropic-only plan returned 503).
- src/protocol.rs (new): pairwise request/response converters between
openai_chat / anthropic / responses (system↔top-level, tool_use/
tool_result ↔ tool_calls, usage prompt/completion ↔ input/output,
stop/finish reason mapping, anthropic max_tokens default 4096),
ported from openlocalrouter transform.rs per host instruction;
determine_forwarding_protocol: same-protocol first → anthropic →
openai_chat → responses fallback
- gateway: resolve_outbound picks per-key outbound protocol; request
body transformed when crossing protocols; upstream response converted
back to the inbound protocol; usage parsed from the upstream protocol
for accurate billing; /v1/responses endpoint added; streaming still
same-protocol passthrough (SSE conversion deferred to P3-B → 400 with
explicit message)
- resolve_endpoint: responses → {base}/responses; parse_usage handles
responses (input/output_tokens)
- tests 72→92 (+15 protocol unit tests, +5 gateway e2e: chat→anthropic
conversion with request-body capture, anthropic→chat reverse, /v1/
responses conversion, responses same-protocol passthrough, streaming+
conversion 400); fake upstreams pre-bind listeners (parallel port fix)
- version 0.3.4 → 0.4.0; README status + endpoint list updated
Verified: cargo test 92/92, fmt, clippy -D warnings; live smoke (temp
DB/config, anthropic-only mock plan): openai chat → 200 converted,
/v1/responses → 200, anthropic passthrough → 200, streaming+conversion
→ 400; ledger records cost/consume/earn correctly.
CI check formatting failed on src/protocol.rs:40 (the manual_find clippy fix was not reformatted). No behavior change.
4 tasks done
argszero
added a commit
that referenced
this pull request
Aug 18, 2026
…v0.4.1) (#84) OpenAI-compatible GET /v1/models (alias /models) with optional auth: - no Bearer -> plain model list (id/object/created/owned_by/display_name/context_window) - with Bearer -> adds available_keys per model - models table gains context_window column (ensure_column migration for existing DBs) - seed_models reads context_window from data/models.example.json Closes rant 2026-08-18T18:10:18 (GET /v1/models missed in P3-A #83). Co-authored-by: argszero <argszero@argszerodeMac-mini.local>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
P3-A gateway protocol conversion (host rant
2026-08-18T16:15:42): any listed model can now be called via OpenAI Chat API / OpenAI Responses API / Anthropic API with automatic protocol conversion. Previously the gateway only did same-protocol passthrough — an OpenAI Chat request hitting a plan with only Anthropic endpoints returned 503.Changes
src/protocol.rs(new): pairwise request/response converters betweenopenai_chat/anthropic/responses— system↔top-level field,tool_use/tool_result↔tool_calls, usageprompt/completion↔input/output, stop/finish-reason mapping, Anthropicmax_tokensdefault 4096. Ported/adapted fromopenlocalroutersrc/router/transform.rsper host instruction.determine_forwarding_protocol— same-protocol endpoint first (passthrough, zero conversion overhead) → Anthropic (best compatibility) → OpenAI Chat → Responses; all unavailable → 503.gateway::forward: picks per-key outbound protocol, transforms the request body when crossing protocols, converts the upstream response back to the inbound protocol; usage is parsed from the upstream protocol for accurate billing.POST /v1/responses(OpenAI Responses compatible).400with an explicit message; same-protocol streaming stays as passthrough.0.3.4 → 0.4.0; README status + endpoint list updated.Rant reference
Host rant
2026-08-18T16:15:42— P3-A 网关协议转换(OpenAI Chat / OpenAI Responses / Anthropic 三协议互转 + /v1/responses 端点)Tests
cargo test92/92,cargo fmt --check,cargo clippy --all-targets -- -D warningsall green/v1/responses→ 200, Anthropic passthrough → 200, streaming+conversion → 400; ledger records cost/consume/earn correctly