Skip to content
Easy AI How-To

AdvancedClaudeBuilding

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
Tools
Anthropic: Migrating to API version 2026-10-21, Anthropic: API versions, Anthropic Python SDK: migration notes, Anthropic: API errors

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

  1. 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 (the anthropic-version header) that fixes how the API behaves for you. The new one has breaking changes. The biggest:

    You send On 2023-06-01 On 2026-10-21
    temperature, top_p or top_k Accepted on models that support them 400 error, even at the default value
    A document block directly in an assistant message Accepted 400 error
    A text block with citations in a user message Accepted 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-01 is 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 send 2026-10-21 by default.

    Language Package First version on 2026-10-21
    Python anthropic 2.0.0
    TypeScript @anthropic-ai/sdk 1.0.0
    Go github.com/anthropics/anthropic-sdk-go/v2 2.0.0
    Java com.anthropic:anthropic-java 3.0.0
    C# Anthropic 13.0.0
    Ruby anthropic 2.0.0
    PHP anthropic-ai/sdk 1.0.0
    CLI ant 2.0.0

    So an unpinned pip install anthropic or npm install @anthropic-ai/sdk in a fresh build can move you over without anyone deciding to.

  2. 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        # TypeScript
    

    If the Python version starts with 0 or 1, put this line in requirements.txt (or the same range in pyproject.toml):

    anthropic<2
    

    For TypeScript on a 0.x version, set "@anthropic-ai/sdk": "<1" in package.json. Now builds stay on 2023-06-01 until you're ready.

  3. 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 temperature field. 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.

  4. 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.2 directly fails before any request goes out, with TypeError: ... unexpected keyword argument 'temperature'. In TypeScript SDK 1.0, the compiler reports that 'temperature' does not exist in the request type.

    Will the answers change? Without the parameters, Claude uses the defaults (a temperature of 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 lowered temperature for 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.

  5. Fix the other Messages changes

    Two more request shapes now return a 400. Both are rare, but the scan's citations hits point you to the second one.

    • A document block directly in an assistant message. Send documents in user messages instead. A document nested inside another block, such as a web fetch result Claude returned, is still fine.
    • citations on a text block in a user message, including inside search_result blocks. Remove the citations list from those blocks and keep the text. Citations in Claude's own earlier replies (assistant messages) 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_id instead of workspace_id). The migration guide has the full table.

  6. 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 of X-Api-Key. The Claude API accepts either, but a company proxy, gateway, log filter or test stub that reads X-Api-Key will suddenly see no key. Update it to read Authorization before you upgrade.
    • Python: MessageParam is now a union of one type per role. Calling MessageParam(role="user", content="Hello") raises a TypeError. 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-version header to 2026-10-21 when your fixes are in.

  7. 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        # TypeScript
    

    Update 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 see SDK 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 to 2023-06-01 and 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"}]}'
    
  8. 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 on 2023-06-01 while you fix the rest.

Tips

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.

Free newsletter

Learn AI by doing, one how-to at a time

New how-tos across all of AI: everyday tools, RAG, agents, local models, and taking a proof of concept to production. Each one is something you can try yourself, because the best way to learn AI is by doing it. Free, and you can unsubscribe in one click.

Subscribe free

Opens our sign-up page on beehiiv. Privacy