A gateway that keeps your cache marks, then bills cached tokens at full price

An old brass cash register pushes out a long paper tape over a full coin tray, next to parcels that already wear a green paid stamp.

Blind spend meter No public channel to report

A self-hosted gateway that passes native requests through byte for byte and reads every provider's usage correctly, derived from One API.

≈ 1,200,000 tokens per 1,000 calls, billed uncached on Studio's agent legs to Claude, which carry no cache mark (call mix assumed) estimate

Estimates, not measurements. Every figure on this page is an estimate from reading the code, not a measurement of the app in use.

Repository
infinmalum/a1o-platform
Commit audited
1e44601
leanprompt version
0.1.0-dev.15
Audit date
Status
The repository has issues and discussions turned off, so there was no public channel to report this. The maintainers can reach us at info@podwarden.com.
How it ran
Unattended audit: nobody was asked during the run, so priority, volume and prices were left open; the questions for the owner are listed at the end.

A self-hosted LLM gateway that converts between the OpenAI, Anthropic and Gemini formats and bills a per-user quota from provider usage, with a built-in agent, Studio. Its billing prices cache reads as ordinary input, and requests it converts for Claude carry no cache mark. Figures are estimates from the code. leanprompt is made by the LM Warden Team, whose LM Warden is in the same market.

leanprompt read the code at commit 1e44601 and found 6 places where its LLM calls could use fewer tokens, plus 5 other problems, not scored. Static score: 81 of 100 (an estimate from the findings). The code may have changed since.

This project is a gateway or proxy. 5 items are about the gateway's own calls, 6 items about what it does to its clients' calls; each card says which.

