Skip to content

feat(minimax): auto-detect CN/global endpoint and region label#230

Merged
robinebers merged 13 commits intorobinebers:mainfrom
FrankieeW:feat-minimax-endpoint-selection
Feb 25, 2026
Merged

feat(minimax): auto-detect CN/global endpoint and region label#230
robinebers merged 13 commits intorobinebers:mainfrom
FrankieeW:feat-minimax-endpoint-selection

Conversation

@FrankieeW
Copy link
Contributor

@FrankieeW FrankieeW commented Feb 24, 2026

Description

Adds MiniMax region auto-detection and improves CN usability without manual endpoint config.

  • Removes manual endpoint env selection.
  • Auto-detects region using available keys:
    • with MINIMAX_CN_API_KEY: tries CN -> GLOBAL
    • without MINIMAX_CN_API_KEY: tries GLOBAL -> CN
  • Uses CN key precedence in CN path (MINIMAX_CN_API_KEY first).
  • Adds visible session label by selected region: Session (CN) / Session (GLOBAL).
  • Updates Tauri host env allowlist for required MiniMax vars.
  • Updates MiniMax docs and tests to match final behavior.

Related Issue

N/A

Type of Change

  • Bug fix
  • New feature
  • New provider plugin
  • Documentation
  • Performance improvement
  • Other (describe below)

Testing

  • I ran bun run build and it succeeded
  • I ran bun run test and all tests pass
  • I tested the change locally with bun tauri dev

Additional validation:

  • bun run test -- plugins/minimax/plugin.test.js (pass)
  • bun run test:coverage was executed; suite passed, but repo-level coverage thresholds currently fail in pre-existing unrelated files.

Screenshots

Verified locally with screenshot showing MiniMax Session (CN) and live usage values.

Checklist

  • I read CONTRIBUTING.md
  • My PR targets the main branch
  • I did not introduce new dependencies without justification

Summary by cubic

Auto-detects MiniMax CN vs GLOBAL and removes manual endpoint config. Converts CN model-call counts to prompts, adds a region suffix to the plan, and keeps the Session label stable.

  • New Features

    • Auto-only region selection with cross-region fallback (CN→GLOBAL if MINIMAX_CN_API_KEY exists; else GLOBAL→CN).
    • Region-specific key order and endpoints (minimaxi.com for CN); shared URL retry helper.
    • Plan suffix “(CN)/(GLOBAL)” and tier inference split: GLOBAL tiers as before; CN infers only exact 600/1500/4500. Env allowlist, docs, and tests updated.
  • Bug Fixes

    • Convert CN model-call counts to prompts (÷15).
    • Preserve the first meaningful error across cross-region retries; unified auth error message.
    • Updated missing key error: “MiniMax API key missing. Set MINIMAX_API_KEY or MINIMAX_CN_API_KEY.”

Written for commit 8805c34. Summary will update on new commits.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ba1c2be45a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}
lastError = "Could not parse usage data."
} catch (e) {
lastError = String(e)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve auth error when fallback endpoint also fails

The fallback loop always overwrites lastError on each failed region attempt, so a definitive auth failure from the first endpoint can be replaced by a later unrelated failure from the fallback endpoint (for example: GLOBAL returns 401/403, then CN returns 5xx/network), and users get a misleading "Request failed" message instead of a key-expired message. This regression makes credential issues harder to diagnose compared with the previous behavior where auth failures surfaced directly.

Useful? React with 👍 / 👎.

@FrankieeW FrankieeW marked this pull request as draft February 24, 2026 13:35
@FrankieeW
Copy link
Contributor Author

Addressed review feedback in commit 4759164:\n\n1. Restored stable MiniMax line label to (no dynamic region suffix), so overview/tray matching stays intact.\n2. Updated AUTO retry error handling to preserve the first meaningful failure instead of always overwriting with later retry errors.\n3. Added regression tests for both precedence directions:\n - first non-auth error preserved when later retry is auth\n - first auth error preserved when later retry is non-auth\n\nValidation:
RUN v4.0.18 /Users/fwmbam4/Documents/10. Code & Repos/10.1 GitHub/FrankieeW/openusage

✓ plugins/minimax/plugin.test.js (38 tests) 15ms

Test Files 1 passed (1)
Tests 38 passed (38)
Start at 13:42:01
Duration 587ms (transform 34ms, setup 94ms, import 16ms, tests 15ms, environment 368ms) (38/38 passing).

@FrankieeW
Copy link
Contributor Author

Correction (clean summary):\n\nAddressed feedback in commit 4759164.\n- Restored stable MiniMax line label to 'Session' (no region suffix), preserving overview/tray matching.\n- AUTO retry now preserves the first meaningful error instead of overwriting with later retry errors.\n- Added regression tests for both precedence directions (non-auth then auth, auth then non-auth).\n\nValidation: bun run test -- plugins/minimax/plugin.test.js (38/38 passing).

@FrankieeW
Copy link
Contributor Author

Initially I considered keeping endpoint selection configurable. After revisiting the use case, there are only two valid regions (CN/GLOBAL), so I simplified the implementation to automatic detection/fallback instead. This has now been updated in the latest commit.

@FrankieeW
Copy link
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Another round soon, please!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…RL retry logic

- Add (CN)/(GLOBAL) suffix to plan name based on successful endpoint
- Extract tryUrls() helper to reduce duplicate URL retry logic
- Simplify fetchUsagePayload() to use shared tryUrls()
- Update tests to verify region labels in plan names

Benefits:
- Users can now see which region their plan is using
- Single source of truth for URL retry logic
- Easier to maintain when adding/removing fallback URLs
- Separate GLOBAL and CN plan tier mappings
- GLOBAL: 100/300/1000/2000 model calls for Starter/Plus/Max/Ultra
- CN: 600/1500/4500 model calls (40/100/300 prompts × 15) for Starter/Plus/Max
- Update parsePayloadShape to accept endpointSelection parameter
- Add tests for CN plan inference (Starter/Plus/Max)
@FrankieeW FrankieeW marked this pull request as ready for review February 24, 2026 17:36
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 4 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="docs/providers/minimax.md">

<violation number="1" location="docs/providers/minimax.md:29">
P3: Documentation is internally inconsistent: the Authentication section still lists only `MINIMAX_API_KEY` and `MINIMAX_API_TOKEN` as the lookup order, but the newly added region-specific lookup says CN checks `MINIMAX_CN_API_KEY` first. Update the initial key-order description to reflect the CN key precedence.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

- Remove inconsistent description that only listed MINIMAX_API_KEY and MINIMAX_API_TOKEN
- Consolidate region auto-selection and key lookup into one clear section
- Emphasize that CN region checks MINIMAX_CN_API_KEY first
- Fix internal inconsistency in documentation
@FrankieeW
Copy link
Contributor Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c1c3d6502a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +20 to +23
// CN plan tiers (based on model call counts = prompts × 15)
// Starter: 40 prompts = 600, Plus: 100 prompts = 1500, Max: 300 prompts = 4500
const CN_PROMPT_LIMIT_TO_PLAN = {
600: "Starter",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Convert CN model-call totals before labeling as prompts

In the CN path, limits are explicitly treated as model-call counts (600/1500/4500), but probe still returns used/limit under format.suffix: "prompts"; when CN is selected this reports values ~15x larger than actual prompt usage (e.g., 600 shown as prompts instead of 40), so quota tracking becomes materially inaccurate for users. Please normalize CN counts before emitting the line or emit a unit that matches model calls.

Useful? React with 👍 / 👎.

P1: Fix incorrect unit display for CN region

Problem:
- CN API returns model call counts (e.g., 4500 for Max plan)
- Plugin displayed these as "prompts" without conversion
- Users saw 15x inflated values (4500 instead of 300 prompts)
- Quota tracking was materially inaccurate

Solution:
- Detect CN endpoint in probe()
- Convert CN values: model_calls / 15 = prompts
- GLOBAL values remain unchanged (already in prompts)

Examples:
- CN Max: 4500 model_calls → 300 prompts ✓
- CN Plus: 1500 model_calls → 100 prompts ✓
- CN Starter: 600 model_calls → 40 prompts ✓

Tests updated to reflect correct conversion.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds automatic MiniMax CN vs GLOBAL endpoint selection to improve usability (especially for CN users) by probing region-specific endpoints and annotating output with the chosen region.

Changes:

  • Add CN/GLOBAL region auto-detection with region-specific endpoint + API-key precedence and cross-region fallback.
  • Adjust usage/plan parsing to support CN model-call counts (÷15) and append region to the displayed plan name.
  • Update Tauri env allowlist, docs, and plugin tests for the new CN variable and behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src-tauri/src/plugin_engine/host_api.rs Allowlists MINIMAX_CN_API_KEY so the plugin can read it in the Tauri runtime.
plugins/minimax/plugin.js Implements region probing, CN endpoints, CN plan inference, and CN count conversion + region plan labels.
plugins/minimax/plugin.test.js Adds/updates tests for auto-selection, fallback behavior, CN plan inference, and auth error handling.
docs/providers/minimax.md Documents region auto-selection, key lookup order, and CN endpoints.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 13 to 19
// GLOBAL plan tiers (based on model call counts)
const GLOBAL_PROMPT_LIMIT_TO_PLAN = {
100: "Starter",
300: "Plus",
1000: "Max",
2000: "Ultra",
}
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says the GLOBAL plan tiers are “based on model call counts”, but the mapping keys (100/300/1000/2000) are prompt limits (the GLOBAL API is treated as prompts elsewhere in this plugin). Please correct the comment to avoid confusion when maintaining the tier inference logic.

Copilot uses AI. Check for mistakes.
throw "Session expired. Check your MiniMax API key."
if (!parsed) {
if (lastError) throw lastError
throw "MiniMax API key missing. Set MINIMAX_API_KEY."
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The missing-credentials error message only tells users to set MINIMAX_API_KEY, but this plugin now also supports MINIMAX_CN_API_KEY (and will attempt both regions). Update the message to mention the valid env var options (at least MINIMAX_API_KEY and MINIMAX_CN_API_KEY) so CN users aren’t misled.

Suggested change
throw "MiniMax API key missing. Set MINIMAX_API_KEY."
throw "MiniMax API key missing. Set MINIMAX_API_KEY or MINIMAX_CN_API_KEY."

Copilot uses AI. Check for mistakes.
Comment on lines 24 to 27
If no key is found after attempting both regions, it throws:

- `MiniMax API key missing. Set MINIMAX_API_KEY.`

Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs say the plugin throws MiniMax API key missing. Set MINIMAX_API_KEY., but the plugin now supports MINIMAX_CN_API_KEY as well. Once the runtime error message is updated, please update this doc snippet to list the supported env vars (e.g., MINIMAX_API_KEY / MINIMAX_CN_API_KEY) so it matches actual configuration options.

Copilot uses AI. Check for mistakes.
Comment on lines 368 to +381
const line = {
label: "Session",
used: parsed.used,
limit: parsed.total,
used: Math.round(parsed.used * displayMultiplier),
limit: Math.round(parsed.total * displayMultiplier),
format: { kind: "count", suffix: "prompts" },
}
if (parsed.resetsAt) line.resetsAt = parsed.resetsAt
if (parsed.periodDurationMs !== null) line.periodDurationMs = parsed.periodDurationMs

const result = { lines: [ctx.line.progress(line)] }
if (parsed.planName) result.plan = parsed.planName
if (parsed.planName) {
const regionLabel = successfulEndpoint === "CN" ? " (CN)" : " (GLOBAL)"
result.plan = parsed.planName + regionLabel
}
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description states the selected region will be shown in the Session label (e.g., Session (CN) / Session (GLOBAL)), but the implementation keeps label: "Session" and instead appends the region to result.plan. Please either update the PR description to match the implemented behavior or change the output label to include the region as described.

Copilot uses AI. Check for mistakes.
@robinebers
Copy link
Owner

Am fixing the remaining issues now and then preparing it for release. Thanks all!

…rence

- Updated error message to indicate both MINIMAX_API_KEY and MINIMAX_CN_API_KEY are required.
- Clarified plan tier inference logic for CN mode to only use exact known limits.
- Adjusted documentation to reflect changes in API key requirements and plan tier inference.
- Added tests to ensure correct error handling and plan inference behavior.
davidarny
davidarny previously approved these changes Feb 25, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +64 to +69
- Treat `current_interval_usage_count` as remaining prompts (MiniMax remains API behavior).
- If only remaining aliases are provided, compute `used = total - remaining`.
- If explicit used-count fields are provided, prefer them.
- Plan name is taken from explicit plan/title fields when available.
- If plan fields are missing, infer plan tier from known limits (`100/300/1000/2000` prompts or `1500/4500/15000/30000` model-call equivalents).
- If plan fields are missing in GLOBAL mode, infer plan tier from known limits (`100/300/1000/2000` prompts or `1500/4500/15000/30000` model-call equivalents).
- If plan fields are missing in CN mode, infer only exact known CN limits (`600/1500/4500` model-call counts).
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In CN mode, current_interval_total_count/current_interval_usage_count are treated as model-call counts and later converted to prompts (÷15). This bullet currently says current_interval_usage_count is remaining prompts, which is misleading for the CN endpoint—consider rewording to “remaining count (same unit as total), converted to prompts for display” or calling out the CN model-call unit explicitly.

Copilot uses AI. Check for mistakes.
{
model_name: "MiniMax-M2",
current_interval_total_count: 600, // 40 prompts × 15
current_interval_usage_count: 500, // Remaining (not used!)
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inline comment // Remaining (not used!) is inaccurate here: current_interval_usage_count is used (as the inferred remaining count) to compute used = total - remaining for this test. Please update or remove the comment to avoid confusion.

Suggested change
current_interval_usage_count: 500, // Remaining (not used!)
current_interval_usage_count: 500, // Remaining

Copilot uses AI. Check for mistakes.
Comment on lines 370 to 374
const line = {
label: "Session",
used: parsed.used,
limit: parsed.total,
used: Math.round(parsed.used * displayMultiplier),
limit: Math.round(parsed.total * displayMultiplier),
format: { kind: "count", suffix: "prompts" },
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description mentions a visible session label like Session (CN) / Session (GLOBAL), but this code keeps the progress line label as Session and instead adds the region suffix to result.plan. Either update the session line label to include the region, or adjust the PR description to match the implemented behavior.

Copilot uses AI. Check for mistakes.
@robinebers robinebers merged commit 903e6b2 into robinebers:main Feb 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs plugin rust Pull requests that update rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants