# open_router: Add prompt caching for Anthropic models \(\#57498\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/f844c93c948dfbe68d99ec9fb7cd2482a8622a09)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: f844c93c948dfbe68d99ec9fb7cd2482a8622a09

Requested commit: f844c93c948dfbe68d99ec9fb7cd2482a8622a09

Commit: f844c93c948dfbe68d99ec9fb7cd2482a8622a09

Tree: 6dab35b8bb7fa17bba88b6e095fd2bfdd44646fe

Author: James St-Pierre

Committer: GitHub

## Message

```
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>
```

## Parents

- [7187d657743a9391ee72ad02067204a381e36187](https://git.cafe/gitcafe/zed/commit/7187d657743a9391ee72ad02067204a381e36187?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/f844c93c948dfbe68d99ec9fb7cd2482a8622a09?format=markdown)
