---
url: >-
  https://docs.byesu.com/errors/claude-api-400-temperature-top-p-not-supported.md
description: >-
  解决 Anthropic API 2026-10-21 及新版 SDK 传入 temperature、top_p、top_k 报 400 Bad
  Request：移除采样参数或临时锁定 2023-06-01。
---

# Claude API 400：`temperature` / `top_p` / `top_k` 参数不支持（`2026-10-21`）

升级到 Anthropic API 版本 **`2026-10-21`**（Anthropic Python SDK `v2.0.0+`、TypeScript SDK `v1.0.0+` 默认发送该版本）后，只要在 `/v1/messages` 请求体里带上 `temperature`、`top_p` 或 `top_k`，**哪怕传默认值 `temperature: 1.0`**，也会直接返回 **HTTP 400 `invalid_request_error`**。

::: tip 一句话结论

1. **推荐修法**：从请求体里**彻底删除** `temperature`、`top_p`、`top_k` 字段（不要传 `1.0` 或 `0.0`）。
2. **临时过渡**：如果旧框架会自动注入 `temperature`，可在请求头里显式锁定 `anthropic-version: 2023-06-01`，待框架升级后再切回新版。
   :::

## 报错原因

在 `2026-10-21` 协议版本中，Anthropic 为配合新一代模型的自适应思考（Adaptive Thinking），将传统采样参数 `temperature`、`top_p`、`top_k` 从请求 Schema 中移除，传入多余字段会直接被校验拦截：

```json
{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "temperature: Extra inputs are not permitted"
  }
}
```

## 修法 1：彻底移除采样参数

修改前（`2026-10-21` / Python SDK v2+ 报 400）：

```python
response = client.messages.create(
    model="claude-sonnet-5-5",
    max_tokens=1024,
    temperature=0.2,   # 2026-10-21 直接报 400
    top_p=0.9,         # 2026-10-21 直接报 400
    messages=[{"role": "user", "content": "总结这段 diff。"}],
)
```

修改后（新旧版本通用）：

```python
response = client.messages.create(
    model="claude-sonnet-5-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "总结这段 diff。"}],
)
```

如果使用 LangChain、LlamaIndex、Cherry Studio 或自定义客户端，注意在模型参数配置里取消勾选或清空 `temperature`，确保最终发出的 JSON 中不包含该键。

## 修法 2：迁移期间临时锁定 `anthropic-version: 2023-06-01`

```bash
curl https://byesu.com/v1/messages \
  -H "Authorization: Bearer $BYESU_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{"model":"claude-sonnet-5-5","max_tokens":256,"messages":[{"role":"user","content":"你好"}]}'
```

## `2026-10-21` 同批次另外两项 400 变更

删掉采样参数后若仍报 400，顺带核对两项同批次变更：

* **`assistant` 消息内禁止出现 `document` 块**：需移至 `user` 消息。
* **`user` 文本块内禁止出现非空 `citations` 数组**：发送前清理用户侧的 `citations` 字段。

相关排查见 [Claude 400 thinking 不可关闭](/errors/claude-api-400-thinking-disabled-not-supported) 与 [Claude 400 messages 角色必须交替](/errors/claude-api-400-messages-role-alternation)。

## 经由网关排查

使用 [半页酥 API（byesu）](https://byesu.com) 调用原生 `/v1/messages`（Base URL `https://byesu.com`）时，同样建议省略 `temperature`/`top_p`/`top_k`；线路状态可在 [渠道状态页](https://byesu.com/status) 核验。
