Send one of the two. Anthropic documents the rule for Claude Haiku 4.5, developers hit the same 400 on Claude Opus 4.6 and Sonnet 4.6, and on Claude Opus 4.7 and later it tightens to neither. Often the culprit is a client or framework filling in the parameter you never set.
The error
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "`temperature` and `top_p` cannot both be specified for this model. Please use only one."
},
"request_id": "req_..."
}Causes and fixes at a glance
| Cause | Fix |
|---|---|
| Your code, or a framework under it, sends both | Send only the one you mean and delete the other key. |
| The second one is a “neutral” default, such as top_p: 1 | Reported to fail all the same. Remove the key rather than normalizing it. |
| An older LangChain JS or n8n build | Upgrade: @langchain/anthropic 1.3.24 or later, n8n 1.114.1 or later. |
| LiteLLM passes both through | Add additional_drop_params: ["top_p"] to that model. |
| You moved to Claude Opus 4.7 or later, Sonnet 5 or Fable 5 | Stricter rule there: remove both — any non-default value of either is rejected. |
Which Claude models enforce it (as of September 2026)
Anthropic's Haiku 4.5 migration guide: use only temperature or top_p, not both — setting both returns a 400 on Claude Haiku 4.5, a breaking change for code coming from Claude 3.x (https://platform.claude.com/docs/en/models/haiku-4-5/migration-guide). Anthropic's API release notes flagged the same rule at the Claude Opus 4.1 launch on August 5, 2025, a model since retired (https://platform.claude.com/docs/en/release-notes/api). AWS states it for Claude Sonnet 4.5 and Claude Haiku 4.5 on Bedrock (https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-anthropic-claude-messages-request-response.html). We found no Anthropic page that states the rule for the 4.6 models, but developers report this exact 400 from Claude Opus 4.6 (OpenHands issue #12846) and Claude Sonnet 4.6 (opencommit issue #566). Claude Opus 4.7 and later are covered below: there, one is already too many.
Send one — and delete the other key
Keep temperature unless you have a reason not to: Anthropic's API reference describes top_p as recommended for advanced use cases only (https://platform.claude.com/docs/en/api/messages). Remove the second key rather than setting it to a value you think is neutral — a developer reported that a top_p of 1.0 next to a temperature of 0.3 still failed on Claude Sonnet 4.5 (n8n issue #18304).
from openai import OpenAI
client = OpenAI(base_url="https://api.kunavo.com/v1", api_key="sk-kn-...")
def one_sampling_knob(params: dict) -> dict:
"""Where the rule applies, send temperature or top_p, not both. Keep temperature."""
if params.get("temperature") is not None:
params.pop("top_p", None)
return params
sampling = one_sampling_knob({"temperature": 0.3, "top_p": 0.9}) # {"temperature": 0.3}
resp = client.chat.completions.create(
model="claude-haiku-4-5",
max_tokens=512,
messages=[{"role": "user", "content": "Classify this support ticket: ..."}],
**sampling,
)
print(resp.choices[0].message.content)Fix it in the client that adds the second one
LangChain JS: ChatAnthropic 0.3.x sent a default temperature alongside the top_p you set (issue #9258, fixed on the 0.3 line by PR #9362 in November 2025), and PR #10420, released in @langchain/anthropic 1.3.24 on March 17, 2026, stops it adding any sampling key you leave unset (https://github.com/langchain-ai/langchainjs/pull/10420). n8n: the Anthropic Chat Model node passed LangChain's defaults (topP -1, temperature 0.7); fixed in n8n 1.114.1, released October 2, 2025 (https://github.com/n8n-io/n8n/pull/20286). LiteLLM: name the parameter to remove with additional_drop_params, per call or per model (https://docs.litellm.ai/docs/completion/drop_params) — except on its Anthropic pass-through route, where the report was closed on the grounds that pass-through requests are not modified (https://github.com/BerriAI/litellm/issues/15097). Amazon Bedrock: set temperature or topP in the Converse inferenceConfig, or temperature or top_p in the InvokeModel body — never both (https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InferenceConfiguration.html).
model_list:
- model_name: claude-haiku-4-5
litellm_params:
model: openai/claude-haiku-4-5 # Kunavo speaks the OpenAI chat shape
api_base: https://api.kunavo.com/v1
api_key: sk-kn-...
additional_drop_params: ["top_p"] # keep temperature, never send top_pOn Claude Opus 4.7 and later, send neither
Newer models go further. Setting temperature, top_p or top_k to any non-default value on Claude Opus 4.7 and later models returns a 400 (https://platform.claude.com/docs/en/models/opus-5-5/migration-guide); the same holds for Claude Sonnet 5 (https://platform.claude.com/docs/en/models/sonnet-5/migration-guide) and carries over to Claude Fable 5 (https://platform.claude.com/docs/en/models/fable-5/migration-guide) and Fable 5.1 (https://platform.claude.com/docs/en/models/fable-5-1/migration-guide). The message changes — developers see “`temperature` is deprecated for this model.” — and Anthropic's API reference now marks all three parameters deprecated: on models released after Claude Opus 4.6 it accepts only a temperature of 1.0 or a top_p of 0.99 and above, for backwards compatibility, and rejects top_k at any value (https://platform.claude.com/docs/en/api/messages). The Anthropic Python SDK removed them from its Messages methods in v1.0, released August 20, 2026 (https://platform.claude.com/docs/en/release-notes/api).
API version 2026-10-21: any temperature, top_p or top_k is a 400
On October 21, 2026 Anthropic released API version 2026-10-21, and the SDK versions in the table below send it by default. Under that version, a request that sends temperature, top_p or top_k returns a 400 error on any model, even at the parameter's default value. Two other request shapes become 400 errors with it: a document block placed directly in an assistant message, and a text block with a non-empty citations array in a user message (https://platform.claude.com/docs/en/api/migration-2026-10-21, read October 22, 2026). The new SDKs no longer have the three parameters at all: in our test on October 22, 2026, client.messages.create(temperature=0.2) raised a TypeError in the Python SDK 2.0.0 before any request was sent.
Python anthropic 2.0.0
TypeScript @anthropic-ai/sdk 1.0.0
Go anthropic-sdk-go/v2 2.0.0
Java com.anthropic:anthropic-java 3.0.0
C# Anthropic 13.0.0
PHP anthropic-ai/sdk 1.0.0
Ruby anthropic 2.0.0
CLI ant 2.0.0
Earlier versions send anthropic-version: 2023-06-01.Remove the three parameters, or keep that request on 2023-06-01
Removing them is Anthropic's answer, and on Claude Opus 4.7 and later models nothing changes, because those models already sample only at the defaults. On a model that still accepts other values, such as Claude Sonnet 4.6, a request that lowered temperature loses that effect, and no other setting replaces it. If a request depends on a non-default value, keep it on API version 2023-06-01: the Python and TypeScript SDKs let you set the anthropic-version header yourself, and the parameter then has to travel in the request body, because the SDK method no longer accepts it.
import anthropic
# The 2.x SDK sends anthropic-version: 2026-10-21; this client keeps 2023-06-01.
client = anthropic.Anthropic(default_headers={"anthropic-version": "2023-06-01"})
msg = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=512,
messages=[{"role": "user", "content": "Classify this support ticket: ..."}],
extra_body={"temperature": 0.2}, # 2.x has no temperature argument
)
print(msg.content[0].text)
# TypeScript 1.x: new Anthropic({ defaultHeaders: { "anthropic-version": "2023-06-01" } })Through Kunavo, the upstream request still uses 2023-06-01
Kunavo's /v1/messages takes a request whatever anthropic-version it carries, and it calls the upstream with 2023-06-01, so such a request is judged by the older rules described earlier on this page. We tested this on October 22, 2026 with the Python SDK 2.0.0 and 2.1.0 and the TypeScript SDK 1.0.0 and 1.1.0, which sent 2026-10-21 and a bearer key: Kunavo accepted every request. On the Claude models where Anthropic removed the sampling parameters, Kunavo deletes temperature, top_p and top_k before forwarding and names what it deleted in the X-Kunavo-Dropped-Params response header; on the other models it forwards them unchanged. A document block in an assistant message, and citations in a user message, go upstream as you sent them. The chat completions reference lists, from our catalog, the models on which the parameters are dropped, and the header shows it for any single request. How the new SDKs send the key is covered in the guide to ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY.
If you’re calling through Kunavo
On the seven claude-* models where Anthropic removed sampling — claude-fable-5-1, claude-fable-5, claude-opus-5-5, claude-opus-5, claude-opus-4-8, claude-opus-4-7 and claude-sonnet-5 — Kunavo deletes temperature, top_p and top_k from the request before it leaves the gateway, on /v1/chat/completions and /v1/messages alike. You will not see this error from those seven, but the values you sent have no effect: the request goes upstream as if you had left them out. On claude-opus-4-6, claude-sonnet-4-6 and claude-haiku-4-5 Kunavo strips nothing: the chat translator copies any numeric temperature, top_p or top_k into the Claude request unchanged, and /v1/messages forwards your body as sent, so send one of the two there. If the upstream rejects the pair, its 400 reaches you with the upstream's message text unchanged, is not retried on another channel, and is recorded at zero cost. Another request parameter that newer models reject is covered in the max_tokens vs max_completion_tokens guide.
Frequently asked questions
Should I use temperature or top_p with Claude?
Temperature, unless you have a specific reason. Anthropic's API reference recommends top_p for advanced use cases only, and on Claude Opus 4.7 and later neither can be set to a non-default value.
Does top_p = 1 count as not setting it?
Don't count on it. A developer reported the same 400 with top_p at 1.0 alongside a temperature on Claude Sonnet 4.5 (n8n issue #18304). Delete the key instead of setting it to a value that looks neutral.
Why does n8n or LangChain send top_p when I never set it?
Both passed defaults through. n8n's Anthropic Chat Model node sent LangChain's defaults (topP -1, temperature 0.7) until 1.114.1, and ChatAnthropic in LangChain JS 0.3.x sent a default temperature alongside the top_p you set. Upgrade: n8n 1.114.1 or later, @langchain/anthropic 1.3.24 or later.
What does “`temperature` is deprecated for this model” mean?
It is the stricter rule on Claude Opus 4.7 and later, Sonnet 5 and Fable 5 and 5.1: those models reject non-default sampling values outright. Remove the parameters. Through Kunavo, the ones we serve have them stripped, so the call goes through.
Does a rejected request cost anything on Kunavo?
No. A request the upstream rejects is recorded at zero cost.
Why does temperature fail after upgrading to the Anthropic Python SDK 2.0?
Because the Python SDK 2.0.0 and the TypeScript SDK 1.0.0 send API version 2026-10-21, under which temperature, top_p and top_k are a 400 on every model, and the Python SDK no longer takes the arguments at all. Remove them, or keep the requests that need a non-default value on 2023-06-01 by setting the anthropic-version header yourself.
Related guides
- “This model does not support assistant message prefill” — which Claude models dropped prefill, and what replaces it
- “Unsupported parameter: 'max_tokens' is not supported with this model” — use max_completion_tokens
- ANTHROPIC_AUTH_TOKEN vs ANTHROPIC_API_KEY — which one Claude Code actually reads
- n8n AI API cost: one execution, many model calls, two bills
- How to call the Claude API on Kunavo: keys, SDKs, models and caching
More error semantics live in the error reference; getting a key takes a minute via signing up and the authentication guide.