Lean into provider-native caching (explicit Gemini context caching, docs, visibility)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 176
- Forks
- 28
- Avg merge
- 18h 42m
- Merged PRs (30d)
- 16
Description
Motivation
Client-side response caches (LangChain's set_llm_cache, LiteLLM's caching layer) date from early 2023, before Anthropic prompt caching (Aug 2024), OpenAI automatic prompt caching (Oct 2024), or Gemini context caching existed. The providers now solve the underlying cost/latency problem better, and chatlas already leans into that harder than most frameworks:
- Anthropic/Bedrock:
cache="5m"on by default, withcache_controlinjection and cache-write cost multipliers (1.25×/2×) reflected inget_cost()(_provider_anthropic.py). - OpenAI: automatic server-side caching;
cached_tokensextracted and priced (_provider_openai.py). - Google: implicit-cache token counts tracked (
_provider_google.py). get_tokens()/get_cost()exposecached_inputas a first-class field; prior art in #103, #133, #158, #243 (all closed).
What remains is closing the gaps, not adding a new cache layer.
Proposed work
- Explicit Gemini context caching — the one concrete API gap. Support Google's explicit caching (
client.caches.create(...)with a TTL, then reference the cached content across calls). This dovetails with the newChat.filesaccessor: same "register once, reference cheaply across turns" model. Whether it surfaces as achat.files-like accessor, a content type (cf. #136content_ephemeral()), or aChatGoogle()parameter is the main design question. - A caching guide in the docs — the current defaults are good but invisible. Cover: what each provider does automatically, how to read
cached_inputfromget_tokens()to check your hit rate, Anthropic TTL tradeoffs ("5m"vs"1h"write multipliers), and how to keep prompts cache-friendly (stable prefix; don't churn the system prompt or tool set mid-conversation). - Small parameter exposure — e.g. OpenAI's
prompt_cache_keyrouting hint for improving hit rates. Low priority for chatlas's typical single-process user, but cheap. - Cross-issue design note — prefix caches reward immutable history, so history compaction (#356) and mutable system prompts are cache-busting operations. The #356 design should account for the one-time cost cliff after a compaction.
Non-goal: client-side response cache
A LangChain-style client-side response cache is out of scope. Its one honest use case — replaying an identical request without paying again (prompt caching discounts input tokens but never eliminates the call or the output tokens) — is better served elsewhere:
- Notebook/script re-runs: that's a persistence problem — reload the earlier conversation (#352
chat.save()/Chat.load()) instead of re-asking the model. - Tests/CI: VCR-style request recording (what chatlas's own test suite uses via
pytest-recording) is purpose-built for this. - Treating nondeterministic calls as cacheable pure functions also has real surprise potential (a cache silently freezes responses that users expect to vary).
Part of the July 2026 competitive-review workstreams (#360).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with _provider_google.py and the new Chat.files accessor, then compare cache handling in _provider_anthropic.py and _provider_openai.py. Clarify the API design for explicit Gemini context caching, the caching guide, and any small parameter exposure. Done means the agreed provider-native caching behavior and documentation cover cached_input, provider defaults, TTL tradeoffs, and cache-friendly prompts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- ai, documentation
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100