148 Commits
Author SHA1 Message Date
Agus Zubiaga c5d6f0b2ca language_model: Allow explicit prompt cache keys (#64460)
## Objective

Related conversations can’t share an OpenAI cache key without also
sharing a thread ID. We currently derive `prompt_cache_key` directly
from `thread_id`, tying cache reuse to conversation identity.

## Solution

Add an optional `prompt_cache_key` to `LanguageModelRequest` and use it
in both OpenAI Chat Completions and Responses conversions. We still fall
back to `thread_id` when no key is supplied, so existing callers keep
their current behavior.

This lets callers share a cache key across parent and child
conversations while keeping their conversation and transport identities
separate.

## Testing

Added regression coverage for explicit keys, legacy fallback, provider
capability gating, and serialization compatibility.

## 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 adheres to Zed's UI standards
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- N/A
2026-09-18 18:44:49 +00:00
Finn Evers 20d55798db Fix cargo shear warnings (#64340)
Also updates CI to always run this - that way we ensure that disabling
or enabling tests does not become stale at some point and thus can
safely add this.

Release Notes:

- N/A
- [GPUI] N/A
2026-09-17 08:49:31 +00:00
MartinYe1234 616ac232d4 Add provider-backed input token counting (#64194)
## Stack

Part 2 of the split. #64047 is merged, and this PR now targets `main`.
Current main was merged into this branch without rewriting history. The
diff contains only counting/consent work and the required README review
acknowledgment (8 files, +837/-80). The Copilot metadata sibling #64195
does not depend on this PR.

## Summary

Add optional provider-backed input counting for direct Anthropic, direct
OpenAI Responses, and hosted Anthropic/OpenAI models. Preserve
structured input and reuse provider conversion, authentication refresh,
and client request limiting. Unsupported providers return `None`;
provider and malformed-response errors remain visible.

Keep the existing hosted data-retention consent rule common to counting,
native compaction, and generation. Counting never sends input before
consent. The matched Cloud endpoint support is merged; its deployment
remains a prerequisite for downstream callers.

This PR does not change Copilot prompt/context metadata, compaction
thresholds, or tooltips. No chunking or paid tests are introduced.

## Validation

- After resolving the main merge: 226 tests passed across anthropic,
open_ai, language_models, and language_models_cloud. Main’s consolidated
output-limit tests and renamed serialization test are preserved.
- Scoped script/clippy passed for anthropic, open_ai, language_models,
and language_models_cloud.
- Formatting and whitespace checks passed.
- Coverage includes images, structured request fields, authenticated
hosted requests, unsupported providers, error propagation, and consent
rejection before HTTP.
- No live provider calls were made.

Release Notes:

- Fixed data-retention consent checks for hosted counting and compaction
requests.
2026-09-15 14:52:14 +00:00
MartinYe1234 411b31e9a5 Add per-request model output limits (#64047)
## Stack

- This PR: output-limit plumbing, based on `main`.
- #64194: provider input counting and consent, based on this branch.
- #64195: Copilot metadata and consumers, independently based on this
branch.

After this PR lands, rebase/retarget both children onto `main` as
needed, especially after a squash merge. At split time, a synthetic
merge of the two child heads exactly matched the saved pre-split source
tree. PR1 has since consolidated overlapping tests without changing
production code.

## Summary

Part 1 of a three-PR split: add optional per-request
`max_output_tokens`, forward it through provider payloads, and clamp it
against known output limits. Unset requests preserve existing defaults.
Unknown Copilot output metadata is not treated as a zero-token maximum
when forwarding a cap.

This PR also supplies the combined-window and native-capability
interfaces used by downstream budget calculations. It does not add
input-token counting, data-retention consent integration, or change
Copilot prompt/context metadata, compaction thresholds, or tooltips.
Those changes are split into two child PRs based on this branch.

The net diff is 24 files, +438/-55. Forward narrowing commits preserve
the original review history; there was no force-push.

## Test consolidation

Eight overlapping standalone tests have been folded into existing
conversion tests, preserving coverage of unset limits, explicit limits,
clamping, and serialized payloads. Four distinct tests remain separate:
request serialization compatibility, Copilot wire formats, DeepSeek
conversion (no existing conversion suite), and hosted OpenAI
normal-completion HTTP behavior. This cleanup changes no production Rust
code.

## Validation

- Latest run: 269 tests passed across anthropic, google_ai, open_ai,
language_models, copilot_chat, and language_models_cloud.
- Five extended existing tests failed when cap selection was temporarily
broken and passed after restoration. No mutations remain.
- Latest scoped script/clippy, formatting, and whitespace checks passed.

Earlier split validation:

- 229 tests passed across language_model_core, anthropic, open_ai,
copilot_chat, and language_models_cloud.
- Scoped script/clippy passed for copilot_chat, language_models_cloud,
language_models, agent, and agent_ui.
- Formatting and whitespace checks passed.
- Permanent tests cover payload propagation, absent/explicit limits,
unknown output metadata, direct and hosted native-compaction caps, and
hosted OpenAI clamping.
- No live provider requests were made for the split.

## Review notes

The separately identified fixed/non-interleaved thinking-budget versus
smaller output-cap concern remains open in this PR; it must not be
hidden in the counting or metadata PRs. The README acknowledgment is
retained for human review.

Downstream applications using input counting must consume the counting
child PR as well, not repin to this branch alone.

Release Notes:

- N/A
2026-09-14 20:15:15 +00:00
Conrad Irwin 7556e307d2 anthropic: Classify exhausted credits as payment required (#63988)
Anthropic reports exhausted credits as `invalid_request_error` rather
than the documented `billing_error`. Recognize the specific
credit-balance message when converting Anthropic API errors to
`PaymentRequired`.

This preserves the original status, code, and message, handles errors
with or without an HTTP status, and leaves other invalid requests
unchanged. The comment links to Anthropic's error documentation.

Closes DELTA-77

Validation: the existing Anthropic billing-error test and package
formatting check pass. A temporary classification test also passed for
exhausted credits and malformed requests, with and without HTTP status;
it is not included in this PR.

Release Notes:

- Fixed Anthropic credit exhaustion being classified as a malformed
request instead of a payment issue.
2026-09-10 14:33:24 +00:00
Mikayla Maki cd0241b7e3 anthropic: Handle Claude Fable 5.1 API changes (#63571)
Claude Fable 5.1 introduces two breaking Messages API changes that
produce 400 errors with request shapes Zed currently sends. This change
adapts the shared Anthropic request path so the model works out of the
box, without restructuring how requests are built.

The first change is thinking-block prefix binding. Fable 5.1 binds each
thinking block to the exact conversation prefix that produced it, and
replaying a block after anything earlier changed (the system prompt, the
tools array, or an edited turn) fails the whole request with a 400
reading "The block is bound to a different conversation". Zed routinely
rebuilds the system prompt and tool list between requests (rules file
changes, profile switches, MCP servers coming online), so this would
surface as a hard error mid-thread. Requests to Fable 5.1 now send the
`thinking-binding-controls-2026-08-01` beta header with
`thinking.block_binding.prefix_mismatch_behavior: "drop_block"`, which
makes the API drop invalidated blocks and continue instead of rejecting
the request. Claude Mythos 5.1 doesn't run this check and is excluded.
The cloud and Copilot Chat paths pass `block_binding: None` since their
proxies control the upstream beta headers; opting in there belongs
server-side.

The second change is that forced tool use (`tool_choice: "any"` or
`"tool"`) now returns a 400. Zed sends `"any"` from inline assist's
streaming-tools path, which is on by default. The Anthropic and
Zed-cloud providers now report `tool_choice: any` as unsupported for
Fable/Mythos 5.1, and inline assist already degrades gracefully to
prompt-guided auto tool choice, which is Anthropic's recommended
migration.

Finally, `claude-fable-5-1` and `claude-mythos-5-1` are added to the
compaction model list. This matters more than a routine table update:
with prefix binding, server-side compaction is the sanctioned way to
trim history without invalidating thinking blocks. Everything else
already carries over via the existing `claude-fable-5` id prefix logic
(data-retention consent, Opus 4.8 refusal fallback, which remains a
permitted fallback target for 5.1). Bedrock is intentionally untouched.

Deeper follow-up work is deferred: keeping conversation history
append-only so blocks aren't invalidated in the first place (turn-scoped
system messages, mid-conversation tool changes) and monitoring
`input_transformations` for drop reporting.

Testing:

- New unit tests covering the `block_binding` wire format (sent for
`claude-fable-5-1` only) and beta-header wiring in `Model::from_listed`.
- `cargo nextest run` for `anthropic`, `language_models`,
`language_models_cloud`, and `copilot_chat`; `cargo fmt --check`.

Release Notes:

- Improved support for Claude Fable 5.1
2026-09-01 18:58:47 +00:00
Conrad Irwin c8518b3317 Preserve language model provider rejection details (#63095)
Language model providers can reject a request inside an otherwise
successful response stream. Those failures were represented by
overlapping completion-error variants and provider-specific code enums,
and OpenAI Responses errors such as `cyber_policy` fell through to
`Other`. Agent sessions consequently retried permanent provider
rejections and user interfaces lost the provider's actionable message.

This gives every provider-originated failure one shared representation.
`ProviderRejection` preserves the provider, exact message, retry delay,
raw provider code, and an HTTP status only when one was actually
reported. `ProviderErrorCategory` supplies the normalized meaning used
by shared UI and policy code. Provider adapters map their native wire
errors into that category explicitly, so typed SDK exceptions and errors
embedded in successful streams no longer fabricate HTTP statuses.

Retry selection is independent from error construction.
`LanguageModelCompletionError::retry_delay` owns transient
classification and a bounded schedule of 5, 10, 20, then 40 seconds. A
provider-supplied `retry_after` overrides that schedule. The scheduling
layer adds positive jitter of up to 10%, while interactive requests and
evaluation runs retain their own attempt budgets. Permanent status-less
errors such as `cyber_policy` do not retry. OpenRouter also keeps its
numeric body code distinct from an optional HTTP status, including for
errors embedded in a stream.

Testing performed:

- `corgi test -p language_model_core`
- `corgi test -p anthropic` (33 tests)
- `corgi test -p open_ai` (77 tests)
- `cargo nextest run -p open_router -p copilot_chat -p
language_models_cloud -p language_models` (125 tests)
- `cargo nextest run -p agent -p agent_ui` (1,153 tests; 11 skipped)
- `cargo check -p open_router -p copilot_chat -p language_models_cloud
-p language_models -p agent -p agent_ui`
- `./script/clippy -p language_model_core -p anthropic -p open_ai -p
open_router -p copilot_chat -p language_models_cloud -p language_models
-p agent -p agent_ui` completed the release Clippy phase; Cargo Shear
then reported the repository's existing warnings
- `cargo fmt --all --check`

Suggested .rules additions

None.

Release Notes:

- Fixed permanent language model provider rejections being retried and
displayed without their actionable provider message.
2026-08-24 19:36:04 +00:00
Conrad Irwin a637a0a25d language_model: Include hosts in transport errors (#62990)
Language model transport errors currently retain only a provider display
name after an HTTP request fails. Downstream clients therefore cannot
tell users which configured endpoint was unreachable without parsing the
source error or hard-coding provider names.

Make the request hostname a required part of
`LanguageModelCompletionError::HttpSend` and preserve it through the
Anthropic, OpenAI-compatible, OpenRouter, Vercel AI Gateway, and Zed
Cloud transports. Each transport captures the parsed hostname from the
request URI before sending it, using the configured base URL as the
defensive fallback. This supports production, development, and custom
endpoints without string matching.

Tests exercise transport failures through the real request paths and
verify hostnames for Anthropic, ChatGPT Subscription, generic
OpenAI-compatible providers, and Zed Cloud.

Testing:

- `cargo fmt --check`
- `cargo nextest run -p anthropic -p open_ai -p open_router -p
language_models_cloud -p language_models` — 209 tests passed
- `cargo check -p agent -p agent_ui --all-targets`
- `git diff --check`
- `./script/clippy -p language_model_core -p anthropic -p open_ai -p
open_router -p language_models_cloud -p language_models` — clippy
passed; the script subsequently failed in the repository-wide `cargo
shear --deny-warnings` step on 203 pre-existing target and doctest
configuration warnings

Release Notes:

- Improved language model connection errors to identify the unreachable
host.
2026-08-21 14:53:09 +00:00
Conrad Irwin 0ac96c12fc anthropic: Handle additional API error codes (#62984)
Anthropic now returns distinct error types for billing failures, request
conflicts, and gateway timeouts. Because the Anthropic client did not
recognize these values, they fell through to
`LanguageModelCompletionError::Other`, losing their structured status
and causing callers to apply generic handling.

Recognize the documented `billing_error`, `conflict_error`, and
`timeout_error` codes. Billing failures now become `PaymentRequired`,
conflicts preserve their HTTP 409 status and provider message, and
timeouts become typed upstream HTTP 504 failures. End-to-end tests
exercise each mapping through the HTTP response parsing path.

Testing:

- `cargo fmt --check`
- `cargo nextest run -p anthropic`
- `./script/clippy -p anthropic`
- `git diff --check`

Release Notes:

- Fixed handling of Anthropic billing, conflict, and timeout errors.
2026-08-21 05:38:56 +00:00
Conrad Irwin 52f9567fb4 Preserve typed errors when listing Anthropic models (#62791)
Anthropic model-list requests currently flatten request, transport,
response, and API failures into `anyhow` strings. Callers therefore
cannot distinguish an invalid API key from connectivity or provider
failures, even though Anthropic returns a structured error payload.

This changes `list_models` to return `AnthropicError`, maps each request
stage to its existing typed variant, and routes unsuccessful responses
through the same structured response handler used by completion
requests. The language model provider converts that error at its
existing `LanguageModelCompletionError` boundary. A regression test
verifies that an authentication response retains both its error category
and Anthropic's human-readable message.

Testing performed:

- `cargo fmt --check`
- `cargo nextest run -p anthropic -p language_models`
- `./script/clippy -p anthropic -p language_models`

Release Notes:

- Fixed Anthropic API key errors being reported as generic model-list
failures.
2026-08-18 03:44:43 +00:00
Anant Goel 3d5fb8133a anthropic: Preserve request context during explicit compaction (#62745)
Explicit compaction currently removes tool definitions before sending
the request. That changes the prompt-cache prefix and can lower the
effective input size below Anthropic's minimum compaction trigger,
causing the request to complete without producing replacement context.

Keep tool definitions in explicit compaction requests while setting
`tool_choice` to `none`, preserving the input context without allowing
tool calls. Also append a user turn when the conversation ends with an
assistant message, since current Anthropic models reject that shape as
unsupported assistant prefill.

Testing:

- `cargo test -p anthropic`
- `cargo fmt --check`
- `./script/clippy -p anthropic`

Release Notes:

- N/A
2026-08-17 08:07:14 +00:00
Eric HolkandAnant Goel a3bf217dba Improve explicit compaction for Anthropic models (#62139)
Explicit compaction (`LanguageModel::compact`) was previously
implemented only for OpenAI-routed cloud models, which use a dedicated
compact operation proxied through `/completions/compact`. Anthropic
models only compacted automatically when a request's `compact_at_tokens`
trigger was crossed, leaving consumers without a provider-backed way to
request compaction immediately.

Anthropic has no compact-on-demand operation, but the `compact_20260112`
context-management edit provides the necessary pieces: the lowest
trigger the API accepts, 50,000 input tokens, combined with
`pause_after_compaction`, which stops the response after the compaction
block. Explicit compaction requests remove tools so the internal
summarizer must produce replacement context while retaining Anthropic's
default summarization prompt. The resulting readable summary, optional
opaque provider state, and usage are collected consistently.

This implements explicit compaction for both direct and hosted Anthropic
models. Hosted requests use the normal `/completions` endpoint; gateway
support for forwarding the compaction fields landed in
zed-industries/cloud#3216. Models expose the 50,000-token minimum so
callers can disable explicit compaction below the provider's floor.
Calls made below that floor still fail if the stream produces no
finalized compaction context.

The existing OpenAI compact operation is moved into a provider-specific
helper without changing its request, endpoint, response handling, or
provider-state ownership.

Testing:

- `cargo nextest run -p anthropic -p language_models_cloud -p
language_models`
- `./script/clippy -p anthropic -p language_model -p
language_models_cloud -p language_models`
- `cargo fmt --all --check`
- `git diff --check`

Release Notes:

- N/A

---------

Co-authored-by: Anant Goel <anant@zed.dev>
2026-08-17 04:27:38 +00:00
Bennet Bo Fenner af8d81593a anthropic: Filter models with null token limits (#62618)
According to the docs these fields can be null:

https://platform.claude.com/docs/en/api/models/list#model_info.max_input_tokens

https://platform.claude.com/docs/en/api/models/list#model_info.max_tokens

Instead of failing the whole request, we filter those models out since
we can't handle models without knowing their context window size. Seems
like ClaudeCode follows the same approach.

Release Notes:

- N/A
2026-08-14 09:32:13 +00:00
Bobo db7d5ddd19 Skip [DONE] stream terminator in anthropic and google_ai SSE parsers (#61627)
## Problem

When `api_url` points to a proxy or gateway that appends `data: [DONE]`
to the SSE stream, every streaming completion fails with:

```
error deserializing Anthropic API response: expected value at line 1 column 2
```

In the UI this surfaces as **"error deserializing Anthropic API response
— Retrying (Attempt 3 of 3)"** followed by **"Connection Interrupted"**,
even though the proxy returned a well-formed stream and the model's full
response was already delivered before the terminator. The failure is
100% reproducible on multi-turn tool-use conversations (Zed reads the
stream to completion after each turn, so it always reaches the trailing
`[DONE]`) and intermittent on single-turn conversations (depending on
whether the connection closes before the line is read). The same class
of error appears in the `google_ai` crate as `Error parsing JSON: ...
"[DONE]"`.

Neither side is at fault here. Zed's current parser is a correct
implementation of the Anthropic and Gemini specs, which terminate
streams by connection close and never emit `[DONE]`; at the same time,
appending a `[DONE]` terminator is a common, legitimate convention among
SSE gateways. This PR is a compatibility improvement that makes Zed
robust to that widely-used stream shape, so streaming works whether or
not the upstream emits the terminator.

## Why Zed crashes but the Anthropic SDK does not

The Anthropic TypeScript and Python SDKs handle this correctly
**without** any explicit `[DONE]` check. Their SSE parser uses a
two-layer architecture:

1. **SSE framing layer** — parses `event:` / `data:` fields into
`{event, data}` objects without inspecting the data payload.
2. **Event dispatch layer** — only calls `JSON.parse` on events whose
`event` name is in a known whitelist (`message_start`,
`content_block_delta`, etc.). A bare `data:` line with no preceding
`event:` line yields `event: null`, which is not in the whitelist and is
silently ignored.

So when a proxy sends `data: [DONE]`, the SDK produces `{event: null,
data: "[DONE]"}`, the dispatch layer drops it, and `JSON.parse` is never
run on `[DONE]`. Claude Code and Cline both use the Anthropic SDK under
the hood, so they inherit this behavior and never crash on `[DONE]`.

Zed's `anthropic` and `google_ai` crates use a simpler single-layer
parser: strip the `data:` prefix, then unconditionally
`serde_json::from_str` the remainder. There is no event-name dispatch,
so `[DONE]` goes straight into the JSON parser — `[` looks like an array
start, `D` is not a valid value, serde reports `expected value at line 1
column 2`, and the stream dies.

## Fix

Add a one-line guard after prefix stripping: if the trimmed payload is
`[DONE]`, return `None` from the `filter_map` closure. This is a
lightweight equivalent of the SDK's whitelist-ignore behavior — same
result (silently skip the terminator), without restructuring the parser
into a full event-name dispatch architecture.

Two commits, one per crate:

1. `anthropic` — guard in `stream_completion_with_rate_limit_info`
2. `google_ai` — identical guard in `stream_generate_content`

## Scope

The other ten SSE-based providers in this repo (`open_ai`, `deepseek`,
`mistral`, `open_router`, `lmstudio`, `llama_cpp`, `copilot_chat`)
already handle `[DONE]` because their upstream specs (OpenAI-compatible)
define it as a required stream terminator. `ollama` (NDJSON) and
`bedrock` (AWS SDK event stream) do not use SSE. After this PR, every
SSE parser in Zed handles `[DONE]` without error.

## Safety

- Official Anthropic and Gemini APIs never send `[DONE]`; the guard is a
no-op on direct connections.
- `line.trim() == "[DONE]"` handles both `data: [DONE]` and
`data:[DONE]`.
- Returning `None` drops the line silently; the stream concludes on the
next EOF as usual.

Release Notes:

- Fixed streaming completions failing with "error deserializing
Anthropic API response" when the SSE endpoint appends a `[DONE]` stream
terminator (affects custom `api_url` proxies for Anthropic and Google
Gemini)
2026-07-27 12:07:31 +00:00
Richard Feldman 8457a4ccf4 Opus 5 BYOK Support (#61596)
<img width="844" height="404" alt="Screenshot 2026-07-24 at 3 47 04 PM"
src="https://github.com/user-attachments/assets/4691a246-bab9-4426-aa0b-6a7cfa2aa486"
/>
action support, and explicit thinking opt-out behavior.

Adds Claude Opus 5 to the Anthropic and Amazon Bedrock BYOK providers,
including its documented context and output limits, regional inference
profiles, fast mode and comp

Release Notes:

- Added Claude Opus 5 support for Anthropic and Amazon Bedrock BYOK
providers.
2026-07-24 19:56:07 +00:00
Nathan Sobo fe4f59add6 Add explicit OpenAI conversation compaction and fix Anthropic compaction (#61370)
# Objective

Add explicit conversation compaction for OpenAI Responses API models,
available through both direct OpenAI connections and Zed Cloud models.

Keep finalized replacement context provider-neutral and separate from
the lifecycle events emitted while automatic compaction is in progress.

## Solution

- Add opt-in explicit compaction support to the `LanguageModel` trait.
- Separate streamed `CompactionUpdate` lifecycle events from finalized
`CompactedContext`.
- Represent provider-native compacted context as an opaque, versioned
state owned by the originating provider.
- Construct compact requests through the same OpenAI request conversion
used for completions, then narrow the request to fields supported by
`/responses/compact`.
- Preserve and validate the complete canonical replacement window
returned by OpenAI.
- Replay the replacement window before messages sent after compaction,
without resending the superseded transcript.
- Support explicit compaction through both the direct OpenAI provider
and `CloudLanguageModel`.
- Update automatic OpenAI and Anthropic compaction to use the same
finalized context representation.
- Reject empty, malformed, incorrectly versioned, and incorrectly owned
provider state.

The corresponding Cloud change adds the `/completions/compact` proxy
route: https://github.com/zed-industries/cloud/pull/3099.

The downstream Delta UI integration is
https://github.com/zed-industries/delta/pull/1739.

## Testing

- `cargo nextest run -p anthropic -p open_ai -p language_models_cloud`
- `cargo check -p language_models --tests`
- `cargo fmt --all --check`
- `git diff --check`

The focused tests cover request construction, canonical-window
preservation and replay, direct and Cloud transports, automatic
compaction lifecycle events, malformed provider state, provider
ownership, format compatibility, and HTTP failure handling.

## 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 adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

---

Release Notes:

- Added: System messages are now sent through the `instructions` field
in OpenAI Responses API requests.
2026-07-24 16:53:45 +00:00
tidely 16fd124094 anthropic: Deprecate fast mode for Opus 4.6 and Opus 4.7 (#61341)
TLDR: Opus 4.6 has been falling back to standard speed. Opus 4.7 fast
mode API will error after July 24th.

This will likely need to be cherry-picked to stable for either
Wednesday's release, or be pushed out separately on the 24th to maximize
availability. Although I don't think there are many Opus 4.7 fast mode
users, so Wednesday seems better to me.

> Fast mode for Claude Opus 4.7 is deprecated as of June 25, 2026, and
will be removed on July 24, 2026. After removal, requests to
claude-opus-4-7 with speed: "fast" will return an error; unlike Claude
Opus 4.6 (see the following note), Claude Opus 4.7 does not fall back to
standard speed. The model itself remains available at standard speed. To
continue using fast mode, migrate to Claude Opus 4.8.

Source: https://platform.claude.com/docs/en/build-with-claude/fast-mode

Release Notes:

- Deprecated Fast Mode for Opus 4.6 and Opus 4.7
2026-07-20 17:23:54 +00:00
Nakano KenjiandBennet Bo Fenner 5c48f982fe anthropic: Allow configured models to opt into fast mode (#58225)
Adds support for enabling Anthropic fast mode on configured models.

Previously, Anthropic models configured through
`language_models.anthropic.available_models` were always marked as not
supporting fast mode, so `speed: "fast"` would be stripped before
sending requests even when the configured model supported Anthropic fast
mode.

This adds an optional `supports_fast_mode` field to configured Anthropic
models. When enabled, the model is marked as supporting fast mode and
the required Anthropic beta header is added automatically. Built-in
fast-mode model detection remains the fallback when the setting is
omitted.

Testing:
- `cargo fmt --package anthropic --package language_models --package
settings_content`
- `cargo test -p language_models available_model --lib`
- `cargo test -p anthropic from_listed_enables_fast_mode --lib`
- `cargo check -p language_models`
- Manual: verified in a local build that a configured Anthropic model
can send fast mode requests correctly.

Release Notes:

- agent: Allow specifying if fast mode is supported for custom anthropic
models

Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
2026-07-10 15:01:47 +00:00
Ben Kunkle aec35a284c language_model: Add OpenAI Responses API custom tool support (#60638)
# Objective

Allow zed's language model stack to express OpenAI Responses API custom
tools (freeform text-input tools with an optional lark/regex grammar),
so downstream consumers can offer tools like a freeform `apply_patch` to
GPT models.
## Solution

- `LanguageModelRequestTool` now carries a Function-vs-Custom input
variant; `LanguageModelCustomToolFormat` models text/grammar formats.
- `LanguageModelToolUse.input` becomes a typed
`LanguageModelToolUseInput::{Json, Text}`. Serialization is tagged so
persisted Text inputs round-trip losslessly; legacy plain JSON values
still deserialize as `Json`.
- `open_ai` gains the custom tool wire types (tool definition,
`custom_tool_call`/`custom_tool_call_output` input items with
string-or-content-part outputs, output item, and
`custom_tool_call_input` delta/done stream events). The Responses event
mapper accumulates raw text deltas into `ToolUse` events, and history
replay derives custom-vs-function tool results from the matching
`ToolUse` by id.
- All non-OpenAI providers and the Chat Completions path error
explicitly when a request contains custom tools — no silent drops or
empty-schema coercions.

Release Notes:

- N/A
2026-07-09 12:05:50 +00:00
Agus Zubiaga 01b6149a36 Support provider-side compaction in the language model clients (#59145)
Adds provider-side context compaction support to the Anthropic and
OpenAI API clients. Client plumbing only; not wired into the UI.

Release Notes:

- N/A
2026-06-16 13:06:20 +00:00
527ee5c91c language_models: Add Anthropic-compatible provider support in settings (#50381)
Release Notes:

- Added Anthropic-compatible provider support in settings


1. add anthropic-compatible provider via menu


https://github.com/user-attachments/assets/14b33d59-ae08-4215-b05f-9f3896a4a6f2


2. use anthropic-compatible



https://github.com/user-attachments/assets/8bc7f1c5-644e-4528-942e-29150c35fed0

---------

Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
Co-authored-by: Anant Goel <anant@zed.dev>
Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
2026-06-12 03:00:42 +00:00
Richard FeldmanandMikayla Maki 3877fad40a Add Claude Fable 5 to Anthropic BYOK (#58945)
<img width="325" height="201" alt="Screenshot 2026-06-09 at 1 38 32 PM"
src="https://github.com/user-attachments/assets/a6518073-1e17-41ff-a8fc-cb279fcd4436"
/>

Adds support for Anthropic's Claude Fable 5 model when using your own
Anthropic API key. Because Fable 5 cannot be offered under Zero Data
Retention (Anthropic retains inference logs for 30 days), this gates the
model behind an explicit data-retention consent: a new
telemetry.anthropic_retention setting (default off, surfaced in the
Privacy section of the settings UI), and a hard, non-retryable check in
the cloud completion path that raises a typed error when consent is
missing.

When Fable 5 declines a request, it transparently falls back to Claude
Opus 4.8 (matching Anthropic's server-side behavior), and the agent
panel shows a callout for the consent error with "Switch to Opus 4.8" /
"Accept" actions that resume the failed turn so the user's message
continues without retyping.

Closes AI-382

Release Notes:

- Add Claude Fable 5 to Anthropic BYOK

---------

Co-authored-by: Mikayla Maki <mikayla@zed.dev>
2026-06-09 17:53:59 +00:00
Aurabindo Pillai d524bc9a78 language_models: Support custom HTTP headers for provider requests (#55246)
Add a `custom_headers` setting to each HTTP-based language model
provider
(Anthropic, Bedrock, DeepSeek, Google, LM Studio, Mistral, Ollama,
OpenAI,
OpenAI-compatible, OpenCode, OpenRouter, Vercel AI Gateway, and xAI) so
users
can attach extra headers to every outgoing request. Headers managed by
Zed
(authentication, content-type, etc.) cannot be overridden and are
skipped with
a warning.

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)
- [] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Added support for configuring custom HTTP headers on language model
  providers via `language_models.<provider>.custom_headers`.

Signed-off-by: Aurabindo Pillai <mail@aurabindo.in>
2026-06-02 13:29:23 +00:00
Marshall Bowers 59b7620c20 anthropic: Fix serialized representation of Effort::XHigh (#57985)
This PR fixes the serialized representation of the `Effort::XHigh`
variant, as it should be `xhigh`, not `x_high`.


https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking#adaptive-thinking-with-the-effort-parameter

Release Notes:

- Fixed using `xhigh` thinking effort with Anthropic models.
2026-05-28 18:20:11 +00:00
Richard Feldman ab59e61f3e Add Claude Opus 4.8 support (#57984)
<img width="627" height="752" alt="Screenshot 2026-05-28 at 1 20 22 PM"
src="https://github.com/user-attachments/assets/0a7825f0-73c5-49e9-b59a-83924a45de98"
/>

Adds Claude Opus 4.8 for BYOK providers, including Anthropic fast-mode
handling and Bedrock/OpenCode model definitions.

Closes AI-336

Release Notes:

- Added Claude Opus 4.8 BYOK support
2026-05-28 17:45:54 +00:00
Tom Houlé 9b3457fff5 anthropic: Pass beta header for speed in BYOK (#57707)
We were sending the `speed` field set to `"standard"` for BYOK Anthropic
but without the corresponding beta header. leading the requests to fail
with "invalid request format to Anthropic's API: speed: Extra inputs are
not permitted".

This makes sure to attach the beta header whenever the `speed` parameter
is used.

Release Notes:

- Fixed "speed: Extra inputs are not permitted" errors for Opus 4.6 and
4.7 in the Anthropic API provider.
2026-05-26 09:00:33 +00:00
David Wu 076d63af7f agent: Add Opus 4.7 speed support (#56701)
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:

- N/A
2026-05-15 13:57:33 +00:00
Bennet Bo Fenner 7fc0b5ac66 copilot: Fix cache control error (#56632)
#56472 broke Copilot chat

> Failed to connect to API: 400 Bad Request {"message":"cache_control:
Extra inputs are not permitted"}

This PR makes it so that we still use the legacy caching approach for
Copilot

Release Notes:

- N/A
2026-05-13 13:34:47 +00:00
Richard FeldmanandMartin Ye cbb6e6737f anthropic: Use automatic prompt caching with long-lived anchors on tools and system (#56472)
Switches the Anthropic provider from hand-stamping `cache_control` onto
the last message content block over to Anthropic's top-level automatic
prompt caching, paired with explicit long-TTL (1h) anchors on the last
tool definition and on the system prompt.

The prefix order `tools` → `system` → `messages` satisfies Anthropic's
requirement that longer TTLs appear earlier in the prefix, so the static
prefix is cached for 1h (surviving idle gaps longer than the 5-minute
default) while the rapidly-changing conversation tail uses the
free-to-refresh 5-minute TTL via the top-level automatic breakpoint.
Three of the four available cache breakpoints are used (last tool,
system, automatic conversation), leaving one in reserve.

As a side benefit, this fixes a latent issue where the previous stamping
loop could place `cache_control` on a `Thinking` content block, which
the Anthropic API does not allow. Automatic caching is documented to
walk past ineligible blocks (including thinking) when selecting its
breakpoint, so we now delegate that responsibility to the server.

The new shape we send (when caching is enabled):

```json
{
  "tools": [{ "...": "...", "cache_control": {"type": "ephemeral", "ttl": "1h"} }],
  "system": [
    {"type": "text", "text": "...", "cache_control": {"type": "ephemeral", "ttl": "1h"}}
  ],
  "messages": [ /* no per-block cache_control */ ],
  "cache_control": {"type": "ephemeral"}
}
```

Release Notes:

- Improved Anthropic prompt cache utilization, reducing latency and cost
for ongoing conversations

---------

Co-authored-by: Martin Ye <martinye022@gmail.com>
2026-05-12 21:09:39 +00:00
Bennet Bo FennerandBen Brandt 18c68d2fc9 anthropic: Dynamically fetch models from /models (#56397)
Most compelling reason to make this change is that we don't have to ship
a new Zed binary if Anthropic releases a new model

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:

- anthropic: Dynamically fetch available models from Anthropic API

---------

Co-authored-by: Ben Brandt <benjamin.j.brandt@gmail.com>
2026-05-11 13:19:20 +00:00
Bennet Bo Fenner 6e8b8b2fbd agent: Allow tools to output multiple content parts (#54518)
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

Closes #ISSUE

Release Notes:

- N/A
2026-04-27 12:36:11 +00:00
Finn EversandDanilo Leal c49ffd1e88 Fix bad GitHub merge queue merge (#54721)
No, sadly, the title is not a typo. See
https://www.githubstatus.com/incidents/zsg1lk7w13cf for the context.
I'll read with joy and popcorn through that root cause analysis.

It makes literally zero sense what happened here, but for some completly
bonkers reason GitHub completely messed up the merge queue with
https://github.com/zed-industries/zed/pull/54632.

I have no idea how it happened. It makes literally zero sense. A PR
going into the merge queue should have the same LoC when getting out of
it. GitHub obviously does not check this. GitHub causes extra work with
a feature that is supposed to save time.

Thanks, I guess.

Release Notes:

- N/A

---------

Co-authored-by: Danilo Leal <daniloleal09@gmail.com>
2026-04-23 23:47:30 +00:00
Danilo Leal 184e1d93e3 branch_picker: Add button to filter remote branches (#54632)
This PR brings back the button to filter remote branches when accessing
the title bar's branch picker with the mouse. It was unintentionally
removed when we introduced the new worktree picker.

Release Notes:

- N/A
2026-04-23 18:26:44 +00:00
Eric Holk 86d625784b Request summarized thinking for Claude Opus 4.7 (#54217)
Starting with Claude Opus 4.7, Anthropic omits thinking content from
responses by default; callers must pass `display: "summarized"` to keep
seeing thinking summaries. Without opting in, the agent UI shows a long
pause with no visible thinking, and users get no progress indication
during extended reasoning.

This extends the adaptive-thinking wire type with an optional `display`
field and requests `Summarized` from every call site that builds an
adaptive thinking request (direct Anthropic, Copilot Chat proxy, Zed
Cloud, and Bedrock).

## Notes

- Applied at the adaptive-thinking layer rather than special-casing Opus
4.7. The `display` parameter is accepted by every
adaptive-thinking-capable model, and the previous behavior (visible
summaries) is what users already see on Opus 4.6 / Sonnet 4.6, so there
is no behavior change for those models.

Release Notes:

- Restored thinking summaries for Claude Opus 4.7.
2026-04-23 15:43:02 +00:00
Ben Brandt 91c6fd2b7d language_models: Remove unused language model token counting (#54177)
Drop the `count_tokens` API and related implementations across
providers, and remove the unused `tiktoken-rs` dependency.

I was going to update the dependency becuase they finally released a fix
we needed. But then I realized we only used this api in one place, the
Rules library. And for most models it would have been wildly incorrect
becuase we use tiktoken, i.e. OpenAI tokenizers, for almost every model,
which is going to give incorrect results.

Given that, I just removed these because the difference in how we get
these has caused plenty of confusion in the past.

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:

- N/A
2026-04-22 13:39:48 +00:00
Richard Feldman 3cc50f53b6 Add Claude Opus 4.7 BYOK (#54077)
<img width="767" height="428" alt="Screenshot 2026-04-16 at 11 29 13 AM"
src="https://github.com/user-attachments/assets/e8b450fa-aefc-4dec-a286-b211bd492011"
/>

Add Claude Opus 4.7 (`claude-opus-4-7`) to the anthropic, bedrock, and
opencode provider crates.

Key specs:
- 1M token context window
- 128k max output tokens
- Adaptive thinking support
- AWS Bedrock cross-region inference (global, US, EU, AU)

Release Notes:

- Added Claude Opus 4.7 as an available language model
2026-04-17 10:51:32 -04:00
Enochandcopilot-swe-agent[bot] 9290ddf8fc anthropic: Preserve custom model thinking mode after thinking-toggle refactor (#52975)
PR #51946 broke `Model::Custom` thinking behavior: `mode()`,
`supports_thinking()`, and `supports_adaptive_thinking()` all inferred
capabilities from hardcoded built-in model lists, so any `Custom`
variant always fell back to `Default` regardless of its configured
`mode` field.

### Fixes

- **`Model::mode()`** — `Custom` now short-circuits to `mode.clone()`
before the built-in inference logic
- **`Model::supports_thinking()`** — `Custom` returns `true` when `mode`
is `Thinking { .. }` or `AdaptiveThinking`
- **`Model::supports_adaptive_thinking()`** — `Custom` returns `true`
when `mode` is `AdaptiveThinking`

Built-in model behavior is unchanged.

### Tests

Three regression tests added covering the three `Custom` mode cases:
explicit `Thinking`, `AdaptiveThinking`, and `Default` (which must
disable both flags).

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] 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 custom Anthropic models losing their configured
thinking/adaptive-thinking mode after the thinking-toggle refactor
(#51946)

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-04-14 12:06:17 +03:00
Danilo Leal 367f4f77cf docs: Update mentions to "assistant panel" (#53514)
We don't use this terminology anymore; now it's "agent panel".

Release Notes:

- N/A
2026-04-09 10:42:21 -03:00
Agus ZubiagaandJohn Tur 8edaf7f69c language_models: Refactor deps and extract cloud (#53270)
- `language_model` no longer depends on provider-specific crates such as
`anthropic` and `open_ai` (inverted dependency)
- `language_model_core` was extracted from `language_model` which
contains the types for the provider-specific crates to convert to/from.
- `gpui::SharedString` has been extracted into its own crate (still
exposed by `gpui`), so `language_model_core` and provider API crates
don't have to depend on `gpui`.
- Removes some unnecessary `&'static str` | `SharedString` -> `String`
-> `SharedString` conversions across the codebase.
- Extracts the core logic of the cloud `LanguageModelProvider` into its
own crate with simpler dependencies.


Release Notes:

- N/A

---------

Co-authored-by: John Tur <john-tur@outlook.com>
2026-04-07 12:28:19 -03:00
Richard Feldman 08647a542a Remove deprecated 1M context beta header for Sonnet 4.5 (#52767)
The `CONTEXT_1M_BETA_HEADER` (`context-1m-2025-08-07`) is deprecated for
Sonnet 4 and 4.5. This removes the constant from the anthropic crate and
the match arm in `beta_headers()` that sent it for
`ClaudeSonnet4_5_1mContext`.

Note: The bedrock crate still has its own copy of this constant, used
when the user-configurable `allow_extended_context` setting is enabled.
That may warrant a separate cleanup.

Closes AI-114

Release Notes:

- N/A
2026-03-31 10:54:52 -04:00
John Tur 59467e05f0 Remove settings dependency from anthropic (#51979)
Release Notes:

- N/A
-
2026-03-19 19:48:30 -04:00
Bennet Bo FennerandMarshall Bowers d388994829 anthropic: Add support for thinking toggle (#51946)
This adds support for the thinking toggle + reasoning effort for the
Anthropic provider

Release Notes:

- anthropic: Added support for selecting reasoning effort

---------

Co-authored-by: Marshall Bowers <git@maxdeviant.com>
2026-03-19 17:43:06 +01:00
Mikayla Maki 0b6e7387a3 Update BYOK to 1m context windows (#51625)
Before you mark this PR as ready for review, make sure that you have:
- [x] Added a solid test coverage and/or screenshots from doing manual
testing
- [x] Done a self-review taking into account security and performance
aspects
- [x] Aligned any UI changes with the [UI
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

Release Notes:

- Updated our BYOK integration to support the new 1M context windows for
Opus and Sonnet.
2026-03-16 09:10:01 -07:00
Piotr Osiewicz 4d70e3b436 Remove unreferenced dev dependencies (#51093)
This will help with test times (in some cases), as nextest cannot figure
out whether a given rdep is actually an alive edge of the build graph

Closes #ISSUE

Before you mark this PR as ready for review, make sure that you have:
- [ ] Added a solid test coverage and/or screenshots from doing manual
testing
- [ ] Done a self-review taking into account security and performance
aspects
- [ ] Aligned any UI changes with the [UI
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

Release Notes:

- N/A
2026-03-09 13:22:12 +01:00
John Tur 938c8870e4 Enable extended reasoning for Anthropic models in Copilot (#46540)
Fixes https://github.com/zed-industries/zed/issues/45668

https://github.com/microsoft/vscode-copilot-chat used as a reference for
headers and properties we need to set

| Before | After | 
| --- | --- |
| <img width="300"
src="https://github.com/user-attachments/assets/d112a9ef-52d2-42ff-a77b-4b4b15f950fe"
/>| <img width="300"
src="https://github.com/user-attachments/assets/0f1d7ae0-bee1-46f7-92ef-aea0fa6cde7a"
/> |

Release Notes:

- Enabled thinking mode when using Anthropic models with Copilot
2026-03-08 09:34:46 +00:00
Tom Houlé 881d167340 Add fast mode toggle in agent panel (#49714)
This is a staff only toggle for now, since the consequences of
activating it are not obvious and quite dire (tokens costs 6 times
more).

Also, persist thinking, thinking effort and fast mode in DbThread so the
thinking mode toggle and thinking effort are persisted.

Release Notes:

- Agent: The thinking mode toggle and thinking effort are now persisted
when selecting a thread from history.
2026-02-26 21:19:41 +01:00
Bennet Bo FennerandZed Zippy 9eb452a692 agent: Implement streaming for edit file tool (#50004)
Before you mark this PR as ready for review, make sure that you have:
- [x] Added a solid test coverage and/or screenshots from doing manual
testing
- [x] Done a self-review taking into account security and performance
aspects
- [x] Aligned any UI changes with the [UI
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

Release Notes:

- N/A

---------

Co-authored-by: Zed Zippy <234243425+zed-zippy[bot]@users.noreply.github.com>
2026-02-25 22:58:25 +00:00
Raphael LüthyandBen Brandt 1396cb9463 anthropic: Support alternative provider SSE formatting (#47847)
The issue I ran into was that responses from anthropic compatible
providers, like Kimi for Coding, have no space after `data:`. This
change just adds a quick check to also allow for those providers to
work.

Before it just resolved but did not show any output:
<img width="50%" alt="CleanShot 2026-01-28 at 12 50 31@2x"
src="https://github.com/user-attachments/assets/c3c8fe27-348e-4b21-a5f1-25bcc82f3774"
width=50%/>

Now it returns the proper result:
<img width="50%" alt="CleanShot 2026-01-28 at 12 56 30@2x"
src="https://github.com/user-attachments/assets/4e524c1e-78ab-4956-bd65-a919d46adc59"
width=50%/>

Normal Anthropic models still work as expected:
<img width="50%" alt="CleanShot 2026-01-28 at 12 58 37@2x"
src="https://github.com/user-attachments/assets/5a2906aa-1183-45b6-939b-01a6830f3385"
/>

Config to test
```json
 "language_models": {
    "anthropic": {
      "api_url": "https://api.kimi.com/coding",
      "available_models": [
          {
            "name": "kimi-for-coding",
            "display_name": "Kimi 2.5 Coding",
            "max_tokens": 262144,
            "max_output_tokens": 32768,
          },
      ],
    },
}
```


TLDR:
- Accepts SSE data:{...} lines (no space) emitted by some alternative
Anthropic providers, in addition to the standard data: {...} format.

Release Notes:

- Fixed Anthropic streaming for alternative providers by accepting SSE data:{...} (no space) lines.

---------

Co-authored-by: Ben Brandt <benjamin.j.brandt@gmail.com>
2026-02-20 09:47:00 +00:00
Ben Brandt a3606082ec anthropic: Remove deprecated models (#49522)
Release Notes:

- anthropic: Removed models that have been deprecated from their API.
2026-02-18 20:19:38 +00:00
Richard Feldman 3baac2b00b Add support for Claude Sonnet 4.6 (#49386)
<img width="435" height="211" alt="Screenshot 2026-02-17 at 1 32 48 PM"
src="https://github.com/user-attachments/assets/136c188d-5001-4526-961e-9f7faccc5f7a"
/>


Add support for the new Claude Sonnet 4.6 model across the anthropic,
bedrock, and language_models crates. Includes base, thinking, and 1M
context variants.

Closes AI-39

Release Notes:

- Added BYOK support for Claude Sonnet 4.6
2026-02-17 18:45:12 +00:00