Skip to content

Commit 0a051ba

Browse files
committed
Fix region auto-detection on key change, improve error hints, remove --auto-lyrics
- Re-detect region when API key fingerprint changes (stored in config.yaml) - Fix key precedence in fingerprint check to match credential resolver order - Add minimum plan requirements to model access and quota error messages - Use region-aware upgrade URL in error hints - Remove broken --auto-lyrics flag from music generate - Warn when no lyrics provided for music generation
1 parent e575ab6 commit 0a051ba

9 files changed

Lines changed: 26 additions & 16 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Run `minimax <command> --help` to see the full list of options, defaults, and us
9191
| `video generate` | Create a video generation task | `--model`, `--prompt`, `--first-frame`, `--callback-url`, `--wait`, `--poll-interval`, `--download` |
9292
| `video task get` | Query video task status | `--task-id` |
9393
| `video download` | Download a completed video by file ID | `--file-id`, `--out` |
94-
| `music generate` | Generate a song | `--prompt`, `--lyrics`, `--lyrics-file`, `--auto-lyrics`, `--format`, `--sample-rate`, `--bitrate`, `--stream`, `--out`, `--out-format` |
94+
| `music generate` | Generate a song | `--prompt`, `--lyrics`, `--lyrics-file`, `--format`, `--sample-rate`, `--bitrate`, `--stream`, `--out`, `--out-format` |
9595
| `search query` | Search the web via MiniMax | `--q` |
9696
| `vision describe` | Describe an image using MiniMax VLM | `--image`, `--prompt` |
9797
| `quota show` | Display Token Plan usage and remaining quotas ||
@@ -178,7 +178,7 @@ minimax music generate --prompt "Indie folk, melancholic" --lyrics "La la la..."
178178
minimax music generate --prompt "Upbeat pop" --lyrics-file song.txt --out summer.mp3
179179

