feat: chat() front door and Claude cache marking on LiteLLM routes - #405
Merged
Conversation
…'d entries, so it cannot replace it
…l turns, local rejects; extra fields drop
This was referenced Aug 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports the eight pending commits from
feat/local-chat(the v0.2.10 line) tomain, following the #402/#404 pattern. After this merge,git diff main feat/local-chatis empty — main and the 0.2.10 branch are content-identical again (verified on the branch before opening this PR).client.chat()— the answer-out front doorchat(messages, doc_id=None, stream=False, model=None)returns the answer string (a text-chunk iterator when streaming). It is thin sugar overchat_completions()in both modes — same wire, envelope unwrapped, nothing rewritten. Multi-turn is the caller-maintainedrole/contentlist; a bare query string works as the minimal call. This is the only format-unpinned contract:chat_completions()/responses()/messages()stay the protocol doors for callers who need the envelope or the process.Managed-prefix cache marking on LiteLLM-routed Claude models
Claude prompt caching is opt-in per request (unlike OpenAI's automatic caching), so without a marker every managed turn re-pays full input price.
chat_completions()now cache-marks the managed prompt prefix automatically on Claude models routed through LiteLLM — Anthropic direct, Bedrock Claude, Vertex Claude — via two documented parameter surfaces end to end:ModelSettings.extra_args→ LiteLLM'scache_control_injection_points. No subclassing, no hooks, no content rewriting; user messages and the response envelope are untouched. Provider resolution asks LiteLLM's ownget_llm_providerinstead of hand-parsed prefixes.Enablement doctrine: a wrong marker costs users a silent 1.25× cache-write premium, so each channel was live-verified write→read before being opened — Anthropic full-stack per-turn reads, Bedrock
us.anthropic.claude-sonnet-5(w7264→r7264), Vertexclaude-sonnet-4-5(w4842→r4842) — and non-Claude routes are pinned off by negative tests.Also in the port
Review remediation and docs: the missing-openai-agents error now points anthropic-extra users at
messages(); two silent vendor chains gained guards (recorder attachment asserted against the realOpenAIResponsesModel, and a wire-level test assertingcache_controlreaches the Anthropic HTTP body throughLitellmModel); the local text-only history contract is stated onchat_completions()(cloud forwards tool turns, local rejects; extra message fields drop); the max-tokens docstring trimmed to the contract.Verification
276 tests green (3 skipped without the claude extra) on the ported branch. Cache marking was live-verified on all three Claude channels before landing on
feat/local-chat, where #400 carries the full line for review.