Skip to content

fix(quota): use /v1/token_plan/remains and honor custom base URL#175

Merged
kapelame merged 1 commit into
mainfrom
fix/cli-quota-endpoint-token-plan
Jun 8, 2026
Merged

fix(quota): use /v1/token_plan/remains and honor custom base URL#175
kapelame merged 1 commit into
mainfrom
fix/cli-quota-endpoint-token-plan

Conversation

@kapelame

@kapelame kapelame commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

What

mmx quota show (and region auto-detection) call a stale, hardcoded quota endpoint. Two problems in quotaEndpoint():

export function quotaEndpoint(baseUrl: string): string {
  // Quota endpoint uses api subdomain
  const host = baseUrl.includes('minimaxi.com') ? 'https://api.minimaxi.com' : 'https://api.minimax.io';
  return `${host}/v1/api/openplatform/coding_plan/remains`;
}
  1. Ignores baseUrl — it rebuilds the host from a minimaxi.com substring check instead of using the argument. It's the only endpoint in endpoints.ts that doesn't use the passed baseUrl, so --base-url / MINIMAX_BASE_URL / custom gateways are silently dropped for quota.
  2. Stale path/v1/api/openplatform/coding_plan/remains. The server now serves quota at /v1/token_plan/remains (consistent with the Token Plan naming). This file originally used token_plan/remains; it was changed to the openplatform path and that path now misbehaves.

Evidence

With a line-matched API key (no OAuth needed):

path result
…/v1/api/openplatform/coding_plan/remains 1004 cookie is missing, log in again
…/v1/token_plan/remains model_remains returned

Confirmed on both lines (api.minimax.io and api.minimaxi.com).

Changes

  • src/client/endpoints.tsreturn \${baseUrl}/v1/token_plan/remains`; drop the host rewrite. REGIONSbase URLs are alreadyapi.*` hosts, so no host fix-up is needed, and custom base URLs are now honored.
  • src/config/detect-region.ts — region probe uses the same new path.
  • Tests — update endpoints / sdk/quota / auth/timeout-fix expectations to the new path; add a test asserting a custom base URL is honored.

Verification

  • bun test — 356 pass / 0 fail
  • tsc --noEmit clean
  • Live mmx quota show on both lines renders the quota table; --verbose confirms GET …/v1/token_plan/remains.

Scope

Independent of #173/#174 (those fix quota rendering); this fixes the quota endpoint. Branches off main.

quotaEndpoint() ignored its baseUrl argument and rebuilt the host from a
`baseUrl.includes('minimaxi.com')` check, which broke `--base-url` /
custom gateways — it was the only endpoint in the file not using the
passed baseUrl. It also pointed at the legacy
`/v1/api/openplatform/coding_plan/remains` path; the server now serves
the quota under `/v1/token_plan/remains` (matching the Token Plan
naming). With a line-matched API key the old path returns
"cookie is missing, log in again" while the new path works.

- quotaEndpoint: return `${baseUrl}/v1/token_plan/remains`, dropping the
  host rewrite (REGIONS base URLs are already api-subdomain hosts).
- detect-region: probe the same new path.
- update endpoint/sdk/timeout mocks and add a custom-base-URL test.

Verified live on both lines: `quota show` renders quota over
GET .../v1/token_plan/remains for global and cn.
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

dummy

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

Summary

Renames the quota endpoint from /v1/api/openplatform/coding_plan/remains/v1/token_plan/remains and makes quotaEndpoint() honor custom base URLs instead of hardcoding api.minimaxi.com/api.minimax.io. This is a targeted, well-scoped fix. Test coverage for the new custom-base-URL behavior is included.


Checks

Check Result Note
bun run typecheck ✅ Pass No type errors
bun test ✅ Pass 356 tests across 56 files
bun run lint ⚠️ Pre-existing 14 problems (2 errors, 12 warnings) in unrelated files — not introduced by this PR

Issues by File

No blocking issues in the changed files.

  • src/client/endpoints.ts — clean
  • src/config/detect-region.ts — clean
  • test/auth/timeout-fix.test.ts, test/client/endpoints.test.ts, test/sdk/quota.test.ts — clean; all route strings updated consistently

Suggestions (non-blocking)

The new test in test/client/endpoints.test.ts covers the custom base URL case nicely. One small thought: the route string /v1/token_plan/remains now appears in three files (endpoints.ts, detect-region.ts, and all the test mocks). If this path ever changes again, it would be easy to miss one. A shared constant could help, but it's not worth refactoring for — the current approach is clear enough.


Verdict

Approve — all required checks green, no blocking issues introduced by this PR.

@kapelame kapelame merged commit f42ee5e into main Jun 8, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant