Skip to content

fix(ai): stop sending sampling parameters that SDK 2 refuses #5096

Closed

Description

@dan-petty

Problem Description

The Claude client sends temperature and top_p in extra_body (src/devops_cli/ai/client/claude.py:143-156). Anthropic SDK 2.0.0 sends anthropic-version: 2026-10-21 (src/anthropic/_constants.py), and under that API version temperature, top_p and top_k return HTTP 400. So the move to SDK 2 breaks every Claude call at run time. No test catches it, because the tests mock the client and the parameters go in extra_body, outside the types.

pyproject.toml pins anthropic; the baseline (#5065) moves it to 1.17.0, the newest 1.x. The newest is 2.8.0, and Renovate (#4893) will offer it.

Other SDK 2 changes (migration guide https://platform.claude.com/docs/en/api/migration-2026-10-21):

  • API keys go out as Authorization: Bearer in place of X-Api-Key. claude.py:298-315 builds anthropic.Anthropic with api_key and base_url; check the LiteLLM gateway route that the client can use.
  • MessageParam becomes a union of UserMessageParam, AssistantMessageParam and SystemMessageParam; Message.to_param returns AssistantMessageParam; betas is removed from models.retrieve and models.list.
  • fastmcp-slim[anthropic] caps anthropic<2 (the project does not use that extra). pydantic-ai-slim needs anthropic>=1.15.0 (2.68) with no cap; check pydantic-ai AnthropicModel on SDK 2.

Research of 2026-11-12 (research-python, migration anthropic).

Reproduction Steps

  1. Set anthropic==2.8.0 in pyproject.toml and run uv lock.
  2. Run the full test suite: no test fails (the client is mocked).
  3. Make one real Claude call with the client (direct or through the gateway): the API answers HTTP 400 for temperature or top_p.

Expected vs Actual Behavior

Expected: a test at the HTTP seam fails while the client sends a parameter that the pinned API version refuses, and the client sends only accepted parameters.

Actual: the client sends temperature and top_p in extra_body, and only a live call shows the HTTP 400.

Environment Diagnostics

devops-cli main at the merge of #5065; anthropic 1.17.0 locked, 2.8.0 newest; Python 3.14.

Logs, Traces, or Terminal Output

Research run of 2026-11-12: with anthropic 2.8.0, the suite passed; the risk is at run time.

Source: #4893

Alternatives check of 2026-11-15: none.
Tool: none found.

Proposed design

Problem statement

The Claude client puts temperature and top_p in extra_body. Anthropic SDK 2 sends API version 2026-10-21, which returns HTTP 400 for temperature, top_p and top_k. The tests mock the client, so they do not see the request body and do not catch the failure. This change makes the Claude client omit the refused sampling parameters on SDK 2. It adds an HTTP-seam test that fails if a refused parameter is sent.

Acceptance criteria

Requirement: SDK 2 omits refused sampling parameters

The Claude client SHALL omit temperature, top_p and top_k from the Anthropic request body when the installed SDK major version is 2 or later.

Scenario: SDK 2 request body

  • WHEN A test forces the Anthropic SDK 2 path, configures sampling, and captures the request body at the HTTP seam.
  • THEN The captured JSON body has no temperature, top_p or top_k field.

Requirement: HTTP seam rejects refused sampling parameters

The Claude client MUST pass the HTTP-seam test that returns HTTP 400 when the request body holds temperature, top_p or top_k.

Scenario: Refused parameter guard

  • WHEN A test forces the Anthropic SDK 2 path and uses a fake HTTP transport that returns HTTP 400 for temperature, top_p or top_k.
  • THEN The Claude call succeeds and the captured request body has none of those fields.

Requirement: SDK 1 sampling behavior stays

The Claude client SHALL keep sending temperature and top_p when the installed SDK major version is 1.

Scenario: SDK 1 request body

  • WHEN A test uses Anthropic SDK 1.17 and configures temperature and top_p.
  • THEN The captured request body has the configured temperature and top_p values.

Existing Tool Considered

No open, maintained tool or library covers the need. The alternatives check considered anthropic, pydantic-ai, LiteLLM and anthropic-sdk-python. The SDK causes the HTTP 400. The gateway and pydantic-ai sit above the API. None strips the client's extra_body or adds the HTTP-seam test. The fix stays in src/devops_cli/ai/client/claude.py and its tests.

Key questions

  • Where does the Claude client send the sampling parameters?: The client puts temperature and top_p in extra_body in src/devops_cli/ai/client/claude.py:143-156. [sources: src/devops_cli/ai/client/claude.py:143-156]
  • How should the Claude client stop sending refused sampling parameters?: Gate on the installed Anthropic SDK major version. Use importlib.metadata.version("anthropic") and set send_sampling to false when the major is 2 or later. Keep the SDK 1.x path. (best practice) [sources: src/devops_cli/ai/client/claude.py:143-156, pyproject.toml]
    • Chosen: Gate on the Anthropic SDK major version. SDK 2 sends the API version that refuses the fields, and SDK 1.17 keeps the current behavior.
    • Rejected: Remove sampling parameters for all SDK versions. This drops a working setting for the pinned SDK 1.17 and changes more than the issue asks.
    • Rejected: Keep extra_body and rely on the API error. This breaks every Claude call on SDK 2 at run time.
  • What test proves the fix at the HTTP seam?: Add an offline test with a fake HTTP transport that returns HTTP 400 when temperature, top_p or top_k is present. Force the SDK 2 path and assert the call succeeds with none of those fields. (best practice) [sources: src/devops_cli/ai/client/claude.py:143-156, pyproject.toml]
    • Chosen: Fake HTTP transport at the SDK seam. It sees the actual request body that extra_body builds and can return HTTP 400.
    • Rejected: Mock the client. It hides the request body and cannot catch the HTTP 400.
    • Rejected: Live API call. It needs a secret and network, so it is not an offline test.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    on Nov 12, 2026
  2. added
    type/bug
    scope/ai
    status/new
    value/medium
    effort/low
    on Nov 12, 2026
  3. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor
  4. added
    priority/p2-medium
    on Nov 12, 2026
  5. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: The searches turned up the Anthropic Python SDK 2.8.0 itself — the component whose new API version returns HTTP 400 for temperature/top_p/top_k — plus the LiteLLM gateway and pydantic-ai, which sit in front of or above the same Anthropic API rather than fixing what the project's own Claude client puts in extra_body. No open tool removes those parameters from the client's request or adds the HTTP-seam test the issue asks for, so the fix stays in claude.py and its tests.

    Tool: none found

    Lacks:

    • No library strips the sampling parameters the client puts in extra_body before the request reaches the API
    • No external tool adds a test at the HTTP seam that fails while a refused parameter is sent
    • LiteLLM is a gateway the client can point at, not a change to the request body the client builds
    • pydantic-ai's AnthropicModel still maps model settings such as temperature onto the same Anthropic API
    • The Anthropic SDK 2 is the source of the HTTP 400, not a fix for it

    Tools considered:

    Searches run:

    • anthropic python SDK 2.0 temperature top_p top_k HTTP 400 anthropic-version 2026-10-21, results: 5
    • LiteLLM anthropic drop unsupported params temperature top_p, results: 5
    • pydantic-ai AnthropicModel anthropic 2.0 migration sampling parameters, results: 5
    • anthropic python sdk github repository, results: 5
    • pydantic-ai AnthropicModel, results: 5
    • LiteLLM proxy github, results: 5
    • anthropic, results: 5
    • pydantic-ai, results: 5
    • litellm, results: 5
    • litellm drop_params unsupported parameters documentation, results: 5

    Sources:

    Checked on 2026-11-15. A person decides what this means for the item. The check changes no label and closes no issue.

  6. added
    status/ready
    and removed
    status/new
    on Nov 17, 2026
  7. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at b8c7632 (see proposed design in issue body).

  8. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 17, 2026
  9. removed
    status/in-review
    on Nov 17, 2026
  10. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor
  11. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-17 16:55 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumscope/aisource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions