Commit Graph
3 Commits
Author SHA1 Message Date
yetone 82e778e629 gateway: prompt_cache_test keeps its tests — ac2340d wrote TestAnthropicPromptCache over the file, dropping TestCodexThreadOnChatUpstreamCaches, TestPromptCacheKeyRefused and TestChatUsageCache; they're back, the new test after them 2026-09-29 00:08:17 +08:00
yetone ac2340d580 gateway: a request translated for Claude is cached (Passluo: 用户直接用 magpie 把 claude api 接入到 codex,这样没有申明缓存,用户没有写缓存) — Anthropic caches a prompt only up to a block marked cache_control, and a request from Codex (Responses) or a Chat client, rebuilt as Messages, had none, so every turn paid the whole conversation again. buildAnthropic now marks the system prompt (as a text block; the last tool when there's none) and the conversation's last block that can be (never thinking), so the next turn, which only adds to it, reads it from the cache; two marks, within Anthropic's four with the one Claude's sign-in adds. Anthropic's cache_read tokens already come back as Codex's cached_tokens 2026-09-29 00:05:29 +08:00
yetone 9c44e5b8c0 gateway: Codex on a Chat Completions relay keeps its prompt cache, and is told what it read (Codex 通过 magpie 走 OpenAI 兼容中转站,缓存好像没生效、token 用量很高) — Codex's prompt_cache_key (its thread's id) was dropped when its Responses request was made a Chat Completions one, so OpenAI and the relays that route a conversation by it to where its prompt is cached sent each turn somewhere cold; it now goes along to Chat and Responses upstreams alike, and a vendor that turns the unknown field away (400/422 naming it: Gemini's Unknown name, Mistral's extra_forbidden, Groq's unsupported) is asked again without it and not sent it again; so is one whose 400/422 doesn't name it, remembered only once the request works without it, and a 400 for something else still gets the key next time. What was read from the cache reached Codex, magpie's usage and affinity only as OpenAI's prompt_tokens_details.cached_tokens; DeepSeek's prompt_cache_hit_tokens, Moonshot's cached_tokens, OpenRouter's cache_write_tokens and a Claude relay's cache_read/cache_creation_input_tokens (its prompt_tokens taken as the whole prompt when it is at least those, as Anthropic counts otherwise) are read too — before, a DeepSeek-style relay's hits showed as cached_tokens 0 and affinity saw no cache worth staying for. The converted request was already prefix-stable turn to turn (instructions first, tools in Codex's order and schemas as sent, sorted keys, no ids or times added); tested with two Codex turns against a fake Chat upstream: every message of the first sent again byte for byte, tools the same, the key on both, 2048 cached tokens back to Codex 2026-09-28 23:04:34 +08:00