{"slug": "show-hn-wiretuple-cut-llm-structured-output-tokens-with-positional-tuples", "title": "Show HN: Wiretuple – Cut LLM structured-output tokens with positional tuples", "summary": "A new open-source Go reverse proxy called Wiretuple cuts 35–60% of LLM structured-output and function-calling tokens losslessly by rewriting repeated JSON keys into positional tuples on the wire, according to its Show HN release. Wiretuple's benchmark table reports 60.8% output-token savings on an e-commerce invoice scenario (2,041 to 801 tokens, 59.2% net), 44.5% on a dev-tool pull request batch (1,602 to 889, 43.0% net) and 56.0% on an MCP tool-invocation batch (1,617 to 711, 53.7% net), with structural equality confirmed via reflect.DeepEqual and p99 overhead under 0.1 ms. The single-binary proxy ships with zero external dependencies and supports OpenAI and Anthropic endpoints, including SSE streaming rehydration and a shadow-mode SQLite audit that estimates savings before activating rewrites.", "body_md": "**Cut 35–60 % of the output tokens of LLM Structured Outputs and Function\nCalling — losslessly.** `wiretuple` is a single-binary HTTP reverse proxy\nwritten in Go with zero external dependencies: your app keeps calling the same\nAPI, and repeated JSON keys become positional tuples on the wire.\n\n```\nclient ──► wiretuple ──► upstream API\n              │\n   request:  schema {\"items\":[{\"id\",\"total\",\"currency\"}]}\n             rewritten to prefixItems + \"Tuple: [id, total, currency]\"\n              │\n   response: [[\"a1\", 12.5, \"EUR\"], [\"a2\", 3, \"USD\"]]\n             rehydrated to [{\"id\":\"a1\",\"total\":12.5,\"currency\":\"EUR\"}, ...]\n              │\n              └─ incremental SSE rehydration, same bytes downstream\n```\n\nA schema that asks for 40 line items with 7 fields makes the model emit the same\nseven key names 40 times. Those keys are pure overhead: the receiver already\nknows them from the schema. `wiretuple` moves the key list into one legend and\nsends values as positions.\n\n```\ngo build -trimpath -ldflags=\"-s -w\" -o bin/wiretuple ./cmd/wiretuple\n```\n\nNo `go.mod` requirements, no cgo, no runtime data files.\n\n```\n# OpenAI-compatible client\nexport OPENAI_BASE_URL=http://127.0.0.1:8787/v1\n./bin/wiretuple -upstream https://api.openai.com\n\n# Anthropic-compatible client\nexport ANTHROPIC_BASE_URL=http://127.0.0.1:8787\n./bin/wiretuple -upstream https://api.anthropic.com\n```\n\nFlags:\n\n| Flag | Default | Meaning | \n|---|---|---|\n| `-upstream` | – | upstream base URL (required) | \n| `-listen` | `127.0.0.1:8787` | listen address | \n| `-break-even` | `5.0` | minimum net savings (%) to rewrite a schema | \n| `-legend-tokens` | `0` | fixed legend cost (0 = estimate) | \n| `-activate` | `true` | master switch | \n| `-shadow <path>` | – | passive audit into a SQLite file | \n| `-max-body` | `4 MiB` | request body limit | \n\n| Provider | Endpoint | Structured output | Function calling | \n|---|---|---|---|\n| OpenAI | `/v1/chat/completions` | `response_format.json_schema.schema` | `tools[].function.parameters` | \n| Anthropic | `/v1/messages` | tool schema in `input_schema` | `tools[].input_schema` | \n\nBoth `stream: false` (recomputed `Content-Length`) and `stream: true` (SSE,\nrehydrating only the JSON fragments) are covered. Anything that is not JSON\n(for example `[DONE]` or a non-JSON event) is forwarded byte for byte.\n\nSmall payloads are not worth a legend. The gate estimates saved output tokens\nagainst the fixed legend cost and keeps the request byte-identical when net\nsavings are below `-break-even`:\n\n```\nnet_savings_% = (tokens_before - tokens_after - legend_tokens) / tokens_before * 100\n```\n\nA single flat object usually stays untouched; a repeated object array with long keys activates.\n\n```\n./bin/wiretuple -upstream https://api.openai.com -shadow audit.db\n```\n\nTraffic passes through untouched. Each request/response pair is simulated and appended to a zero-dependency SQLite 3 file, readable with any SQLite client:\n\n```\nSELECT count(*), avg(net_savings_pct) FROM shadow_records;\n```\n\nThe console prints a summary on shutdown:\n`rows`, `activated`, `activation_rate`, `tokens_before`, `tokens_after`,\n`output_savings`, `net_savings`.\n\nDeterministic scenarios (e-commerce invoice, dev-tool pull request batch, MCP tool definitions) with structural equality asserted after rehydration:\n\n``` bash\n$ make bench\n| Scenario | tokens_before | tokens_after | output_savings_% | net_savings_% | p99_overhead_ms | equality |\n|---|---:|---:|---:|---:|---:|---|\n| E-commerce invoice line items | 2041 | 801 | 60.8% | 59.2% | 0.095 | OK |\n| Dev-tool pull request batch | 1602 | 889 | 44.5% | 43.0% | 0.078 | OK |\n| MCP tool invocations batch | 1617 | 711 | 56.0% | 53.7% | 0.084 | OK |\n```\n\nToken counts use a deterministic size model (one token per four UTF-8 bytes),\nso the table is reproducible without an API key. Equality is checked with\n`reflect.DeepEqual` on decoded values plus legend key order.\n\n- `internal/compiler` — lossless`SchemaNode` , deterministic key order\n(`required` first, then lexicographic), tuple schemas with`prefixItems` and`items: false` (Draft 2020-12, accepted by structured-output APIs that reject`additionalItems` ), nested tuples, and the rehydration tree.\n- `internal/gate` — break-even estimator with an injectable token model.\n- `internal/rehydrator` — byte-level state machine; handles UTF-8 split across\nchunks, escaped quotes/backslashes, brackets and commas inside strings,\nnested tuples, and degrades to raw output on shape violations without\nbreaking the stream.\n- `internal/proxy` — reverse proxy, provider detection, SSE codec, bounded\nbodies, upstream-only forwarding, cancellation.\n- `internal/shadow` — passive audit plus a pure-Go SQLite 3 writer.\n\n```\nmake test    # go test ./...\nmake race    # go test -race ./...\nmake bench   # savings table + equality checks\nmake build   # bin/wiretuple, bin/wiretuple-bench\nmake vet\n```\n\nMIT © 2026 Dimoncelli.", "url": "https://wpnews.pro/news/show-hn-wiretuple-cut-llm-structured-output-tokens-with-positional-tuples", "canonical_source": "https://github.com/Dimoncelli/wiretuple", "published_at": "2026-11-19 14:33:17+00:00", "updated_at": "2026-11-19 14:46:36.678569+00:00", "lang": "en", "topics": ["large-language-models", "ai-tools", "ai-agents", "agent-protocols", "developer-tools"], "entities": ["Wiretuple", "OpenAI", "Anthropic", "Go", "Model Context Protocol"], "also_reported_by": [], "takeaway": "Wiretuple rewrites repeated JSON keys into a positional legend, cutting 60.8% of output tokens on a 40-item invoice schema (2,041 to 801) with 0.095 ms p99 overhead and byte-identical rehydrated JSON.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/show-hn-wiretuple-cut-llm-structured-output-tokens-with-positional-tuples", "markdown": "https://wpnews.pro/news/show-hn-wiretuple-cut-llm-structured-output-tokens-with-positional-tuples.md", "text": "https://wpnews.pro/news/show-hn-wiretuple-cut-llm-structured-output-tokens-with-positional-tuples.txt", "jsonld": "https://wpnews.pro/news/show-hn-wiretuple-cut-llm-structured-output-tokens-with-positional-tuples.jsonld"}}