# Claude temperature, top_p and top_k errors: Anthropic's rules and the fixed request

> Markdown mirror of https://router.one/claude-sampling-parameters-400 for AI assistants and crawlers. Router One is a unified, OpenAI-compatible LLM API gateway.
> Last updated: 2026-10-30

Two different errors show up when code sends temperature, top_p or top_k to Claude. With anthropic 1.0.0 or later, the Python SDK raises a TypeError on your machine before any request is sent. When a request does carry them, Anthropic's rules can reject it with HTTP 400: Anthropic says Claude 4.7 and later models accept only the default values, its Claude Sonnet 5.5 page says setting any of the three returns a 400 error, and on API version 2026-10-21 any of them returns a 400 on every model. This page sets out both errors with Anthropic's rules and the date they were checked, and shows the fixed request on Router One, a unified LLM API gateway for 30+ models, for /v1/chat/completions and /v1/messages.

## Which error do you have?

- TypeError: Messages.create() got an unexpected keyword argument 'temperature' (or 'top_p', 'top_k'): raised by the Python SDK on your machine; no request was sent. See the SDK section below.
- HTTP 400 with type invalid_request_error and code INVALID_REQUEST: the request was sent and rejected. If it carries temperature, top_p or top_k, compare it with Anthropic's rules below.

## Why does the Anthropic Python SDK raise a TypeError?

From anthropic 1.0.0 (released 2026-08-20) on, messages.create() has no temperature, top_p or top_k argument; 0.125.0, the release before it, still had them (per the SDK source, checked 2026-10-30). Passing any of them, even at its default value, raises a TypeError in Python before a request is built, so nothing reaches Router One and no 400 is involved. Remove them from the call and the SDK sends the request. Moving the values into extra_body is no fix either: from anthropic 2.0.0 on, the SDK sends API version 2026-10-21, on which Anthropic returns a 400 for any of the three, even at its default value, and Anthropic's migration guide for that version says to remove them.

`app.py`

```python
import anthropic

client = anthropic.Anthropic(
    base_url="https://api.router.one",
    api_key="sk-your-router-one-key",
)

# anthropic 1.0.0 and later: TypeError ... unexpected keyword argument 'temperature'
# client.messages.create(model=..., temperature=0.7, ...)

# Fixed: no sampling arguments
message = client.messages.create(
    model="anthropic/claude-sonnet-5.5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)
```

## What does Anthropic say about each model?

Anthropic sets these rules per model and per API version. The table gives them as written on Anthropic's pages on 2026-10-30. The pages do not all say whether a default value may be sent; a request without the three parameters meets every rule in the table.

| Applies to | Anthropic's rule | Where Anthropic says it |
| --- | --- | --- |
| Claude Sonnet 5.5 (anthropic/claude-sonnet-5.5) | Setting temperature, top_p or top_k returns a 400 error | Claude Sonnet 5.5 model page |
| Claude Haiku 5.5 (anthropic/claude-haiku-5.5) | Omit temperature, top_p and top_k; sampling parameters are listed as a breaking change that can return an error | Claude Haiku 5.5 model page, what's new and migration guide |
| Claude 4.7 and later models | Accept only the default values on API version 2023-06-01 | Migrating to API version 2026-10-21 |
| Every model on API version 2026-10-21 | A request that sends any of the three returns a 400 error, even at the default value | API versions page; Migrating to API version 2026-10-21 |

## Does the anthropic-version header matter?

On Anthropic's API it does. Per Anthropic's API versions page and its migration guide for version 2026-10-21 (both checked 2026-10-30), version 2026-10-21 removes temperature, top_p and top_k: a request that sends any of them returns a 400 error on every model, even at the default value. Anthropic's Python SDK sends 2026-10-21 from anthropic 2.0.0 on; 1.x sends 2023-06-01. On 2023-06-01, Claude 4.7 and later models still accept only the defaults, so an older header is no fix for current models. Remove the three parameters: without them, Anthropic says a request samples with the defaults, including a temperature of 1.0.

## What does the 400 look like?

HTTP 400 with type invalid_request_error and code INVALID_REQUEST. On /v1/chat/completions the body has this shape; on /v1/messages the same type, message and code sit inside Anthropic's error envelope, {"type": "error", "error": {...}}:

`response.json`

```json
{
  "error": {
    "message": "...",
    "type": "invalid_request_error",
    "code": "INVALID_REQUEST"
  }
}
```

## How do I fix the request?

- Remove temperature, top_p and top_k from the request. Anthropic's advice for Claude Haiku 5.5 is to guide the model's behavior with the prompt instead.
- Python SDK: leave the three arguments out of messages.create(), and do not move them into extra_body.
- OpenAI-compatible clients and frameworks: some send temperature or top_p on their own, so if your code never sets them, check the client's model settings.
- Per Anthropic's 2026-10-21 migration guide, no other setting replaces a lowered temperature; constrain the output with the prompt.

## Example: /v1/chat/completions

OpenAI-compatible request to Claude Sonnet 5.5 with no temperature, top_p or top_k:

`terminal.sh`

```bash
curl https://api.router.one/v1/chat/completions \
  -H "Authorization: Bearer sk-your-router-one-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-5.5",
    "messages": [{"role": "user", "content": "Hello"}]
  }'
```

## Example: /v1/messages

Anthropic-format request to Claude Haiku 5.5 with no temperature, top_p or top_k:

`terminal.sh`

```bash
curl https://api.router.one/v1/messages \
  -H "x-api-key: sk-your-router-one-key" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-haiku-5.5",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello"}]
  }'
```

## FAQ

### Why does temperature=1 raise a TypeError in the Python SDK?

Because from anthropic 1.0.0 on, messages.create() has no temperature argument at all, so any value, including 1, is an unexpected keyword argument in Python. Remove it.

### Does extra_body get around the error?

It gets past the local TypeError by sending the parameter anyway, which is not what Anthropic advises: its guidance is to remove the three parameters, and on API version 2026-10-21, the version anthropic 2.0.0 and later use, Anthropic returns a 400 for any of them, even at the default value. Remove them instead.

### Will switching anthropic-version to 2023-06-01 fix it?

Not on current Claude models. Per Anthropic's migration guide for API version 2026-10-21 (checked 2026-10-30), Claude 4.7 and later models accept only the default values on 2023-06-01 too, and Anthropic's Claude Sonnet 5.5 page says setting any of the three returns a 400 error. Remove the parameters rather than changing the header.

### Do other Claude models have the same rule?

Per Anthropic (checked 2026-10-30), Claude 4.7 and later models accept only the default values, and its Claude Sonnet 5 page says, like the Claude Sonnet 5.5 page, that setting temperature, top_p or top_k returns a 400 error. A request that sends none of the three meets these rules on every Claude model.

### What should I send to Claude Haiku 5.5 instead of temperature?

Nothing in its place. Anthropic's Claude Haiku 5.5 migration guide says to omit temperature, top_p and top_k and to use prompting to guide the model's behavior instead (checked 2026-10-30).

## See also

- LLM API error codes: https://router.one/llm-api-error-codes
- Claude Sonnet 5.5 API guide: https://router.one/blog/claude-sonnet-5-5-api-guide
- Claude Haiku 5.5 API guide: https://router.one/blog/claude-haiku-5-5-api-guide
- Claude Opus 5.5 migration guide: https://router.one/blog/claude-opus-5-5-migration-guide
- API docs: https://router.one/docs
- Canonical page: https://router.one/claude-sampling-parameters-400
- Models and per-model token rates: https://router.one/models (markdown: https://router.one/models.md)
- Pricing: https://router.one/pricing
- API docs (markdown): https://router.one/docs.md
- Company facts: https://router.one/facts/company.md
