Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(minimax): normalize unsupported image detail "auto" (#17281)

zerafachris6851acb3fdf5
diff --git a/packages/model-runtime/src/providers/minimax/index.test.ts b/packages/model-runtime/src/providers/minimax/index.test.ts
index 3a779279f38..32981617a2e 100644
--- a/packages/model-runtime/src/providers/minimax/index.test.ts
+++ b/packages/model-runtime/src/providers/minimax/index.test.ts
@@ -418,6 +418,44 @@ describe('LobeMinimaxAI - handlePayload', () => {
expect(result.messages[0].content).toBe(content);
});
+ it('omits rejected image detail "auto" to use MiniMax default behavior', () => {
+ const imagePart = {
+ image_url: { detail: 'auto', url: 'https://example.com/image.png' },
+ type: 'image_url',
+ };
+ const content = [{ text: 'describe this image', type: 'text' }, imagePart];
+
+ const result = handlePayload({
+ messages: [{ content, role: 'user' }],
+ model: 'MiniMax-M3',
+ } as any);
+
+ expect((result.messages[0].content as any)[1].image_url).toEqual({
+ url: 'https://example.com/image.png',
+ });
+ // Original payload must not be mutated in place.
+ expect(imagePart.image_url.detail).toBe('auto');
+ });
+
+ it('leaves supported image detail values untouched', () => {
+ const content = [
+ { image_url: { detail: 'low', url: 'https://example.com/image.png' }, type: 'image_url' },
+ {
+ image_url: { detail: 'default', url: 'https://example.com/image.png' },
+ type: 'image_url',
+ },
+ { image_url: { detail: 'high', url: 'https://example.com/image.png' }, type: 'image_url' },
+ { image_url: { url: 'https://example.com/image.png' }, type: 'image_url' },
+ ];
+
+ const result = handlePayload({
+ messages: [{ content, role: 'user' }],
+ model: 'MiniMax-M3',
+ } as any);
+
+ expect(result.messages[0].content).toBe(content);
+ });
+
it('keeps reasoning_split enabled for non-M3 MiniMax models', () => {
const result = handlePayload({
messages: [{ content: 'hi', role: 'user' }],
diff --git a/packages/model-runtime/src/providers/minimax/index.ts b/packages/model-runtime/src/providers/minimax/index.ts
index 240003c7212..280102032db 100644
--- a/packages/model-runtime/src/providers/minimax/index.ts
+++ b/packages/model-runtime/src/providers/minimax/index.ts
@@ -11,7 +11,7 @@ import { createOpenAICompatibleRuntime } from '../../core/openaiCompatibleFactor
import { resolveParameters } from '../../core/parameterResolver';
import type { CreateRouterRuntimeOptions } from '../../core/RouterRuntime';
import { createRouterRuntime } from '../../core/RouterRuntime';
-import type { ChatStreamPayload } from '../../types';
+import type { ChatStreamPayload, OpenAIChatMessage } from '../../types';
import { getModelPropertyWithFallback } from '../../utils/getFallbackModelProperty';
import { resolveSafeMaxTokens } from '../../utils/resolveSafeMaxTokens';
import { createMiniMaxImage } from './createImage';
@@ -31,6 +31,29 @@ const isEmptyContent = (content: unknown) =>
const hasReasoningContent = (reasoning: any) => typeof reasoning?.content === 'string';
+// MiniMax accepts `low`, `default`, and `high`, but rejects OpenAI's `auto`.
+// Omit `auto` so MiniMax applies its equivalent `default` behavior.
+const MINIMAX_UNSUPPORTED_IMAGE_DETAIL = 'auto';
+
+const normalizeMiniMaxImageDetail = (content: OpenAIChatMessage['content']) => {
+ if (!Array.isArray(content)) return content;
+
+ let changed = false;
+
+ const next = content.map((part) => {
+ if (part.type === 'image_url' && part.image_url.detail === MINIMAX_UNSUPPORTED_IMAGE_DETAIL) {
+ changed = true;
+ const { detail: _detail, ...imageUrl } = part.image_url;
+
+ return { ...part, image_url: imageUrl };
+ }
+
+ return part;
+ });
+
+ return changed ? next : content;
+};
+
const normalizeMiniMaxAnthropicBaseURL = (baseURL?: string | null) =>
baseURL?.replace(MINIMAX_ANTHROPIC_MESSAGES_PATH_PATTERN, '');
@@ -122,11 +145,13 @@ export const buildMiniMaxOpenAIPayload = (payload: ChatStreamPayload) => {
// Interleaved thinking
const processedMessages = messages.map((message: any) => {
+ let processed = message;
+
if (message.role === 'assistant' && message.reasoning) {
// Only process historical reasoning content without a signature
if (!message.reasoning.signature && message.reasoning.content) {
const { reasoning, ...messageWithoutReasoning } = message;
- return {
+ processed = {
...messageWithoutReasoning,
reasoning_details: [
{
@@ -138,13 +163,18 @@ export const buildMiniMaxOpenAIPayload = (payload: ChatStreamPayload) => {
},
],
};
+ } else {
+ // If there is a signature or no content, remove the reasoning field
+ const { reasoning: _reasoning, ...messageWithoutReasoning } = message;
+ processed = messageWithoutReasoning;
}
-
- // If there is a signature or no content, remove the reasoning field
- const { reasoning: _reasoning, ...messageWithoutReasoning } = message;
- return messageWithoutReasoning;
}
- return message;
+
+ const normalizedContent = normalizeMiniMaxImageDetail(processed.content);
+
+ return normalizedContent === processed.content
+ ? processed
+ : { ...processed, content: normalizedContent };
});
// MiniMax API enforces `input_tokens + max_tokens <= context_window`,