badgr-cli 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/api.js +9 -2
- package/src/badgr.js +3 -0
- package/src/commands/capacity.js +104 -0
- package/src/commands/run.js +40 -5
package/package.json
CHANGED
package/src/api.js
CHANGED
|
@@ -48,21 +48,28 @@ export async function callApi(path, { method = 'GET', apiKey, baseUrl, body } =
|
|
|
48
48
|
if (!res.ok) {
|
|
49
49
|
let detail = '';
|
|
50
50
|
let rawBody = '';
|
|
51
|
+
let errorData = null;
|
|
51
52
|
try {
|
|
52
53
|
rawBody = await res.text();
|
|
53
54
|
dbg('Error response body:', rawBody);
|
|
54
55
|
const json = JSON.parse(rawBody);
|
|
56
|
+
errorData = json;
|
|
55
57
|
detail = json?.detail ?? json?.message ?? json?.error ?? rawBody;
|
|
56
58
|
} catch {
|
|
57
59
|
detail = rawBody || res.statusText || '';
|
|
58
60
|
}
|
|
61
|
+
const isCapacityError = errorData?.code === 'NO_CAPACITY_MATCH';
|
|
59
62
|
const hint =
|
|
60
63
|
res.status === 401 ? '\n Hint: Invalid or missing API key — run: badgr login' :
|
|
61
64
|
res.status === 403 ? '\n Hint: Access denied — check your API key permissions' :
|
|
62
65
|
res.status === 404 ? `\n Hint: Endpoint not found — check BADGR_API_URL (currently: ${baseUrl})` :
|
|
63
|
-
res.status === 502 || res.status === 503
|
|
66
|
+
(res.status === 502 || res.status === 503) && !isCapacityError
|
|
67
|
+
? '\n Hint: Server error — no GPU capacity available or backend is down' :
|
|
64
68
|
'';
|
|
65
|
-
|
|
69
|
+
const err = new Error(`${method} ${path} → HTTP ${res.status}: ${detail}${hint}`);
|
|
70
|
+
err.errorData = errorData;
|
|
71
|
+
err.httpStatus = res.status;
|
|
72
|
+
throw err;
|
|
66
73
|
}
|
|
67
74
|
return res.json();
|
|
68
75
|
}
|
package/src/badgr.js
CHANGED
|
@@ -10,6 +10,7 @@ import { receiptsCommand } from './commands/receipts.js';
|
|
|
10
10
|
import { runCommand } from './commands/run.js';
|
|
11
11
|
import { serveCommand } from './commands/serve.js';
|
|
12
12
|
import { modelsCommand } from './commands/models.js';
|
|
13
|
+
import { capacityCommand } from './commands/capacity.js';
|
|
13
14
|
|
|
14
15
|
const HELP = `
|
|
15
16
|
${chalk.bold('badgr')} — run or serve GPU workloads from one command
|
|
@@ -22,6 +23,7 @@ ${chalk.bold('CORE COMMANDS')}
|
|
|
22
23
|
${chalk.cyan('badgr logs <id>')} Stream logs for a deployment
|
|
23
24
|
${chalk.cyan('badgr down <id>')} Terminate a deployment (stop billing)
|
|
24
25
|
${chalk.cyan('badgr receipts [<id>|<n>]')} Show receipts — pass ID for single, number for list
|
|
26
|
+
${chalk.cyan('badgr capacity [--gpu <type>]')} Check live GPU availability and alternatives
|
|
25
27
|
|
|
26
28
|
${chalk.bold('badgr run OPTIONS')}
|
|
27
29
|
--gpu <type> GPU: RTX_4090, A100, L40S, H100 (default: RTX_4090)
|
|
@@ -83,6 +85,7 @@ async function main() {
|
|
|
83
85
|
case 'down': return downCommand(config, rest, chalk);
|
|
84
86
|
case 'receipts': return receiptsCommand(config, rest, chalk);
|
|
85
87
|
case 'models': return modelsCommand(config, chalk);
|
|
88
|
+
case 'capacity': return capacityCommand(config, rest, chalk);
|
|
86
89
|
// legacy aliases kept for compatibility
|
|
87
90
|
case 'up': return upCommand(config, rest, chalk);
|
|
88
91
|
case 'config': {
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { requireApiKey } from '../config.js';
|
|
2
|
+
import { callApi } from '../api.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* badgr capacity # check RTX_4090 at default $10/hr cap
|
|
6
|
+
* badgr capacity --gpu L40S # check a specific GPU type
|
|
7
|
+
* badgr capacity --gpu A100 --region EU
|
|
8
|
+
* badgr capacity --max-price 5
|
|
9
|
+
*
|
|
10
|
+
* Internal diagnostic command: shows per-provider availability breakdown.
|
|
11
|
+
* Provider display names come from the backend — none are hardcoded here.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
function parseCapacityArgs(args) {
|
|
15
|
+
const flags = {};
|
|
16
|
+
let i = 0;
|
|
17
|
+
while (i < args.length) {
|
|
18
|
+
if (args[i] === '--gpu') { flags.gpu = args[++i]; i++; continue; }
|
|
19
|
+
if (args[i] === '--region') { flags.region = args[++i]; i++; continue; }
|
|
20
|
+
if (args[i] === '--max-price') { flags.maxPrice = parseFloat(args[++i]); i++; continue; }
|
|
21
|
+
i++;
|
|
22
|
+
}
|
|
23
|
+
return flags;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function capacityCommand(config, args, chalk) {
|
|
27
|
+
const flags = parseCapacityArgs(args);
|
|
28
|
+
requireApiKey(config);
|
|
29
|
+
|
|
30
|
+
const gpu = flags.gpu || 'RTX_4090';
|
|
31
|
+
const maxPrice = flags.maxPrice ?? 10;
|
|
32
|
+
|
|
33
|
+
const params = new URLSearchParams({ gpu, max_price: String(maxPrice) });
|
|
34
|
+
if (flags.region) params.set('region', flags.region.toUpperCase());
|
|
35
|
+
|
|
36
|
+
console.log(chalk.bold(`\n⚡ GPU Capacity Check\n`));
|
|
37
|
+
console.log(` ${chalk.bold('GPU:')} ${gpu}`);
|
|
38
|
+
if (flags.region) console.log(` ${chalk.bold('Region:')} ${flags.region.toUpperCase()}`);
|
|
39
|
+
console.log(` ${chalk.bold('Max price:')} $${maxPrice.toFixed(2)}/hr`);
|
|
40
|
+
console.log();
|
|
41
|
+
|
|
42
|
+
let data;
|
|
43
|
+
try {
|
|
44
|
+
data = await callApi(`/capacity/suggestions?${params}`, {
|
|
45
|
+
apiKey: config.apiKey,
|
|
46
|
+
baseUrl: config.baseUrl,
|
|
47
|
+
});
|
|
48
|
+
} catch (err) {
|
|
49
|
+
console.error(chalk.red(`\n ✗ Capacity check failed: ${err.message}\n`));
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Per-provider breakdown
|
|
54
|
+
const diags = data.diagnostics ?? [];
|
|
55
|
+
if (diags.length > 0) {
|
|
56
|
+
console.log(chalk.bold(' Provider breakdown:'));
|
|
57
|
+
for (const d of diags) {
|
|
58
|
+
const padded = (d.display_name ?? 'Unknown').padEnd(12);
|
|
59
|
+
if (d.status === 'no_key') {
|
|
60
|
+
console.log(` ${chalk.dim(padded)} ${chalk.dim('disabled — ' + d.reason)}`);
|
|
61
|
+
} else if (d.status === 'error') {
|
|
62
|
+
console.log(` ${chalk.dim(padded)} ${chalk.red('error — ' + d.reason)}`);
|
|
63
|
+
} else if (d.status === 'ok') {
|
|
64
|
+
const price = d.cheapest_price != null ? chalk.green(`cheapest $${d.cheapest_price.toFixed(2)}/hr`) : '';
|
|
65
|
+
console.log(` ${chalk.bold(padded)} ${d.eligible_count} eligible ${price}`);
|
|
66
|
+
} else {
|
|
67
|
+
const reason = d.reason ? chalk.dim(` — ${d.reason}`) : '';
|
|
68
|
+
console.log(` ${chalk.dim(padded)} 0 eligible${reason}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
console.log();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Direct matches
|
|
75
|
+
const matches = data.matches ?? [];
|
|
76
|
+
if (matches.length > 0) {
|
|
77
|
+
console.log(chalk.bold(' Available now:'));
|
|
78
|
+
for (const m of matches) {
|
|
79
|
+
console.log(` ${chalk.green('•')} ${m.gpu} in ${m.region} $${m.price.toFixed(2)}/hr`);
|
|
80
|
+
}
|
|
81
|
+
console.log();
|
|
82
|
+
console.log(chalk.bold(' Run:'));
|
|
83
|
+
console.log(chalk.cyan(` badgr run ... --gpu ${gpu}${flags.region ? ' --region ' + flags.region.toUpperCase() : ''}`));
|
|
84
|
+
} else {
|
|
85
|
+
console.log(chalk.dim(` No ${gpu} found under $${maxPrice.toFixed(2)}/hr${flags.region ? ' in ' + flags.region.toUpperCase() : ' globally'}.`));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Alternatives
|
|
89
|
+
const alternatives = data.alternatives ?? [];
|
|
90
|
+
if (alternatives.length > 0 && matches.length === 0) {
|
|
91
|
+
console.log();
|
|
92
|
+
console.log(chalk.bold(' Alternatives:'));
|
|
93
|
+
for (const a of alternatives) {
|
|
94
|
+
console.log(` ${chalk.dim('•')} ${a.gpu} in ${a.region} $${a.price.toFixed(2)}/hr`);
|
|
95
|
+
}
|
|
96
|
+
console.log();
|
|
97
|
+
console.log(chalk.bold(' Try:'));
|
|
98
|
+
for (const a of alternatives) {
|
|
99
|
+
console.log(chalk.cyan(` badgr run ... --gpu ${a.gpu}`));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
console.log();
|
|
104
|
+
}
|
package/src/commands/run.js
CHANGED
|
@@ -113,16 +113,51 @@ export async function runCommand(config, args, chalk) {
|
|
|
113
113
|
image,
|
|
114
114
|
gpu: gpu.toUpperCase().replace('-', '_'),
|
|
115
115
|
gpu_count: flags.count || 1,
|
|
116
|
-
region: flags.region
|
|
116
|
+
...(flags.region ? { region: flags.region.toUpperCase() } : {}),
|
|
117
117
|
max_price_per_hour: flags.maxPrice,
|
|
118
118
|
name: flags.name,
|
|
119
119
|
},
|
|
120
120
|
});
|
|
121
121
|
} catch (err) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
const d = err.errorData;
|
|
123
|
+
if (d?.code === 'NO_CAPACITY_MATCH') {
|
|
124
|
+
const f = d.filters ?? {};
|
|
125
|
+
const scope = f.region && f.region !== 'any' ? `in ${f.region}` : 'globally';
|
|
126
|
+
console.error(chalk.red(`\n ✗ No ${f.gpu || gpu} found under ${f.max_price || '$10/hr'} ${scope}.\n`));
|
|
127
|
+
|
|
128
|
+
const sameGpuElsewhere = Array.isArray(d.same_gpu_other_regions) ? d.same_gpu_other_regions : [];
|
|
129
|
+
const alternatives = Array.isArray(d.alternatives) ? d.alternatives : [];
|
|
130
|
+
const cmdPrefix = command ? command.join(' ') : flags.image ? `--image ${flags.image}` : '...';
|
|
131
|
+
|
|
132
|
+
if (sameGpuElsewhere.length > 0) {
|
|
133
|
+
// Requested GPU exists, but not in the specified region.
|
|
134
|
+
console.error(chalk.dim(` ${f.gpu} is available in other regions:\n`));
|
|
135
|
+
console.error(chalk.dim(' Try:'));
|
|
136
|
+
for (const a of sameGpuElsewhere) {
|
|
137
|
+
console.error(chalk.cyan(` badgr run ${cmdPrefix} --gpu ${a.gpu} --region ${a.region}`));
|
|
138
|
+
console.error(chalk.dim(` from $${a.price.toFixed(2)}/hr`));
|
|
139
|
+
}
|
|
140
|
+
} else if (alternatives.length > 0) {
|
|
141
|
+
// Global search failed — show what is actually available.
|
|
142
|
+
console.error(chalk.dim(' Available right now:\n'));
|
|
143
|
+
for (const a of alternatives) {
|
|
144
|
+
console.error(chalk.dim(` • ${a.gpu} in ${a.region} from $${a.price.toFixed(2)}/hr`));
|
|
145
|
+
}
|
|
146
|
+
console.error(chalk.dim('\n Try:'));
|
|
147
|
+
for (const a of alternatives) {
|
|
148
|
+
console.error(chalk.cyan(` badgr run ${cmdPrefix} --gpu ${a.gpu}`));
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
console.error(chalk.dim(' No alternative GPU capacity found right now.'));
|
|
152
|
+
console.error(chalk.dim(' Try increasing --max-price or contact support for a manual quote.'));
|
|
153
|
+
}
|
|
154
|
+
console.error('');
|
|
155
|
+
} else {
|
|
156
|
+
console.error(chalk.red(`\n ✗ Job failed to start: ${err.message}`));
|
|
157
|
+
console.error(chalk.dim(`\n Debug: BADGR_DEBUG=1 badgr run … — shows full request/response`));
|
|
158
|
+
console.error(chalk.dim(` Config: badgr config`));
|
|
159
|
+
console.error(chalk.dim(` Docs: badgr --help\n`));
|
|
160
|
+
}
|
|
126
161
|
process.exit(1);
|
|
127
162
|
}
|
|
128
163
|
|