Back to blog

TroubleshootingGuide

Claude API 400 error on temperature, top_p, top_k: how to fix it

Your Claude request started returning 400 on API version 2026-10-21? Remove temperature, top_p and top_k, or pin the old version. Steps inside.

By CheapTokens TeamPublished 4 min read

Terminal-style card: error 400 for temperature, top_p and top_k in the Claude API
On this page
  1. What the failing request looks like
  2. The fix: remove the three parameters
  3. Will answers change after you remove them?
  4. Quick checklist when you see the 400
  5. One code path for Claude and OpenAI-style APIs

Your Claude request worked yesterday, you moved it to API version 2026-10-21 (the anthropic-version header, or an SDK release built for it), and now it comes back with a 400. Look at the body of the request: if it has temperature, top_p or top_k, that's the cause. Delete those three fields and the request goes through.

According to Anthropic's migration guide for version 2026-10-21 (https://platform.claude.com/docs/en/api/migration-2026-10-21, checked 24 October 2026), a Messages or Message Batches request that sends any of the three returns a 400 error. It happens even if the value is the parameter's default. Look for the 400 status and for those field names in your request.

What the failing request looks like#

Say you have a small script that asks Claude to summarise a ticket and keeps the answer steady with a low temperature:

python
import anthropic

client = anthropic.Anthropic()

reply = client.messages.create(
    model="<your Claude model>",
    max_tokens=500,
    temperature=0.2,  # <- this line now causes the 400
    messages=[{"role": "user", "content": "Summarise this ticket in two lines: ..."}],
)

Same story over plain HTTP. If you set the version header yourself, this is the line that moves you to the new behaviour:

bash
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": "<your Claude model>", "max_tokens": 500, "top_p": 0.9,
       "messages": [{"role": "user", "content": "Hello"}]}'

The fix: remove the three parameters#

Delete temperature, top_p and top_k from every Messages and Message Batches request. Without them the model samples with its defaults (temperature 1.0), exactly as a 2023-06-01 request that leaves them out did.

python
reply = client.messages.create(
    model="<your Claude model>",
    max_tokens=500,
    messages=[{"role": "user", "content": "Summarise this ticket in two lines: ..."}],
)
Before and after: the request with temperature returns 400, the same request without it goes through
The same request before and after removing temperature

The latest major SDK versions and the ant CLI (2.0.0) no longer have these parameters at all, so after upgrading you have to remove them from your code. A 400 comes from requests that go out with anthropic-version: 2026-10-21 and still carry one of the three fields. The .NET IChatClient adapters take a softer route: they now ignore ChatOptions.Temperature, TopK and TopP. Exact SDK version numbers per language are in the Upgrade steps tabs of the guide.

If you call the API without an SDK, the version is the anthropic-version header, and 2026-10-21 is the value that turns the new rule on.

Will answers change after you remove them?#

Depends on the model, and the guide is specific here.

  • Claude 4.7 and later already accept only default sampling values. Nothing changes for you: they sampled by defaults before and still do.
  • Models that accept other values, such as Claude Sonnet 4.6: if you lowered temperature to get more consistent output, that effect disappears, and no other setting replaces it.

If a particular request really relies on a non-default value, you have two options from the guide: stop sending the parameter and accept default sampling, or keep that one request on anthropic-version: 2023-06-01.

If your answers must be strictly consistent, put the consistency into the prompt instead: a fixed output format, a short example of the answer you want, and a check in your code that rejects anything off-format. It's more work than one number, but it doesn't depend on a sampling knob.

Quick checklist when you see the 400#

  1. Search the project for temperature, top_p, top_k, including wrappers and shared config files.
  2. Check batch jobs: the rule applies to each request inside a Message Batch created with 2026-10-21, so look at the params of every request in the batch.
  3. Check what changed: SDK major version, CLI version, or the anthropic-version header.
  4. Remove the fields, or pin that request to 2023-06-01 if it needs a non-default value.
  5. Run one request before you re-launch a large batch.

One code path for Claude and OpenAI-style APIs#

A common setup: a single helper that builds the request and sends it either to Anthropic Messages or to an OpenAI-style Chat Completions endpoint. The simplest fix is to split the parameters. Keep temperature in the OpenAI-style branch only, and don't add it to the Messages branch.

In the Chat Completions format the setting is a normal request field. On CheapTokens it works through the OpenAI-compatible address https://api.cheaptokens.dev/v1. Here is a request to DeepSeek-V4-Flash (380K context, up to 32,768 output tokens per answer), with the full model id from the CheapTokens docs:

bash
curl https://api.cheaptokens.dev/v1/chat/completions \
  -H "Authorization: Bearer $CHEAPTOKENS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-ai/DeepSeek-V4-Flash-0731",
    "temperature": 0.2,
    "max_tokens": 300,
    "messages": [{"role": "user", "content": "Summarise this ticket in two lines: ..."}]
  }'

A request like that, with 1,000 input tokens and 300 output tokens, costs $0.000045 at the current price. DeepSeek-V4-Flash has one price at any time of day, with no peak hours, and one balance covers all models. For the same code path with a 390K context window there is also GLM-5.3-Flash (zai-org/GLM-5.3-Flash, up to 8,192 output tokens). Current prices for all models are on the pricing page.

To see how the setting behaves, read System prompt and temperature: what they do and how to set them. To call Claude-format Messages from Python, see Anthropic Python SDK with CheapTokens. The base address and key setup are in the CheapTokens docs.