Repository navigation
Replies: 1 comment 1 reply
|
Thank you for the detailed proposal and the measurements. A new setting, |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Summary
PREFIX_CACHE_OPTIMIZED_PROMPTS(#316) keeps the title and summary prompts byte-identical up to the end of the transcript, so a provider can reuse the transcript between the two calls. OpenAI models do this automatically. Anthropic models, called directly or through OpenRouter, only cache up to an explicitcache_controlbreakpoint. Speakr never sends one, so with an Anthropic text model the full transcript is billed twice for every recording: once for the title and once for the summary.The new
TEXT_MODEL_EXTRA_BODYin v0.10.16 can't fix this. A top-levelcache_controlcaches the whole message. The title and summary user messages differ after the transcript, so neither call reuses the other's cache, and both pay the cache-write surcharge.Measurements
These were measured through OpenRouter with
anthropic/claude-sonnet-5.5, using a synthetic prompt of about 13k tokens.cache_control, first callThe last two rows show the title/summary case: the same transcript prefix with a different instruction after it gets no cache hit.
On a real two-hour, six-speaker recording (about 71k prompt tokens), each recording costs:
The title and summary calls run seconds apart, well inside Anthropic's 5-minute cache lifetime. For gpt-5-mini, the existing
token_usagerows already show the summary reading the title's cached prefix (cached_tokens20,992 of 22,197).Proposed change
When
PREFIX_CACHE_OPTIMIZED_PROMPTSis on, send the user message as two text parts instead of one string. The first part is the shared prefix (_shared_user_prefix(transcript_text)) withcache_control, and the second is the task-specific suffix:{"role": "user", "content": [ {"type": "text", "text": _shared_user_prefix(transcript_text), "cache_control": {"type": "ephemeral"}}, {"type": "text", "text": "\n".join(suffix_parts)}, ]}src/tasks/processing.py, which build_shared_user_prefix(...) + suffixtoday.cache_controlmay reject the unknown field, and some local servers don't accept array content. So the breakpoint could be gated on the model name (anthropic/orclaude) or on a setting such asTEXT_MODEL_CACHE_BREAKPOINTS=true.CHAT_MODEL_EXTRA_BODYwith a top-levelcache_controlmay already do this, because each follow-up repeats the earlier conversation exactly.Environment
TEXT_MODEL_EXTRA_BODY)TEXT_MODEL_BASE_URL=https://openrouter.ai/api/v1,TEXT_MODEL_NAME=anthropic/claude-sonnet-5.5PREFIX_CACHE_OPTIMIZED_PROMPTS=true,transcript_length_limit=-1Drafted with an AI assistant; the measurements were run on my own instance.
All reactions