zed/crates/open_router
James St-Pierre f844c93c94
open_router: Add prompt caching for Anthropic models (#57498)
Closes https://github.com/zed-industries/zed/issues/52576

## Overview

Adds prompt caching support for Anthropic Claude models when accessed
via OpenRouter.

This mirrors Zed's native Anthropic provider by using explicit per-block
`cache_control` breakpoints:

- A long-lived 1-hour breakpoint on the system message's last text
block, covering the tools and system prefix.
- A default 5-minute breakpoint on the last `cache: true` conversation
message.

The implementation intentionally avoids OpenRouter's top-level automatic
`cache_control` field so routing remains available across
Anthropic-compatible providers including Anthropic, Bedrock, and Vertex
AI. It also adds `session_id` sticky routing from the request thread ID
and maps OpenRouter cache usage fields into Zed's token usage
accounting.

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fixed Anthropic prompt caching when using OpenRouter.

---------

Co-authored-by: Anant Goel <anant@zed.dev>
2026-06-23 23:01:58 +00:00
..
src open_router: Add prompt caching for Anthropic models (#57498) 2026-06-23 23:01:58 +00:00
Cargo.toml language_models: Refactor deps and extract cloud (#53270) 2026-04-07 12:28:19 -03:00
LICENSE-GPL Add support for OpenRouter as a language model provider (#29496) 2025-06-03 15:59:46 +00:00