Conversation
…_write_tokens field
|
This will likely fix the issue I am encountering, I seem to go trough Codex limits much faster with Hermes than with Kilo. |
|
Linking this into the #17459 cache/time-awareness cluster. This remains relevant for Codex/Responses caching, but should align with the umbrella direction:
|
|
Thanks for isolating both caching concerns. The cache-write accounting portion remains relevant on current main: Problems
Suggested changes
Automated hermes-sweeper review. |
|
I looked more closely at the current OpenAI prompt-caching documentation. For GPT-5.6 and later model families, OpenAI reports cache writes separately as Hermes already includes GPT-5.6 cache-write pricing, so accurately reading this field seems important for keeping cache usage and cost accounting consistent. I reproduced the current behavior with a small usage fixture containing So, independently of the now-stale session-header changes, the OpenAI documentation: |
|
Adding independent wire evidence for the The field is live on the wire. Two-call probe today (2026-07-23) against
Current main's Why it now matters beyond telemetry: as @sheldon-im noted, GPT-5.6+ bills cache writes at 1.25× the uncached input rate (prompt caching guide), and Hermes already carries GPT-5.6 cache-write pricing — the broken field read is the only thing between current main and correct cost reporting for 5.6 traffic. On 5.5 the drop was invisible (writes free/unreported); on 5.6 it systematically under-prices every cache-writing request. We've adopted exactly the salvage shape the sweeper suggested into our fork ( |
|
Status update: the The session-routing-headers half ( |
Problem
Prompt caching does not work when using
codex_responsesAPI mode with OpenAI-compatible providers (e.g. theclawbay). Every request is a cache miss despiteprompt_cache_keybeing set in the request body.Root cause
Two issues:
1. Missing session routing headers (
run_agent.py)The OpenAI client is initialized without
session_idorx-client-request-idheaders for codex providers. These headers are required for server-side cache routing — they tell the backend to route requests to the same server that holds the cached prompt prefix.The official Codex CLI sends these unconditionally. Hermes sets
default_headersfor OpenRouter, GitHub Copilot, Kimi, and Qwen — but never for Codex/theclawbay.2. Wrong field name for cache_write_tokens (
agent/usage_pricing.py)The
codex_responsesbranch readscache_creation_tokens(Anthropic naming convention) instead ofcache_write_tokens(OpenAI Responses API naming). This means cache write tokens are always reported as 0.Fix
Patch 1: Session routing headers
After
session_idis assigned during__init__, injectsession_idandx-client-request-idintodefault_headersforcodex_responsesmode. Also applied in_apply_client_headers_for_base_url()so headers survive/modelswitches.Patch 2: cache_write_tokens field
Read
cache_write_tokensfirst (OpenAI naming), fall back tocache_creation_tokensfor backward compatibility.Tests
test_codex_responses_reads_cache_write_tokens_field— verifies correct field is readtest_codex_responses_falls_back_to_cache_creation_tokens— backward compattest_codex_responses_injects_session_routing_headers— verifies headers are setAffected files
run_agent.pycodex_responsesmode (+22 lines)agent/usage_pricing.pycache_write_tokensbeforecache_creation_tokens(+3/-1 lines)tests/agent/test_usage_pricing.pytests/run_agent/test_run_agent.py