Feat: Add MiniMax AI provider (#7094)

* feat: add minimax ai

* feat: api

* feat: mmx

* feat: name

* feat: model name

* feat: fix

* feat: fix

* feat: add model info

* feat: format code

* feat: format code

* feat: code

* fix: log

* feat: param

* feat: add m2

* feat: add m2

* feat: format code

* feat: info

---------

Co-authored-by: xiaose <xiaose@minmaxi.com>
This commit is contained in:
Maosghoulandxiaose authored and GitHub committed 2025-10-27 11:18:34 -07:00
1 parent 604dbd7bb0
commit aae9d432fd
14 files changed
+261

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"claude-dev": minor
---
Add support for MiniMaxAI MiniMax-M2
+2
View File
@@ -672,6 +672,8 @@ func parseApiProvider(value string) (cline.ApiProvider, error) {
return cline.ApiProvider_DIFY, nil
case "oca":
return cline.ApiProvider_OCA, nil
case "minimax":
return cline.ApiProvider_MINIMAX, nil
default:
return cline.ApiProvider_ANTHROPIC, fmt.Errorf("invalid api_provider '%s'", value)
}
+3
View File
@@ -229,6 +229,7 @@ enum ApiProvider {
QWEN_CODE = 33;
DIFY = 34;
OCA = 35;
MINIMAX = 36;
}
// Model info for OpenAI-compatible models
@@ -346,6 +347,8 @@ message ModelsApiConfiguration {
optional string oca_refresh_token = 75;
optional string oca_mode = 76;
optional bool aws_use_global_inference = 77;
optional string minimax_api_key = 78;
optional string minimax_api_line = 79;
// Plan mode configurations
optional ApiProvider plan_mode_api_provider = 100;
+8
View File
@@ -18,6 +18,7 @@ import { HuaweiCloudMaaSHandler } from "./providers/huawei-cloud-maas"
import { HuggingFaceHandler } from "./providers/huggingface"
import { LiteLlmHandler } from "./providers/litellm"
import { LmStudioHandler } from "./providers/lmstudio"
import { MinimaxHandler } from "./providers/minimax"
import { MistralHandler } from "./providers/mistral"
import { MoonshotHandler } from "./providers/moonshot"
import { NebiusHandler } from "./providers/nebius"
@@ -389,6 +390,13 @@ function createHandlerForProvider(
: options.actModeOcaModelInfo?.supportsPromptCache,
taskId: options.ulid,
})
case "minimax":
return new MinimaxHandler({
onRetryAttempt: options.onRetryAttempt,
minimaxApiKey: options.minimaxApiKey,
minimaxApiLine: options.minimaxApiLine,
apiModelId: mode === "plan" ? options.planModeApiModelId : options.actModeApiModelId,
})
default:
return new AnthropicHandler({
onRetryAttempt: options.onRetryAttempt,
+95
View File
@@ -0,0 +1,95 @@
import { Anthropic } from "@anthropic-ai/sdk"
import OpenAI from "openai"
import { MinimaxModelId, ModelInfo, minimaxDefaultModelId, minimaxModels } from "@/shared/api"
import { ApiHandler, CommonApiHandlerOptions } from "../index"
import { withRetry } from "../retry"
import { convertToOpenAiMessages } from "../transform/openai-format"
import { ApiStream } from "../transform/stream"
interface MinimaxHandlerOptions extends CommonApiHandlerOptions {
minimaxApiKey?: string
minimaxApiLine?: string
apiModelId?: string
}
export class MinimaxHandler implements ApiHandler {
private client: OpenAI | undefined
constructor(private readonly options: MinimaxHandlerOptions) {}
private ensureClient(): OpenAI {
if (!this.client) {
if (!this.options.minimaxApiKey) {
throw new Error("MiniMax API key is required")
}
try {
this.client = new OpenAI({
baseURL:
this.options.minimaxApiLine === "china" ? "https://api.minimaxi.com/v1" : "https://api.minimax.io/v1",
apiKey: this.options.minimaxApiKey,
})
} catch (error) {
throw new Error(`Error creating MiniMax client: ${error.message}`)
}
}
return this.client
}
@withRetry()
async *createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream {
const client = this.ensureClient()
const model = this.getModel()
const openAiMessages: OpenAI.Chat.ChatCompletionMessageParam[] = [
{ role: "system", content: systemPrompt },
...convertToOpenAiMessages(messages),
]
const stream = await client.chat.completions.create({
model: model.id,
messages: openAiMessages,
max_tokens: model.info.maxTokens,
stream: true,
stream_options: { include_usage: true },
})
for await (const chunk of stream) {
const delta = chunk.choices[0]?.delta
if (delta?.content) {
yield {
type: "text",
text: delta.content,
}
}
if (delta && "reasoning_content" in delta && delta.reasoning_content) {
yield {
type: "reasoning",
reasoning: (delta.reasoning_content as string | undefined) || "",
}
}
if (chunk.usage) {
yield {
type: "usage",
inputTokens: chunk.usage.prompt_tokens || 0,
outputTokens: chunk.usage.completion_tokens || 0,
// @ts-ignore-next-line
cacheReadTokens: chunk.usage.prompt_cache_hit_tokens || 0,
// @ts-ignore-next-line
cacheWriteTokens: chunk.usage.prompt_cache_miss_tokens || 0,
}
}
}
}
getModel(): { id: MinimaxModelId; info: ModelInfo } {
const modelId = this.options.apiModelId
if (modelId && modelId in minimaxModels) {
const id = modelId as MinimaxModelId
return { id, info: minimaxModels[id] }
}
return { id: minimaxDefaultModelId, info: minimaxModels[minimaxDefaultModelId] }
}
}
+6
View File
@@ -489,6 +489,8 @@ export class StateManager {
difyBaseUrl,
vercelAiGatewayApiKey,
zaiApiKey,
minimaxApiKey,
minimaxApiLine,
requestTimeoutMs,
ocaBaseUrl,
ocaMode,
@@ -673,6 +675,7 @@ export class StateManager {
difyBaseUrl,
qwenCodeOauthPath,
ocaBaseUrl,
minimaxApiLine,
ocaMode,
})
@@ -712,6 +715,7 @@ export class StateManager {
difyApiKey,
vercelAiGatewayApiKey,
zaiApiKey,
minimaxApiKey,
})
}
@@ -983,6 +987,7 @@ export class StateManager {
difyApiKey: this.secretsCache["difyApiKey"],
vercelAiGatewayApiKey: this.secretsCache["vercelAiGatewayApiKey"],
zaiApiKey: this.secretsCache["zaiApiKey"],
minimaxApiKey: this.secretsCache["minimaxApiKey"],
// Global state (with remote config precedence for applicable fields)
awsRegion:
@@ -1052,6 +1057,7 @@ export class StateManager {
qwenCodeOauthPath: this.taskStateCache["qwenCodeOauthPath"] || this.globalStateCache["qwenCodeOauthPath"],
difyBaseUrl: this.taskStateCache["difyBaseUrl"] || this.globalStateCache["difyBaseUrl"],
ocaBaseUrl: this.globalStateCache["ocaBaseUrl"],
minimaxApiLine: this.taskStateCache["minimaxApiLine"] || this.globalStateCache["minimaxApiLine"],
ocaMode: this.globalStateCache["ocaMode"],
// Plan mode configurations
+7
View File
@@ -50,6 +50,7 @@ export async function readSecretsFromDisk(context: ExtensionContext): Promise<Se
authNonce,
ocaApiKey,
ocaRefreshToken,
minimaxApiKey,
] = await Promise.all([
context.secrets.get("apiKey") as Promise<Secrets["apiKey"]>,
context.secrets.get("openRouterApiKey") as Promise<Secrets["openRouterApiKey"]>,
@@ -89,6 +90,7 @@ export async function readSecretsFromDisk(context: ExtensionContext): Promise<Se
context.secrets.get("authNonce") as Promise<Secrets["authNonce"]>,
context.secrets.get("ocaApiKey") as Promise<string | undefined>,
context.secrets.get("ocaRefreshToken") as Promise<string | undefined>,
context.secrets.get("minimaxApiKey") as Promise<Secrets["minimaxApiKey"]>,
])
return {
@@ -130,6 +132,7 @@ export async function readSecretsFromDisk(context: ExtensionContext): Promise<Se
awsSessionToken,
ocaApiKey,
ocaRefreshToken,
minimaxApiKey,
}
}
@@ -200,6 +203,7 @@ export async function readGlobalStateFromDisk(context: ExtensionContext): Promis
const qwenApiLine = context.globalState.get<GlobalStateAndSettings["qwenApiLine"]>("qwenApiLine")
const moonshotApiLine = context.globalState.get<GlobalStateAndSettings["moonshotApiLine"]>("moonshotApiLine")
const zaiApiLine = context.globalState.get<GlobalStateAndSettings["zaiApiLine"]>("zaiApiLine")
const minimaxApiLine = context.globalState.get<GlobalStateAndSettings["minimaxApiLine"]>("minimaxApiLine")
const telemetrySetting = context.globalState.get<GlobalStateAndSettings["telemetrySetting"]>("telemetrySetting")
const asksageApiUrl = context.globalState.get<GlobalStateAndSettings["asksageApiUrl"]>("asksageApiUrl")
const planActSeparateModelsSettingRaw =
@@ -505,7 +509,9 @@ export async function readGlobalStateFromDisk(context: ExtensionContext): Promis
difyBaseUrl,
sapAiCoreUseOrchestrationMode: sapAiCoreUseOrchestrationMode ?? true,
ocaBaseUrl,
minimaxApiLine,
ocaMode: ocaMode || "internal",
// Plan mode configurations
planModeApiProvider: planModeApiProvider || apiProvider,
planModeApiModelId,
@@ -693,6 +699,7 @@ export async function resetGlobalState(controller: Controller) {
"difyApiKey",
"ocaApiKey",
"ocaRefreshToken",
"minimaxApiKey",
]
await Promise.all(secretKeys.map((key) => context.secrets.delete(key)))
await controller.stateManager.reInitialize()
+21
View File
@@ -37,6 +37,7 @@ export type ApiProvider =
| "vercel-ai-gateway"
| "zai"
| "oca"
| "minimax"
export interface ApiHandlerSecrets {
apiKey?: string // anthropic
@@ -75,6 +76,7 @@ export interface ApiHandlerSecrets {
basetenApiKey?: string
vercelAiGatewayApiKey?: string
difyApiKey?: string
minimaxApiKey?: string
}
export interface ApiHandlerOptions {
@@ -120,6 +122,7 @@ export interface ApiHandlerOptions {
zaiApiLine?: string
onRetryAttempt?: (attempt: number, maxRetries: number, delay: number, error: any) => void
ocaBaseUrl?: string
minimaxApiLine?: string
ocaMode?: string
// Plan mode configurations
@@ -3826,3 +3829,21 @@ export const qwenCodeModels = {
} as const satisfies Record<string, ModelInfo>
export type QwenCodeModelId = keyof typeof qwenCodeModels
export const qwenCodeDefaultModelId: QwenCodeModelId = "qwen3-coder-plus"
// Minimax
// https://www.minimax.io/platform/document/text_api_intro
// https://www.minimax.io/platform/document/pricing
export type MinimaxModelId = keyof typeof minimaxModels
export const minimaxDefaultModelId: MinimaxModelId = "MiniMax-M2"
export const minimaxModels = {
"MiniMax-M2": {
maxTokens: 128_000,
contextWindow: 192_000,
supportsImages: false,
supportsPromptCache: false,
inputPrice: 0.3,
outputPrice: 1.2,
cacheWritesPrice: 0,
cacheReadsPrice: 0,
},
} as const satisfies Record<string, ModelInfo>
@@ -307,6 +307,8 @@ function convertApiProviderToProto(provider: string | undefined): ProtoApiProvid
return ProtoApiProvider.DIFY
case "oca":
return ProtoApiProvider.OCA
case "minimax":
return ProtoApiProvider.MINIMAX
default:
return ProtoApiProvider.ANTHROPIC
}
@@ -387,6 +389,8 @@ export function convertProtoToApiProvider(provider: ProtoApiProvider): ApiProvid
return "dify"
case ProtoApiProvider.OCA:
return "oca"
case ProtoApiProvider.MINIMAX:
return "minimax"
default:
return "anthropic"
}
@@ -469,6 +473,8 @@ export function convertApiConfigurationToProto(config: ApiConfiguration): ProtoA
difyApiKey: config.difyApiKey,
difyBaseUrl: config.difyBaseUrl,
ocaBaseUrl: config.ocaBaseUrl,
minimaxApiKey: config.minimaxApiKey,
minimaxApiLine: config.minimaxApiLine,
ocaMode: config.ocaMode,
// Plan mode configurations
@@ -621,6 +627,8 @@ export function convertProtoToApiConfiguration(protoConfig: ProtoApiConfiguratio
difyBaseUrl: protoConfig.difyBaseUrl,
ocaBaseUrl: protoConfig.ocaBaseUrl,
ocaMode: protoConfig.ocaMode,
minimaxApiKey: protoConfig.minimaxApiKey,
minimaxApiLine: protoConfig.minimaxApiLine,
// Plan mode configurations
planModeApiProvider:
+2
View File
@@ -106,6 +106,7 @@ export interface Settings {
difyBaseUrl: string | undefined
autoCondenseThreshold: number | undefined // number from 0 to 1
ocaBaseUrl: string | undefined
minimaxApiLine: string | undefined
ocaMode: string | undefined
hooksEnabled: boolean
subagentsEnabled: boolean
@@ -235,6 +236,7 @@ export interface Secrets {
difyApiKey: string | undefined
ocaApiKey: string | undefined
ocaRefreshToken: string | undefined
minimaxApiKey: string | undefined
}
export interface LocalState {
@@ -29,6 +29,7 @@ import { HuaweiCloudMaasProvider } from "./providers/HuaweiCloudMaasProvider"
import { HuggingFaceProvider } from "./providers/HuggingFaceProvider"
import { LiteLlmProvider } from "./providers/LiteLlmProvider"
import { LMStudioProvider } from "./providers/LMStudioProvider"
import { MinimaxProvider } from "./providers/MiniMaxProvider"
import { MistralProvider } from "./providers/MistralProvider"
import { MoonshotProvider } from "./providers/MoonshotProvider"
import { NebiusProvider } from "./providers/NebiusProvider"
@@ -163,6 +164,7 @@ const ApiOptions = ({ showModelOptions, apiErrorMessage, modelIdErrorMessage, is
{ value: "huawei-cloud-maas", label: "Huawei Cloud MaaS" },
{ value: "dify", label: "Dify.ai" },
{ value: "oca", label: "Oracle Code Assist" },
{ value: "minimax", label: "MiniMax" },
]
if (PLATFORM_CONFIG.type !== PlatformType.VSCODE) {
@@ -504,6 +506,10 @@ const ApiOptions = ({ showModelOptions, apiErrorMessage, modelIdErrorMessage, is
<ZAiProvider currentMode={currentMode} isPopup={isPopup} showModelOptions={showModelOptions} />
)}
{apiConfiguration && selectedProvider === "minimax" && (
<MinimaxProvider currentMode={currentMode} isPopup={isPopup} showModelOptions={showModelOptions} />
)}
{apiConfiguration && selectedProvider === "oca" && <OcaProvider currentMode={currentMode} isPopup={isPopup} />}
{apiErrorMessage && (
@@ -0,0 +1,88 @@
import { minimaxModels } from "@shared/api"
import { Mode } from "@shared/storage/types"
import { VSCodeDropdown, VSCodeOption } from "@vscode/webview-ui-toolkit/react"
import { useExtensionState } from "@/context/ExtensionStateContext"
import { ApiKeyField } from "../common/ApiKeyField"
import { ModelInfoView } from "../common/ModelInfoView"
import { DropdownContainer, ModelSelector } from "../common/ModelSelector"
import { normalizeApiConfiguration } from "../utils/providerUtils"
import { useApiConfigurationHandlers } from "../utils/useApiConfigurationHandlers"
/**
* Props for the MinimaxProvider component
*/
interface MinimaxProviderProps {
showModelOptions: boolean
isPopup?: boolean
currentMode: Mode
}
/**
* The Minimax AI Studio provider configuration component
*/
export const MinimaxProvider = ({ showModelOptions, isPopup, currentMode }: MinimaxProviderProps) => {
const { apiConfiguration } = useExtensionState()
const { handleFieldChange, handleModeFieldChange } = useApiConfigurationHandlers()
// Get the normalized configuration
const { selectedModelId, selectedModelInfo } = normalizeApiConfiguration(apiConfiguration, currentMode)
return (
<div>
<DropdownContainer className="dropdown-container" style={{ position: "inherit" }}>
<label htmlFor="minimax-entrypoint">
<span style={{ fontWeight: 500, marginTop: 5 }}>MiniMax Entrypoint</span>
</label>
<VSCodeDropdown
id="minimax-entrypoint"
onChange={(e) => handleFieldChange("minimaxApiLine", (e.target as any).value)}
style={{
minWidth: 130,
position: "relative",
}}
value={apiConfiguration?.minimaxApiLine || "international"}>
<VSCodeOption value="international">api.minimax.io</VSCodeOption>
<VSCodeOption value="china">api.minimaxi.com</VSCodeOption>
</VSCodeDropdown>
</DropdownContainer>
<p
style={{
fontSize: "12px",
marginTop: 3,
color: "var(--vscode-descriptionForeground)",
}}>
Select the API endpoint according to your region: <code>api.minimaxi.com</code> for China, or{" "}
<code>api.minimax.io</code> for all other locations.
</p>
<ApiKeyField
initialValue={apiConfiguration?.minimaxApiKey || ""}
onChange={(value) => handleFieldChange("minimaxApiKey", value)}
providerName="MiniMax"
signupUrl={
apiConfiguration?.minimaxApiLine === "china"
? "https://platform.minimaxi.com/user-center/basic-information/interface-key"
: "https://www.minimax.io/platform/user-center/basic-information/interface-key"
}
/>
{showModelOptions && (
<>
<ModelSelector
label="Model"
models={minimaxModels}
onChange={(e: any) =>
handleModeFieldChange(
{ plan: "planModeApiModelId", act: "actModeApiModelId" },
e.target.value,
currentMode,
)
}
selectedModelId={selectedModelId}
/>
<ModelInfoView isPopup={isPopup} modelInfo={selectedModelInfo} selectedModelId={selectedModelId} />
</>
)}
</div>
)
}
@@ -37,6 +37,8 @@ import {
mainlandQwenModels,
mainlandZAiDefaultModelId,
mainlandZAiModels,
minimaxDefaultModelId,
minimaxModels,
mistralDefaultModelId,
mistralModels,
moonshotDefaultModelId,
@@ -357,6 +359,8 @@ export function normalizeApiConfiguration(
selectedModelId: ocaModelId || "",
selectedModelInfo: ocaModelInfo || liteLlmModelInfoSaneDefaults,
}
case "minimax":
return getProviderData(minimaxModels, minimaxDefaultModelId)
default:
return getProviderData(anthropicModels, anthropicDefaultModelId)
}
@@ -640,6 +644,7 @@ export async function syncModeConfigurations(
case "cerebras":
case "sapaicore":
case "zai":
case "minimax":
default:
updates.planModeApiModelId = sourceFields.apiModelId
updates.actModeApiModelId = sourceFields.apiModelId
+5
View File
@@ -154,6 +154,11 @@ export function validateApiConfiguration(currentMode: Mode, apiConfiguration?: A
return "You must provide a valid API key or choose a different provider."
}
break
case "minimax":
if (!apiConfiguration.minimaxApiKey) {
return "You must provide a valid API key or choose a different provider."
}
break
}
}
return undefined