@infernetprotocol/cli 0.1.68 → 0.1.70

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/commands/help.js CHANGED
@@ -47,7 +47,8 @@ Payments:
47
47
  Managed endpoints:
48
48
  reservation Book a pinned operator + exact model by the hour; keys, limits,
49
49
  per-minute availability report, post-paid invoice data
50
- mcp MCP server (stdio): reservation, credit and invite tools
50
+ order Order a dedicated model endpoint yourself: pay by x402 or CoinPay
51
+ mcp MCP server (stdio): order, reservation, credit and invite tools
51
52
 
52
53
  Other:
53
54
  help Show this help
package/commands/mcp.js CHANGED
@@ -12,12 +12,22 @@
12
12
  */
13
13
  import { createInterface } from 'node:readline';
14
14
  import { resolveClientOptions, createReservationsClient } from '../lib/reservations-client.js';
15
+ import { createOrdersClient, x402KeyFrom, DEFAULT_MAX_USD } from '../lib/orders-client.js';
15
16
  import { resolveCreditsOptions, createCreditsClient } from '../lib/credits-client.js';
16
17
  import { CURRENT_VERSION } from '../lib/version.js';
17
18
 
18
19
  const PROTOCOL_VERSION = '2025-06-18';
19
20
 
20
21
  const id = { type: 'string', description: 'reservation id (uuid)' };
22
+ const ORDER_PROPS = {
23
+ gpu_class: { type: 'string', enum: ['l40s', 'a100', 'h100', 'h100x2'] },
24
+ models: { type: 'array', items: { type: 'string' }, description: 'exact model ids, from order_capacity' },
25
+ hours: { type: 'integer', minimum: 1, maximum: 168 },
26
+ start_at: { type: 'string', description: 'whole UTC hour, ISO; default the next hour' },
27
+ email: { type: 'string' },
28
+ name: { type: 'string' }
29
+ };
30
+ const orderInput = (a) => Object.fromEntries(['gpu_class', 'models', 'hours', 'start_at', 'email', 'name'].filter((k) => a[k] !== undefined).map((k) => [k, a[k]]));
21
31
 
22
32
  export const TOOLS = [
23
33
  {
@@ -85,6 +95,31 @@ export const TOOLS = [
85
95
  inputSchema: { type: 'object', required: ['id'], properties: { id } },
86
96
  run: (c, a) => c.invoice(a.id)
87
97
  },
98
+ // Self-serve orders: anyone can book, no admin token. x402 pays from X402_PRIVATE_KEY.
99
+ { name: 'order_capacity', description: 'What can be ordered right now: per GPU class the price (our cost plus the house margin), how many online nodes are free and which models they serve.', inputSchema: { type: 'object', properties: {} }, run: (c) => c.orders.capacity() },
100
+ {
101
+ name: 'order_quote',
102
+ description: 'Price an order without paying: matches an online node and returns the quote plus the x402 offer.',
103
+ inputSchema: { type: 'object', required: ['gpu_class', 'models'], properties: ORDER_PROPS },
104
+ run: (c, a) => c.orders.quote(orderInput(a))
105
+ },
106
+ {
107
+ name: 'order_create',
108
+ description: 'Order a dedicated model endpoint (prepaid). pay="x402" pays now in USDC from the X402_PRIVATE_KEY wallet (refuses above max_usd) and returns the reservation, buyer token and an API key. pay="checkout" returns a CoinPay checkout URL for a person to pay (any coin or PayPal) and the buyer token; poll order_status.',
109
+ inputSchema: {
110
+ type: 'object', required: ['gpu_class', 'models', 'pay'],
111
+ properties: { ...ORDER_PROPS, pay: { type: 'string', enum: ['x402', 'checkout'] }, max_usd: { type: 'number', description: `x402 spend ceiling, default ${DEFAULT_MAX_USD}` } }
112
+ },
113
+ run: (c, a) => (a.pay === 'checkout'
114
+ ? c.orders.checkout(orderInput(a))
115
+ : c.orders.payX402(orderInput(a), { key: x402KeyFrom(), maxUsd: a.max_usd ?? DEFAULT_MAX_USD }))
116
+ },
117
+ {
118
+ name: 'order_status',
119
+ description: 'An order and, once paid, its reservation. Needs the buyer token the order returned.',
120
+ inputSchema: { type: 'object', required: ['id', 'buyer_token'], properties: { id: { type: 'string' }, buyer_token: { type: 'string' } } },
121
+ run: (c, a) => c.orders.status(a.id, a.buyer_token)
122
+ },
88
123
  // Consumer compute credits + invites for the `infernet login` account.
89
124
  // Credits are never node earnings and cannot be withdrawn.
90
125
  { name: 'credits_balance', description: 'Your consumer compute-credit balance and recent grants (signed-in account).', inputSchema: { type: 'object', properties: {} }, run: (c) => c.credits.balance() },
@@ -136,10 +171,11 @@ export async function handleMessage(msg, client) {
136
171
 
137
172
  export default async function mcp(args) {
138
173
  if (args.has('help') || args.has('h')) {
139
- process.stdout.write('infernet mcp — MCP server (stdio): managed-endpoint reservations, credits and invites\n\n claude mcp add infernet -- infernet mcp\n');
174
+ process.stdout.write('infernet mcp — MCP server (stdio): self-serve orders, managed-endpoint reservations, credits and invites\n\n claude mcp add infernet -- infernet mcp\n');
140
175
  return 0;
141
176
  }
142
177
  const client = createReservationsClient(await resolveClientOptions({ url: args.get('url'), token: args.get('token'), buyerToken: args.get('buyer-token') }));
178
+ client.orders = createOrdersClient({ baseUrl: (await resolveClientOptions({ url: args.get('url') })).baseUrl });
143
179
  client.credits = createCreditsClient(await resolveCreditsOptions({ url: args.get('url'), token: args.get('token') }));
144
180
  const rl = createInterface({ input: process.stdin });
145
181
  for await (const line of rl) {
@@ -0,0 +1,112 @@
1
+ /**
2
+ * `infernet order` — book a managed endpoint yourself, no admin
3
+ * (docs/prd/16-managed-endpoints.md, "Self-serve orders"). Talks to /api/v1/orders/*.
4
+ */
5
+ import { resolveClientOptions } from '../lib/reservations-client.js';
6
+ import { createOrdersClient, orderBodyFromFlags, x402KeyFrom, DEFAULT_MAX_USD } from '../lib/orders-client.js';
7
+
8
+ const HELP = `infernet order — order a dedicated model endpoint by the hour
9
+
10
+ We pin the models on one online node with the GPU class you pick, for the
11
+ hours you book, and you get an OpenAI-compatible API key. Prepaid at the quoted
12
+ price; non-compliant hours are credited or refunded.
13
+
14
+ Usage:
15
+ infernet order capacity what is on sale now: classes, prices, free nodes, models
16
+ infernet order quote --gpu l40s --models m1[,m2] [--hours 1] [--start 2026-10-28T15:00:00Z]
17
+ infernet order create --gpu l40s --models m1[,m2] [--hours 1] [--start ISO] [--email you@x]
18
+ --checkout pay at CoinPay (any coin or PayPal): prints the checkout URL
19
+ --x402 pay now in USDC from X402_PRIVATE_KEY (or --key-file F)
20
+ [--max-usd ${DEFAULT_MAX_USD}] refuse to sign more than this
21
+ infernet order status <id> --buyer-token ifr_buy_… (or INFERNET_BUYER_TOKEN)
22
+
23
+ Admin (INFERNET_ADMIN_TOKEN or --token):
24
+ infernet order margin [PCT] show / set the minimum profit margin over our
25
+ GPU cost, 1-2000 (default 100 = twice our cost)
26
+
27
+ After booking, manage it with \`infernet reservation\` and the same buyer token:
28
+ INFERNET_BUYER_TOKEN=ifr_buy_… infernet reservation key-issue <reservation id>
29
+ `;
30
+
31
+ function out(obj) {
32
+ process.stdout.write(`${JSON.stringify(obj, null, 2)}\n`);
33
+ }
34
+
35
+ function line(o) {
36
+ return `${o.id} ${o.status.padEnd(16)} ${o.gpu_class} ${o.models.join(',')} ${o.start_at} +${o.hours}h $${Number(o.total_usd).toFixed(2)} ${o.operator_name}`;
37
+ }
38
+
39
+ export default async function order(args) {
40
+ const [sub, a1] = args.positional;
41
+ if (!sub || args.has('help') || args.has('h') || sub === 'help') {
42
+ process.stdout.write(HELP);
43
+ return sub || args.has('help') ? 0 : 1;
44
+ }
45
+ const { baseUrl, adminToken } = await resolveClientOptions({ url: args.get('url'), token: args.get('token') });
46
+ const client = createOrdersClient({ baseUrl });
47
+ const json = args.has('json');
48
+ const body = () => orderBodyFromFlags((k) => args.get(k));
49
+
50
+ switch (sub) {
51
+ case 'capacity': {
52
+ const c = await client.capacity();
53
+ if (json) return out(c), 0;
54
+ process.stdout.write(`${c.terms}\nearliest start ${c.earliest_start}, up to ${c.max_hours}h; pay: x402=${c.pay.x402} checkout=${c.pay.checkout}\n\n`);
55
+ for (const k of c.classes) {
56
+ process.stdout.write(`${k.gpu_class.padEnd(7)} ${k.label.padEnd(13)} $${k.price_per_hour.toFixed(2)}/hr + $${k.setup_fee.toFixed(2)} setup ${String(k.nodes_available).padStart(2)} free ${k.models.join(', ') || '—'}\n`);
57
+ }
58
+ return 0;
59
+ }
60
+ case 'quote': {
61
+ const q = await client.quote(body());
62
+ if (json) return out(q), 0;
63
+ const s = q.quote;
64
+ process.stdout.write(`${s.label} x ${s.hours}h from ${s.start_at}: $${s.total_usd.toFixed(2)} ($${s.price_per_hour}/h + $${s.setup_fee} setup) on ${s.operator_name}\n`);
65
+ process.stdout.write(`x402: ${q.accepts.map((a) => a.network).join(', ')} | or: infernet order create ... --checkout\n`);
66
+ return 0;
67
+ }
68
+ case 'create': {
69
+ if (args.has('x402') === args.has('checkout')) throw new Error('pick one: --checkout (CoinPay page) or --x402 (pay now in USDC)');
70
+ if (args.has('checkout')) {
71
+ const r = await client.checkout(body());
72
+ if (json) return out(r), 0;
73
+ process.stdout.write(`order ${line(r.order)}\n`);
74
+ process.stdout.write(`pay here: ${r.checkout_url}\n`);
75
+ process.stdout.write(`buyer token (shown once, keep it):\n ${r.buyer_token}\n`);
76
+ process.stdout.write(`then: infernet order status ${r.order.id} --buyer-token ${r.buyer_token}\n`);
77
+ return 0;
78
+ }
79
+ const key = x402KeyFrom({ keyFile: args.get('key-file') });
80
+ const r = await client.payX402(body(), { key, maxUsd: args.get('max-usd') ?? DEFAULT_MAX_USD });
81
+ if (json) return out(r), 0;
82
+ process.stdout.write(`paid $${r.paid_usd} from ${r.payer} on ${r.network}${r.tx_hash ? ` (tx ${r.tx_hash})` : ''}\n`);
83
+ process.stdout.write(`order ${line(r.order)}\nreservation ${r.reservation?.id}\n`);
84
+ process.stdout.write(`buyer token (shown once):\n ${r.buyer_token}\napi key (shown once):\n ${r.api_key}\n`);
85
+ process.stdout.write(`use: ${r.use.base_url}/chat/completions with Authorization: Bearer <api key>\n`);
86
+ return 0;
87
+ }
88
+ case 'status': {
89
+ if (!a1) throw new Error('usage: infernet order status <id> --buyer-token ifr_buy_…');
90
+ const token = args.get('buyer-token') || process.env.INFERNET_BUYER_TOKEN;
91
+ if (!token) throw new Error('--buyer-token (or INFERNET_BUYER_TOKEN) is required');
92
+ const o = await client.status(a1, token);
93
+ if (json) return out(o), 0;
94
+ process.stdout.write(`${line(o)}\n`);
95
+ if (o.reservation_id) process.stdout.write(`reservation ${o.reservation_id}: INFERNET_BUYER_TOKEN=… infernet reservation key-issue ${o.reservation_id}\n`);
96
+ return 0;
97
+ }
98
+ case 'margin': {
99
+ if (!adminToken) throw new Error('set INFERNET_ADMIN_TOKEN (or pass --token)');
100
+ const v = await client.margin(adminToken, a1 === undefined ? undefined : Number(a1));
101
+ if (json) return out(v), 0;
102
+ process.stdout.write(`minimum profit margin ${v.min_margin_pct}% over our cost (range ${v.range.min}-${v.range.max}%)\n`);
103
+ for (const c of v.classes) {
104
+ process.stdout.write(`${c.gpu_class.padEnd(7)} ${c.label.padEnd(13)} cost $${c.cost_per_hour.toFixed(2)}/h sells $${c.price_per_hour.toFixed(2)}/h + $${c.setup_fee.toFixed(2)} setup\n`);
105
+ }
106
+ return 0;
107
+ }
108
+ default:
109
+ process.stderr.write(`unknown subcommand: ${sub}\n\n${HELP}`);
110
+ return 1;
111
+ }
112
+ }
package/index.js CHANGED
@@ -49,6 +49,7 @@ import inference from './commands/inference.js';
49
49
  import rpc from './commands/rpc.js';
50
50
  import uncensored from './commands/uncensored.js';
51
51
  import reservation from './commands/reservation.js';
52
+ import order from './commands/order.js';
52
53
  import mcp from './commands/mcp.js';
53
54
  import credits, { invites, redeem } from './commands/credits.js';
54
55
 
@@ -112,11 +113,11 @@ const COMMANDS = {
112
113
  // aliases
113
114
  uninstall: remove,
114
115
  start, status, stop, restart, stats, logs,
115
- payout, payments, gpu, firewall, chat, setup, model, train, publish, inference, rpc, uncensored, reservation, reservations: reservation, mcp, credits, invites, redeem, tui, doctor, service, pubkey, debug, deploy, console: consoleCmd, help
116
+ payout, payments, gpu, firewall, chat, setup, model, train, publish, inference, rpc, uncensored, reservation, reservations: reservation, order, orders: order, mcp, credits, invites, redeem, tui, doctor, service, pubkey, debug, deploy, console: consoleCmd, help
116
117
  };
117
118
 
118
119
  // Commands that can run without a loaded config.
119
- const NO_CONFIG = new Set(['init', 'login', 'help', 'stats', 'logs', 'stop', 'restart', 'gpu', 'firewall', 'chat', 'setup', 'model', 'train', 'publish', 'inference', 'rpc', 'uncensored', 'reservation', 'reservations', 'mcp', 'credits', 'invites', 'redeem', 'tui', 'doctor', 'service', 'pubkey', 'debug', 'deploy', 'console', 'upgrade', 'update', 'remove', 'uninstall']);
120
+ const NO_CONFIG = new Set(['init', 'login', 'help', 'stats', 'logs', 'stop', 'restart', 'gpu', 'firewall', 'chat', 'setup', 'model', 'train', 'publish', 'inference', 'rpc', 'uncensored', 'reservation', 'reservations', 'order', 'orders', 'mcp', 'credits', 'invites', 'redeem', 'tui', 'doctor', 'service', 'pubkey', 'debug', 'deploy', 'console', 'upgrade', 'update', 'remove', 'uninstall']);
120
121
  // Commands that need a config but not a control-plane client (none today
121
122
  // — kept as a future escape hatch).
122
123
  const NO_CLIENT = new Set();
@@ -0,0 +1,89 @@
1
+ /**
2
+ * HTTP client for self-serve orders (/api/v1/orders/*) — shared by
3
+ * `infernet order` and the `infernet mcp` order tools.
4
+ *
5
+ * Paying:
6
+ * checkout POST with pay: "checkout" -> a CoinPay checkout URL (any coin, PayPal)
7
+ * x402 the 402 offer is signed with X402_PRIVATE_KEY (or --key-file) by
8
+ * @profullstack/x402-client and the reservation comes back in the
9
+ * same call. --max-usd caps what it will sign (default 50).
10
+ */
11
+ import { readFileSync } from 'node:fs';
12
+ import { createClient as createX402Client } from '@profullstack/x402-client';
13
+
14
+ export const DEFAULT_MAX_USD = 50;
15
+
16
+ export function x402KeyFrom({ key, keyFile } = {}) {
17
+ if (key) return String(key).trim();
18
+ if (keyFile) return readFileSync(keyFile, 'utf8').trim();
19
+ return process.env.X402_PRIVATE_KEY ? process.env.X402_PRIVATE_KEY.trim() : null;
20
+ }
21
+
22
+ export function createOrdersClient({ baseUrl, fetchImpl = fetch, x402 = createX402Client }) {
23
+ async function call(method, path, { body, headers = {} } = {}) {
24
+ const res = await fetchImpl(`${baseUrl}${path}`, {
25
+ method,
26
+ headers: { accept: 'application/json', ...(body === undefined ? {} : { 'content-type': 'application/json' }), ...headers },
27
+ body: body === undefined ? undefined : JSON.stringify(body)
28
+ });
29
+ const text = await res.text();
30
+ let json = null;
31
+ try { json = text ? JSON.parse(text) : null; } catch { /* non-JSON */ }
32
+ if (!res.ok) {
33
+ const detail = json?.details ? `: ${json.details.join('; ')}` : json?.hint ? ` (${json.hint})` : '';
34
+ const err = new Error(`${method} ${path} -> HTTP ${res.status} ${json?.error ?? text.slice(0, 200)}${detail}`);
35
+ err.status = res.status;
36
+ err.body = json;
37
+ throw err;
38
+ }
39
+ return json?.data ?? json;
40
+ }
41
+
42
+ return {
43
+ capacity: () => call('GET', '/api/v1/orders/capacity'),
44
+ /** Admin: read (pct undefined) or set the minimum profit margin. */
45
+ margin: (adminToken, pct) => call(pct === undefined ? 'GET' : 'POST', '/api/v1/admin/orders/pricing', {
46
+ body: pct === undefined ? undefined : { min_margin_pct: pct },
47
+ headers: { authorization: `Bearer ${adminToken}` }
48
+ }),
49
+ status: (id, buyerToken) => call('GET', `/api/v1/orders/${encodeURIComponent(id)}`, { headers: { 'x-buyer-token': buyerToken } }),
50
+ /** Quote without paying: the 402 body (offer + quote). */
51
+ async quote(input) {
52
+ const res = await fetchImpl(`${baseUrl}/api/v1/orders`, {
53
+ method: 'POST',
54
+ headers: { accept: 'application/json', 'content-type': 'application/json' },
55
+ body: JSON.stringify(input)
56
+ });
57
+ const json = await res.json().catch(() => null);
58
+ if (res.status === 402) return json;
59
+ throw Object.assign(new Error(`quote -> HTTP ${res.status} ${json?.error ?? ''}${json?.details ? `: ${json.details.join('; ')}` : ''}`), { status: res.status, body: json });
60
+ },
61
+ checkout: (input) => call('POST', '/api/v1/orders', { body: { ...input, pay: 'checkout' } }),
62
+ /** Pay the order's x402 offer and get the reservation back. */
63
+ async payX402(input, { key, maxUsd = DEFAULT_MAX_USD } = {}) {
64
+ if (!key) throw new Error('x402 needs a wallet key: set X402_PRIVATE_KEY or pass --key-file (or pay with --checkout)');
65
+ const client = x402({ key, maxUsd: Number(maxUsd), fetch: fetchImpl });
66
+ const result = await client.pay(`${baseUrl}/api/v1/orders`, {
67
+ init: { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(input) }
68
+ });
69
+ const body = result.body;
70
+ if (result.status >= 400) throw Object.assign(new Error(`order -> HTTP ${result.status} ${body?.error ?? ''}`), { status: result.status, body });
71
+ return { ...(body?.data ?? body), paid_usd: result.amountUsd, payer: result.payer, network: result.network };
72
+ }
73
+ };
74
+ }
75
+
76
+ /** CLI flags -> order body. Kept here so the MCP tool and CLI agree. */
77
+ export function orderBodyFromFlags(get) {
78
+ const body = {
79
+ gpu_class: get('gpu'),
80
+ models: get('models') ? String(get('models')).split(',').map((s) => s.trim()).filter(Boolean) : undefined,
81
+ hours: get('hours') === undefined ? undefined : Number(get('hours')),
82
+ start_at: get('start'),
83
+ name: get('name'),
84
+ email: get('email'),
85
+ provider_id: get('provider-id')
86
+ };
87
+ for (const k of Object.keys(body)) if (body[k] === undefined) delete body[k];
88
+ return body;
89
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infernetprotocol/cli",
3
- "version": "0.1.68",
3
+ "version": "0.1.70",
4
4
  "description": "GPU-node CLI / daemon for the Infernet Protocol — register a GPU server with a Supabase control plane and start earning.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -25,18 +25,19 @@
25
25
  "@noble/ciphers": "^2.4.0",
26
26
  "@noble/curves": "^2.4.0",
27
27
  "@noble/hashes": "^2.4.0",
28
+ "@profullstack/x402-client": "^0.3.0",
28
29
  "blessed": "^0.1.81",
29
30
  "dotenv": "^18.0.9",
30
31
  "ora": "^9.4.1",
31
32
  "react": "^17.0.2",
32
33
  "react-blessed": "^0.7.2",
33
- "@infernetprotocol/auth": "0.1.68",
34
- "@infernetprotocol/deploy-providers": "0.1.68",
35
- "@infernetprotocol/config": "0.1.68",
36
- "@infernetprotocol/engine": "0.1.68",
37
- "@infernetprotocol/gpu": "0.1.68",
38
- "@infernetprotocol/liquid-agent": "0.1.68",
39
- "@infernetprotocol/rpc-adapter": "0.1.68"
34
+ "@infernetprotocol/config": "0.1.70",
35
+ "@infernetprotocol/auth": "0.1.70",
36
+ "@infernetprotocol/deploy-providers": "0.1.70",
37
+ "@infernetprotocol/engine": "0.1.70",
38
+ "@infernetprotocol/liquid-agent": "0.1.70",
39
+ "@infernetprotocol/rpc-adapter": "0.1.70",
40
+ "@infernetprotocol/gpu": "0.1.70"
40
41
  },
41
42
  "repository": {
42
43
  "type": "git",