wiretuple live terminal demo

When you ask an LLM for structured JSON (via OpenAI response_format json_schema, OpenAI tools[], or Anthropic tools[].input_schema), you pay an invisible output token tax on every single record.

Ask for 40 invoice line items with 7 fields, and the model repeats those 7 JSON key names 40 times. That is 280 key emissions spent on metadata the receiver already knows from the schema.

As a Technical Integrations Specialist working with REST APIs and webhooks, I wanted to fix this at the wire level—so an application can change a single environment variable (OPENAI_BASE_URL or ANTHROPIC_BASE_URL) without rewriting prompts or application models.

That became wiretuple (MIT, Go 1.23, zero external dependencies).

The lossless positional bijection

Given a deterministic key ordering (required fields in schema order, followed by remaining properties sorted lexicographically), an array of objects:

[ {"line_identifier": "li_0000", "product_sku": "SKU-00000", "quantity_units": 1}, {"line_identifier": "li_0001", "product_sku": "SKU-00001", "quantity_units": 2} ] 

is mathematically bijective with an array of positional tuples:

[ ["li_0000", "SKU-00000", 1], ["li_0001", "SKU-00001", 2] ] 

provided the request schema carries one legend (Tuple: [line_identifier, product_sku, quantity_units]) and closes the array with JSON Schema Draft 2020-12 prefixItems and items: false.

Four pieces in pure Go stdlib

  1. Break-Even Gate (internal/gate): A legend costs input tokens once. Before rewriting a schema, the gate compares expected output savings against the fixed legend cost. Small single-instance payloads stay byte-identical at zero overhead.
  2. Bidirectional Schema Compiler (internal/compiler): Preserves unknown JSON Schema properties via Extra round-tripping and handles nested object tuples recursively (KindTuple).
  3. Incremental Byte-Level SSE Rehydrator (internal/rehydrator): No regex and no full-stream buffering. A bounded byte-level state machine handles multi-byte UTF-8 characters split across SSE frames, escaped quotes (\"), brackets/commas inside string literals ("[1,2]"), multi-tool call routing (requestPlan), and falls back to raw output if a model violates arity—keeping the SSE connection alive and JSON valid.
  4. Passive Audit Mode (--shadow, internal/shadow): Leaves live traffic untouched while simulating savings into a pure-Go SQLite 3 writer (shadow_records: timestamps, route, token counts, percentages, latency, activation flag—zero prompt or completion payloads ever stored).

Deterministic benchmarks (make bench)

Measured with make bench using a deterministic 4 UTF-8 bytes/token size model and verified with reflect.DeepEqual plus legend key order assertions:

Scenario tokens_before tokens_after output_savings_% net_savings_% p99_overhead_ms equality
E-commerce invoice line items (40x7) 2041 801 60.8% 59.2% 0.095 OK
MCP tool invocations batch (25x7) 1617 711 56.0% 53.7% 0.084 OK
Dev-tool pull request batch (30x7) 1602 889 44.5% 43.0% 0.078 OK

Try it safely first with --shadow

go build -trimpath -ldflags="-s -w" -o bin/wiretuple ./cmd/wiretuple export OPENAI_BASE_URL=http://127.0.0.1:8787/v1 ./bin/wiretuple -upstream https://api.openai.com -shadow audit.db 

Source and static release builds: github.com/Dimoncelli/wiretuple