Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1178,14 +1178,17 @@ function splitProviderModel(modelRef: string): { provider?: string; model?: stri

/**
* When modelRef is a bare name (no / prefix), infer provider from baseURL.
* Use "." + suffix to prevent fake-minimax.io subdomain spoofing.
* Use "." + suffix to prevent host spoofing (e.g. fake-minimax.io). Both
* MiniMax regional endpoints (minimax.io / minimaxi.com) map to the same
* "minimax" provider id used by the explicit modelRef path (e.g.
* "minimax/MiniMax-M3"), so a bare model name resolves consistently.
*/
export function inferProviderFromBaseURL(baseURL: string | undefined): string | undefined {
if (!baseURL) return undefined;
try {
const url = new URL(baseURL);
const hostname = url.hostname.toLowerCase();
if (hostname.endsWith(".minimax.io")) return "minimax-portal";
if (hostname.endsWith(".minimax.io") || hostname.endsWith(".minimaxi.com")) return "minimax";
if (hostname.endsWith(".openai.com")) return "openai";
if (hostname.endsWith(".anthropic.com")) return "anthropic";
return undefined;
Expand Down
26 changes: 23 additions & 3 deletions test/infer-provider-from-baseurl.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,24 @@ const { inferProviderFromBaseURL } = indexModule;
describe("inferProviderFromBaseURL - PR #713 regression", () => {

describe("URL hostname inference", () => {
it("baseURL with minimax.io returns minimax-portal", () => {
it("baseURL with minimax.io returns minimax", () => {
const result = inferProviderFromBaseURL("https://api.minimax.io/v1");
assert.strictEqual(result, "minimax-portal");
assert.strictEqual(result, "minimax");
});

it("baseURL with minimax.io anthropic endpoint returns minimax", () => {
const result = inferProviderFromBaseURL("https://api.minimax.io/anthropic");
assert.strictEqual(result, "minimax");
});

it("baseURL with minimaxi.com (regional endpoint) returns minimax", () => {
const result = inferProviderFromBaseURL("https://api.minimaxi.com/v1");
assert.strictEqual(result, "minimax");
});

it("baseURL with minimaxi.com anthropic endpoint returns minimax", () => {
const result = inferProviderFromBaseURL("https://api.minimaxi.com/anthropic");
assert.strictEqual(result, "minimax");
});

it("baseURL with openai.com returns openai", () => {
Expand All @@ -41,6 +56,11 @@ describe("inferProviderFromBaseURL - PR #713 regression", () => {
assert.strictEqual(result, undefined);
});

it("fake-minimaxi.com should NOT match (subdomain spoofing protection)", () => {
const result = inferProviderFromBaseURL("https://fake-minimaxi.com");
assert.strictEqual(result, undefined);
});

it("null returns undefined", () => {
assert.strictEqual(inferProviderFromBaseURL(null), undefined);
});
Expand All @@ -57,7 +77,7 @@ describe("inferProviderFromBaseURL - PR #713 regression", () => {
describe("URL path variations", () => {
it("handles baseURL with deep path", () => {
const result = inferProviderFromBaseURL("https://api.minimax.io/v1/chat/completions");
assert.strictEqual(result, "minimax-portal");
assert.strictEqual(result, "minimax");
});

it("handles baseURL without path", () => {
Expand Down