Upgrade to Claude SDK 2.0: fix the new Claude API 400 errors (temperature removed)
Upgraded the Anthropic SDK and now get a Claude API 400 error? Or searching "Claude temperature deprecated"? On October 21, 2026, Anthropic released Claude API version 2026-10-21, and the new SDKs (Python anthropic 2.0, TypeScript @anthropic-ai/sdk 1.0, and the matching Go, Java, C#, Ruby and PHP releases) use it by default. In that API version, temperature, top_p and top_k are removed: the Claude API returns a 400 if you send any of them, even at the default value. This guide shows you how to pin your current version, scan your code for every line that will break, fix it, and upgrade safely.
Prefer to watch? Catch the quick video on YouTube.
The old version, 2023-06-01, is not deprecated, so nothing breaks until you upgrade. The risk is an unplanned upgrade from an unpinned install.
- Time
- About 25 minutes
- Checked
If a button name on the screen does not match this guide, follow the action. These products rename buttons often. This is an advanced guide: it uses code, and each technical term is explained the first time it appears. Model names and prices change, so check the linked docs before you ship.
Steps
Know what changed, and what didn't
On Oct 21, 2026, Anthropic released Claude API version
2026-10-21, its first new version since 2023. An API version is a date you send with each request (theanthropic-versionheader) that fixes how the API behaves for you. The new one has breaking changes. The biggest:You send On 2023-06-01On 2026-10-21temperature,top_portop_kAccepted on models that support them 400 error, even at the default value A documentblock directly in anassistantmessageAccepted 400 error A textblock withcitationsin ausermessageAccepted 400 error Sampling parameters are the three settings that control how random the answer is. A 400 error means the API rejected your request as invalid (
invalid_request_error).What didn't change: Anthropic's developer account, @ClaudeDevs on X, said on Oct 21, 2026 that
2023-06-01is not deprecated, and Anthropic's API versions page lists no end date for it. Your code keeps working until you upgrade. The catch is that upgrading the SDK is what switches you: these versions are the first to send2026-10-21by default.Language Package First version on 2026-10-21 Python anthropic2.0.0 TypeScript @anthropic-ai/sdk1.0.0 Go github.com/anthropics/anthropic-sdk-go/v22.0.0 Java com.anthropic:anthropic-java3.0.0 C# Anthropic13.0.0 Ruby anthropic2.0.0 PHP anthropic-ai/sdk1.0.0 CLI ant2.0.0 So an unpinned
pip install anthropicornpm install @anthropic-ai/sdkin a fresh build can move you over without anyone deciding to.Pin your current version first
Check what you run today, then pin it so nothing upgrades under you while you work:
pip show anthropic # Python: look at "Version" npm ls @anthropic-ai/sdk # TypeScriptIf the Python version starts with 0 or 1, put this line in
requirements.txt(or the same range inpyproject.toml):anthropic<2For TypeScript on a 0.x version, set
"@anthropic-ai/sdk": "<1"inpackage.json. Now builds stay on2023-06-01until you're ready.Scan your code for lines that will break
This script walks a folder and prints every line that touches one of the changes. It's plain text matching, so it also finds settings in config files and code in other languages. Save it as
scan_claude_upgrade.py:# scan_claude_upgrade.py: list lines that may break on Claude API version 2026-10-21 # usage: python scan_claude_upgrade.py [folder] (default: the current folder) import pathlib, re, sys CHECKS = [ (r"(?<![a-z])(temperature|top_p|top_k)(?![a-z])", "sampling parameter: returns a 400 on 2026-10-21, remove it"), (r"x-api-key", "X-Api-Key header: new SDKs send Authorization: Bearer instead"), (r"\bMessageParam\s*\(", "Python SDK 2: MessageParam(...) raises TypeError, write a dict"), (r"anthropic-version", "API version header: check which version you send"), (r"compaction_?[cC]ontrol", "client-side compaction is removed from the tool runner"), (r"\bcitations\b", "citations in user messages return a 400, check where these go"), ] SKIP_DIRS = {".git", "node_modules", ".venv", "venv", "__pycache__", "dist", "build", ".next"} EXTENSIONS = {".py", ".ts", ".tsx", ".js", ".mjs", ".cjs", ".go", ".java", ".kt", ".cs", ".rb", ".php", ".json", ".yaml", ".yml", ".toml", ".env", ".sh", ".ini", ".cfg"} root = pathlib.Path(sys.argv[1] if len(sys.argv) > 1 else ".") hits = 0 for path in sorted(root.rglob("*")): if any(part in SKIP_DIRS for part in path.parts) or not path.is_file(): continue if path.suffix.lower() not in EXTENSIONS and path.name != ".env": continue try: lines = path.read_text(errors="ignore").splitlines() except OSError: continue for number, line in enumerate(lines, 1): for pattern, why in CHECKS: if re.search(pattern, line, re.IGNORECASE): print(f"{path}:{number}: {why}\n {line.strip()[:120]}") hits += 1 print(f"\n{hits} line(s) to check." if hits else "Nothing found. Still run your tests after upgrading.")Run it from your project folder:
python3 scan_claude_upgrade.py .You get a file name, a line number and a reason for each hit. Some hits will be false alarms, like a weather app's
temperaturefield. You decide which ones are Claude requests. Also check settings that come from environment variables or a wrapper library, since those don't always show up in your own code.Remove temperature, top_p and top_k
Delete the three parameters from every Claude request, including Message Batch requests. In Python SDK 1.x they were already gone as arguments, so many projects pass them through
extra_body. That still works on 1.x, but after you upgrade the SDK sends them with the new API version, and the Claude API returns a 400:# Before (Python SDK 1.x) client.messages.create( model="claude-sonnet-4-6", max_tokens=1000, extra_body={"temperature": 0.2}, messages=[{"role": "user", "content": "Summarize this ticket."}], ) # After client.messages.create( model="claude-sonnet-4-6", max_tokens=1000, messages=[{"role": "user", "content": "Summarize this ticket."}], )In Python SDK 2, passing
temperature=0.2directly fails before any request goes out, withTypeError: ... unexpected keyword argument 'temperature'. In TypeScript SDK 1.0, the compiler reports that'temperature' does not existin the request type.Will the answers change? Without the parameters, Claude uses the defaults (a
temperatureof 1.0). Claude 4.7 and later models already accept only the defaults, so they answer the same as before. On a model that accepts other values, such as Claude Sonnet 4.6, a request that loweredtemperaturefor more consistent output loses that effect, and Anthropic says no other setting replaces it. If one request really needs it, keep that code on the old SDK version (anthropic<2) for now, and move the rest.Fix the other Messages changes
Two more request shapes now return a 400. Both are rare, but the scan's
citationshits point you to the second one.- A
documentblock directly in anassistantmessage. Send documents inusermessages instead. A document nested inside another block, such as a web fetch result Claude returned, is still fine. citationson atextblock in ausermessage, including insidesearch_resultblocks. Remove thecitationslist from those blocks and keep the text. Citations in Claude's own earlier replies (assistantmessages) are still accepted, and so is the"citations": {"enabled": true}setting on documents.
If you use the Admin API, some response fields were renamed too (for example, API keys now return
scope.workspace_idinstead ofworkspace_id). The migration guide has the full table.- A
Check your proxy and your typed messages
Two SDK changes can break things that never touch
temperature:- The API key moves to a different header. The new SDKs send
Authorization: Bearer <key>instead ofX-Api-Key. The Claude API accepts either, but a company proxy, gateway, log filter or test stub that readsX-Api-Keywill suddenly see no key. Update it to readAuthorizationbefore you upgrade. - Python:
MessageParamis now a union of one type per role. CallingMessageParam(role="user", content="Hello")raises aTypeError. Write the message as a dict instead. Dict messages, which most code uses, need no change:
# Before message = MessageParam(role="user", content="Hello") # After message: MessageParam = {"role": "user", "content": "Hello"}If you call Claude without an SDK, there's nothing to upgrade: change the
anthropic-versionheader to2026-10-21when your fixes are in.- The API key moves to a different header. The new SDKs send
Upgrade and test
Upgrade in a branch, so you can throw it away if something breaks:
pip install "anthropic>=2,<3" # Python npm install @anthropic-ai/sdk@^1 # TypeScriptUpdate the pin from the earlier step to match. Then run one small call to confirm the new SDK works with your key. Save this as
smoke_test.py:import anthropic print("SDK version:", anthropic.__version__) client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY message = client.messages.create( model="claude-haiku-5-5", max_tokens=50, messages=[{"role": "user", "content": "Say hello in three words."}], ) print(message.content[0].text)Run
python smoke_test.py. You should seeSDK version: 2.something and a short greeting. Then run your own test suite and the scan script again.Want to see the new error for yourself? This one request should fail with a 400
invalid_request_error. Change the version header to2023-06-01and the same request works:curl https://api.anthropic.com/v1/messages \ -H "x-api-key: $ANTHROPIC_API_KEY" \ -H "anthropic-version: 2026-10-21" \ -H "content-type: application/json" \ -d '{"model": "claude-haiku-5-5", "max_tokens": 50, "temperature": 0, "messages": [{"role": "user", "content": "Say hi"}]}'Ship the fixes and the upgrade together
Anthropic's advice is to release the SDK upgrade together with your fixes. Release them in one change, watch your logs for 400 errors for a day, and keep the rollback simple: if something breaks, put the old pin (
anthropic<2) back and redeploy. That puts you back on2023-06-01while you fix the rest.
Tips
Pin every AI SDK you depend on, not just this one. An unpinned install in CI is how a breaking upgrade reaches production without anyone choosing it.
On Amazon Bedrock, 2026-10-21 works only with Claude 4.7 and later models. If you call an older model there, stay on your current SDK version until you switch models.
Don't paste your API key into a chat or commit it to Git. Keep it in the ANTHROPIC_API_KEY environment variable or your CI secrets.
If you relied on temperature 0 to make tests repeatable, test properties instead (valid JSON, the right label, a value in range). Our Write evals for an LLM app guide shows how.
Part of the Before it retires series: Move your custom GPT to a ChatGPT plugin, Find and replace retiring OpenAI models in your code, Move your Agent Builder workflow to the Agents SDK, Turn your Gemini Gems into skills before Nov 17, and Move your OpenAI Evals to Promptfoo before Nov 30, Switch from GPT Image 1.5 to GPT Image 2.6 (Dec 1).
Common questions
Is the old API version being shut down?
Not as of Oct 27, 2026. Anthropic's @ClaudeDevs account on X said on Oct 21, 2026 that 2023-06-01 is not deprecated, and the API versions page lists no end date for it. It also says it plans to release versions more often, so upgrading now is easier than upgrading several versions at once later.
Why do I get a 400 when I send temperature: 1, the default?
On 2026-10-21, sending temperature, top_p or top_k at all returns a 400, even at the default value. Delete the parameter. The default still applies.
Is there a replacement for low temperature?
No. Anthropic's migration guide says no other setting replaces it. Claude 4.7 and later models already ignored other values, so for them nothing changes. For an older model where low temperature mattered, keep that request on the old SDK version for now.
Do I have to upgrade right away?
No. Pin your current SDK version and upgrade when you've fixed the lines the scan finds. What you should avoid is an unplanned upgrade from an unpinned install.
Do the Claude guides on this site still work with SDK 2.0?
Yes. Build your first AI agent with tool use and Call the Claude API with prompt caching use dict messages and no sampling parameters. We checked their request code with Python SDK 2.3.0.
More guides
BeginnerClaudeDocuments
Explain a bill or official letter
Paste a bill or letter into free Claude and get plain English, the deadline, and what is actually being asked.
About 10 minutes using Claude
BeginnerClaudeWriting
Write a clear email
Tell free Claude who you are writing to and what you need. You get a short draft, and you send it yourself.
About 8 minutes using Claude
BeginnerClaudeWriting
Rewrite resume bullets from real work
Ask free Claude for three resume bullets that use only the facts you provide, with blanks where a number is missing.
About 12 minutes using Claude