180180
# Auto-generated lyrics
181-
minimax music generate --prompt "Jazz lounge" --auto-lyrics --out jazz.mp3
181+
minimax music generate --prompt "Jazz lounge" --lyrics "Do do do..." --out jazz.mp3
182182
```
183183

184184
#### search

src/args.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function parseArgs(argv: string[]): ParsedArgs {
4747

4848
// Boolean flags
4949
if (['quiet', 'verbose', 'noColor', 'yes', 'dryRun', 'help', 'stream',
50-
'subtitles', 'autoLyrics', 'wait', 'noBrowser'].includes(camelKey)) {
50+
'subtitles', 'wait', 'noBrowser'].includes(camelKey)) {
5151
(flags as Record<string, unknown>)[camelKey] = true;
5252
i++;
5353
continue;

src/commands/music/generate.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export default defineCommand({
1717
{ flag: '--prompt <text>', description: 'Music style description' },
1818
{ flag: '--lyrics <text>', description: 'Song lyrics' },
1919
{ flag: '--lyrics-file <path>', description: 'Read lyrics from file (use - for stdin)' },
20-
{ flag: '--auto-lyrics', description: 'Auto-generate lyrics from prompt' },
2120
{ flag: '--format <fmt>', description: 'Audio format (default: mp3)' },
2221
{ flag: '--sample-rate <hz>', description: 'Sample rate (default: 44100)' },
2322
{ flag: '--bitrate <bps>', description: 'Bitrate (default: 256000)' },
@@ -27,7 +26,7 @@ export default defineCommand({
2726
],
2827
examples: [
2928
'minimax music generate --prompt "Indie folk, melancholic" --lyrics-file song.txt --out my_song.mp3',
30-
'minimax music generate --prompt "Upbeat pop" --auto-lyrics --out summer.mp3',
29+
'minimax music generate --prompt "Upbeat pop" --lyrics "La la la..." --out summer.mp3',
3130
'minimax music generate --prompt "Jazz lounge" --out-format url --output json',
3231
],
3332
async run(config: Config, flags: GlobalFlags) {
@@ -49,14 +48,17 @@ export default defineCommand({
4948
);
5049
}
5150

51+
if (!lyrics) {
52+
process.stderr.write('Warning: No lyrics provided. Use --lyrics or --lyrics-file to include lyrics.\n');
53+
}
54+
5255
const outFormat = (flags.outFormat as string) || 'hex';
5356
const format = detectOutputFormat(config.output);
5457

5558
const body: MusicRequest = {
5659
model: 'music-2.5',
5760
prompt,
5861
lyrics,
59-
auto_lyrics: flags.autoLyrics === true || undefined,
6062
audio_setting: {
6163
format: (flags.format as string) || 'mp3',
6264
sample_rate: (flags.sampleRate as number) || 44100,

src/config/detect-region.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ export async function detectRegion(apiKey: string): Promise<Region> {
5151
}
5252

5353
/**
54-
* Saves the detected region to ~/.minimax/config.yaml.
54+
* Saves the detected region and key fingerprint to ~/.minimax/config.yaml.
5555
*/
56-
export async function saveDetectedRegion(region: Region): Promise<void> {
56+
export async function saveDetectedRegion(region: Region, keyFingerprint?: string): Promise<void> {
5757
await ensureConfigDir();
5858
const configPath = getConfigPath();
5959

@@ -65,5 +65,8 @@ export async function saveDetectedRegion(region: Region): Promise<void> {
6565
}
6666

6767
existing.region = region;
68+
if (keyFingerprint) {
69+
existing.region_key_fingerprint = keyFingerprint;
70+
}
6871
writeFileSync(configPath, yamlStringify(existing), { mode: 0o600 });
6972
}

src/config/loader.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,17 @@ export function loadConfig(flags: GlobalFlags): Config {
2828

2929
const explicitRegion = (flags.region as string)
3030
|| process.env.MINIMAX_REGION
31-
|| file.region
3231
|| undefined;
3332

34-
const region = (explicitRegion || 'global') as Region;
35-
const needsRegionDetection = !explicitRegion;
33+
const cachedRegion = file.region;
34+
const region = (explicitRegion || cachedRegion || 'global') as Region;
35+
36+
// Re-detect if: no explicit region AND (no cached region OR key fingerprint changed)
37+
// Precedence must match resolver: flag > config file > env var (OAuth skipped — no stable fingerprint)
38+
const activeKey = apiKey || fileApiKey || envApiKey;
39+
const keyFingerprint = activeKey ? activeKey.slice(0, 8) : undefined;
40+
const needsRegionDetection = !explicitRegion
41+
&& (!cachedRegion || (keyFingerprint !== undefined && keyFingerprint !== file.region_key_fingerprint));
3642

3743
// Explicit --base-url overrides region-derived URL
3844
const baseUrl = flags.baseUrl

src/config/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type Region = keyof typeof REGIONS;
1010
export const ConfigSchema = z.object({
1111
api_key: z.string().optional(),
1212
region: z.enum(['global', 'cn']).default('global'),
13+
region_key_fingerprint: z.string().optional(),
1314
base_url: z.string().url().optional(),
1415
output: z.enum(['text', 'json', 'yaml']).default('text'),
1516
timeout: z.number().positive().default(300),

src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ async function main() {
2727
const command = registry.resolve(commandPath);
2828
const config = loadConfig(flags);
2929

30-
// Auto-detect region on first run when no region is configured
30+
// Auto-detect region when no explicit region is set and the API key has changed
3131
if (config.needsRegionDetection) {
32-
const apiKey = config.apiKey || config.fileApiKey;
32+
const apiKey = config.apiKey || config.fileApiKey || config.envApiKey;
3333
if (apiKey) {
3434
const detected = await detectRegion(apiKey);
3535
config.region = detected;
3636
config.baseUrl = REGIONS[detected];
3737
config.needsRegionDetection = false;
38-
await saveDetectedRegion(detected);
38+
await saveDetectedRegion(detected, apiKey.slice(0, 8));
3939
}
4040
}
4141

src/types/api.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ export interface MusicRequest {
158158
model: string;
159159
prompt?: string;
160160
lyrics?: string;
161-
auto_lyrics?: boolean;
162161
audio_setting?: {
163162
format?: string;
164163
sample_rate?: number;

src/types/commands.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ export interface MusicGenerateFlags {
6363
prompt?: string;
6464
lyrics?: string;
6565
lyricsFile?: string;
66-
autoLyrics?: boolean;
6766
format?: string;
6867
sampleRate?: number;
6968
bitrate?: number;

0 commit comments

Comments
 (0)