For gpt-* models the first message of every request is a system prompt that starts with the current time, written with seconds (new Date().toString()).
It differs on every call, so OpenAI's automatic prefix cache cannot reuse anything after it: the memory summary, the mask's context messages and the history.
- What to change
- Drop the time line from the system message, or move it into the newest user message, so the system message is the same on every call.
- Why it matters
- Prompt caching matches from the first byte. A timestamp on line 4 of message 1 makes every later token a cache miss, even when the rest of the prompt is the same as the last turn.
- How big it is
- The code shows the problem and how often it happens; how many tokens it costs each time is assumed. To measure it: On a gpt-* chat whose prompt is over 1,024 tokens, send two turns a minute apart and read cached_tokens on the second; it should be about 0 today and rise after the time line moves.
- Who reaches this
- gpt-* and chatgpt-* models (the default model gpt-4o-mini), default setting on
- Estimate
- about 360,000 prompt tokens per 1,000 calls not served from cache
What the estimate assumes
average prompt 2,000 tokens; 30% of calls on gpt-* have a reusable prefix of about 1,200 tokens (the 1,024 minimum applies; short chats lose nothing); the history window and summaries move on some turns, so not every turn can reuse its prefix. The share is of all prompt tokens of gpt-* sessions.