@infernetprotocol/cli 0.1.78 → 0.1.79

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.
@@ -0,0 +1,213 @@
1
+ /**
2
+ * `infernet batch` / `infernet billing` / `infernet keys` — paid batch
3
+ * inference on the network. Talks to /api/v1/batches/*, /api/v1/billing/*
4
+ * and /api/v1/keys.
5
+ */
6
+ import { randomUUID } from 'node:crypto';
7
+ import { resolveBatchOptions, createBatchClient, readBatchFile, formatBillingBalance } from '../lib/batch-client.js';
8
+
9
+ export const BATCH_HELP = `infernet batch — paid batch inference
10
+
11
+ Many chat requests in one job, prepaid, priced per token. The server holds the
12
+ most the batch can cost up front (input estimate + max_tokens x output price),
13
+ charges each item what it really produced and releases the rest. Token counts
14
+ are server-side estimates: ceil(characters / 4).
15
+
16
+ Input: a JSONL file, one request per line:
17
+ {"custom_id":"q1","messages":[{"role":"user","content":"hi"}],"max_tokens":256}
18
+
19
+ Usage:
20
+ infernet batch quote <file.jsonl> --model qwen2.5:7b max cost, no spend
21
+ infernet batch submit <file.jsonl> --model qwen2.5:7b --max-cost 2.50
22
+ [--funding earned_first|prepaid_first|earned_only|prepaid_only|no_wallet]
23
+ [--idempotency-key K] default: a new uuid (printed; reuse it to retry safely)
24
+ infernet batch status <batch id>
25
+ infernet batch results <batch id> [--out file.jsonl]
26
+ infernet batch receipt <batch id>
27
+ infernet batch cancel <batch id>
28
+
29
+ Auth: INFERNET_API_KEY=ik_live_... (infernet keys create) or \`infernet login\`.
30
+ Options: --json, --url <base>, --key <ik_live_...>
31
+ `;
32
+
33
+ export const BILLING_HELP = `infernet billing — the balance batch inference spends
34
+
35
+ Usage:
36
+ infernet billing balance earned (node earnings), prepaid, holds
37
+ infernet billing topup <usd> CoinPay checkout URL (any coin or PayPal)
38
+ infernet billing topup-status <id> credited once CoinPay confirms payment
39
+ infernet billing funding earned,prepaid,wallet set your default funding order
40
+
41
+ Earned = your confirmed node earnings (c0mpute and Infernet nodes are one
42
+ balance), spendable on compute with no fee; whatever you do not spend stays
43
+ withdrawable with \`infernet payout\`.
44
+ `;
45
+
46
+ export const KEYS_HELP = `infernet keys — API keys for the batch API (needs \`infernet login\`)
47
+
48
+ Usage:
49
+ infernet keys create [--name <label>] prints the key once
50
+ infernet keys list
51
+ infernet keys revoke <key id>
52
+ `;
53
+
54
+ async function client(args) {
55
+ return createBatchClient(await resolveBatchOptions({ url: args.get('url'), key: args.get('key'), token: args.get('token') }));
56
+ }
57
+
58
+ function out(args, data, text) {
59
+ process.stdout.write(args.has('json') ? `${JSON.stringify(data, null, 2)}\n` : `${text}\n`);
60
+ }
61
+
62
+ function batchLine(b) {
63
+ const c = b.counts ?? {};
64
+ return `${b.id} ${b.status}${b.cancelling ? ' (cancelling)' : ''} ${b.model} ${c.completed ?? 0}/${c.total ?? 0} done, ${c.failed ?? 0} failed, ${c.queued ?? 0} queued cost $${b.cost_so_far_usd} of max $${b.max_cost_usd}`;
65
+ }
66
+
67
+ export async function batch(args) {
68
+ const [sub, a1] = args.positional;
69
+ if (!sub || args.has('help') || sub === 'help') {
70
+ process.stdout.write(BATCH_HELP);
71
+ return sub || args.has('help') ? 0 : 1;
72
+ }
73
+ const c = await client(args);
74
+ switch (sub) {
75
+ case 'quote': {
76
+ if (!a1 || !args.get('model')) throw new Error('usage: infernet batch quote <file.jsonl> --model <model>');
77
+ const q = await c.quote({ model: args.get('model'), items: readBatchFile(a1) });
78
+ out(args, q, `${q.item_count} items on ${q.model}: at most $${q.total_max_cost_usd} (input ~${q.estimated_input_tokens} tokens, up to ${q.max_output_tokens} output)\nquote ${q.quote_id}, valid until ${q.expires_at}\n${q.token_counts}`);
79
+ return 0;
80
+ }
81
+ case 'submit': {
82
+ if (!a1 || !args.get('model')) throw new Error('usage: infernet batch submit <file.jsonl> --model <model> --max-cost <usd>');
83
+ const maxCost = args.get('max-cost');
84
+ if (!maxCost) throw new Error('--max-cost <usd> is required: the most this batch may cost');
85
+ const key = args.get('idempotency-key') || randomUUID();
86
+ const body = { model: args.get('model'), items: readBatchFile(a1), max_cost_usd: String(maxCost), idempotency_key: key };
87
+ if (args.get('funding')) body.funding = args.get('funding');
88
+ try {
89
+ const b = await c.submit(body);
90
+ out(args, { ...b, idempotency_key: key }, `${batchLine(b)}\nidempotency key ${key}\nthen: infernet batch status ${b.id}`);
91
+ return 0;
92
+ } catch (err) {
93
+ if (err.status === 402 && err.body) {
94
+ const x = err.body;
95
+ process.stderr.write(`${x.error}: need $${x.needed_usd}, short $${x.shortfall_usd} (earned $${x.earned_spendable_usd}, prepaid $${x.prepaid_available_usd})\n`);
96
+ process.stderr.write(`top up: infernet billing topup <usd>, then retry with --idempotency-key ${key}\n`);
97
+ return 1;
98
+ }
99
+ throw err;
100
+ }
101
+ }
102
+ case 'status': {
103
+ if (!a1) throw new Error('usage: infernet batch status <batch id>');
104
+ const b = await c.status(a1);
105
+ out(args, b, batchLine(b));
106
+ return 0;
107
+ }
108
+ case 'results': {
109
+ if (!a1) throw new Error('usage: infernet batch results <batch id>');
110
+ const text = await c.results(a1);
111
+ if (args.get('out')) {
112
+ const { writeFileSync } = await import('node:fs');
113
+ writeFileSync(args.get('out'), text);
114
+ process.stdout.write(`wrote ${text.split('\n').filter(Boolean).length} lines to ${args.get('out')}\n`);
115
+ } else {
116
+ process.stdout.write(text);
117
+ }
118
+ return 0;
119
+ }
120
+ case 'receipt': {
121
+ if (!a1) throw new Error('usage: infernet batch receipt <batch id>');
122
+ const r = await c.receipt(a1);
123
+ out(args, r, [
124
+ `batch ${r.batch_id} ${r.model} ${r.status}`,
125
+ `items ${r.items.completed}/${r.items.total} completed, ${r.items.failed} failed, ${r.items.cancelled} cancelled`,
126
+ `estimated tokens: ${r.estimated_input_tokens} in, ${r.estimated_output_tokens} out at $${r.price.input_per_m_usd}/$${r.price.output_per_m_usd} per 1M`,
127
+ `charged $${r.total_charged_usd} (provider $${r.provider_share_usd}, platform $${r.platform_fee_usd}); released $${r.released_usd}`,
128
+ `paid from: earned $${r.funding.paid_from.earned_usd}, prepaid $${r.funding.paid_from.prepaid_usd}, wallet $${r.funding.paid_from.wallet_usd}; returned to earnings $${r.funding.returned_to_earnings_usd}`
129
+ ].join('\n'));
130
+ return 0;
131
+ }
132
+ case 'cancel': {
133
+ if (!a1) throw new Error('usage: infernet batch cancel <batch id>');
134
+ const r = await c.cancel(a1);
135
+ out(args, r, `cancelled ${r.cancelled_items} queued items\n${batchLine(r.batch)}`);
136
+ return 0;
137
+ }
138
+ default:
139
+ process.stderr.write(`unknown subcommand: ${sub}\n\n${BATCH_HELP}`);
140
+ return 1;
141
+ }
142
+ }
143
+
144
+ export async function billing(args) {
145
+ const [sub, a1] = args.positional;
146
+ if (args.has('help') || sub === 'help') {
147
+ process.stdout.write(BILLING_HELP);
148
+ return 0;
149
+ }
150
+ const c = await client(args);
151
+ switch (sub ?? 'balance') {
152
+ case 'balance': {
153
+ const b = await c.balance();
154
+ out(args, b, formatBillingBalance(b));
155
+ return 0;
156
+ }
157
+ case 'topup': {
158
+ if (!a1) throw new Error('usage: infernet billing topup <usd>');
159
+ const t = await c.topup(a1);
160
+ out(args, t, `pay here: ${t.checkout_url}\nthen: infernet billing topup-status ${t.topup.id}`);
161
+ return 0;
162
+ }
163
+ case 'topup-status': {
164
+ if (!a1) throw new Error('usage: infernet billing topup-status <id>');
165
+ const t = await c.topupStatus(a1);
166
+ out(args, t, `top-up ${t.id}: ${t.status} $${t.amount_usd}${t.credited ? ' (credited now)' : ''}`);
167
+ return 0;
168
+ }
169
+ case 'funding': {
170
+ if (!a1) throw new Error('usage: infernet billing funding earned,prepaid,wallet');
171
+ const r = await c.setFunding(String(a1).split(',').map((s) => s.trim()).filter(Boolean));
172
+ out(args, r, `funding order: ${r.funding_order.join(' > ')}`);
173
+ return 0;
174
+ }
175
+ default:
176
+ process.stderr.write(`unknown subcommand: ${sub}\n\n${BILLING_HELP}`);
177
+ return 1;
178
+ }
179
+ }
180
+
181
+ export async function keys(args) {
182
+ const [sub, a1] = args.positional;
183
+ if (args.has('help') || sub === 'help') {
184
+ process.stdout.write(KEYS_HELP);
185
+ return 0;
186
+ }
187
+ const c = await client(args);
188
+ switch (sub ?? 'list') {
189
+ case 'create': {
190
+ const k = await c.createKey(args.get('name'));
191
+ out(args, k, `API key (shown once, keep it):\n ${k.key}\nid ${k.id}\nuse: export INFERNET_API_KEY=${k.key}`);
192
+ return 0;
193
+ }
194
+ case 'list': {
195
+ const rows = await c.listKeys();
196
+ out(args, rows, rows.length
197
+ ? rows.map((k) => `${k.id} ${k.prefix}… ${k.name ?? ''} ${k.revoked_at ? 'revoked' : `last used ${k.last_used_at ?? 'never'}`}`).join('\n')
198
+ : 'No keys. infernet keys create');
199
+ return 0;
200
+ }
201
+ case 'revoke': {
202
+ if (!a1) throw new Error('usage: infernet keys revoke <key id>');
203
+ const k = await c.revokeKey(a1);
204
+ out(args, k, `revoked ${k.id} (${k.prefix}…)`);
205
+ return 0;
206
+ }
207
+ default:
208
+ process.stderr.write(`unknown subcommand: ${sub}\n\n${KEYS_HELP}`);
209
+ return 1;
210
+ }
211
+ }
212
+
213
+ export default batch;
package/commands/help.js CHANGED
@@ -44,11 +44,16 @@ Payments:
44
44
  redeem Redeem a credit code: infernet redeem CR-XXXX-XXXX-XXXX-XXXX
45
45
  invites Scarce invites (both sides get credits) and your affiliate link
46
46
 
47
+ Paid inference:
48
+ batch Paid batch inference from a JSONL file: quote, submit, status, results
49
+ billing Compute balance: node earnings, prepaid top-ups, funding order
50
+ keys API keys (ik_live_...) for the batch API
51
+
47
52
  Managed endpoints:
48
53
  reservation Book a pinned operator + exact model by the hour; keys, limits,
49
54
  per-minute availability report, post-paid invoice data
50
55
  order Order a dedicated model endpoint yourself: pay by x402 or CoinPay
51
- mcp MCP server (stdio): order, reservation, credit and invite tools
56
+ mcp MCP server (stdio): order, reservation, credit, invite and batch tools
52
57
 
53
58
  Other:
54
59
  help Show this help
package/commands/mcp.js CHANGED
@@ -14,6 +14,7 @@ import { createInterface } from 'node:readline';
14
14
  import { resolveClientOptions, createReservationsClient } from '../lib/reservations-client.js';
15
15
  import { createOrdersClient, x402KeyFrom, DEFAULT_MAX_USD } from '../lib/orders-client.js';
16
16
  import { resolveCreditsOptions, createCreditsClient } from '../lib/credits-client.js';
17
+ import { resolveBatchOptions, createBatchClient } from '../lib/batch-client.js';
17
18
  import { CURRENT_VERSION } from '../lib/version.js';
18
19
 
19
20
  const PROTOCOL_VERSION = '2025-06-18';
@@ -27,6 +28,22 @@ const ORDER_PROPS = {
27
28
  email: { type: 'string' },
28
29
  name: { type: 'string' }
29
30
  };
31
+ const BATCH_ITEMS = {
32
+ type: 'array',
33
+ description: 'requests: { custom_id, messages: [{ role, content }], max_tokens, temperature? }',
34
+ items: {
35
+ type: 'object',
36
+ required: ['custom_id', 'messages', 'max_tokens'],
37
+ properties: {
38
+ custom_id: { type: 'string' },
39
+ messages: { type: 'array', items: { type: 'object', properties: { role: { type: 'string' }, content: { type: 'string' } } } },
40
+ max_tokens: { type: 'integer', minimum: 1 },
41
+ temperature: { type: 'number' }
42
+ }
43
+ }
44
+ };
45
+ const batchId = { type: 'string', description: 'batch id (uuid)' };
46
+
30
47
  const orderInput = (a) => Object.fromEntries(['gpu_class', 'models', 'hours', 'start_at', 'email', 'name'].filter((k) => a[k] !== undefined).map((k) => [k, a[k]]));
31
48
 
32
49
  export const TOOLS = [
@@ -135,7 +152,41 @@ export const TOOLS = [
135
152
  description: 'Create a single-use invite link (shown once). Both people get credits when a new account joins on it and confirms its email.',
136
153
  inputSchema: { type: 'object', properties: { note: { type: 'string' } } },
137
154
  run: (c, a) => c.credits.createInvite(a.note)
138
- }
155
+ },
156
+ // Paid batch inference (INFERNET_API_KEY or the login bearer). Only
157
+ // batch_submit can spend, and only up to the max_cost_usd you pass.
158
+ {
159
+ name: 'batch_quote',
160
+ description: 'Price a batch of chat requests without spending: per-item and total max cost and a quote_id valid 15 minutes. Token counts are server-side estimates (ceil(chars/4)).',
161
+ inputSchema: { type: 'object', required: ['model', 'items'], properties: { model: { type: 'string' }, items: BATCH_ITEMS } },
162
+ run: (c, a) => c.batch.quote({ model: a.model, items: a.items })
163
+ },
164
+ {
165
+ name: 'batch_submit',
166
+ description: 'SPENDS MONEY. Submit a paid batch: holds up to max_cost_usd from your funding sources (node earnings, prepaid balance; never a wallet payment from here), charges each item its estimated cost and releases the rest. Pass quote_id (from batch_quote) or model + items. max_cost_usd and idempotency_key are required; the same key returns the same batch.',
167
+ inputSchema: {
168
+ type: 'object',
169
+ required: ['max_cost_usd', 'idempotency_key'],
170
+ properties: {
171
+ quote_id: { type: 'string' },
172
+ model: { type: 'string' },
173
+ items: BATCH_ITEMS,
174
+ max_cost_usd: { type: 'string', description: 'hard cap in USD, e.g. "2.50"' },
175
+ idempotency_key: { type: 'string' },
176
+ funding: { type: 'string', enum: ['earned_first', 'prepaid_first', 'earned_only', 'prepaid_only', 'no_wallet'] }
177
+ }
178
+ },
179
+ run: async (c, a) => {
180
+ if (a.max_cost_usd === undefined || a.max_cost_usd === null || a.max_cost_usd === '') throw new Error('max_cost_usd is required');
181
+ if (!a.idempotency_key) throw new Error('idempotency_key is required');
182
+ const body = { max_cost_usd: String(a.max_cost_usd), idempotency_key: a.idempotency_key, funding: a.funding ?? 'no_wallet' };
183
+ if (a.quote_id) body.quote_id = a.quote_id; else Object.assign(body, { model: a.model, items: a.items });
184
+ return c.batch.submit(body);
185
+ }
186
+ },
187
+ { name: 'batch_status', description: 'A batch: status, item counts, cost so far, funding, and outputs once finished.', inputSchema: { type: 'object', required: ['id'], properties: { id: batchId } }, run: (c, a) => c.batch.status(a.id) },
188
+ { name: 'batch_results', description: 'A batch\'s results as JSONL: custom_id, status, output, estimated tokens, cost.', inputSchema: { type: 'object', required: ['id'], properties: { id: batchId } }, run: (c, a) => c.batch.results(a.id) },
189
+ { name: 'billing_balance', description: 'Your compute balance: earned (node earnings) spendable, prepaid available, holds, funding order.', inputSchema: { type: 'object', properties: {} }, run: (c) => c.batch.balance() }
139
190
  ];
140
191
 
141
192
  /** Handle one JSON-RPC message; returns the response object or null for notifications. */
@@ -171,12 +222,13 @@ export async function handleMessage(msg, client) {
171
222
 
172
223
  export default async function mcp(args) {
173
224
  if (args.has('help') || args.has('h')) {
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');
225
+ process.stdout.write('infernet mcp — MCP server (stdio): self-serve orders, managed-endpoint reservations, credits, invites and paid batch inference\n\n claude mcp add infernet -- infernet mcp\n');
175
226
  return 0;
176
227
  }
177
228
  const client = createReservationsClient(await resolveClientOptions({ url: args.get('url'), token: args.get('token'), buyerToken: args.get('buyer-token') }));
178
229
  client.orders = createOrdersClient({ baseUrl: (await resolveClientOptions({ url: args.get('url') })).baseUrl });
179
230
  client.credits = createCreditsClient(await resolveCreditsOptions({ url: args.get('url'), token: args.get('token') }));
231
+ client.batch = createBatchClient(await resolveBatchOptions({ url: args.get('url'), key: args.get('key'), token: args.get('token') }));
180
232
  const rl = createInterface({ input: process.stdin });
181
233
  for await (const line of rl) {
182
234
  if (!line.trim()) continue;
@@ -21,10 +21,11 @@ import {
21
21
  setupRuntime,
22
22
  verifyBundle
23
23
  } from "@infernetprotocol/liquid-agent";
24
+ import { cmdTextRuntime, cmdTextTrain, isTextJob, TEXT_HELP } from "./model-text.js";
24
25
 
25
26
  export const TEMPORAL_SUBCOMMANDS = new Set(["train", "evaluate", "eval", "predict", "serve", "capabilities", "runtime", "synth"]);
26
27
 
27
- export const TEMPORAL_HELP = `
28
+ export const TEMPORAL_HELP = `${TEXT_HELP}
28
29
  Temporal policies (workloads ${WORKLOADS.TRAIN}, ${WORKLOADS.INFER}):
29
30
  infernet model runtime [status] Is the infernet-liquid runtime installed?
30
31
  infernet model runtime setup [--accelerator cpu|cuda] [--yes]
@@ -285,10 +286,16 @@ async function cmdSynth(args) {
285
286
  export async function runTemporal(sub, args) {
286
287
  switch (sub) {
287
288
  case "runtime":
288
- return cmdRuntime(args);
289
+ return args.has("peft") ? cmdTextRuntime(args) : cmdRuntime(args);
289
290
  case "capabilities":
290
291
  return cmdCapabilities(args);
291
292
  case "train":
293
+ // A text job (kind lora/peft) goes to the peft backend; anything
294
+ // else is a liquid-agent temporal job as before.
295
+ if (args.has("job") && !args.has("dataset")) {
296
+ const job = await readJson(args.get("job")).catch(() => null);
297
+ if (isTextJob(job)) return cmdTextTrain(args, args.get("job"));
298
+ }
292
299
  return cmdTrain(args);
293
300
  case "evaluate":
294
301
  case "eval":
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Text fine-tunes (workload infernet.text.train): `infernet model train --job
3
+ * <job.json>` with `kind: "lora"` runs the @infernetprotocol/training peft
4
+ * backend instead of the temporal runtime.
5
+ *
6
+ * infernet model runtime setup --peft [--accelerator cpu|cuda] --yes
7
+ * infernet model runtime status --peft [--json]
8
+ * infernet model train --job job.json [--json]
9
+ *
10
+ * With --json, stdout is the training-protocol v1 event stream, one JSON object
11
+ * per line, ending with `done` (what c0mpute's text worker relays to the
12
+ * buyer). Without it, a progress line per step on stderr and a summary.
13
+ */
14
+
15
+ import path from "node:path";
16
+ import { readFile } from "node:fs/promises";
17
+ import {
18
+ createPeftBackend,
19
+ PEFT_KINDS,
20
+ peftRuntimeStatus,
21
+ setupPeftRuntime
22
+ } from "@infernetprotocol/training";
23
+
24
+ export const TEXT_HELP = `
25
+ Text fine-tunes (workload infernet.text.train):
26
+ infernet model runtime setup --peft [--accelerator cpu|cuda] [--yes]
27
+ Install the peft runtime (PyTorch + transformers
28
+ + peft in their own venv, ~1 GB on CPU).
29
+ infernet model runtime status --peft [--json]
30
+ infernet model train --job <job.json> [--json]
31
+ LoRA-tune job.base_model on job.dataset (jsonl of
32
+ {title, text}); --json streams v1 events.
33
+ `;
34
+
35
+ export function isTextJob(job) {
36
+ return Boolean(job && PEFT_KINDS.includes(job.kind));
37
+ }
38
+
39
+ export async function cmdTextRuntime(args) {
40
+ const sub = args.positional?.[1] ?? "status";
41
+ const accelerator = args.has("accelerator") ? args.get("accelerator") : "cpu";
42
+ if (sub === "setup") {
43
+ if (!args.has("yes") && !args.has("y") && process.env.INFERNET_NONINTERACTIVE !== "1") {
44
+ process.stdout.write(`This installs the peft runtime: a Python venv with PyTorch (${accelerator}), transformers and peft (about ${accelerator === "cuda" ? "5" : "1"} GB). Re-run with --yes to proceed.\n`);
45
+ return 1;
46
+ }
47
+ const rt = await setupPeftRuntime({ accelerator, log: (l) => process.stderr.write(`${l}\n`) });
48
+ process.stdout.write(`installed: ${rt.python} (${rt.accelerator})\n`);
49
+ return 0;
50
+ }
51
+ const st = await peftRuntimeStatus();
52
+ if (args.has("json")) process.stdout.write(`${JSON.stringify(st ? { installed: true, ...st } : { installed: false })}\n`);
53
+ else process.stdout.write(st ? `peft runtime: torch ${st.torch}, transformers ${st.transformers}, peft ${st.peft}, cuda ${st.cuda}\n ${st.python}\n` : "peft runtime: not installed (infernet model runtime setup --peft --yes)\n");
54
+ return st ? 0 : 1;
55
+ }
56
+
57
+ export async function cmdTextTrain(args, jobPath) {
58
+ const file = path.resolve(jobPath);
59
+ const job = JSON.parse(await readFile(file, "utf8"));
60
+ if (!isTextJob(job)) {
61
+ process.stderr.write(`error: ${jobPath} is not a text job (kind must be one of ${PEFT_KINDS.join(", ")})\n`);
62
+ return 2;
63
+ }
64
+ const json = args.has("json");
65
+ const backend = createPeftBackend();
66
+ const run = backend.start({ config: job, jobPath: file });
67
+ const onSignal = () => run.cancel();
68
+ process.once("SIGINT", onSignal);
69
+ process.once("SIGTERM", onSignal);
70
+ let done = null;
71
+ let checkpoint = null;
72
+ for await (const ev of run.stream) {
73
+ if (json) process.stdout.write(`${JSON.stringify(ev)}\n`);
74
+ else if (ev.type === "step") process.stderr.write(`step ${ev.step}/${ev.total_steps ?? "?"} loss ${ev.loss}\n`);
75
+ else if (ev.type === "eval") process.stderr.write(`eval @${ev.step}: ${JSON.stringify(ev.metrics)}\n`);
76
+ else if (ev.type === "error") process.stderr.write(`error: ${ev.message}\n`);
77
+ if (ev.type === "checkpoint") checkpoint = ev;
78
+ if (ev.type === "done") done = ev;
79
+ }
80
+ await backend.shutdown();
81
+ if (!json && checkpoint) process.stdout.write(`adapter ${checkpoint.model} ${checkpoint.path}\n`);
82
+ return done?.reason === "complete" ? 0 : 1;
83
+ }
@@ -60,7 +60,8 @@ export function formatBalance(b = {}) {
60
60
  return [
61
61
  `Earnings: ${fmtUsd(b.pending_approval_usd)} pending approval, ${fmtUsd(b.pending_usd)} awaiting client payment, ${fmtUsd(b.confirmed_usd)} confirmed`,
62
62
  `Payouts: ${fmtUsd(b.paid_usd)} paid, ${fmtUsd(b.requested_usd)} requested, ${fmtUsd(b.available_usd)} available to withdraw`,
63
- `Jobs: ${b.jobs_credited ?? 0} credited`
63
+ `Jobs: ${b.jobs_credited ?? 0} credited`,
64
+ ...(Number(b.spent_on_compute_usd) > 0 ? [`Compute: ${fmtUsd(b.spent_on_compute_usd)} spent on batch inference (infernet billing balance)`] : [])
64
65
  ].join('\n');
65
66
  }
66
67
 
@@ -116,7 +117,7 @@ async function runList(args, ctx) {
116
117
  for (const e of recent) {
117
118
  const when = String(e.earned_at ?? '').replace('T', ' ').slice(0, 16);
118
119
  process.stdout.write(
119
- ` ${when} ${String(e.job_id).slice(0, 8)} ${(e.model_name ?? '-').padEnd(18)} ` +
120
+ ` ${when} ${e.job_id ? String(e.job_id).slice(0, 8) : `res ${String(e.reservation_id ?? '').slice(0, 4)}`} ${(e.model_name ?? '-').padEnd(18)} ` +
120
121
  `${String(e.output_tokens ?? 0).padStart(6)} tok ${fmtUsd(e.amount_usd).padStart(11)} ` +
121
122
  `${e.kind} ${STATUS_LABEL[e.status] ?? e.status}\n`
122
123
  );
package/index.js CHANGED
@@ -52,6 +52,7 @@ import reservation from './commands/reservation.js';
52
52
  import order from './commands/order.js';
53
53
  import mcp from './commands/mcp.js';
54
54
  import credits, { invites, redeem } from './commands/credits.js';
55
+ import batch, { billing, keys } from './commands/batch.js';
55
56
 
56
57
  function parseArgs(argv) {
57
58
  const positional = [];
@@ -113,11 +114,11 @@ const COMMANDS = {
113
114
  // aliases
114
115
  uninstall: remove,
115
116
  start, status, stop, restart, stats, logs,
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
117
+ payout, payments, gpu, firewall, chat, setup, model, train, publish, inference, rpc, uncensored, reservation, reservations: reservation, order, orders: order, mcp, credits, invites, redeem, batch, batches: batch, billing, keys, tui, doctor, service, pubkey, debug, deploy, console: consoleCmd, help
117
118
  };
118
119
 
119
120
  // Commands that can run without a loaded config.
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']);
121
+ 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', 'batch', 'batches', 'billing', 'keys', 'tui', 'doctor', 'service', 'pubkey', 'debug', 'deploy', 'console', 'upgrade', 'update', 'remove', 'uninstall']);
121
122
  // Commands that need a config but not a control-plane client (none today
122
123
  // — kept as a future escape hatch).
123
124
  const NO_CLIENT = new Set();
@@ -0,0 +1,92 @@
1
+ /**
2
+ * HTTP client for paid batch inference, the compute balance and API keys
3
+ * (/api/v1/batches/*, /api/v1/billing/*, /api/v1/keys) — shared by
4
+ * `infernet batch`, `infernet billing`, `infernet keys` and `infernet mcp`.
5
+ *
6
+ * Auth: an API key (--key, INFERNET_API_KEY: ik_live_...) or the
7
+ * `infernet login` bearer. Keys are created/revoked with the login bearer.
8
+ */
9
+ import { readFileSync } from 'node:fs';
10
+ import { loadConfig } from './config.js';
11
+
12
+ const DEFAULT_URL = 'https://infernetprotocol.com';
13
+
14
+ export async function resolveBatchOptions(opts = {}) {
15
+ const config = await loadConfig().catch(() => null);
16
+ const bearer = config?.auth?.bearerToken || null;
17
+ return {
18
+ baseUrl: String(opts.url || process.env.INFERNET_URL || config?.controlPlane?.url || DEFAULT_URL).replace(/\/+$/, ''),
19
+ apiKey: opts.key || process.env.INFERNET_API_KEY || null,
20
+ userToken: opts.token || bearer
21
+ };
22
+ }
23
+
24
+ /** Parse a JSONL file of { custom_id, messages, max_tokens, temperature? } lines. */
25
+ export function readBatchJsonl(text) {
26
+ const items = [];
27
+ String(text).split(/\r?\n/).forEach((line, i) => {
28
+ if (!line.trim()) return;
29
+ let row;
30
+ try { row = JSON.parse(line); } catch { throw new Error(`line ${i + 1}: not valid JSON`); }
31
+ if (!row || typeof row !== 'object' || Array.isArray(row)) throw new Error(`line ${i + 1}: expected an object`);
32
+ items.push(row);
33
+ });
34
+ if (items.length === 0) throw new Error('the file has no items');
35
+ return items;
36
+ }
37
+
38
+ export function readBatchFile(path) {
39
+ return readBatchJsonl(readFileSync(path, 'utf8'));
40
+ }
41
+
42
+ export function createBatchClient({ baseUrl, apiKey, userToken, fetchImpl = fetch }) {
43
+ async function call(method, path, { body, signedIn = false, raw = false, headers: extra = {} } = {}) {
44
+ const token = signedIn ? userToken : (apiKey || userToken);
45
+ if (!token) {
46
+ throw new Error(signedIn
47
+ ? 'not signed in: run `infernet login` first'
48
+ : 'set INFERNET_API_KEY (ik_live_..., from `infernet keys create`) or run `infernet login`');
49
+ }
50
+ const headers = { accept: raw ? '*/*' : 'application/json', authorization: `Bearer ${token}`, ...extra };
51
+ if (body !== undefined) headers['content-type'] = 'application/json';
52
+ const res = await fetchImpl(`${baseUrl}${path}`, { method, headers, body: body === undefined ? undefined : JSON.stringify(body) });
53
+ const text = await res.text();
54
+ if (raw && res.ok) return text;
55
+ let json = null;
56
+ try { json = text ? JSON.parse(text) : null; } catch { /* non-JSON */ }
57
+ if (!res.ok) {
58
+ const detail = json?.details ? `: ${json.details.join('; ')}` : '';
59
+ const err = new Error(`${json?.error ?? `HTTP ${res.status} ${text.slice(0, 200)}`}${detail}`);
60
+ err.status = res.status;
61
+ err.body = json;
62
+ throw err;
63
+ }
64
+ return json?.data ?? json;
65
+ }
66
+ const enc = encodeURIComponent;
67
+ return {
68
+ quote: (body) => call('POST', '/api/v1/batches/quote', { body }),
69
+ /** max_cost_usd and idempotency_key are required; the server refuses without them. */
70
+ submit: (body) => call('POST', '/api/v1/batches', { body }),
71
+ status: (id) => call('GET', `/api/v1/batches/${enc(id)}`),
72
+ results: (id) => call('GET', `/api/v1/batches/${enc(id)}/results`, { raw: true }),
73
+ cancel: (id) => call('POST', `/api/v1/batches/${enc(id)}/cancel`),
74
+ receipt: (id) => call('GET', `/api/v1/batches/${enc(id)}/receipt`),
75
+ balance: () => call('GET', '/api/v1/billing/balance'),
76
+ topup: (amountUsd) => call('POST', '/api/v1/billing/topup', { body: { amount_usd: amountUsd } }),
77
+ topupStatus: (id) => call('GET', `/api/v1/billing/topup/${enc(id)}`),
78
+ setFunding: (order) => call('PUT', '/api/v1/billing/funding', { body: { funding_order: order } }),
79
+ createKey: (name) => call('POST', '/api/v1/keys', { body: { name: name ?? null }, signedIn: true }),
80
+ listKeys: () => call('GET', '/api/v1/keys', { signedIn: true }),
81
+ revokeKey: (id) => call('DELETE', `/api/v1/keys/${enc(id)}`, { signedIn: true })
82
+ };
83
+ }
84
+
85
+ export function formatBillingBalance(b = {}) {
86
+ return [
87
+ `Earned (spendable on compute): $${b.earned_spendable_usd ?? '0'} confirmed node earnings, Infernet + c0mpute`,
88
+ `Prepaid available: $${b.prepaid_available_usd ?? '0'} (balance $${b.balance_usd ?? '0'}, held $${b.held_usd ?? '0'})`,
89
+ `Total spendable: $${b.total_spendable_usd ?? '0'}`,
90
+ `Funding order: ${(b.funding_order ?? []).join(' > ')}`
91
+ ].join('\n');
92
+ }
@@ -126,6 +126,11 @@ export function renderInvoice(inv) {
126
126
  ''
127
127
  ];
128
128
  for (const l of inv.lines) lines.push(` h${String(l.hour).padStart(3)} ${l.start} ${l.status.padEnd(13)} ${String(l.confirmed_minutes).padStart(2)} min ${money(l.amount)}`);
129
- lines.push('', `amount due: ${money(inv.amount_due)}`, inv.note);
129
+ lines.push('');
130
+ if (inv.billing === 'prepaid') {
131
+ lines.push(`amount paid: ${money(inv.amount_paid)}${inv.payment_tx_hash ? ` tx ${inv.payment_tx_hash}` : ''}`);
132
+ lines.push(`refundable: ${money(inv.refundable_usd)}${inv.refund_state ? ` (${inv.refund_state})` : ''}`);
133
+ }
134
+ lines.push(`amount due: ${money(inv.amount_due)}`, inv.note);
130
135
  return lines.join('\n');
131
136
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infernetprotocol/cli",
3
- "version": "0.1.78",
3
+ "version": "0.1.79",
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",
@@ -32,13 +32,14 @@
32
32
  "ora": "^9.4.1",
33
33
  "react": "^17.0.2",
34
34
  "react-blessed": "^0.7.2",
35
- "@infernetprotocol/auth": "0.1.78",
36
- "@infernetprotocol/config": "0.1.78",
37
- "@infernetprotocol/deploy-providers": "0.1.78",
38
- "@infernetprotocol/gpu": "0.1.78",
39
- "@infernetprotocol/engine": "0.1.78",
40
- "@infernetprotocol/liquid-agent": "0.1.78",
41
- "@infernetprotocol/rpc-adapter": "0.1.78"
35
+ "@infernetprotocol/auth": "0.1.79",
36
+ "@infernetprotocol/config": "0.1.79",
37
+ "@infernetprotocol/deploy-providers": "0.1.79",
38
+ "@infernetprotocol/engine": "0.1.79",
39
+ "@infernetprotocol/gpu": "0.1.79",
40
+ "@infernetprotocol/liquid-agent": "0.1.79",
41
+ "@infernetprotocol/rpc-adapter": "0.1.79",
42
+ "@infernetprotocol/training": "0.1.79"
42
43
  },
43
44
  "repository": {
44
45
  "type": "git",