Skip to content

Commit a54980a

Browse files
fix(auth): document MMX_CONFIG_DIR in credential errors
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 5f13ef5 commit a54980a

5 files changed

Lines changed: 37 additions & 2 deletions

File tree

ERRORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This document lists all error scenarios and the messages users will see.
1515
| OAuth error in callback | `OAuth error: ${error}` |
1616
| OAuth token exchange failed | `OAuth token exchange failed: ${body}` |
1717
| `MINIMAX_API_KEY` already set (non-interactive) | `Warning: MINIMAX_API_KEY is already set in environment.` |
18+
| No credentials found (non-interactive) | `No credentials found.` + hint: `Log in: mmx auth login`, `--api-key sk-xxxxx`, `MINIMAX_API_KEY=sk-xxxxx`, or `MMX_CONFIG_DIR=/path/to/.mmx` |
1819

1920
### `mmx auth logout`
2021

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,18 @@ Useful for CI/CD (`mmx auth login --api-key sk-xxxxx`), or pass per-command via
158158
OAuth and API key are mutually exclusive — logging in with one clears the other.
159159
Credential priority: `--api-key` flag > OAuth (config) > `api_key` (config).
160160

161+
### Environment variables
162+
163+
| Variable | Description |
164+
|---|---|
165+
| `MINIMAX_API_KEY` | API key (alternative to `--api-key` / login). |
166+
| `MINIMAX_REGION` | `global` or `cn`. |
167+
| `MINIMAX_BASE_URL` | Override the API base URL. |
168+
| `MINIMAX_OUTPUT` | `text` or `json`. |
169+
| `MINIMAX_TIMEOUT` | Request timeout in seconds. |
170+
| `MINIMAX_VERBOSE` | `1` to enable verbose HTTP logging. |
171+
| `MMX_CONFIG_DIR` | Directory containing the `config.json` file (default: `~/.mmx`). Set this when `mmx` runs from a subprocess, service, or CI job whose home directory differs from where you logged in. |
172+
161173
### `mmx config` · `mmx quota`
162174

163175
```bash

src/auth/resolver.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export async function resolveCredential(config: Config): Promise<ResolvedCredent
2626
throw new CLIError(
2727
'No credentials found.',
2828
ExitCode.AUTH,
29-
'Log in: mmx auth login\nPass directly: --api-key sk-xxxxx',
29+
'Log in: mmx auth login\n' +
30+
'Pass per-call: --api-key sk-xxxxx\n' +
31+
'Or set env vars: MINIMAX_API_KEY=sk-xxxxx\n' +
32+
' MMX_CONFIG_DIR=/path/to/.mmx',
3033
);
3134
}

src/auth/setup.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ export async function ensureAuth(config: Config): Promise<void> {
4646
throw new CLIError(
4747
'No credentials found.',
4848
ExitCode.AUTH,
49-
'Log in: mmx auth login\nPass directly: --api-key sk-xxxxx',
49+
'Log in: mmx auth login\n' +
50+
'Pass per-call: --api-key sk-xxxxx\n' +
51+
'Or set env vars: MINIMAX_API_KEY=sk-xxxxx\n' +
52+
' MMX_CONFIG_DIR=/path/to/.mmx',
5053
);
5154
}
5255

test/auth/resolver.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { describe, it, expect, beforeEach, afterEach } from 'bun:test';
22
import { resolveCredential } from '../../src/auth/resolver';
3+
import { CLIError } from '../../src/errors/base';
34
import type { Config } from '../../src/config/schema';
45
import { mkdirSync, rmSync } from 'fs';
56
import { join } from 'path';
@@ -59,6 +60,21 @@ describe('resolveCredential', () => {
5960
await expect(resolveCredential(config)).rejects.toThrow('No credentials found');
6061
});
6162

63+
it('no-credentials hint mentions MMX_CONFIG_DIR and all remediation options', async () => {
64+
const config = makeConfig();
65+
try {
66+
await resolveCredential(config);
67+
throw new Error('expected resolveCredential to throw');
68+
} catch (err) {
69+
expect(err).toBeInstanceOf(CLIError);
70+
const hint = (err as CLIError).hint ?? '';
71+
expect(hint).toContain('mmx auth login');
72+
expect(hint).toContain('--api-key');
73+
expect(hint).toContain('MINIMAX_API_KEY');
74+
expect(hint).toContain('MMX_CONFIG_DIR');
75+
}
76+
});
77+
6278
it('prefers flag over file api key', async () => {
6379
const config = makeConfig({ apiKey: 'sk-flag', fileApiKey: 'sk-file' });
6480
const cred = await resolveCredential(config);

0 commit comments

Comments
 (0)