Skip to content

feat(anthropic): server-side fallback request side (July beta, default, Claude API only) - #4690

Merged
aheritier merged 7 commits into
mainfrom
feat/claude5x-fallback-request
Oct 22, 2026
Merged

aheritier merged 7 commits into
mainfrom
feat/claude5x-fallback-request

Conversation

@aheritier

@aheritier aheritier commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #4584 (PR 1 of 3). Part of epic #4580.

What

The request side of Claude API server-side fallback. fallbacks now accepts default or a list of up to three models. It is sent with the July beta, only where the API supports it, and validated at startup. The temporary Claude 5.x block stays: 5.x chains are still rejected until PR 2 (stream and continuation) and PR 3 (per-attempt billing) land.

Commit Change
feat(anthropic): parse and validate server-side fallbacks fallbacks: default, or a list of at most three distinct models, none equal to the primary. Claude Haiku 5.5 (new NoServerSideFallback in the model table): a list is rejected, default logs that it has no effect. The Claude 5.x block still rejects Haiku first, so these rules take effect in PR 3
refactor(anthropic): read fallbacks through one parser The four readers (request, thinking_display, cache_preserving_updates, thinking binding) and the 5.x block all go through parseFallbacks. With default the server picks the targets, so per-model checks validate the primary only
feat: allow server-side fallback only on the Claude API A non-empty fallbacks is rejected at construction on Vertex AI, on Bedrock (silently ignored until now), behind a gateway, or with a base URL whose host isn't api.anthropic.com
feat(anthropic): send server-side fallbacks with the July beta server-side-fallback-2026-07-01 with the typed fallbacks param. Any request with fallbacks goes through the beta Messages API, whose types carry the fallback content block that PR 2 needs
docs(anthropic): document July server-side fallbacks Provider docs, schema description, example with both forms
fix(anthropic): tighten server-side fallback validation Review fixes: ANTHROPIC_BASE_URL (which the SDK uses when base_url is unset) passes the same host check; case-insensitive host; the 5.x block runs first so Haiku 5.5 gets one accurate error; docs say default checks per-model options against the primary only
fix(anthropic): keep the request shape when fallbacks route to beta From Copilot's review: the beta path now forwards temperature/top_p as the standard path does (thinking off, model accepts them), and honors an explicit interleaved_thinking: false

Behavior changes

  • Errors at startup instead of silent ignoring: a malformed fallbacks value (not default, not a list of model IDs, more than three entries, duplicates, or the primary model itself) used to be ignored silently. It now fails client construction.
  • fallbacks on Bedrock used to be ignored silently; now it's an error.
  • Claude 5.x block: fallbacks: default on a Claude 5.x model now hits the temporary block. The old list-only reader let it through, unsent.
  • Header: June lists keep working. They're now sent under the July header, which accepts lists.
  • Beta path: any config with fallbacks now uses the beta Messages API (?beta=true). Little changes in practice: interleaved_thinking, auto-enabled whenever thinking is on, already routes most Anthropic requests there.
  • ANTHROPIC_BASE_URL: with fallbacks, it must point at api.anthropic.com.
  • Sampling on beta-routed requests: temperature and top_p are now sent on every beta-routed request without thinking, including structured output and task budgets, where they used to be dropped silently.

Why the July header only

The July header accepts both forms, so June configs keep working with no client-side branch. Under July the API itself converts a Sonnet 5.5 between_tools request falling back to Sonnet 5: the fallback attempt runs with thinking disabled. #4584 asks for exactly that conversion, so the client has nothing to rewrite.

Tests

Test Pins
TestParseFallbacks, TestValidateFallbackSpec Accepted and rejected values; the self-reference and Haiku 5.5 rules
TestNewClient_RejectsMalformedFallbacks Malformed values fail at construction
TestNewClient_FallbacksOnlyOnClaudeAPI, TestNewClient_FallbacksCheckEnvBaseURL, Vertex and Bedrock TestNewClient_RejectsFallbacks Host restriction, for both forms and for ANTHROPIC_BASE_URL
TestServerSideFallbackRequests (pkg/model/provider/providers, request capture through the real factory) Beta path (?beta=true), July header, "fallbacks":"default" and [{"model":…}], nothing without the option. Sending the June header makes both cases fail
One default case per reader Primary-only validation

Not added, and why

  • Per-entry overrides (max_tokens, thinking, output_config, speed per fallback): not needed for feat(Claude): end-to-end server fallback for Claude 5.x #4584; a non-string entry is rejected rather than half-supported.
  • Stream handling, continuation and billing: PR 2 and PR 3. Until then, 5.x chains stay blocked.

References

Rule Documentation
"The beta header must carry exactly the date 2026-07-01, which supports both "default" and the explicit-list form, or 2026-06-01, which accepts only the explicit-list form" Refusals and fallback: server-side fallback
"A list of up to three models … Each must be distinct from the other entries and from the requested model"; the Sonnet 5.5 between_tools conversion under July Naming your own fallback models
"In beta on the Claude API … not available on Amazon Bedrock, Google Cloud, or Microsoft Foundry"; "Claude Haiku 5.5 has no server-side fallback: with fallbacks: "default", a declined request stays declined, and a list of fallback models returns a 400 error" Refusals and fallback: server-side fallback

Validation

  • task build passes.

  • task test passes.

  • golangci-lint v2.14.0 reports 0 issues, and go run ./lint . reports no offenses.

  • go test -race -shuffle=on ./pkg/model/provider/... passes.

  • An independent review found no critical issues and two important ones, both fixed here:

    • ANTHROPIC_BASE_URL bypassed the host check;
    • the Haiku 5.5 rules were unreachable behind the 5.x block, with misleading docs and hint.

    Also fixed: a stale comment and dead test case, the host case, and docs on default validation. Deferred: the Haiku default warning has no request context (validation runs without one).


This is part 1 of 2 in a stack made with GitButler:

@aheritier
aheritier requested a review from a team as a code owner October 21, 2026 16:35
Copilot AI balanced review requested due to automatic review settings October 21, 2026 16:35
@aheritier
aheritier enabled auto-merge October 21, 2026 16:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Beta routing drops configured sampling settings and overrides explicit interleaved-thinking opt-outs for existing fallback chains.

2 open issues
What changed in this PR

Adds July-beta server-side fallback requests for the Claude API while retaining the temporary Claude 5.x restriction.

Changes:

  • Supports default or up to three validated fallback models.
  • Restricts fallbacks to the Claude API and routes requests through beta Messages.
  • Updates documentation, examples, and validation/request tests.
File Description
pkg/​modelinfo/​claude5.go Records Haiku fallback limitations.
pkg/​modelinfo/​claude5_test.go Tests updated model metadata.
pkg/​model/​provider/​providerutil/​provider_opts.go Adds non-empty option detection.
pkg/​model/​provider/​providerutil/​provider_opts_test.go Tests option detection.
pkg/​model/​provider/​providers/​fallback_requests_test.go Checks fallback payloads and beta routing.
pkg/​model/​provider/​providers/​claude5_requests_test.go Captures request query parameters.
pkg/​model/​provider/​bedrock/​client.go Rejects Bedrock fallbacks.
pkg/​model/​provider/​bedrock/​client_test.go Tests Bedrock rejection.
pkg/​model/​provider/​anthropic/​vertex/​vertex.go Rejects Vertex fallbacks.
pkg/​model/​provider/​anthropic/​vertex/​vertex_test.go Tests Vertex rejection.
pkg/​model/​provider/​anthropic/​thinking.go Uses shared fallback parsing.
pkg/​model/​provider/​anthropic/​thinking_test.go Tests primary-only default validation.
pkg/​model/​provider/​anthropic/​thinking_binding.go Integrates validation and shared parsing.
pkg/​model/​provider/​anthropic/​thinking_binding_test.go Tests default fallback binding behavior.
pkg/​model/​provider/​anthropic/​fallbacks.go Implements parsing, validation, and July parameters.
pkg/​model/​provider/​anthropic/​fallbacks_test.go Tests fallback rules and endpoint restrictions.
pkg/​model/​provider/​anthropic/​conversation_updates.go Uses parsed fallback targets.
pkg/​model/​provider/​anthropic/​conversation_updates_test.go Tests default fallback validation.
pkg/​model/​provider/​anthropic/​client.go Validates hosts and selects beta routing.
pkg/​model/​provider/​anthropic/​beta_client.go Sends typed July fallback parameters.
examples/​anthropic-fallbacks.yaml Demonstrates both fallback forms.
docs/​providers/​anthropic/​index.md Documents support and restrictions.
agent-schema.json Updates fallback option documentation.

Review effort: Balanced

Comment thread pkg/model/provider/anthropic/client.go
Comment thread pkg/model/provider/anthropic/client.go
@aheritier aheritier added area/providers For features/issues/fixes related to LLM providers (Bedrock, LiteLLM, Qwen, custom, etc.) area/providers/anthropic For features/issues/fixes related to the usage of Anthropic models area/providers/bedrock AWS Bedrock provider support kind/feat PR adds a new feature (maps to feat:). Use on PRs only. labels Oct 21, 2026
fallbacks accepts "default" or a list of at most three distinct models,
none equal to the requested model. Claude Haiku 5.5 has no server-side
fallback: a list is rejected and "default" only warns. Malformed values,
silently ignored until now, fail at client construction.

Signed-off-by: Arnaud Héritier <aheritier@apache.org>
Every reader of the fallbacks option now understands "default". Its
targets are picked by the server, so per-model checks validate the
primary only, and the temporary Claude 5.x block now also catches
"default" on a 5.x model.

Signed-off-by: Arnaud Héritier <aheritier@apache.org>
The fallbacks parameter is a Claude API beta: Bedrock, Google Cloud and
proxies don't support it. Reject a non-empty fallbacks at construction
on Vertex AI, Bedrock, a gateway, or a base_url other than
api.anthropic.com, instead of sending or silently ignoring it.

Signed-off-by: Arnaud Héritier <aheritier@apache.org>
Send fallbacks as "default" or a list of models under
server-side-fallback-2026-07-01, which accepts both forms; June lists
keep working unchanged. Requests with fallbacks go through the beta
Messages API, whose types carry the fallback content block.

Signed-off-by: Arnaud Héritier <aheritier@apache.org>
Cover fallbacks: default and lists of up to three models, the July beta,
the Claude API-only restriction and the Haiku 5.5 rules, in the provider
docs, the schema description and the example.

Signed-off-by: Arnaud Héritier <aheritier@apache.org>
- Check ANTHROPIC_BASE_URL, which the SDK uses when base_url is unset,
  and compare the host case-insensitively.
- Run the temporary Claude 5.x block before the fallback rules, so a
  Haiku 5.5 config gets one accurate error instead of a misleading
  warning and hint.
- Document that default checks per-model options against the primary
  only.

Signed-off-by: Arnaud Héritier <aheritier@apache.org>
Fallbacks send every request through the beta Messages API, which never
forwarded temperature and top_p and always enabled interleaved thinking.
Forward sampling settings as the standard path does (thinking off, model
accepts them) and honor an explicit interleaved_thinking: false. This
also fixes sampling settings on other beta-routed requests, such as
structured output.

Signed-off-by: Arnaud Héritier <aheritier@apache.org>
@aheritier
aheritier force-pushed the feat/claude5x-fallback-request branch from 9d45dc7 to e274805 Compare October 21, 2026 20:03
@aheritier
aheritier added this pull request to the merge queue Oct 22, 2026
Merged via the queue into main with commit d73146b Oct 22, 2026
22 checks passed
@aheritier
aheritier deleted the feat/claude5x-fallback-request branch October 22, 2026 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/providers/anthropic For features/issues/fixes related to the usage of Anthropic models area/providers/bedrock AWS Bedrock provider support area/providers For features/issues/fixes related to LLM providers (Bedrock, LiteLLM, Qwen, custom, etc.) kind/feat PR adds a new feature (maps to feat:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants