diff --git a/README.en.md b/README.en.md index 9461824..e10231d 100644 --- a/README.en.md +++ b/README.en.md @@ -215,7 +215,7 @@ node package/cli.js -r ### Configure MiniMax -MiniMax can be selected directly through the built-in provider registry. The default region is `global_en`; use `cn_zh` for the China endpoint. +MiniMax can be selected directly through the built-in provider registry. The default model is `MiniMax-M3.1-Flash`. The default region is `global_en`; use `cn_zh` for the China endpoint. ```json { @@ -230,10 +230,26 @@ MiniMax can be selected directly through the built-in provider registry. The def Run either registered model explicitly when needed: ```bash +node package/cli.js --settings settings.json --model MiniMax-M3.1-Flash node package/cli.js --settings settings.json --model MiniMax-M3 -node package/cli.js --settings settings.json --model MiniMax-M2.7 ``` +Both models have a 1,000,000-token context window and accept text, image, and video input. MiniMax-M3.1-Flash always uses adaptive thinking; disabling it is not supported. Its `output_config.effort` accepts `low`, `medium`, `high`, `xhigh`, and `max` (default). For example, select `xhigh` with `CLAUDE_CODE_EXTRA_BODY='{"output_config":{"effort":"xhigh"}}'`. `none` is invalid. Flash does not support `service_tier`, so this client omits that field for Flash requests. + +MiniMax-M3 supports adaptive or disabled thinking, defaults to disabled for this Messages client, and ignores effort. Its OpenAI-compatible API defaults to adaptive thinking; that API uses `reasoning_effort` for Flash instead of `output_config.effort`. + +Prices below are USD per million tokens (input / output / cache read); cache-write prices are unknown: + +| Model | Standard pricing | +| --- | --- | +| MiniMax-M3.1-Flash | $0.15 / $0.60 / $0.015 | +| MiniMax-M3, request input ≤512k | $0.30 / $1.20 / $0.06 | +| MiniMax-M3, request input >512k | $0.60 / $2.40 / $0.12 | + +MiniMax-M3 Priority costs 1.5× the Standard rates. The estimator retains its existing 512,000-token boundary; the official pricing page publishes `512k` without an integer expansion. No model-specific output limit is assumed. + +Sources: [models](https://platform.minimax.io/docs/guides/models-intro.md), [pricing](https://platform.minimax.io/docs/pricing/overview.md), [Messages API](https://platform.minimax.io/docs/api-reference/text-chat-anthropic.md), [OpenAI-compatible API](https://platform.minimax.io/docs/api-reference/text-chat-openai.md). + | Region | Anthropic-compatible base URL | OpenAI-compatible base URL | Documentation | | --- | --- | --- | --- | | `global_en` | `https://api.minimax.io/anthropic` | `https://api.minimax.io/v1` | `https://platform.minimax.io/docs` | diff --git a/src/services/api/claude.ts b/src/services/api/claude.ts index 1eb4fbf..ea32734 100644 --- a/src/services/api/claude.ts +++ b/src/services/api/claude.ts @@ -21,7 +21,9 @@ import type { TextBlockParam } from '@anthropic-ai/sdk/resources/index.mjs' import type { Stream } from '@anthropic-ai/sdk/streaming.mjs' import { randomUUID } from 'crypto' import { + configureMiniMaxRequest, getAPIProvider, + getMiniMaxModel, isFirstPartyAnthropicBaseUrl, } from 'src/utils/model/providers.js' import { @@ -445,6 +447,9 @@ function configureEffortParams( betas: string[], model: string, ): void { + // MiniMax effort is validated after custom output_config parameters are merged. + if (getMiniMaxModel(model)) return + if (!modelSupportsEffort(model) || 'effort' in outputConfig) { return } @@ -1703,7 +1708,7 @@ async function* queryModel( lastRequestBetas = betasParams - return { + const params = { model: normalizeModelStringForAPI(options.model), messages: addCacheBreakpoints( messagesForAPI, @@ -1733,6 +1738,8 @@ async function* queryModel( }), ...(speed !== undefined && { speed }), } + configureMiniMaxRequest(options.model, params, effort) + return params } // Compute log scalars synchronously so the fire-and-forget .then() closure diff --git a/src/utils/__tests__/minimax.test.ts b/src/utils/__tests__/minimax.test.ts new file mode 100644 index 0000000..342eed8 --- /dev/null +++ b/src/utils/__tests__/minimax.test.ts @@ -0,0 +1,91 @@ +import { test } from 'node:test' +import assert from 'node:assert/strict' +import { + configureMiniMaxRequest, + getMiniMaxModel, + getMiniMaxPricing, + MINIMAX_MODELS, +} from '../model/providers.js' +import { ALL_MODEL_CONFIGS } from '../model/configs.js' + +const flash = 'MiniMax-M3.1-Flash' + +test('MiniMax catalog and defaults contain only the current models', () => { + assert.deepEqual(MINIMAX_MODELS.map(model => model.modelId), [flash, 'MiniMax-M3']) + assert.equal(getMiniMaxModel(flash.toLowerCase())?.modelId, flash) + assert.equal(getMiniMaxModel('MiniMax-M2.7'), undefined) + for (const model of MINIMAX_MODELS) { + assert.equal(model.contextWindow, 1_000_000) + assert.deepEqual(model.inputModalities, ['text', 'image', 'video']) + assert.equal(model.pricingUsdPerMillionTokens.cacheWrite, null) + } + for (const config of Object.values(ALL_MODEL_CONFIGS)) { + assert.equal(config.minimax, flash) + } +}) + +test('MiniMax-M3 pricing selects context and service tiers at the boundary', () => { + for (const tokens of [0, 511_999, 512_000, 512_001, 1_000_000]) { + const longContext = tokens > 512_000 + for (const tier of ['standard', 'priority', undefined]) { + const expected = tier === 'priority' + ? (longContext ? [0.9, 3.6, 0.18] : [0.45, 1.8, 0.09]) + : (longContext ? [0.6, 2.4, 0.12] : [0.3, 1.2, 0.06]) + const pricing = getMiniMaxPricing('MiniMax-M3', tokens, tier)! + assert.deepEqual([pricing.input, pricing.output, pricing.cacheRead], expected) + assert.equal(pricing.cacheWrite, null) + } + } +}) + +test('Flash pricing stays flat and unknown models retain generic pricing fallback', () => { + for (const tokens of [0, 512_000, 512_001, 1_000_000]) { + assert.deepEqual(getMiniMaxPricing(flash, tokens), { + input: 0.15, output: 0.6, cacheRead: 0.015, cacheWrite: null, + }) + } + assert.equal(getMiniMaxPricing('custom-model'), undefined) +}) + +test('Flash enforces adaptive thinking and omits unsupported service tier', () => { + for (const thinking of [undefined, { type: 'disabled' }, { type: 'enabled', budget_tokens: 1000 }]) { + const params: Record = { thinking, service_tier: 'priority', max_tokens: 1234 } + configureMiniMaxRequest(flash, params, undefined) + assert.deepEqual(params.thinking, { type: 'adaptive' }) + assert.deepEqual(params.output_config, { effort: 'max' }) + assert.equal('service_tier' in params, false) + assert.equal(params.max_tokens, 1234) + } +}) + +test('Flash supports every published effort and preserves output format', () => { + for (const effort of ['low', 'medium', 'high', 'xhigh', 'max']) { + const format = { type: 'json_schema' } + const params: Record = { output_config: { effort, format } } + configureMiniMaxRequest(flash, params, 'low') + assert.deepEqual(params.output_config, { effort, format }) + const fromSetting: Record = {} + configureMiniMaxRequest(flash, fromSetting, effort) + assert.deepEqual(fromSetting.output_config, { effort }) + } + for (const effort of ['none', 'invalid', 42]) { + assert.throws(() => configureMiniMaxRequest(flash, { output_config: { effort } }, undefined), /Unsupported effort/) + } +}) + +test('MiniMax-M3 defaults thinking off, supports adaptive, and ignores effort', () => { + for (const thinking of [undefined, { type: 'disabled' }, { type: 'enabled', budget_tokens: 1000 }, { type: 'adaptive' }]) { + const params: Record = { thinking, output_config: { effort: 'max' }, service_tier: 'priority' } + configureMiniMaxRequest('MiniMax-M3', params, 'low') + assert.deepEqual(params.thinking, { type: thinking && thinking.type !== 'disabled' ? 'adaptive' : 'disabled' }) + assert.equal('output_config' in params, false) + assert.equal(params.service_tier, 'priority') + } +}) + +test('Custom model request parameters pass through unchanged', () => { + const params = { thinking: { type: 'enabled' }, output_config: { effort: 'custom' }, service_tier: 'priority' } + const original = structuredClone(params) + configureMiniMaxRequest('custom-model', params, undefined) + assert.deepEqual(params, original) +}) diff --git a/src/utils/effort.ts b/src/utils/effort.ts index cafcf3d..8a8deeb 100644 --- a/src/utils/effort.ts +++ b/src/utils/effort.ts @@ -3,7 +3,7 @@ import { isUltrathinkEnabled } from './thinking.js' import { getInitialSettings } from './settings/settings.js' import { isProSubscriber, isMaxSubscriber, isTeamSubscriber } from './auth.js' import { getFeatureValue_CACHED_MAY_BE_STALE } from 'src/services/analytics/growthbook.js' -import { getAPIProvider } from './model/providers.js' +import { getAPIProvider, getMiniMaxModel } from './model/providers.js' import { get3PModelCapabilityOverride } from './model/modelSupportOverrides.js' import { isEnvTruthy } from './envUtils.js' import type { EffortLevel } from 'src/entrypoints/sdk/runtimeTypes.js' @@ -21,6 +21,9 @@ export type EffortValue = EffortLevel | number // @[MODEL LAUNCH]: Add the new model to the allowlist if it supports the effort parameter. export function modelSupportsEffort(model: string): boolean { + const miniMaxModel = getMiniMaxModel(model) + if (miniMaxModel) return miniMaxModel.reasoningEfforts.length > 0 + const m = model.toLowerCase() if (isEnvTruthy(process.env.CLAUDE_CODE_ALWAYS_ENABLE_EFFORT)) { return true @@ -51,6 +54,9 @@ export function modelSupportsEffort(model: string): boolean { // @[MODEL LAUNCH]: Add the new model to the allowlist if it supports 'max' effort. // Per API docs, 'max' is Opus 4.6 only for public models — other models return an error. export function modelSupportsMaxEffort(model: string): boolean { + const miniMaxModel = getMiniMaxModel(model) + if (miniMaxModel) return miniMaxModel.defaultEffort === 'max' + const supported3P = get3PModelCapabilityOverride(model, 'max_effort') if (supported3P !== undefined) { return supported3P @@ -279,6 +285,9 @@ export function getOpusDefaultEffortConfig(): OpusDefaultEffortConfig { export function getDefaultEffortForModel( model: string, ): EffortValue | undefined { + const miniMaxModel = getMiniMaxModel(model) + if (miniMaxModel) return miniMaxModel.defaultEffort + if (process.env.USER_TYPE === 'ant') { const config = getAntModelOverrideConfig() const isDefaultModel = diff --git a/src/utils/model/configs.ts b/src/utils/model/configs.ts index 6b4d76f..728a950 100644 --- a/src/utils/model/configs.ts +++ b/src/utils/model/configs.ts @@ -11,7 +11,7 @@ export const CLAUDE_3_7_SONNET_CONFIG = { bedrock: 'us.anthropic.claude-3-7-sonnet-20250219-v1:0', vertex: 'claude-3-7-sonnet@20250219', foundry: 'claude-3-7-sonnet', - minimax: 'MiniMax-M3', + minimax: 'MiniMax-M3.1-Flash', } as const satisfies ModelConfig export const CLAUDE_3_5_V2_SONNET_CONFIG = { @@ -19,7 +19,7 @@ export const CLAUDE_3_5_V2_SONNET_CONFIG = { bedrock: 'anthropic.claude-3-5-sonnet-20241022-v2:0', vertex: 'claude-3-5-sonnet-v2@20241022', foundry: 'claude-3-5-sonnet', - minimax: 'MiniMax-M3', + minimax: 'MiniMax-M3.1-Flash', } as const satisfies ModelConfig export const CLAUDE_3_5_HAIKU_CONFIG = { @@ -27,7 +27,7 @@ export const CLAUDE_3_5_HAIKU_CONFIG = { bedrock: 'us.anthropic.claude-3-5-haiku-20241022-v1:0', vertex: 'claude-3-5-haiku@20241022', foundry: 'claude-3-5-haiku', - minimax: 'MiniMax-M2.7', + minimax: 'MiniMax-M3.1-Flash', } as const satisfies ModelConfig export const CLAUDE_HAIKU_4_5_CONFIG = { @@ -35,7 +35,7 @@ export const CLAUDE_HAIKU_4_5_CONFIG = { bedrock: 'us.anthropic.claude-haiku-4-5-20251001-v1:0', vertex: 'claude-haiku-4-5@20251001', foundry: 'claude-haiku-4-5', - minimax: 'MiniMax-M2.7', + minimax: 'MiniMax-M3.1-Flash', } as const satisfies ModelConfig export const CLAUDE_SONNET_4_CONFIG = { @@ -43,7 +43,7 @@ export const CLAUDE_SONNET_4_CONFIG = { bedrock: 'us.anthropic.claude-sonnet-4-20250514-v1:0', vertex: 'claude-sonnet-4@20250514', foundry: 'claude-sonnet-4', - minimax: 'MiniMax-M3', + minimax: 'MiniMax-M3.1-Flash', } as const satisfies ModelConfig export const CLAUDE_SONNET_4_5_CONFIG = { @@ -51,7 +51,7 @@ export const CLAUDE_SONNET_4_5_CONFIG = { bedrock: 'us.anthropic.claude-sonnet-4-5-20250929-v1:0', vertex: 'claude-sonnet-4-5@20250929', foundry: 'claude-sonnet-4-5', - minimax: 'MiniMax-M3', + minimax: 'MiniMax-M3.1-Flash', } as const satisfies ModelConfig export const CLAUDE_OPUS_4_CONFIG = { @@ -59,7 +59,7 @@ export const CLAUDE_OPUS_4_CONFIG = { bedrock: 'us.anthropic.claude-opus-4-20250514-v1:0', vertex: 'claude-opus-4@20250514', foundry: 'claude-opus-4', - minimax: 'MiniMax-M3', + minimax: 'MiniMax-M3.1-Flash', } as const satisfies ModelConfig export const CLAUDE_OPUS_4_1_CONFIG = { @@ -67,7 +67,7 @@ export const CLAUDE_OPUS_4_1_CONFIG = { bedrock: 'us.anthropic.claude-opus-4-1-20250805-v1:0', vertex: 'claude-opus-4-1@20250805', foundry: 'claude-opus-4-1', - minimax: 'MiniMax-M3', + minimax: 'MiniMax-M3.1-Flash', } as const satisfies ModelConfig export const CLAUDE_OPUS_4_5_CONFIG = { @@ -75,7 +75,7 @@ export const CLAUDE_OPUS_4_5_CONFIG = { bedrock: 'us.anthropic.claude-opus-4-5-20251101-v1:0', vertex: 'claude-opus-4-5@20251101', foundry: 'claude-opus-4-5', - minimax: 'MiniMax-M3', + minimax: 'MiniMax-M3.1-Flash', } as const satisfies ModelConfig export const CLAUDE_OPUS_4_6_CONFIG = { @@ -83,7 +83,7 @@ export const CLAUDE_OPUS_4_6_CONFIG = { bedrock: 'us.anthropic.claude-opus-4-6-v1', vertex: 'claude-opus-4-6', foundry: 'claude-opus-4-6', - minimax: 'MiniMax-M3', + minimax: 'MiniMax-M3.1-Flash', } as const satisfies ModelConfig export const CLAUDE_SONNET_4_6_CONFIG = { @@ -91,7 +91,7 @@ export const CLAUDE_SONNET_4_6_CONFIG = { bedrock: 'us.anthropic.claude-sonnet-4-6', vertex: 'claude-sonnet-4-6', foundry: 'claude-sonnet-4-6', - minimax: 'MiniMax-M3', + minimax: 'MiniMax-M3.1-Flash', } as const satisfies ModelConfig // @[MODEL LAUNCH]: Register the new config here. diff --git a/src/utils/model/providers.ts b/src/utils/model/providers.ts index da8ce46..e31515c 100644 --- a/src/utils/model/providers.ts +++ b/src/utils/model/providers.ts @@ -15,6 +15,24 @@ type MiniMaxPricingTier = { } export const MINIMAX_MODELS = [ + { + modelId: 'MiniMax-M3.1-Flash', + contextWindow: 1_000_000, + pricingUsdPerMillionTokens: { + input: 0.15, + output: 0.6, + cacheRead: 0.015, + cacheWrite: null, + }, + pricingTiersUsdPerMillionTokens: [], + inputModalities: ['text', 'image', 'video'], + thinking: ['adaptive'], + defaultThinking: 'adaptive', + alwaysUsesThinking: true, + reasoningEfforts: ['low', 'medium', 'high', 'xhigh', 'max'], + defaultEffort: 'max', + supportsServiceTier: false, + }, { modelId: 'MiniMax-M3', contextWindow: 1_000_000, @@ -24,65 +42,36 @@ export const MINIMAX_MODELS = [ cacheRead: 0.06, cacheWrite: null, }, + // Preserve the existing 512,000-token interpretation of the published 512k tier. pricingTiersUsdPerMillionTokens: [ { serviceTier: 'standard', maxInputTokens: 512_000, - pricing: { - input: 0.3, - output: 1.2, - cacheRead: 0.06, - cacheWrite: null, - }, + pricing: { input: 0.3, output: 1.2, cacheRead: 0.06, cacheWrite: null }, }, { serviceTier: 'standard', maxInputTokens: null, - pricing: { - input: 0.6, - output: 2.4, - cacheRead: 0.12, - cacheWrite: null, - }, + pricing: { input: 0.6, output: 2.4, cacheRead: 0.12, cacheWrite: null }, }, { serviceTier: 'priority', maxInputTokens: 512_000, - pricing: { - input: 0.45, - output: 1.8, - cacheRead: 0.09, - cacheWrite: null, - }, + pricing: { input: 0.45, output: 1.8, cacheRead: 0.09, cacheWrite: null }, }, { serviceTier: 'priority', maxInputTokens: null, - pricing: { - input: 0.9, - output: 3.6, - cacheRead: 0.18, - cacheWrite: null, - }, + pricing: { input: 0.9, output: 3.6, cacheRead: 0.18, cacheWrite: null }, }, ], inputModalities: ['text', 'image', 'video'], thinking: ['adaptive', 'disabled'], defaultThinking: 'disabled', - }, - { - modelId: 'MiniMax-M2.7', - contextWindow: 204_800, - pricingUsdPerMillionTokens: { - input: 0.3, - output: 1.2, - cacheRead: 0.06, - cacheWrite: 0.375, - }, - pricingTiersUsdPerMillionTokens: [], - inputModalities: ['text'], - thinking: ['always_on'], - defaultThinking: 'always_on', + alwaysUsesThinking: false, + reasoningEfforts: [], + defaultEffort: undefined, + supportsServiceTier: true, }, ] as const @@ -142,6 +131,46 @@ export function getMiniMaxPricing( return pricingTier?.pricing ?? model.pricingUsdPerMillionTokens } +/** Apply MiniMax's Messages contract after merging custom request parameters. */ +export function configureMiniMaxRequest( + modelId: string, + params: Record, + effort: unknown, +): void { + const model = getMiniMaxModel(modelId) + if (!model) return + + const thinking = params.thinking as { type?: string } | null | undefined + params.thinking = { + type: + model.alwaysUsesThinking || (thinking != null && thinking.type !== 'disabled') + ? 'adaptive' + : 'disabled', + } + + const outputConfig = { + ...((params.output_config as Record) ?? {}), + } + if (model.reasoningEfforts.length > 0) { + const requestedEffort = outputConfig.effort ?? effort ?? model.defaultEffort + if (!(model.reasoningEfforts as readonly unknown[]).includes(requestedEffort)) { + throw new Error( + `Unsupported effort for ${model.modelId}: ${String(requestedEffort)}`, + ) + } + outputConfig.effort = requestedEffort + } else { + // MiniMax-M3 ignores effort; do not advertise a setting that has no effect. + delete outputConfig.effort + } + if (Object.keys(outputConfig).length > 0) { + params.output_config = outputConfig + } else { + delete params.output_config + } + if (!model.supportsServiceTier) delete params.service_tier +} + export type APIProvider = | 'firstParty' | 'bedrock' diff --git a/src/utils/thinking.ts b/src/utils/thinking.ts index 5eb2f28..3a76a9c 100644 --- a/src/utils/thinking.ts +++ b/src/utils/thinking.ts @@ -114,7 +114,7 @@ export function modelSupportsThinking(model: string): boolean { } export function modelAlwaysUsesThinking(model: string): boolean { - return getMiniMaxModel(model)?.defaultThinking === 'always_on' + return getMiniMaxModel(model)?.alwaysUsesThinking ?? false } // @[MODEL LAUNCH]: Add the new model to the allowlist if it supports adaptive thinking. @@ -156,6 +156,8 @@ export function modelSupportsAdaptiveThinking(model: string): boolean { } export function shouldEnableThinkingByDefault(): boolean { + if (modelAlwaysUsesThinking(getMainLoopModel())) return true + if (process.env.MAX_THINKING_TOKENS) { return parseInt(process.env.MAX_THINKING_TOKENS, 10) > 0 }