Skip to content

fix: omit temperature for the Anthropic provider - #6

Open
lipowen wants to merge 1 commit into
withmargin:mainfrom
lipowen:fix/anthropic-omit-temperature
Open

lipowen wants to merge 1 commit into
withmargin:mainfrom
lipowen:fix/anthropic-omit-temperature

Conversation

@lipowen

@lipowen lipowen commented Oct 31, 2026

Copy link
Copy Markdown

Summary

Translation with the Anthropic Claude provider fails on every block when the model is a current Claude model. Each request hard-codes temperature: 0, which the API now rejects:

Provider request failed with 400: {"type":"error","error":{"type":"invalid_request_error","message":"`temperature` is deprecated for this model."},"request_id":"req_011CgZxrTzCfhde1s4VwnSUc"}

This PR stops sending temperature from the Anthropic provider. The Anthropic Compatible provider keeps temperature: 0, since local runtimes may still honor it.

How it was found

Set up Margin from source with the Anthropic Claude provider and model claude-haiku-5-5 (the provider's built-in default, claude-3-5-haiku-latest, is an older model). Clicking Translate this page on a Hacker News thread rendered the 400 above in place of every translation; the API key and credits were valid, as the error came from the API itself.

Why

Two changes on Anthropic's side make the fixed temperature: 0 fail:

  1. Per model, on API version 2023-06-01 (what Margin sends today): Claude 4.7 and later models accept only the default sampling values, so any explicit temperature other than the default returns a 400.

  2. On API version 2026-10-21: temperature, top_p and top_k are removed for every model. From the migration guide:

    In 2026-10-21, a request that sends temperature, top_p, or top_k returns a 400 error, even at the parameter's default value.

    The same section notes that a request without these parameters samples with the defaults, and that models which already accept only the defaults, "such as Claude 4.7 and later models, sample as before."

Omitting the field works on both API versions and every model, so the provider won't need another change when Margin moves to 2026-10-21. The trade-off: on older models that still accept it (for example Claude Haiku 4.5), translations sample at the default temperature of 1.0 instead of 0.

Changes

  • anthropic.ts: send temperature: 0 only when settings.provider is not "anthropic".
  • anthropic.test.ts: assert the Anthropic request has no temperature and the Anthropic Compatible request keeps temperature: 0.
  • CHANGELOG.md: entry under Unreleased → Fixed.

Testing

  • pnpm check, pnpm lint, pnpm fmt:check, pnpm check:extension pass
  • pnpm test: 472 tests in 42 files pass

Not in this PR

  • The Anthropic provider's default model claude-3-5-haiku-latest is an older model; updating that default is left for a separate change.
  • The provider forces tool_choice: { type: "tool" }, which some newer Claude models (such as Claude Opus 5.5 and Claude Sonnet 5.5) also reject. Users on Haiku are unaffected; this is worth a follow-up.

Claude 4.7 and later models reject temperature: 0 with a 400
invalid_request_error, and API version 2026-10-21 rejects the
parameter on every model. Keep sending it only for Anthropic
Compatible endpoints, where local runtimes may still honor it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant