Skip to content

Suno-style web UI for a self-hosted MiniMax-Music3 inference server

feat: show "Loading model…" when the upstream /health answers 503

Adam Benhassene5ca1ac3b10c
diff --git a/README.md b/README.md
index 26c78a0..86ab4c4 100644
--- a/README.md
+++ b/README.md
@@ -107,13 +107,14 @@ The fake upstream (`server/test/fakeUpstream.ts`) implements `GET /v1/models` an
```bash
FAKE_AUDIO=/path/to/real.wav FAKE_RENDER_MS=8000 npm run fake -w server
+FAKE_LOADING=1 npm run fake -w server # exposes /health → 503, UI shows "Loading model…"
```
## UI server API
| Method | Path | Description |
|---|---|---|
-| `GET` | `/api/health` | Upstream `/health` plus `upstreamReachable` |
+| `GET` | `/api/health` | `upstreamReachable` (via `/v1/models`), `ready` (false only if an optional upstream `/health` answers 503), queue state |
| `GET` | `/api/library` | Tracks, newest first |
| `POST` | `/api/generate` | `{title?, prompt, lyrics?, duration, seed?, format, takes}` → created tracks (queued) |
| `GET` | `/api/tracks/:id/audio` | Stream audio (`?download` for an attachment) |
diff --git a/server/src/upstream.ts b/server/src/upstream.ts
index 3ec242b..4b41c63 100644
--- a/server/src/upstream.ts
+++ b/server/src/upstream.ts
@@ -71,6 +71,8 @@ export class UpstreamClient {
* Reachability probe via GET /v1/models. Any HTTP answer means the server is up — a 404 just
* means this build doesn't expose the models list (the official card only documents
* /v1/audio/speech). Only a failed connection counts as unreachable.
+ * `ready` comes from an optional GET /health: a 503 means the model is still loading; anything
+ * else (404 on stock sgl-omni, timeouts) counts as ready.
*/
async health(): Promise<UpstreamHealth> {
let res: Response;
@@ -80,11 +82,23 @@ export class UpstreamClient {
throw new UpstreamError(`upstream unreachable: ${(err as Error).message}`);
}
if (res.status === 401 || res.status === 403) throw new UpstreamError(`upstream ${res.status} on /v1/models — check the API key`, res.status);
- if (!res.ok) return { ready: true, models: [] };
- const json = (await res.json().catch(() => ({}))) as { data?: { id?: string }[] };
- const models = (json.data ?? []).map((m) => m.id ?? '').filter(Boolean);
- if (models.length) this.modelId = models[0];
- return { ready: true, models };
+ let models: string[] = [];
+ if (res.ok) {
+ const json = (await res.json().catch(() => ({}))) as { data?: { id?: string }[] };
+ models = (json.data ?? []).map((m) => m.id ?? '').filter(Boolean);
+ if (models.length) this.modelId = models[0];
+ }
+ return { ready: await this.ready(), models };
+ }
+
+ /** false only when GET /health answers 503 (model still loading); the route is optional. */
+ private async ready(): Promise<boolean> {
+ try {
+ const res = await fetch(`${this.baseUrl}/health`, { headers: this.headers() });
+ return res.status !== 503;
+ } catch {
+ return true;
+ }
}
/** POST /v1/audio/speech, streaming the audio into `dest`. Returns the seed the server reports (X-Seed), if any. */
diff --git a/server/test/app.test.ts b/server/test/app.test.ts
index 9fe9ac9..b787345 100644
--- a/server/test/app.test.ts
+++ b/server/test/app.test.ts
@@ -87,6 +87,17 @@ describe('app', () => {
expect(fake!.requests.find((r) => r.path === '/v1/audio/speech')?.body).toMatchObject({ model: 'MiniMaxAI/MiniMax-Music3' });
});
+ it('reports ready:false while an optional /health answers 503, true once it recovers', async () => {
+ const { app } = await setup({ loading: true });
+ const loading = await request(app).get('/api/health');
+ expect(loading.body).toMatchObject({ upstreamReachable: true, ready: false, models: ['minimax_ttm'] });
+ expect(fake!.requests.map((r) => r.path)).toEqual(['/v1/models', '/health']);
+ await fake!.close();
+ fake = await startFakeUpstream({ loading: false, port: Number(new URL(fake!.url).port) });
+ const ready = await request(app).get('/api/health');
+ expect(ready.body).toMatchObject({ upstreamReachable: true, ready: true });
+ });
+
it('works against a server without /v1/models (official card shape): reachable + default model id', async () => {
const { app, lib } = await setup({ modelId: null, strictModel: true });
const h = await request(app).get('/api/health');
diff --git a/server/test/fakeUpstream.ts b/server/test/fakeUpstream.ts
index ba18560..7f0c588 100644
--- a/server/test/fakeUpstream.ts
+++ b/server/test/fakeUpstream.ts
@@ -14,6 +14,8 @@ export interface FakeUpstreamOptions {
modelId?: string | null;
/** reject requests whose `model` differs from modelId (or DEFAULT when modelId is null) */
strictModel?: boolean;
+ /** expose GET /health answering 503 (model loading) — like inference/server.py; default: no /health route (stock sgl-omni) */
+ loading?: boolean;
}
export interface FakeUpstream {
@@ -38,6 +40,14 @@ export async function startFakeUpstream(opts: FakeUpstreamOptions = {}): Promise
res.json({ object: 'list', data: [{ id: modelId, object: 'model' }] });
});
+ if (opts.loading !== undefined) {
+ app.get('/health', (req, res) => {
+ requests.push({ method: 'GET', path: req.path });
+ if (opts.loading) return res.status(503).json({ detail: 'loading model' });
+ res.json({ status: 'ready' });
+ });
+ }
+
app.post('/v1/audio/speech', (req, res) => {
const entry = { method: 'POST', path: req.path, body: req.body, auth: req.header('authorization') ?? undefined, aborted: false };
requests.push(entry);
diff --git a/server/test/fakeUpstreamServer.ts b/server/test/fakeUpstreamServer.ts
index 70e99d7..046b454 100644
--- a/server/test/fakeUpstreamServer.ts
+++ b/server/test/fakeUpstreamServer.ts
@@ -2,8 +2,9 @@ import fs from 'node:fs';
import { startFakeUpstream } from './fakeUpstream.js';
// Standalone fake for `npm run dev:fake` — no GPU needed.
-// FAKE_AUDIO=path/to/file.wav serves a real, playable file; FAKE_RENDER_MS sets the blocking render time.
+// FAKE_AUDIO=path/to/file.wav serves a real, playable file; FAKE_RENDER_MS sets the blocking render time;
+// FAKE_LOADING=1 exposes /health answering 503 (model still loading).
const port = Number(process.env.FAKE_PORT ?? 7999);
const audioBytes = process.env.FAKE_AUDIO ? fs.readFileSync(process.env.FAKE_AUDIO) : undefined;
-const fake = await startFakeUpstream({ renderMs: Number(process.env.FAKE_RENDER_MS ?? 8000), audioBytes, port });
+const fake = await startFakeUpstream({ renderMs: Number(process.env.FAKE_RENDER_MS ?? 8000), audioBytes, port, loading: process.env.FAKE_LOADING ? true : undefined });
console.log(`fake MiniMax-Music3 server (POST /v1/audio/speech) listening on ${fake.url}${audioBytes ? ` (audio: ${process.env.FAKE_AUDIO})` : ''}`);
diff --git a/web/src/components/CreatePanel.tsx b/web/src/components/CreatePanel.tsx
index 320b716..de648d0 100644
--- a/web/src/components/CreatePanel.tsx
+++ b/web/src/components/CreatePanel.tsx
@@ -64,7 +64,8 @@ export function CreatePanel({ health, form, onFormChange, onSubmit }: Props) {
const online = !!health?.upstreamReachable;
- const canSubmit = online && form.prompt.trim().length > 0 && !submitting;
+ const loading = online && !health!.ready;
+ const canSubmit = online && !loading && form.prompt.trim().length > 0 && !submitting;
const estMin = useMemo(() => Math.round((form.duration * 3 * form.takes) / 60 * 10) / 10, [form.duration, form.takes]);
const submit = async () => {
@@ -213,7 +214,7 @@ export function CreatePanel({ health, form, onFormChange, onSubmit }: Props) {
<Sparkle width={16} height={16} /> {submitting ? 'Queuing…' : form.takes > 1 ? `Create ${form.takes} takes` : 'Create'}
</button>
<span className="text-[11px] text-zinc-500">
- {online ? `≈ ${estMin} min of GPU time` : health ? 'Inference server offline' : 'Connecting…'}
+ {loading ? 'Loading model…' : online ? `≈ ${estMin} min of GPU time` : health ? 'Inference server offline' : 'Connecting…'}
</span>
</div>
</div>