gproxy-transform
Convert requests, responses, and streaming events between the OpenAI, Anthropic Claude, and Google Gemini APIs.
gproxy-transform is the transform layer of
GPROXY, built on the wire types in
gproxy-protocol. It is a pure,
synchronous library: no HTTP client, no runtime, no I/O.
Usage
[]
= "2"
Resolve a pair from the source/target operation keys, then run the bytes-level dispatch:
use ;
use ;
let source = content_generation;
let target = content_generation;
// Request direction: inbound OpenAI chat body → upstream Claude messages body.
let pair = resolve?;
let ctx = new.with_request;
let upstream_body = request_bytes?;
// Response direction uses the REVERSE pair.
let back = resolve?;
let back_ctx = new;
let inbound_body = response_bytes?;
// Streaming converts one decoded SSE frame at a time, same reverse pair.
let inbound_event = stream_event_value?;
Design
- Pairwise, no intermediate representation. Every conversion is a direct
source → targetmodule. This keeps provider-specific quirks in the one file that owns them instead of leaking into a shared IR. - Organized by operation, not by provider.
generate_content,count_tokens,models,embeddings,images,compact. - Same-kind traffic never enters this crate. Route it as passthrough.
extrafields are not preserved. Sourceextrais dropped; targetextrastarts empty.- Cross-event aggregation (block indexes, tool-call identity, final usage) is a
concern of the runtime adapter in
stream_adapter, not of the stateless per-eventstream_eventfunctions.
Use dispatch::is_wired to check whether a resolved pair has a bytes-level
implementation before routing traffic through it.
Modules
| Module | Purpose |
|---|---|
dispatch |
Bytes-level (pair, ctx, body) -> body entry points |
generate_content |
Chat/messages/generateContent pairs, streaming included |
count_tokens |
Token-count request/response pairs |
models |
Model list/get pairs |
embeddings |
Embedding pairs |
images |
Image create/edit pairs |
compact |
Context-compaction pairs |
routing |
Compiled routing rules → passthrough / transform / unsupported |
stream_adapter |
Runtime SSE adapter (decode → convert → re-encode) |
common |
Mechanical helpers only (SSE framing, roles, tool ids, usage) |
License
Licensed under the MIT License.