Suno-style web UI for a self-hosted MiniMax-Music3 inference server
TypeScript ai-musicdiffusersdockerexpressminimaxminimax-musicmusic-generationreactself-hostedsgl-omnisunotailwindcsstext-to-musictypescriptvite
fix: use the model id from /v1/models (default MiniMaxAI/MiniMax-Music3); 404 on /v1/models still counts as reachable
Adam Benhassene8c1065c81e0
diff --git a/README.md b/README.mdindex f543a21..2666c00 100644--- a/README.md+++ b/README.md@@ -126,8 +126,8 @@ The server speaks the standard MiniMax-Music3 contract (the same one `sgl-omni s| Method | Path | ||---|---|---|-| `GET` | `/v1/models` | Reachability probe; expected to list `minimax_ttm` |-| `POST` | `/v1/audio/speech` | `{model: "minimax_ttm", input: <lyrics>, instructions: <style>, response_format: wav\|flac\|mp3, seed?, max_new_tokens: duration×25 (≤ 9000), stream: false}` → audio bytes; `X-Seed` header (if present) is stored |+| `GET` | `/v1/models` | Reachability probe. Optional — a 404 still counts as "up". If present, the first listed id is used as `model`; otherwise `MiniMaxAI/MiniMax-Music3` (the model card's example) |+| `POST` | `/v1/audio/speech` | `{model: <from /v1/models or "MiniMaxAI/MiniMax-Music3">, input: <lyrics>, instructions: <style>, response_format: wav\|flac\|mp3, seed?, max_new_tokens: duration×25 (≤ 9000), stream: false}` → audio bytes; `X-Seed` header (if present) is stored |The call blocks for the whole render (roughly 2.5–3× the audio length), so the UI server queues renders one at a time and shows an estimated bar. Optional `Authorization: Bearer <key>` is sent when an API key is configured.diff --git a/server/src/upstream.ts b/server/src/upstream.tsindex c4a81a4..c6d96db 100644--- a/server/src/upstream.ts+++ b/server/src/upstream.ts@@ -12,6 +12,8 @@ const FRAMES_PER_SECOND = 25;const MAX_FRAMES = 9000;const EXT: Record<string, string> = { wav: 'wav', flac: 'flac', mp3: 'mp3' };+/** Model id in the official model card's example; used when /v1/models doesn't tell us otherwise. */+export const DEFAULT_MODEL = 'MiniMaxAI/MiniMax-Music3';export const extFor = (format: string) => EXT[format] ?? format;export class UpstreamError extends Error {@@ -30,6 +32,7 @@ export interface SpeechBody {export interface UpstreamHealth {ready: boolean;+ /** ids from GET /v1/models; empty when the server doesn't expose that route */models: string[];}@@ -39,11 +42,19 @@ export interface UpstreamHealth {* POST /v1/audio/speech → audio bytes (blocking for the whole render)*/export class UpstreamClient {+ private modelId: string | null = null;+constructor(private baseUrl: string, private apiKey: string | null = null) {}configure(baseUrl: string, apiKey: string | null): void {this.baseUrl = baseUrl.replace(/\/+$/, '');this.apiKey = apiKey;+ this.modelId = null;+ }++ /** Model id sent in requests: whatever /v1/models advertised, else the official default. */+ get model(): string {+ return this.modelId ?? DEFAULT_MODEL;}get url(): string {@@ -56,7 +67,11 @@ export class UpstreamClient {return h;}- /** Reachability probe: the server is up when /v1/models answers. */+ /**+ * 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.+ */async health(): Promise<UpstreamHealth> {let res: Response;try {@@ -64,16 +79,19 @@ export class UpstreamClient {} catch (err) {throw new UpstreamError(`upstream unreachable: ${(err as Error).message}`);}- if (!res.ok) throw new UpstreamError(`upstream ${res.status} on /v1/models`, res.status);+ 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 };}/** POST /v1/audio/speech, streaming the audio into `dest`. Returns the seed the server reports (X-Seed), if any. */async speechToFile(body: SpeechBody, dest: string, signal?: AbortSignal): Promise<{ seed: number | null }> {+ if (!this.modelId) await this.health().catch(() => undefined);const payload = {- model: 'minimax_ttm',+ model: this.model,input: body.lyrics,instructions: body.prompt,response_format: body.format,diff --git a/server/test/app.test.ts b/server/test/app.test.tsindex 02609d3..d929286 100644--- a/server/test/app.test.ts+++ b/server/test/app.test.ts@@ -80,6 +80,22 @@ describe('app', () => {expect(dl.headers['content-disposition']).toMatch(/^attachment; filename=".+\.flac"$/);});+ it('uses the model id advertised by /v1/models', async () => {+ const { app, lib } = await setup({ modelId: 'MiniMaxAI/MiniMax-Music3', strictModel: true });+ const res = await request(app).post('/api/generate').send({ prompt: 'x' });+ await until(() => lib.get(res.body[0].id)?.status === 'done');+ expect(fake!.requests.find((r) => r.path === '/v1/audio/speech')?.body).toMatchObject({ model: 'MiniMaxAI/MiniMax-Music3' });+ });++ 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');+ expect(h.body).toMatchObject({ upstreamReachable: true, ready: true, models: [] });+ const res = await request(app).post('/api/generate').send({ prompt: 'x' });+ await until(() => lib.get(res.body[0].id)?.status === 'done');+ expect(fake!.requests.find((r) => r.path === '/v1/audio/speech')?.body).toMatchObject({ model: 'MiniMaxAI/MiniMax-Music3' });+ });+it('random seed → seed reported by the server (X-Seed) is stored', async () => {const { app, lib } = await setup();const res = await request(app).post('/api/generate').send({ prompt: 'x' });diff --git a/server/test/fakeUpstream.ts b/server/test/fakeUpstream.tsindex b41d825..330dfd0 100644--- a/server/test/fakeUpstream.ts+++ b/server/test/fakeUpstream.ts@@ -10,6 +10,10 @@ export interface FakeUpstreamOptions {audioBytes?: Buffer;prefix?: string;port?: number;+ /** advertised model id; null = no /v1/models route at all (stock sgl-omni per the model card) */+ modelId?: string | null;+ /** reject requests whose `model` differs from modelId (or DEFAULT when modelId is null) */+ strictModel?: boolean;}export interface FakeUpstream {@@ -27,9 +31,11 @@ export async function startFakeUpstream(opts: FakeUpstreamOptions = {}): Promiseconst audio = opts.audioBytes ?? Buffer.from('RIFF-fake-audio');const renderMs = opts.renderMs ?? 30;+ const modelId = opts.modelId === undefined ? 'minimax_ttm' : opts.modelId;app.get('/v1/models', (req, res) => {requests.push({ method: 'GET', path: req.path, auth: req.header('authorization') ?? undefined });- res.json({ object: 'list', data: [{ id: 'minimax_ttm', object: 'model' }] });+ if (modelId === null) return res.status(404).json({ detail: 'Not Found' });+ res.json({ object: 'list', data: [{ id: modelId, object: 'model' }] });});app.post('/v1/audio/speech', (req, res) => {@@ -37,6 +43,7 @@ export async function startFakeUpstream(opts: FakeUpstreamOptions = {}): Promiserequests.push(entry);const b = req.body ?? {};if (b.stream === true) return res.status(400).json({ error: 'stream: true is not supported' });+ if (opts.strictModel && b.model !== (modelId ?? 'MiniMaxAI/MiniMax-Music3')) return res.status(404).json({ error: `model ${b.model} not found` });if (!b.instructions) return res.status(422).json({ detail: 'instructions required' });if (!['wav', 'flac', 'mp3'].includes(b.response_format ?? 'wav')) return res.status(422).json({ detail: 'response_format must be wav, flac or mp3' });const timer = setTimeout(() => {