MCPcopy
hub / github.com/MiniMax-AI/cli / probeRegion

Function probeRegion

src/config/detect-region.ts:10–40  ·  view source on GitHub ↗
(
  region: Region,
  apiKey: string,
  timeoutMs: number,
)

Source from the content-addressed store, hash-verified

8}
9
10async function probeRegion(
11 region: Region,
12 apiKey: string,
13 timeoutMs: number,
14): Promise<boolean> {
15 // MiniMax endpoints accept either Bearer or x-api-key auth — try both.
16 // Some API key types only work with one style; trying both prevents false
17 // negatives that would cause the wrong region to be selected, leading to
18 // every subsequent request timing out or returning 401.
19 const authHeaders: Record<string, string>[] = [
20 { Authorization: `Bearer ${apiKey}` },
21 { "x-api-key": apiKey },
22 ];
23
24 for (const authHeader of authHeaders) {
25 try {
26 const res = await fetch(quotaUrl(region), {
27 headers: { ...authHeader, "Content-Type": "application/json" },
28 signal: AbortSignal.timeout(timeoutMs),
29 });
30 if (!res.ok) continue;
31 const data = (await res.json()) as {
32 base_resp?: { status_code?: number };
33 };
34 if (data.base_resp?.status_code === 0) return true;
35 } catch {
36 // Try next auth style before giving up on this region
37 }
38 }
39 return false;
40}
41
42export async function detectRegion(apiKey: string): Promise<Region> {
43 process.stderr.write("Detecting region...");

Callers 1

detectRegionFunction · 0.85

Calls 2

fetchFunction · 0.85
quotaUrlFunction · 0.85

Tested by

no test coverage detected