-
-
Notifications
You must be signed in to change notification settings - Fork 707
fix: use OpenAI-compatible adapter for MiniMax provider #1167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
omeraplak
merged 2 commits into
VoltAgent:main
from
octo-patch:fix/minimax-provider-openai-compatible
Mar 30, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@voltagent/core": patch | ||
| --- | ||
|
|
||
| fix: use OpenAI-compatible adapter for MiniMax provider |
170 changes: 170 additions & 0 deletions
170
packages/core/src/registries/model-provider-registry-minimax.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| // Track calls to createOpenAICompatible across module resets | ||
| let createOpenAICompatibleCalls: unknown[][] = []; | ||
| let createAnthropicCalls: unknown[][] = []; | ||
|
|
||
| // Mock @voltagent/internal to avoid build dependency | ||
| vi.mock("@voltagent/internal", () => ({ | ||
| safeStringify: (value: unknown) => JSON.stringify(value), | ||
| })); | ||
|
|
||
| // Mock @ai-sdk/openai-compatible with a tracking wrapper | ||
| vi.mock("@ai-sdk/openai-compatible", () => ({ | ||
| createOpenAICompatible: (...args: unknown[]) => { | ||
| createOpenAICompatibleCalls.push(args); | ||
| const mockModel = { | ||
| modelId: "mock-model", | ||
| specificationVersion: "v1", | ||
| provider: "minimax", | ||
| }; | ||
| return { | ||
| languageModel: () => mockModel, | ||
| chatModel: () => mockModel, | ||
| }; | ||
| }, | ||
| })); | ||
|
|
||
| // Mock @ai-sdk/anthropic to track if it's called for MiniMax | ||
| vi.mock("@ai-sdk/anthropic", () => ({ | ||
| createAnthropic: (...args: unknown[]) => { | ||
| createAnthropicCalls.push(args); | ||
| return { | ||
| languageModel: () => ({ modelId: "anthropic-model" }), | ||
| chatModel: () => ({ modelId: "anthropic-model" }), | ||
| }; | ||
| }, | ||
| anthropic: { | ||
| languageModel: () => ({ modelId: "anthropic-model" }), | ||
| chatModel: () => ({ modelId: "anthropic-model" }), | ||
| }, | ||
| })); | ||
|
|
||
| describe("MiniMax provider registry", () => { | ||
| const originalEnv = { ...process.env }; | ||
|
|
||
| beforeEach(() => { | ||
| createOpenAICompatibleCalls = []; | ||
| createAnthropicCalls = []; | ||
| (globalThis as Record<string, unknown>).___voltagent_model_provider_registry = undefined; | ||
| process.env = { ...originalEnv }; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| process.env = originalEnv; | ||
| (globalThis as Record<string, unknown>).___voltagent_model_provider_registry = undefined; | ||
| }); | ||
|
|
||
| it("should list minimax as a registered provider", async () => { | ||
| const { ModelProviderRegistry } = await import("./model-provider-registry"); | ||
| const registry = ModelProviderRegistry.getInstance(); | ||
| const providers = registry.listProviders(); | ||
| expect(providers).toContain("minimax"); | ||
| }); | ||
|
|
||
| it("should list minimax-cn as a registered provider", async () => { | ||
| const { ModelProviderRegistry } = await import("./model-provider-registry"); | ||
| const registry = ModelProviderRegistry.getInstance(); | ||
| const providers = registry.listProviders(); | ||
| expect(providers).toContain("minimax-cn"); | ||
| }); | ||
|
|
||
| it("should load minimax provider via @ai-sdk/openai-compatible", async () => { | ||
| process.env.MINIMAX_API_KEY = "test-key-minimax"; | ||
|
|
||
| const { ModelProviderRegistry } = await import("./model-provider-registry"); | ||
| const registry = ModelProviderRegistry.getInstance(); | ||
| const model = await registry.resolveLanguageModel("minimax/MiniMax-M2.7"); | ||
|
|
||
| expect(model).toBeDefined(); | ||
| expect(createOpenAICompatibleCalls.length).toBeGreaterThan(0); | ||
|
|
||
| const lastCall = createOpenAICompatibleCalls[createOpenAICompatibleCalls.length - 1]; | ||
| const config = lastCall[0] as Record<string, unknown>; | ||
| expect(config.name).toBe("minimax"); | ||
| expect(config.baseURL).toBe("https://api.minimax.io/v1"); | ||
| expect(config.apiKey).toBe("test-key-minimax"); | ||
| }); | ||
|
|
||
| it("should load minimax-cn provider with China base URL", async () => { | ||
| process.env.MINIMAX_API_KEY = "test-key-minimax-cn"; | ||
|
|
||
| const { ModelProviderRegistry } = await import("./model-provider-registry"); | ||
| const registry = ModelProviderRegistry.getInstance(); | ||
| const model = await registry.resolveLanguageModel("minimax-cn/MiniMax-M2.7"); | ||
|
|
||
| expect(model).toBeDefined(); | ||
|
|
||
| // Find the call for minimax-cn | ||
| const cnCall = createOpenAICompatibleCalls.find((call) => { | ||
| const config = call[0] as Record<string, unknown>; | ||
| return config.name === "minimax-cn"; | ||
| }); | ||
| expect(cnCall).toBeDefined(); | ||
| const config = cnCall![0] as Record<string, unknown>; | ||
| expect(config.baseURL).toBe("https://api.minimaxi.com/v1"); | ||
| expect(config.apiKey).toBe("test-key-minimax-cn"); | ||
| }); | ||
|
|
||
| it("should support MINIMAX_BASE_URL override", async () => { | ||
| process.env.MINIMAX_API_KEY = "test-key"; | ||
| process.env.MINIMAX_BASE_URL = "https://custom.minimax.io/v1"; | ||
|
|
||
| const { ModelProviderRegistry } = await import("./model-provider-registry"); | ||
| const registry = ModelProviderRegistry.getInstance(); | ||
| await registry.resolveLanguageModel("minimax/MiniMax-M2.7"); | ||
|
|
||
| const minimaxCall = createOpenAICompatibleCalls.find((call) => { | ||
| const config = call[0] as Record<string, unknown>; | ||
| return config.name === "minimax"; | ||
| }); | ||
| expect(minimaxCall).toBeDefined(); | ||
| const config = minimaxCall![0] as Record<string, unknown>; | ||
| expect(config.baseURL).toBe("https://custom.minimax.io/v1"); | ||
| }); | ||
|
|
||
| it("should throw if MINIMAX_API_KEY is not set", async () => { | ||
| delete process.env.MINIMAX_API_KEY; | ||
|
|
||
| const { ModelProviderRegistry } = await import("./model-provider-registry"); | ||
| const registry = ModelProviderRegistry.getInstance(); | ||
|
|
||
| await expect(registry.resolveLanguageModel("minimax/MiniMax-M2.7")).rejects.toThrow( | ||
| /MINIMAX_API_KEY/, | ||
| ); | ||
| }); | ||
|
|
||
| it("should resolve multiple MiniMax model variants", async () => { | ||
| process.env.MINIMAX_API_KEY = "test-key"; | ||
|
|
||
| const { ModelProviderRegistry } = await import("./model-provider-registry"); | ||
| const registry = ModelProviderRegistry.getInstance(); | ||
|
|
||
| const modelIds = [ | ||
| "MiniMax-M2.7", | ||
| "MiniMax-M2.7-highspeed", | ||
| "MiniMax-M2.5", | ||
| "MiniMax-M2.5-highspeed", | ||
| ]; | ||
|
|
||
| for (const modelId of modelIds) { | ||
| const model = await registry.resolveLanguageModel(`minimax/${modelId}`); | ||
| expect(model).toBeDefined(); | ||
| } | ||
| }); | ||
|
|
||
| it("should not use @ai-sdk/anthropic adapter for minimax", async () => { | ||
| process.env.MINIMAX_API_KEY = "test-key"; | ||
|
|
||
| const anthropicCallsBefore = createAnthropicCalls.length; | ||
|
|
||
| const { ModelProviderRegistry } = await import("./model-provider-registry"); | ||
| const registry = ModelProviderRegistry.getInstance(); | ||
| await registry.resolveLanguageModel("minimax/MiniMax-M2.7"); | ||
|
|
||
| // Anthropic adapter should NOT have been called for MiniMax | ||
| expect(createAnthropicCalls.length).toBe(anthropicCallsBefore); | ||
| // OpenAI-compatible adapter SHOULD have been called | ||
| expect(createOpenAICompatibleCalls.length).toBeGreaterThan(0); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Manual edits in an auto-generated provider doc (and removal of the generated-file warning) create doc drift and overwrite risk when the generation script runs.
Prompt for AI agents