Findings

  1. LP-PC-08 Cache-aware compaction

    agent/context.go:352 · severity medium · saves prefill · how often is assumed · the gateway's own calls

    What happens. Once a Studio chat passes the context budget, every new turn makes an extra summarising call with its own system prompt over the whole older transcript. The summary is stored but older messages are never marked as done: the next turn loads all messages again (model/chat.go:270), is over the budget again, and summarises the same history again, plus the previous summary.

    The change. Load only the messages after CompactedThrough, keep the stored summary, and summarise only when the uncompacted tail passes the budget again; run the summary as a continuation of the same instructions, tools and history so it reads the cache.

    Why it helps. The summariser re-reads tens of thousands of tokens of history on every turn and writes up to 1,536 output tokens that the next turn throws away and recomputes.

    Overlaps. Finding 5 loses some of the same tokens; the totals count the larger once.

    Estimate about 1.2M prompt tokens and 30k output tokens per 1,000 calls (estimate)

    Assumptions. Studio chat turns are 20% of calls (two legs per turn on average); 15% of those turns are in sessions past the 32k budget, so 3% of calls trigger a summariser call; each re-reads about 40k tokens of older transcript (messages cut at 4,000 characters) and writes about 1,000 tokens.

    How often. How many Studio chat turns run in sessions whose estimated context exceeds ChatContextBudgetTokens (32,000 by default): count context_compacted run events per session; more than one per session (one per turn) confirms the repeat.

  2. LP-PC-01 Put cache marks where the provider needs them

    relay/bridge/responses_anthropic.go:197 · severity high · saves prefill · how often is assumed · the gateway's own calls

    What happens. When a Responses-format request goes to a Claude channel, the converter builds the Anthropic request with no cache mark at all. Studio's own agent (Chat, Work, subagents) uses exactly this path for every claude-* model (agent/executor.go:326-327 prefers the Anthropic wire). Anthropic caches nothing without a mark, so on every leg of the agent loop the instructions, tools and whole history are billed at the full input price again.

    The change. In the converter, add Anthropic's top-level automatic cache mark ({"cache_control":{"type":"ephemeral"}}) to the request it builds, or marks on the last tool, the system text and the newest message. Bedrock rejects the top-level form, so on AwsClaude channels use block-level marks.

    Why it helps. An agent leg resends everything the previous leg sent plus one tool result. Without a mark the provider recomputes all of it at the full input price instead of about a tenth of it.

    Estimate about 1.2M prompt tokens per 1,000 calls billed uncached that the cache could serve (estimate)

    Assumptions. 40% of calls are Studio agent legs, 30% of those on Claude (12% of all calls); average prompt 12k tokens, 85% of it repeated from the previous leg or turn; legs return within seconds, well inside the 5-minute lifetime, so marks pay back (break-even (1.25-1)/(1-0.1) = 0.28 reads per write). Cache writes of the new tail (~1.8k per call) at 1.25x are listed as cache_write.

    How often. Share of model calls that go Responses-wire to an Anthropic, Bedrock-Claude or Vertex-Claude channel: every Studio Chat/Work/subagent leg on a claude-* model, plus API clients of /v1/responses on Claude. Read it from the consume log by channel type and from model_invocations.upstream_protocol = anthropic.

  3. LP-PC-01 Put cache marks where the provider needs them

    relay/bridge/chat_anthropic.go:184 · severity high · saves prefill · how often is assumed · clients' calls through the gateway

    What happens. OpenAI-format clients routed to a Claude channel go through this converter, which never adds a cache mark, and a client cannot add one either: extra keys on a message or a text part (such as cache_control) are rejected (relay/bridge/chat_anthropic.go:32, relay/bridge/chat_common.go:128). So every Chat Completions request that reaches Claude through the gateway is billed at the full input price, however much it repeats.

    The change. Add the top-level automatic cache mark to the converted request (block-level marks on Bedrock), optionally behind a channel setting, and accept cache_control on text parts so clients that already mark can keep their marks.

    Why it helps. A chat or agent client resends its whole history each turn; on Claude only a marked prefix is read from the cache at a tenth of the price.

    Estimate about 1.1M prompt tokens per 1,000 calls billed uncached that the cache could serve (estimate)

    Assumptions. 15% of all calls are Chat Completions requests bridged to Claude; average prompt 12k tokens, 60% of it repeated from the client's previous request within 5 minutes; new tail ~1.8k per call written at 1.25x (cache_write).

    How often. Share of /v1/chat/completions traffic that lands on Anthropic, AwsClaude or Vertex-Claude channels (controller/relay.go:48-59), and how much of it is multi-turn, from the consume log.

  4. LP-PC-12 Do not split one prefix across models or keys that do not share a cache

    model/ability.go:109 · severity medium · saves prefill · how often is assumed · clients' calls through the gateway

    What happens. Each request picks a channel at random among the same-priority channels for the model (model/ability.go:109, model/cache.go:299), with no memory of the conversation. Studio's agent does the same per leg (agent/executor.go:146). When those channels are different provider accounts, consecutive requests of one conversation hit different caches, and most of them start cold.

    The change. Choose the channel once per conversation (hash a session, conversation or prompt_cache_key value, or the client's token and first message, onto the eligible channels) and fall back to another only on error.

    Why it helps. Anthropic and OpenAI never share a cache between organisations (Anthropic also not between workspaces), so splitting one conversation over N accounts leaves about (N-1)/N of its requests without a cache hit.

    Estimate about 600k prompt tokens per 1,000 calls not served from cache (estimate)

    Assumptions. 30% of calls are for models served by two equal-priority channels on different accounts, so half of their continuing requests miss; about 4k reusable tokens per such request. Zero on a deployment with one account per model.

    How often. Whether the deployment serves one model through two or more channels of the same priority that use different provider organisations or workspaces; and, from the consume log, how often consecutive requests of one conversation land on different channels.

  5. LP-PC-06 Append-only history

    agent/context.go:281 · severity medium · saves prefill · how often is assumed · the gateway's own calls

    What happens. In a long Studio chat the kept history is recomputed every turn as the newest messages that fit in two fifths of the budget, so the conversation the model sees starts at a different message on every turn. Everything after the instructions and tools is new to the provider's cache on each turn's first leg.

    The change. Keep a fixed compaction boundary (CompactedThrough) between compactions, so the history after it only grows at the end until the next compaction.

    Why it helps. A prefix cache reuses only an unchanged start; moving the start of the history each turn forfeits the reuse of up to 12,800 tokens of history per turn.

    Overlaps. Finding 1 loses some of the same tokens; the totals count the larger once.

    Estimate about 300k prompt tokens per 1,000 calls not served from cache (estimate)

    Assumptions. 3% of calls are first legs of turns in sessions past the budget; about 10k tokens of kept history per such leg would otherwise be read from an automatic cache (OpenAI, Gemini). On Claude nothing is cached today anyway (finding responses-claude-no-marks).

    How often. Same as the compaction finding: the number of chat turns in sessions past the context budget, and the upstream cached tokens on the first leg of those turns on an automatic-cache provider (OpenAI, Gemini).

  6. LP-PC-06 Append-only history

    agent/skills.go:62 · severity medium · saves prefill · how often is assumed · the gateway's own calls

    What happens. After the model loads a Skill, its instructions are appended as an extra user message at the very end of the input on every following leg. Each leg adds the new tool call and result before them, so the instructions move back one step each time and are recomputed on every leg.

    The change. Insert the loaded instructions once, at the point in the history where the Skill was loaded (right after its tool result), and keep them there for the rest of the turn.

    Why it helps. Content that moves is never part of the unchanged prefix, so the skill text is billed uncached on every leg after it loads.

    Estimate about 120k prompt tokens per 1,000 calls not served from cache (estimate)

    Assumptions. 10% of Studio legs (4% of calls) run after a Skill was loaded; about 3k tokens of instructions per leg would otherwise be cached by an automatic-cache provider.

    How often. How often a Studio turn loads a Skill and how long its instructions are (skills import up to 64 KiB): count Skill tool calls in tool_executions and the instruction length of the skills they load.

Other problems the audit found

Problems read in the code that cost no tokens of their own, such as a cost meter or an error path. Not scored.

  1. The code bills cache reads and writes at the full input price

    relay/billing/native.go:142 · LP-GE-11 Meter every billed token, cached and unfinished ones too · severity medium · clients' calls through the gateway

    What happens. The quota charged is (Input + Output x completion ratio) x model ratio x group ratio, and Input includes cache reads and cache writes (relay/native/usage.go:78). The price book has only an input price and an output ratio per model (relay/billing/ratio/model.go:24-29), and the OpenRouter price sync reads only prompt and completion (controller/channel_models.go:343-346). So the code bills cache reads, which providers price at a fraction of input, at the full input price, and Anthropic cache writes (1.25x or 2x) at 1x.

    The change. Add cached-input and cache-write prices per model (sync them from OpenRouter's input_cache_read and input_cache_write), and charge Input minus CacheRead minus CacheCreation at the input price, CacheRead and CacheCreation at their own prices.

    Why it matters. Worked example (estimate; assumes the operator's ratios equal Anthropic's list prices): a coding-agent request of 100k input tokens (95k cache reads, 3k 5-minute writes, 2k uncached) and 1k output priced at 5x input. The provider's bill is 9.5k + 3.75k + 2k + 5k = 20.25k input-token equivalents; the code charges 100k + 5k = 105k, about 5x. List prices, checked 2026-11-26: Anthropic reads 0.1x input by default, writes 1.25x (5 minutes) or 2x (1 hour) (platform.claude.com, prompt caching); OpenAI reads 0.25x or 0.5x by model (OpenRouter's provider notes).

    To check. For one Claude request with a cached prefix, the consume log's quota equals the provider's bill for the same usage fields priced by hand.

  2. The compaction summary never reaches the model

    agent/engine.go:212 · the gateway's own calls · the same problem as finding 1

    What happens. compactIfNeeded stores a summary in session.Summary and drops the older messages from the working history, but the leg input is built from the reference files and the kept messages only (agent/engine.go:207-221); session.Summary is read only by the token estimate and by the next summariser call (agent/context.go:265, 328-331). Past the budget the model sees only the last ~12,800 tokens of the chat, though a summary call was made for it. A design note the project later removed (commit 31df916a) lists history plus summary as the context builder's job and repeated summary billing as forbidden.

    The change. Put the summary in the input as the first message after the instructions (not in the instructions, so the head stays cached), and load only messages after CompactedThrough.

    To check. In a session past the budget, ask about a fact from the first turn: the leg's request input contains the summary and the model can answer.

  3. OpenAI-format requests to Claude are capped at 1,024 output tokens when no limit is sent

    relay/bridge/chat_anthropic.go:24 · clients' calls through the gateway

    What happens. Anthropic requires max_tokens, so when a Chat Completions or Responses client omits its limit the converters set 1024 (relay/bridge/chat_anthropic.go:24, relay/bridge/responses_anthropic.go:41; reservation at controller/native.go:126-128). On OpenAI the omitted limit means the model's maximum, so the same client gets answers cut at 1,024 tokens on Claude channels. The cut is reported faithfully as finish_reason length.

    The change. Default to the model's maximum output (or an operator setting per channel) instead of 1024, and document the default.

    To check. A Chat Completions request without max_tokens asking for a 2,000-word essay on a Claude channel ends with finish_reason stop, not length.

  4. Some successful Claude replies become a 502 and are charged at the reservation

    relay/bridge/chat_anthropic.go:248 · LP-GE-12 Read the finish reason before using an answer · severity high · clients' calls through the gateway

    What happens. The non-streaming Chat converter rejects stop_reason refusal (the streaming one maps it, relay/bridge/stream.go:170), and all four Anthropic-to-OpenAI converters reject model_context_window_exceeded (chat_anthropic.go:248, stream.go:176, stream_responses_anthropic.go:346, responses_anthropic.go:447). The upstream reply was generated and billed, but the client gets a 502 and the gateway settles with no usage, which keeps the reservation (relay/lifecycle/forward.go:410-414, relay/billing/native.go:147-150), not the provider's figures.

    The change. Map refusal to finish_reason content_filter (or stop with the refusal text) and model_context_window_exceeded to length, and settle failed conversions from the usage in the upstream body.

    To check. A non-streaming Chat request that Claude refuses returns 200 with the refusal, and the consume log shows the provider's token counts.

  5. Strict field lists block common clients on cross-protocol routes

    relay/bridge/chat_common.go:25 · clients' calls through the gateway

    What happens. Converters reject unknown fields instead of dropping them. That is safe for semantics, but it also rejects cache hints whose loss is harmless: Anthropic requests with cache_control on a block or tool fail when routed to an OpenAI-chat, Responses or Gemini upstream (relay/bridge/anthropic_chat.go:77 and 186, anthropic_responses.go:154, messages_gemini.go:121), and Chat requests to Claude or Gemini channels fail on stream_options, user or parallel_tool_calls (chat_common.go:25; only the Responses converter accepts stream_options, chat_responses.go:29).

    The change. Accept and drop cache_control when the upstream caches automatically, accept stream_options.include_usage on every Chat converter (the stream already reports usage), and list the rejected fields in the docs.

    To check. An Anthropic Messages request with cache_control on a block routed to an OpenAI channel, and a streaming Chat request with stream_options.include_usage routed to a Claude channel, both succeed.

The maintainers’ response

The maintainer wrote to us privately after the audit was published and said the report was useful. They also explained the agent SDK's history: Norma-e is their fork of the Norma SDK, written by the developer of ARTEX, with multimodal support added.

The maintainers,

How this was made

The llm-call-audit skill read the code and wrote findings.json; nothing was run against the project’s providers. The full audit page is what leanprompt report --html writes from the same findings.

Corrections and takedown: email info@podwarden.com or open an issue.