{"id":"Fh6FvnFc","creatorId":"anonymous","title":"#14352 Anthropic sampling settings forwarded on anthropic-version 2026-10-21 (public Agent path)","createdAt":1795545846465,"updatedAt":1795545846465,"latestVersionNum":1,"versions":[{"versionNum":1,"version":null,"branchName":null,"branchSha":null,"runRelease":true,"runBranch":false,"sdkDeps":{"pip":["anthropic SDK (1.x or 2.x; only the explicit default header matters)","httpx (or httpx2 where the environment's SDK binds it)","pydantic-ai with the anthropic extra"]},"snippets":[{"id":"harness","name":"Public-path harness: Agent + real SDK client + captured wire request","code":"import json, warnings\nimport httpx2 as httpx\nfrom anthropic import AsyncAnthropic\nfrom pydantic_ai import Agent, ModelSettings\nfrom pydantic_ai.models.anthropic import AnthropicModel\nfrom pydantic_ai.providers.anthropic import AnthropicProvider\n\nSENTINEL_200 = {\n    \"id\": \"msg_0123\", \"type\": \"message\", \"role\": \"assistant\",\n    \"model\": \"claude-sonnet-4-6\",\n    \"content\": [{\"type\": \"text\", \"text\": \"OK\"}],\n    \"stop_reason\": \"end_turn\",\n    \"usage\": {\"input_tokens\": 5, \"output_tokens\": 1},\n}\nERROR_400 = {\n    \"type\": \"error\",\n    \"error\": {\"type\": \"invalid_request_error\", \"message\": \"temperature: Extra inputs are not permitted\"},\n    \"request_id\": \"req_mock_14352\",\n}\n\nasync def run_case(label, model_name, version_header, settings, status=200):\n    captured = {}\n    def handler(request):\n        captured[\"headers\"] = dict(request.headers)\n        captured[\"body\"] = json.loads(request.content.decode())\n        return httpx.Response(status, json=SENTINEL_200 if status == 200 else ERROR_400)\n    hc = httpx.AsyncClient(transport=httpx.MockTransport(handler))\n    client = AsyncAnthropic(\n        api_key=\"x\", base_url=\"https://api.anthropic.example\",\n        http_client=hc, default_headers={\"anthropic-version\": version_header},\n    )\n    agent = Agent(AnthropicModel(model_name, provider=AnthropicProvider(anthropic_client=client)))\n    with warnings.catch_warnings(record=True) as caught:\n        warnings.simplefilter(\"always\")\n        try:\n            result = await agent.run(\"Say hi\", model_settings=settings)\n            outcome = f\"run OK, output={result.output!r}\"\n        except Exception as e:\n            outcome = f\"raised {type(e).__name__}: {e}\"\n    wire = captured.get(\"body\", {})\n    sampling = {k: wire[k] for k in (\"temperature\", \"top_p\", \"top_k\") if k in wire}\n    print(f\"--- {label}\")\n    print(f\"    wire anthropic-version: {captured.get('headers', {}).get('anthropic-version')}\")\n    print(f\"    wire sampling params  : {sampling}\")\n    print(f\"    outcome               : {outcome}\")\n    for w in caught:\n        print(f\"    warning: {w.category.__name__}: {w.message}\")\n    await hc.aclose()","primaryOutput":null,"comparisonOutput":null},{"id":"cases","name":"Observed cases: trigger, differential control, header blindness, mocked 400","code":"# Case A (reported trigger): sampling settings kept on the wire for models WITHOUT\n# anthropic_disallows_sampling_settings, regardless of the API version header.\ntemp_only = ModelSettings(temperature=0, max_tokens=5)\nawait run_case(\"A1 sonnet-4-6 / 2026-10-21\", \"claude-sonnet-4-6\", \"2026-10-21\", temp_only)\n# -> wire anthropic-version: 2026-10-21 ; wire sampling params: {'temperature': 0} ; run OK, no warning\nawait run_case(\"A2 sonnet-4-6 / 2026-10-21 / top_k\", \"claude-sonnet-4-6\", \"2026-10-21\", ModelSettings(top_k=20, max_tokens=5))\n# -> {'top_k': 20} forwarded\nawait run_case(\"H  haiku-4-5  / 2026-10-21\", \"claude-haiku-4-5\", \"2026-10-21\", temp_only)\n# -> {'temperature': 0} forwarded (second reported model)\n\n# Case C (header blindness): byte-identical wire body to A1 on the legacy header.\nawait run_case(\"C  sonnet-4-6 / 2023-06-01\", \"claude-sonnet-4-6\", \"2023-06-01\", temp_only)\n# -> {'temperature': 0} forwarded; drop decision ignores anthropic-version\n\n# Case B (control): profile flag drops the setting even on the new header.\nawait run_case(\"B  opus-4-8 / 2026-10-21\", \"claude-opus-4-8\", \"2026-10-21\", temp_only)\n# -> wire sampling params: {} + UserWarning: Sampling parameters ['temperature'] are not supported by 'claude-opus-4-8'...\n\n# Case D: the provider 400 the reporter saw surfaces through the public path.\nawait run_case(\"D  sonnet-4-6 / 2026-10-21 / provider 400\", \"claude-sonnet-4-6\", \"2026-10-21\", temp_only, status=400)\n# -> ModelRequestRejectedError: status_code: 400 ... 'temperature: Extra inputs are not permitted'","primaryOutput":null,"comparisonOutput":null}],"createdAt":1795545846465}]}