minimax: a site without the membership API shows its credits and no plan (#666)

hetingyi's side note on #666: on agent.minimax.io both
/matrix/api/v1/user/get_user_extra_info and
/matrix/api/v1/commerce/get_membership_info answer 404 "404 page not
found", even through a proxy. membership() fell back from the first to
the second and threw the second's "membership: HTTP 404", so the
international account's whole usage card was that error, its credits
ledger never shown.

Both answering 404 is now "no membership API here": no plan is said
(not Free, which nothing read), and the card goes on with the credits
ledger as before. Any other failure of either call is still the card's
error, and a refused sign-in still throws.

Run at this commit on mote: bun test packages/minimax 88 pass, 0 fail.
The new usage test (the reporter's 404 body) is red against
origin/main's index.mjs.

Not tried: a real global account; whether such an account's M Plan
lives elsewhere on the international site is unknown.
This commit is contained in:
yetone
2026-11-03 17:56:49 +08:00
parent 0e072cdf09
commit d119f4f789
3 changed files with 39 additions and 7 deletions
+3 -1
View File
@@ -123,7 +123,9 @@ The usage card shows:
when the soonest of them runs out, from the credit details MiniMax's own
client lists (`/minimax-cloud/api/v1/credit/details`); beside an M Plan
it is aside, since the plan's windows come first;
- the plan: Free, or the M Plan's tier and when it ends;
- the plan: Free, or the M Plan's tier and when it ends; none when the
site has no membership API (the international site answers both of its
calls with 404), and the card goes on with the credits;
- for an M Plan, its windows (5 hours, 7 days, and any model's own) from
`coding_plan/remains`.
+13 -5
View File
@@ -474,7 +474,7 @@ async function accountCall(site, path, opts, what) {
const { url, init } = signed(site, path, opts)
const res = await siteFetch(site, url, { ...init, signal: AbortSignal.timeout(15000) }, what)
if (res.status === 401 || res.status === 403) throw new AccountRefused(`${what}: the sign-in was refused (HTTP ${res.status})`, res.status)
if (!res.ok) throw new Error(`${what}: HTTP ${res.status}`)
if (!res.ok) throw Object.assign(new Error(`${what}: HTTP ${res.status}`), { status: res.status })
let env
try {
env = obj(JSON.parse(await res.text()))
@@ -531,8 +531,16 @@ async function membership(site, access, userID) {
}
}
} catch (e) {
if (e instanceof AccountRefused) throw e
return membershipOf(await accountCall(site, "/matrix/api/v1/commerce/get_membership_info", { access, userID, body: {} }, "membership"))
if (e instanceof AccountRefused || e instanceof OtherSite) throw e
try {
return membershipOf(await accountCall(site, "/matrix/api/v1/commerce/get_membership_info", { access, userID, body: {} }, "membership"))
} catch (e2) {
// neither is on this site: the international one answers both with
// 404 "404 page not found" (#666), so its plan is unknown, not Free,
// and the card goes on with the credits ledger
if (e.status === 404 && e2.status === 404 && !(e2 instanceof AccountRefused)) return { unknown: true }
throw e2
}
}
if (!ws) return {}
try {
@@ -672,9 +680,9 @@ function creditsWindow(batches, now = Date.now()) {
// usageOf is the card: the plan (the M Plan's tier, else Free), the credits
// left, and the M Plan's windows when there are any.
function usageOf(m, windows = []) {
const plan = m.hasTokenPlan ? (m.tier ? "M Plan " + m.tier : "M Plan") : "Free"
const plan = m.hasTokenPlan ? (m.tier ? "M Plan " + m.tier : "M Plan") : m.unknown ? undefined : "Free"
return {
plan,
...(plan ? { plan } : {}),
...(m.hasTokenPlan && m.expiresAt ? { until: new Date(m.expiresAt < 1e12 ? m.expiresAt * 1000 : m.expiresAt).toISOString() } : {}),
...(m.balance !== undefined ? { balance: credits(m.balance) } : {}),
windows,
+23 -1
View File
@@ -3,7 +3,7 @@
// them. Nothing is claimed: no check-in is made.
import "./nonet.mjs"
import { afterEach, expect, test } from "bun:test"
import { MiniMaxCodeAuthPlugin, _internal } from "./index.mjs"
import { MiniMaxCodeAuthPlugin, MiniMaxCodeGlobalAuthPlugin, _internal } from "./index.mjs"
import { fakeMiniMax, json } from "./fake.mjs"
let f
@@ -162,3 +162,25 @@ test("beside an M Plan the credits are aside; a ledger it can't read leaves the
expect(u).toMatchObject({ plan: "M Plan Plus", balance: "88.5 credits" })
expect(u.error).toBeUndefined()
})
// #666's side note: on the international site both membership endpoints
// answer 404 "404 page not found", even through a proxy. That is no plan
// read, not a Free one, and the card goes on with the credits ledger.
test("a site without the membership API shows its credits and no plan", async () => {
f = fakeMiniMax()
const notFound = () => new Response("404 page not found", { status: 404, headers: { "content-type": "text/plain; charset=utf-8" } })
f.route("GET /v1/api/user/info", () => json({ statusInfo: { code: 0 }, data: { userInfo: { realUserID: "u-42", userEmail: "a@example.com" } } }))
f.route("POST /matrix/api/v1/user/get_user_extra_info", notFound)
f.route("POST /matrix/api/v1/commerce/get_membership_info", notFound)
const live = Date.now() + 30 * day
ledger(f, [[batch(2, "500", "100", "400", live)]])
const hooks = await MiniMaxCodeGlobalAuthPlugin({ client: {} })
const u = await hooks.auth.usage(async () => auth)
expect(u.error).toBeUndefined()
expect(u.plan).toBeUndefined()
expect(u.user).toBe("a@example.com")
expect(u.windows.map((w) => [w.name, w.display])).toEqual([["Credits", "100 / 500"]])
// one of them failing another way is still an error
f.route("POST /matrix/api/v1/commerce/get_membership_info", () => new Response("no", { status: 500 }))
expect((await hooks.auth.usage(async () => auth)).error).toBe("membership: HTTP 500")
})