Skip to content

The Anthropic provider sends a gateway what it sends Anthropic, and the docs say what LiteLLM needs to pass it on - #1263

Merged
misterjohannesson merged 2 commits into
development-2026-11-28-2from
fix/1048-anthropic-gateway-fields
Nov 28, 2026
Merged

misterjohannesson merged 2 commits into
development-2026-11-28-2from
fix/1048-anthropic-gateway-fields

Conversation

@misterjohannesson

Copy link
Copy Markdown
Contributor

Closes #1048.

What was there

Three unchecked claims about apps/troupe_core/lib/troupe/llm/providers/anthropic.ex behind a gateway that speaks Anthropic's Messages API: whether cache_control (D65), output_config (D69) and anthropic-beta, carried into Bedrock's anthropic_beta body field (D92), survive LiteLLM or another such gateway.

What was found

Troupe's side: checked, nothing dropped. Nothing in the provider depends on base_url except which key may go there. A new test (apps/troupe_core/test/troupe/llm/anthropic_gateway_test.exs) points the provider at a stand-in gateway on a real loopback socket, at the proxy root (LiteLLM's /v1/messages, bearer) and at /anthropic (LiteLLM's pass-through, x-api-key). It asserts that the cache marks (last tool, system prompt before the task list, last block of the last two user messages), output_config: {effort: high} with thinking: {type: adaptive, display: summarized, block_binding: {prefix_mismatch_behavior: drop_block}}, the signed thinking block, and the header anthropic-beta: thinking-binding-controls-2026-08-01 all reach the wire as the provider sends them to Anthropic. These tests pass before the change, because nothing is dropped. They go in as the check the issue asks for. To confirm they catch a drop, I emptied binding_header/1 for one run: 2 of the 4 failed on anthropic-beta. The provider is unchanged.

LiteLLM's side, read at BerriAI/litellm@ccb97776b1 (main, 2026-11-28):

  • /anthropic pass-through forwards the body unchanged and the caller's headers apart from LiteLLM's own secrets. Its "What Does NOT Change" list starts with "Request body" (architecture.md). The route is "/anthropic/{endpoint:path}" (llm_passthrough_endpoints.py#L1492-L1497), and its headers come from caller_headers_without_litellm_secrets(...) (#L3561-L3587).
  • At /v1/messages, the proxy copies ANTHROPIC_API_HEADERS = {"anthropic-version", "anthropic-beta"} (types/llms/anthropic.py#L863-L866) into a ProviderSpecificHeader for anthropic, bedrock, bedrock_mantle, vertex_ai (litellm_pre_call_utils.py#L5013-L5019, #L5039-L5066).
  • The Bedrock Invoke messages transform reads the caller's betas with user_beta_set: Final = set(get_anthropic_beta_from_headers(headers)), filters them through filter_and_transform_beta_headers, and writes what is left as anthropic_messages_request["anthropic_beta"] = filtered_betas (anthropic_claude_transformation.py#L548, #L603-L626, #L815-L816). A beta with no entry is dropped, with the warning "dropping unsupported anthropic-beta values".
  • The filter's bedrock column maps "thinking-binding-controls-2026-08-01": "thinking-binding-controls-2026-08-01" (anthropic_beta_headers_config.json#L229). The entry came in with BerriAI/litellm#41203, merged 2026-09-18. Its commit message says the header was dropped before, "so Bedrock and Vertex reject the request with 'thinking.adaptive.block_binding: Extra inputs are not permitted'". I compared against tags: v1.102.1 has no entry and v1.103.0 (2026-09-28) is the first release with it. On that release, thinking.block_binding is stripped only where no active beta unlocks it (anthropic_beta_gated_fields.py#L47, #L71-L73).
  • cache_control on Bedrock: only scope and an unsupported ttl are removed (#L171-L210). Troupe sends {type: ephemeral} alone, so its marks pass.
  • output_config on Bedrock is on the Invoke allowlist (output_config: dict, types/llms/bedrock.py#L1242-L1284). An effort above the model's ceiling is lowered by normalize_bedrock_opus_output_config_effort (#L789-L796). It is dropped only when litellm.drop_params is True and the model is not one LiteLLM lists as taking an effort (#L844-L855).
  • Noticed in passing: LiteLLM's /v1/messages does not pass Anthropic's metadata on (# TODO: Add Anthropic \metadata` support, [anthropic/messages/native/transformation.py#L157](https://github.com/BerriAI/litellm/blob/ccb97776b12b23392c77c0837d471b6dbcb3f5bd/litellm/llms/anthropic/messages/native/transformation.py#L157)). The session owner's user_id` therefore stops at the gateway.

What changed

  • apps/troupe_core/test/troupe/llm/anthropic_gateway_test.exs: the check described above (4 tests).
  • docs/admin/integrations.md §5 now has a bullet on what anthropic sends a gateway. It covers both LiteLLM routes, the Bedrock beta-to-anthropic_beta path and the minimum version for the thinking-binding beta (v1.103.0). Behind an older proxy, thinking_binding must stay at default. It also covers litellm_settings.drop_params: true and output_config, and that metadata is not passed on.
  • docs/user/configuration/providers.md: the Anthropic-gateway paragraph says where a LiteLLM proxy takes the call and links to the admin section.

No provider change. LiteLLM needs no header or body shape that Troupe does not send. The one condition, the proxy version when thinking_binding is set, is a gateway setting, so it is documented rather than worked around.

Verified

Root wslx env KUBECONFIG=<empty file> mix check, run before the merge of the chunk branch:

credo: 21500 mods/funs, found no issues.
boundaries ok: 4 app rule(s), 0 module rule(s), no violations
troupe_protocol: 325 passed (2 doctests, 323 tests)
troupe_operator: Result: 193 passed, 78 excluded
troupe_plane:    Result: 1606 passed, 9 excluded
troupe_core:     Result: 2019/2031 passed (13/13 doctests, 3/3 properties, 2003/2015 tests)
troupe_gateway:  Result: 437 passed (2 properties, 435 tests), 2 skipped
troupe_worker:   Result: 359 passed
troupe_daemon:   Result: 32 passed
troupe_a2a:      Result: 53 passed

The 12 core failures are the known WSL rg-shim ones: FileToolsTest grep/list_files ×6, ReadRootsTest, ReadOutputTest, PathOnlyLookupTest, BenchTest ×2 and DoctorTest's bench line. None is in llm/.

After merging development-2026-11-28-2, the following still pass:

  • mix test test/troupe/llm: Result: 194 passed (13 doctests, 181 tests).
  • mix credo --strict: 21521 mods/funs, found no issues.
  • mix format --check-formatted: clean.
  • decision-citations: "3 file(s) changed ..., none adds a decision number to code".
  • doc-size: "765 Markdown files, none past 400 lines".
  • doc-links: "1171 links in 765 files".
  • mkdocs build --strict: built.

Decisions

Read: mix troupe.decisions --for apps/troupe_core/lib/troupe/llm/providers/anthropic.ex. The ones that bear on this: 770 (cache marks), 805/815/863 (thinking kept, binding beta, mismatch header) and 787 (metadata). None is changed. None was taken: no behaviour changes, so this is a check and a doc.

Left

  • Not tried against a live LiteLLM or Bedrock; the brief says fakes only. The LiteLLM behaviour above is from its source at the commit named.
  • LiteLLM releases before v1.103.0 were checked only for the thinking-binding entry. I did not walk their cache_control or output_config handling.

…hropic

A loopback stand-in for LiteLLM's /v1/messages and /anthropic routes
asserts that the cache_control marks, adaptive thinking's output_config
and the thinking-binding anthropic-beta header reach the gateway as the
provider sends them direct. Nothing was dropped on Troupe's side.

The admin page says what LiteLLM does with them: the pass-through
forwards body and headers unchanged; /v1/messages carries the beta to
Bedrock as anthropic_beta, the thinking-binding beta from LiteLLM
v1.103.0, so an older proxy needs thinking_binding left at default; and
drop_params can drop output_config for a model it lists without effort.

Signed-off-by: Martin Johannesson <martin.johannesson@it-minds.dk>
Signed-off-by: Martin Johannesson <martin.johannesson@it-minds.dk>
@misterjohannesson
misterjohannesson merged commit 1761630 into development-2026-11-28-2 Nov 28, 2026
14 checks passed
@misterjohannesson
misterjohannesson deleted the fix/1048-anthropic-gateway-fields branch November 28, 2026 17:10
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