Skip to content

Commit 94aed06

Browse files
authored
fix(anthropic): allow both temperature and topP for non-Anthropic models (#14052)
## Background The `@ai-sdk/anthropic` provider enforces temperature/topP mutual exclusivity for all models (#11458), matching a constraint in the Anthropic API. However, providers like Minimax use the Anthropic-compatible API endpoint with non-Anthropic models (e.g. `MiniMax-M2.7`) that require both `temperature` and `top_p` to be set simultaneously. The SDK currently drops `topP` whenever both are provided, with no way to override this behavior. ## Summary - Renamed `isKnownModel` to `isKnownAnthropicModel` for clarity - Updated the fallback in `getModelCapabilities` to return `true` for unknown models whose ID starts with `claude-` (forward-compatible with future Anthropic models) - Added `isKnownAnthropicModel` as a guard for the temperature/topP mutual exclusivity check — non-Anthropic models using the Anthropic-compatible API can now send both parameters ## Manual Verification Created a test using a non-Anthropic model ID (`MiniMax-M2.7`) that verifies both `temperature` and `top_p` are sent in the request body without warnings.
1 parent 2122d7a commit 94aed06

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@ai-sdk/anthropic': patch
3+
---
4+
5+
fix(anthropic): allow both temperature and topP for non-Anthropic models using the Anthropic-compatible API
6+
7+
The temperature/topP mutual exclusivity check now only applies to known Anthropic models (model IDs starting with `claude-`). Non-Anthropic models using the Anthropic-compatible API (e.g. Minimax) can now send both parameters as required by their APIs.

packages/anthropic/src/anthropic-messages-language-model.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,26 @@ describe('AnthropicMessagesLanguageModel', () => {
11681168
expect(requestBody.temperature).toBeUndefined();
11691169
expect(requestBody.top_p).toBeUndefined();
11701170
});
1171+
1172+
it('should send both temperature and topP for non-Anthropic models', async () => {
1173+
prepareJsonFixtureResponse('anthropic-text');
1174+
1175+
const nonAnthropicModel = provider('MiniMax-M2.7');
1176+
const { warnings } = await nonAnthropicModel.doGenerate({
1177+
prompt: TEST_PROMPT,
1178+
temperature: 0.7,
1179+
topP: 0.9,
1180+
});
1181+
1182+
const requestBody = await server.calls[0].requestBodyJson;
1183+
expect(requestBody.temperature).toBe(0.7);
1184+
expect(requestBody.top_p).toBe(0.9);
1185+
expect(warnings).not.toContainEqual(
1186+
expect.objectContaining({
1187+
feature: 'topP',
1188+
}),
1189+
);
1190+
});
11711191
});
11721192

11731193
it('should limit max output tokens to the model max and warn', async () => {

packages/anthropic/src/anthropic-messages-language-model.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
272272
isKnownModel,
273273
} = getModelCapabilities(this.modelId);
274274

275+
const isAnthropicModel = isKnownModel || this.modelId.startsWith('claude-');
276+
275277
const supportsStructuredOutput =
276278
(this.config.supportsNativeStructuredOutput ?? true) &&
277279
modelSupportsStructuredOutput;
@@ -535,8 +537,10 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
535537
// adjust max tokens to account for thinking:
536538
baseArgs.max_tokens = maxTokens + (thinkingBudget ?? 0);
537539
} else {
538-
// Only check temperature/topP mutual exclusivity when thinking is not enabled
539-
if (topP != null && temperature != null) {
540+
// Only check temperature/topP mutual exclusivity for known Anthropic models
541+
// when thinking is not enabled. Non-Anthropic models using the Anthropic-compatible
542+
// API (e.g. Minimax) may require both parameters to be set.
543+
if (isAnthropicModel && topP != null && temperature != null) {
540544
warnings.push({
541545
type: 'unsupported',
542546
feature: 'topP',

0 commit comments

Comments
 (0)