Skip to content

feat: chat() front door and Claude cache marking on LiteLLM routes - #405

Merged
rejojer merged 8 commits into
mainfrom
feat/chat-front-door
Aug 14, 2026
Merged

feat: chat() front door and Claude cache marking on LiteLLM routes#405
rejojer merged 8 commits into
mainfrom
feat/chat-front-door

Conversation

@rejojer

@rejojer rejojer commented Aug 14, 2026

Copy link
Copy Markdown
Member

Ports the eight pending commits from feat/local-chat (the v0.2.10 line) to main, following the #402/#404 pattern. After this merge, git diff main feat/local-chat is 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 door

chat(messages, doc_id=None, stream=False, model=None) returns the answer string (a text-chunk iterator when streaming). It is thin sugar over chat_completions() in both modes — same wire, envelope unwrapped, nothing rewritten. Multi-turn is the caller-maintained role/content list; 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's cache_control_injection_points. No subclassing, no hooks, no content rewriting; user messages and the response envelope are untouched. Provider resolution asks LiteLLM's own get_llm_provider instead 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), Vertex claude-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 real OpenAIResponsesModel, and a wire-level test asserting cache_control reaches the Anthropic HTTP body through LitellmModel); the local text-only history contract is stated on chat_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.

@rejojer
rejojer merged commit ec48510 into main Aug 14, 2026
8 checks passed
@rejojer
rejojer deleted the feat/chat-front-door branch August 14, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant