@aaronjmars/openroutercli 0.1.6 → 0.2.0

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.
@@ -1,16 +1,16 @@
1
- import { parseArgs, authFromValues } from '../args.js';
2
- import { api } from '../api.js';
3
- import { c, isJsonMode, outln, pricePerMillion, printResult, table } from '../output.js';
1
+ import { parseArgs, authFromValues } from "../args.js";
2
+ import { api } from "../api.js";
3
+ import { c, isJsonMode, outln, pricePerMillion, printResult, table } from "../output.js";
4
4
 
5
- const ENDPOINT_SORT_FIELDS = ['throughput', 'latency', 'prompt', 'completion', 'uptime', 'context'];
6
- const MODEL_SORT_FIELDS = ['id', 'name', 'context', 'prompt', 'completion'];
5
+ const ENDPOINT_SORT_FIELDS = ["throughput", "latency", "prompt", "completion", "uptime", "context"];
6
+ const MODEL_SORT_FIELDS = ["id", "name", "context", "prompt", "completion"];
7
7
 
8
8
  const PRICE_COLUMN = {
9
- label: 'in/out $/M',
9
+ label: "in/out $/M",
10
10
  value: (x) => {
11
11
  const p = x.pricing || {};
12
12
  return `${pricePerMillion(p.prompt)}/${pricePerMillion(p.completion)}`;
13
- }
13
+ },
14
14
  };
15
15
 
16
16
  const HELP = `Usage: openrouter models [subcommand] [options]
@@ -21,44 +21,65 @@ Subcommands:
21
21
  architecture, supported params, top provider).
22
22
  Aliases: info, detail
23
23
  endpoints <author>/<slug> List endpoints (provider variants) for a model
24
+ parameters <author>/<slug> Supported params + popularity analytics (p10/p50/p90)
24
25
  user Models filtered by your workspace preferences
25
26
  count Get the total model count
26
27
 
27
28
  Options for list:
28
- --category <name> programming|roleplay|marketing|technology|...
29
+ --category <name> programming|roleplay|marketing|marketing/seo|
30
+ technology|science|translation|legal|finance|
31
+ health|trivia|academia
29
32
  --supported <param> Filter by supported parameter (e.g. tools)
33
+ --input-modalities <csv> text,image,audio,file (or "all")
30
34
  --output-modalities <csv> text,image,audio,embeddings (or "all")
35
+ --order <sort> Server-side sort: most-popular|newest|top-weekly|
36
+ pricing-low-to-high|pricing-high-to-low|
37
+ context-high-to-low|throughput-high-to-low|
38
+ latency-low-to-high|intelligence-high-to-low|
39
+ coding-high-to-low|agentic-high-to-low
31
40
  --filter <substr> Local substring filter on id/name
32
41
  --free Only :free models
33
- --sort <field> id|name|context|prompt|completion (default: as-returned)
42
+ --sort <field> Local sort: id|name|context|prompt|completion
34
43
  `;
35
44
 
45
+ // Server-side filters shared by `list` and `user`.
46
+ function listQuery(values) {
47
+ const query = {};
48
+ if (values.category) query.category = values.category;
49
+ if (values.supported) query.supported_parameters = values.supported;
50
+ if (values["input-modalities"]) query.input_modalities = values["input-modalities"];
51
+ if (values["output-modalities"]) query.output_modalities = values["output-modalities"];
52
+ if (values.order) query.sort = values.order;
53
+ return query;
54
+ }
55
+
36
56
  function listFormatter(data) {
37
57
  const rows = data.data || [];
38
58
  table(rows.slice(0, 200), [
39
- { label: 'id', value: (m) => m.id },
59
+ { label: "id", value: (m) => m.id },
40
60
  {
41
- label: 'context',
42
- value: (m) => (m.context_length || '').toLocaleString?.() ?? m.context_length
61
+ label: "context",
62
+ value: (m) => (m.context_length || "").toLocaleString?.() ?? m.context_length,
43
63
  },
44
64
  PRICE_COLUMN,
45
- { label: 'name', value: (m) => m.name || '' }
65
+ { label: "name", value: (m) => m.name || "" },
46
66
  ]);
47
- if (rows.length > 200) outln(c.dim(`... ${rows.length - 200} more (use --json for the full list)`));
67
+ if (rows.length > 200)
68
+ outln(c.dim(`... ${rows.length - 200} more (use --json for the full list)`));
48
69
  }
49
70
 
50
71
  function fmtPerMillion(x) {
51
- if (x == null || x === '') return '-';
72
+ if (x == null || x === "") return "-";
52
73
  const n = Number(x);
53
74
  if (!Number.isFinite(n)) return String(x);
54
- return '$' + (n * 1e6).toFixed(n * 1e6 < 0.1 ? 4 : 2) + '/M';
75
+ return "$" + (n * 1e6).toFixed(n * 1e6 < 0.1 ? 4 : 2) + "/M";
55
76
  }
56
77
 
57
78
  function fmtFlat(x) {
58
- if (x == null || x === '') return '-';
79
+ if (x == null || x === "") return "-";
59
80
  const n = Number(x);
60
81
  if (!Number.isFinite(n)) return String(x);
61
- return '$' + n.toFixed(n < 0.001 ? 6 : 4);
82
+ return "$" + n.toFixed(n < 0.001 ? 6 : 4);
62
83
  }
63
84
 
64
85
  function renderModelDetail(m) {
@@ -66,92 +87,107 @@ function renderModelDetail(m) {
66
87
  outln(c.dim(m.id));
67
88
  if (m.canonical_slug && m.canonical_slug !== m.id) outln(c.dim(`canonical: ${m.canonical_slug}`));
68
89
  if (m.hugging_face_id) outln(c.dim(`hugging_face: ${m.hugging_face_id}`));
69
- outln('');
90
+ outln("");
70
91
  if (m.description) {
71
92
  outln(m.description);
72
- outln('');
93
+ outln("");
73
94
  }
74
95
 
75
96
  const a = m.architecture || {};
76
- outln(c.bold('architecture'));
77
- outln(` modality: ${a.modality ?? '-'}`);
78
- outln(` input_modalities: ${(a.input_modalities || []).join(', ') || '-'}`);
79
- outln(` output_modalities: ${(a.output_modalities || []).join(', ') || '-'}`);
80
- outln(` tokenizer: ${a.tokenizer ?? '-'}`);
81
- outln(` instruct_type: ${a.instruct_type ?? '-'}`);
82
- outln('');
97
+ outln(c.bold("architecture"));
98
+ outln(` modality: ${a.modality ?? "-"}`);
99
+ outln(` input_modalities: ${(a.input_modalities || []).join(", ") || "-"}`);
100
+ outln(` output_modalities: ${(a.output_modalities || []).join(", ") || "-"}`);
101
+ outln(` tokenizer: ${a.tokenizer ?? "-"}`);
102
+ outln(` instruct_type: ${a.instruct_type ?? "-"}`);
103
+ outln("");
83
104
 
84
105
  const tp = m.top_provider || {};
85
- outln(c.bold('top provider'));
86
- outln(` context_length: ${tp.context_length ?? m.context_length ?? '-'}`);
87
- outln(` max_completion_tokens: ${tp.max_completion_tokens ?? '-'}`);
88
- outln(` is_moderated: ${tp.is_moderated ?? '-'}`);
89
- outln('');
106
+ outln(c.bold("top provider"));
107
+ outln(` context_length: ${tp.context_length ?? m.context_length ?? "-"}`);
108
+ outln(` max_completion_tokens: ${tp.max_completion_tokens ?? "-"}`);
109
+ outln(` is_moderated: ${tp.is_moderated ?? "-"}`);
110
+ outln("");
90
111
 
91
112
  const p = m.pricing || {};
92
- outln(c.bold('pricing ') + c.dim('(per token unless noted)'));
113
+ outln(c.bold("pricing ") + c.dim("(per token unless noted)"));
93
114
  const priceRows = [
94
- ['prompt (input)', fmtPerMillion(p.prompt)],
95
- ['completion (output)', fmtPerMillion(p.completion)],
96
- ['input cache read', fmtPerMillion(p.input_cache_read)],
97
- ['input cache write', fmtPerMillion(p.input_cache_write)],
98
- ['internal reasoning', fmtPerMillion(p.internal_reasoning)],
99
- ['image input', p.image != null ? fmtFlat(p.image) + ' /image' : '-'],
100
- ['request', p.request != null ? fmtFlat(p.request) + ' /request' : '-'],
101
- ['web search', p.web_search != null ? fmtFlat(p.web_search) + ' /search' : '-']
115
+ ["prompt (input)", fmtPerMillion(p.prompt)],
116
+ ["completion (output)", fmtPerMillion(p.completion)],
117
+ ["input cache read", fmtPerMillion(p.input_cache_read)],
118
+ ["input cache write", fmtPerMillion(p.input_cache_write)],
119
+ ["internal reasoning", fmtPerMillion(p.internal_reasoning)],
120
+ ["image input", p.image != null ? fmtFlat(p.image) + " /image" : "-"],
121
+ ["request", p.request != null ? fmtFlat(p.request) + " /request" : "-"],
122
+ ["web search", p.web_search != null ? fmtFlat(p.web_search) + " /search" : "-"],
102
123
  ];
103
124
  for (const [k, v] of priceRows) {
104
- if (v === '-') continue;
125
+ if (v === "-") continue;
105
126
  outln(` ${k.padEnd(22)} ${v}`);
106
127
  }
107
- outln('');
128
+ outln("");
129
+
130
+ outln(c.bold("supported_parameters"));
131
+ outln(" " + ((m.supported_parameters || []).join(", ") || "-"));
132
+ outln("");
108
133
 
109
- outln(c.bold('supported_parameters'));
110
- outln(' ' + ((m.supported_parameters || []).join(', ') || '-'));
111
- outln('');
134
+ if (m.reasoning && Object.keys(m.reasoning).length) {
135
+ outln(c.bold("reasoning"));
136
+ for (const [k, v] of Object.entries(m.reasoning)) {
137
+ outln(` ${k}: ${typeof v === "object" ? JSON.stringify(v) : v}`);
138
+ }
139
+ outln("");
140
+ }
141
+
142
+ if (m.supported_voices && m.supported_voices.length) {
143
+ outln(c.bold("supported_voices"));
144
+ outln(" " + m.supported_voices.join(", "));
145
+ outln("");
146
+ }
112
147
 
113
148
  if (m.default_parameters && Object.keys(m.default_parameters).length) {
114
- outln(c.bold('default_parameters'));
149
+ outln(c.bold("default_parameters"));
115
150
  for (const [k, v] of Object.entries(m.default_parameters)) {
116
151
  if (v == null) continue;
117
152
  outln(` ${k}: ${v}`);
118
153
  }
119
- outln('');
154
+ outln("");
120
155
  }
121
156
 
122
157
  if (m.knowledge_cutoff) outln(c.dim(`knowledge_cutoff: ${m.knowledge_cutoff}`));
123
158
  if (m.expiration_date) outln(c.dim(`expiration_date: ${m.expiration_date}`));
124
159
  if (m.created) outln(c.dim(`created: ${new Date(m.created * 1000).toISOString()}`));
125
- if (m.per_request_limits) outln(c.dim(`per_request_limits: ${JSON.stringify(m.per_request_limits)}`));
160
+ if (m.per_request_limits)
161
+ outln(c.dim(`per_request_limits: ${JSON.stringify(m.per_request_limits)}`));
126
162
  }
127
163
 
128
164
  export async function modelsCommand(argv) {
129
165
  // A leading non-flag token is the subcommand; otherwise default to list
130
166
  // and keep argv intact so the list branch still sees its flags.
131
- const sub = argv[0] && !argv[0].startsWith('-') ? argv[0] : 'list';
167
+ const sub = argv[0] && !argv[0].startsWith("-") ? argv[0] : "list";
132
168
  const rest = sub === argv[0] ? argv.slice(1) : argv;
133
169
 
134
- if (sub === 'show' || sub === 'info' || sub === 'detail') {
170
+ if (sub === "show" || sub === "info" || sub === "detail") {
135
171
  const { values, positionals } = parseArgs(rest, {});
136
172
  if (values.help || positionals.length === 0) {
137
173
  process.stdout.write(
138
- 'Usage: openrouter models show <model-id>\n\nShow full details (pricing, architecture, capabilities) for one model.\n'
174
+ "Usage: openrouter models show <model-id>\n\nShow full details (pricing, architecture, capabilities) for one model.\n",
139
175
  );
140
176
  return values.help ? 0 : 1;
141
177
  }
142
178
  const target = positionals[0].toLowerCase();
143
- const data = await api('GET', '/models', {
179
+ const data = await api("GET", "/models", {
144
180
  auth: authFromValues(values),
145
- requireAuth: false
181
+ requireAuth: false,
146
182
  });
147
183
  const rows = data.data || [];
148
- let m = rows.find((r) => (r.id || '').toLowerCase() === target);
149
- if (!m) m = rows.find((r) => (r.canonical_slug || '').toLowerCase() === target);
184
+ let m = rows.find((r) => (r.id || "").toLowerCase() === target);
185
+ if (!m) m = rows.find((r) => (r.canonical_slug || "").toLowerCase() === target);
150
186
  if (!m) {
151
187
  const matches = rows.filter(
152
188
  (r) =>
153
- (r.id || '').toLowerCase().includes(target) ||
154
- (r.name || '').toLowerCase().includes(target)
189
+ (r.id || "").toLowerCase().includes(target) ||
190
+ (r.name || "").toLowerCase().includes(target),
155
191
  );
156
192
  if (matches.length === 1) m = matches[0];
157
193
  else if (matches.length > 1) {
@@ -159,7 +195,7 @@ export async function modelsCommand(argv) {
159
195
  `Multiple matches for "${positionals[0]}":\n ${matches
160
196
  .slice(0, 10)
161
197
  .map((r) => r.id)
162
- .join('\n ')}${matches.length > 10 ? `\n ...and ${matches.length - 10} more` : ''}`
198
+ .join("\n ")}${matches.length > 10 ? `\n ...and ${matches.length - 10} more` : ""}`,
163
199
  );
164
200
  }
165
201
  }
@@ -173,36 +209,36 @@ export async function modelsCommand(argv) {
173
209
  return 0;
174
210
  }
175
211
 
176
- if (sub === 'endpoints') {
212
+ if (sub === "endpoints") {
177
213
  const { values, positionals } = parseArgs(rest, {
178
- sort: { type: 'string' },
179
- best: { type: 'boolean' }
214
+ sort: { type: "string" },
215
+ best: { type: "boolean" },
180
216
  });
181
217
  if (values.help || positionals.length === 0) {
182
218
  process.stdout.write(
183
- 'Usage: openrouter models endpoints <author>/<slug> [options]\n\n' +
184
- 'List provider endpoints (variants) for a model, with throughput,\n' +
185
- 'latency, uptime, and pricing.\n\n' +
186
- 'Options:\n' +
187
- ' --sort <field> throughput | latency | prompt | completion | uptime | context\n' +
188
- ' Sort the list before display (best first).\n' +
189
- ' --best Show only the top row after sorting.\n'
219
+ "Usage: openrouter models endpoints <author>/<slug> [options]\n\n" +
220
+ "List provider endpoints (variants) for a model, with throughput,\n" +
221
+ "latency, uptime, and pricing.\n\n" +
222
+ "Options:\n" +
223
+ " --sort <field> throughput | latency | prompt | completion | uptime | context\n" +
224
+ " Sort the list before display (best first).\n" +
225
+ " --best Show only the top row after sorting.\n",
190
226
  );
191
227
  return values.help ? 0 : 1;
192
228
  }
193
229
  if (values.sort && !ENDPOINT_SORT_FIELDS.includes(values.sort)) {
194
230
  throw new Error(
195
- `Unknown --sort field "${values.sort}". Expected: ${ENDPOINT_SORT_FIELDS.join(' | ')}`
231
+ `Unknown --sort field "${values.sort}". Expected: ${ENDPOINT_SORT_FIELDS.join(" | ")}`,
196
232
  );
197
233
  }
198
234
  const target = positionals[0];
199
- const slash = target.indexOf('/');
200
- if (slash === -1) throw new Error('Expected <author>/<slug>');
235
+ const slash = target.indexOf("/");
236
+ if (slash === -1) throw new Error("Expected <author>/<slug>");
201
237
  const author = target.slice(0, slash);
202
238
  const slug = target.slice(slash + 1);
203
- const data = await api('GET', `/models/${author}/${slug}/endpoints`, {
239
+ const data = await api("GET", `/models/${author}/${slug}/endpoints`, {
204
240
  auth: authFromValues(values),
205
- requireAuth: false
241
+ requireAuth: false,
206
242
  });
207
243
  let eps = (data.data && data.data.endpoints) || data.endpoints || [];
208
244
  if (values.sort) {
@@ -212,16 +248,23 @@ export async function modelsCommand(argv) {
212
248
  const t = e.throughput_last_30m || {};
213
249
  const l = e.latency_last_30m || {};
214
250
  switch (key) {
215
- case 'throughput': return -(t.p50 ?? -Infinity);
216
- case 'latency': return l.p50 ?? Infinity;
217
- case 'prompt': return Number(p.prompt ?? Infinity);
218
- case 'completion': return Number(p.completion ?? Infinity);
219
- case 'uptime': return -(e.uptime_last_30m ?? -Infinity);
220
- case 'context': return -(e.context_length ?? -Infinity);
251
+ case "throughput":
252
+ return -(t.p50 ?? -Infinity);
253
+ case "latency":
254
+ return l.p50 ?? Infinity;
255
+ case "prompt":
256
+ return Number(p.prompt ?? Infinity);
257
+ case "completion":
258
+ return Number(p.completion ?? Infinity);
259
+ case "uptime":
260
+ return -(e.uptime_last_30m ?? -Infinity);
261
+ case "context":
262
+ return -(e.context_length ?? -Infinity);
221
263
  }
222
264
  };
223
265
  eps = [...eps].sort((a, b) => {
224
- const va = score(a), vb = score(b);
266
+ const va = score(a),
267
+ vb = score(b);
225
268
  if (Number.isNaN(va)) return 1;
226
269
  if (Number.isNaN(vb)) return -1;
227
270
  return va - vb;
@@ -231,111 +274,138 @@ export async function modelsCommand(argv) {
231
274
 
232
275
  printResult({ ...data, data: { ...(data.data || {}), endpoints: eps } }, () => {
233
276
  table(eps, [
234
- { label: 'provider', value: (e) => e.provider_name || e.name || '' },
235
- { label: 'context', value: (e) => e.context_length ?? '' },
236
- { label: 'max_out', value: (e) => e.max_completion_tokens ?? '' },
277
+ { label: "provider", value: (e) => e.provider_name || e.name || "" },
278
+ { label: "status", value: (e) => e.status ?? "" },
279
+ { label: "context", value: (e) => e.context_length ?? "" },
280
+ { label: "max_out", value: (e) => e.max_completion_tokens ?? "" },
237
281
  PRICE_COLUMN,
238
282
  {
239
- label: 'tput p50',
283
+ label: "tput p50",
240
284
  value: (e) =>
241
285
  e.throughput_last_30m?.p50 != null
242
- ? Number(e.throughput_last_30m.p50).toFixed(0) + ' tok/s'
243
- : ''
286
+ ? Number(e.throughput_last_30m.p50).toFixed(0) + " tok/s"
287
+ : "",
244
288
  },
245
289
  {
246
- label: 'lat p50',
290
+ label: "lat p50",
247
291
  value: (e) =>
248
292
  e.latency_last_30m?.p50 != null
249
- ? Number(e.latency_last_30m.p50).toFixed(0) + ' ms'
250
- : ''
293
+ ? Number(e.latency_last_30m.p50).toFixed(0) + " ms"
294
+ : "",
251
295
  },
252
296
  {
253
- label: 'uptime 30m',
297
+ label: "uptime 30m",
254
298
  value: (e) =>
255
- e.uptime_last_30m != null ? Number(e.uptime_last_30m).toFixed(1) + '%' : ''
299
+ e.uptime_last_30m != null ? Number(e.uptime_last_30m).toFixed(1) + "%" : "",
256
300
  },
257
- { label: 'quant', value: (e) => e.quantization || '' }
301
+ { label: "quant", value: (e) => e.quantization || "" },
258
302
  ]);
259
303
  });
260
304
  return 0;
261
305
  }
262
306
 
263
- if (sub === 'user') {
307
+ if (sub === "user") {
264
308
  const { values } = parseArgs(rest, {
265
- workspace: { type: 'string' }
309
+ workspace: { type: "string" },
310
+ category: { type: "string" },
311
+ supported: { type: "string" },
312
+ "input-modalities": { type: "string" },
313
+ "output-modalities": { type: "string" },
314
+ order: { type: "string" },
266
315
  });
267
316
  if (values.help) {
268
317
  process.stdout.write(
269
- 'Usage: openrouter models user [--workspace <id|slug>]\n\nList models filtered by your workspace provider preferences, privacy, and guardrails.\n'
318
+ "Usage: openrouter models user [--workspace <id|slug>] [--category <c>] [--supported <p>] [--input-modalities <csv>] [--output-modalities <csv>] [--order <sort>]\n\nList models filtered by your workspace provider preferences, privacy, and guardrails.\n",
270
319
  );
271
320
  return 0;
272
321
  }
273
- const query = {};
322
+ const query = listQuery(values);
274
323
  if (values.workspace) query.workspace_id = values.workspace;
275
- const data = await api('GET', '/models/user', {
324
+ const data = await api("GET", "/models/user", {
276
325
  auth: authFromValues(values),
277
- query
326
+ query,
278
327
  });
279
328
  printResult(data, () => listFormatter(data));
280
329
  return 0;
281
330
  }
282
331
 
283
- if (sub === 'count') {
332
+ if (sub === "parameters" || sub === "params") {
333
+ const { values, positionals } = parseArgs(rest, {
334
+ provider: { type: "string" },
335
+ });
336
+ if (values.help || positionals.length === 0) {
337
+ process.stdout.write(
338
+ "Usage: openrouter models parameters <author>/<slug> [--provider <slug>]\n\n" +
339
+ "Show a model's supported parameters plus popularity analytics\n" +
340
+ "(p10/p50/p90 per parameter). Optionally scope to one provider.\n",
341
+ );
342
+ return values.help ? 0 : 1;
343
+ }
344
+ const target = positionals[0];
345
+ const slash = target.indexOf("/");
346
+ if (slash === -1) throw new Error("Expected <author>/<slug>");
347
+ const author = target.slice(0, slash);
348
+ const slug = target.slice(slash + 1);
349
+ const query = {};
350
+ if (values.provider) query.provider = values.provider;
351
+ const data = await api("GET", `/parameters/${author}/${slug}`, {
352
+ auth: authFromValues(values),
353
+ query,
354
+ });
355
+ printResult(data);
356
+ return 0;
357
+ }
358
+
359
+ if (sub === "count") {
284
360
  const { values } = parseArgs(rest, {});
285
- const data = await api('GET', '/models/count', {
361
+ const data = await api("GET", "/models/count", {
286
362
  auth: authFromValues(values),
287
- requireAuth: false
363
+ requireAuth: false,
288
364
  });
289
365
  printResult(data, () => outln(JSON.stringify(data)));
290
366
  return 0;
291
367
  }
292
368
 
293
369
  const { values } = parseArgs(rest, {
294
- category: { type: 'string' },
295
- supported: { type: 'string' },
296
- 'output-modalities': { type: 'string' },
297
- filter: { type: 'string' },
298
- free: { type: 'boolean' },
299
- sort: { type: 'string' }
370
+ category: { type: "string" },
371
+ supported: { type: "string" },
372
+ "input-modalities": { type: "string" },
373
+ "output-modalities": { type: "string" },
374
+ order: { type: "string" },
375
+ filter: { type: "string" },
376
+ free: { type: "boolean" },
377
+ sort: { type: "string" },
300
378
  });
301
379
  if (values.help) {
302
380
  process.stdout.write(HELP);
303
381
  return 0;
304
382
  }
305
- const query = {};
306
- if (values.category) query.category = values.category;
307
- if (values.supported) query.supported_parameters = values.supported;
308
- if (values['output-modalities'])
309
- query.output_modalities = values['output-modalities'];
383
+ const query = listQuery(values);
310
384
 
311
- const data = await api('GET', '/models', {
385
+ const data = await api("GET", "/models", {
312
386
  auth: authFromValues(values),
313
387
  query,
314
- requireAuth: false
388
+ requireAuth: false,
315
389
  });
316
390
 
317
391
  let rows = data.data || [];
318
392
  if (values.filter) {
319
393
  const f = values.filter.toLowerCase();
320
394
  rows = rows.filter(
321
- (m) =>
322
- (m.id || '').toLowerCase().includes(f) ||
323
- (m.name || '').toLowerCase().includes(f)
395
+ (m) => (m.id || "").toLowerCase().includes(f) || (m.name || "").toLowerCase().includes(f),
324
396
  );
325
397
  }
326
- if (values.free) rows = rows.filter((m) => (m.id || '').endsWith(':free'));
398
+ if (values.free) rows = rows.filter((m) => (m.id || "").endsWith(":free"));
327
399
 
328
400
  if (values.sort) {
329
401
  const key = values.sort;
330
402
  if (!MODEL_SORT_FIELDS.includes(key)) {
331
- throw new Error(
332
- `Unknown --sort field "${key}". Expected: ${MODEL_SORT_FIELDS.join(' | ')}`
333
- );
403
+ throw new Error(`Unknown --sort field "${key}". Expected: ${MODEL_SORT_FIELDS.join(" | ")}`);
334
404
  }
335
405
  // Unparseable or missing values must score to a definite extreme, or the
336
406
  // comparator reports them equal to everything and the sort is a no-op.
337
407
  const num = (x) => {
338
- if (x == null || x === '') return null;
408
+ if (x == null || x === "") return null;
339
409
  const n = Number(x);
340
410
  return Number.isFinite(n) ? n : null;
341
411
  };
@@ -346,15 +416,21 @@ export async function modelsCommand(argv) {
346
416
  };
347
417
  const get = (m) => {
348
418
  switch (key) {
349
- case 'id': return m.id || '';
350
- case 'name': return m.name || '';
351
- case 'context': return desc(m.context_length);
352
- case 'prompt': return asc(m.pricing?.prompt);
353
- case 'completion': return asc(m.pricing?.completion);
419
+ case "id":
420
+ return m.id || "";
421
+ case "name":
422
+ return m.name || "";
423
+ case "context":
424
+ return desc(m.context_length);
425
+ case "prompt":
426
+ return asc(m.pricing?.prompt);
427
+ case "completion":
428
+ return asc(m.pricing?.completion);
354
429
  }
355
430
  };
356
431
  rows = [...rows].sort((a, b) => {
357
- const va = get(a), vb = get(b);
432
+ const va = get(a),
433
+ vb = get(b);
358
434
  if (va < vb) return -1;
359
435
  if (va > vb) return 1;
360
436
  return 0;
@@ -369,23 +445,23 @@ export async function modelsCommand(argv) {
369
445
  export async function providersCommand(argv) {
370
446
  const { values } = parseArgs(argv, {});
371
447
  if (values.help) {
372
- process.stdout.write('Usage: openrouter providers\n\nList all providers.\n');
448
+ process.stdout.write("Usage: openrouter providers\n\nList all providers.\n");
373
449
  return 0;
374
450
  }
375
- const data = await api('GET', '/providers', {
451
+ const data = await api("GET", "/providers", {
376
452
  auth: authFromValues(values),
377
- requireAuth: false
453
+ requireAuth: false,
378
454
  });
379
455
  printResult(data, () => {
380
456
  const rows = data.data || [];
381
457
  table(rows, [
382
- { label: 'slug', value: (p) => p.slug || p.id || '' },
383
- { label: 'name', value: (p) => p.name || '' },
384
- { label: 'hq', value: (p) => p.headquarters || '' },
385
- { label: 'datacenters', value: (p) => (p.datacenters || []).join(',') || '' },
386
- { label: 'privacy', value: (p) => (p.privacy_policy_url ? 'yes' : '') },
387
- { label: 'tos', value: (p) => (p.terms_of_service_url ? 'yes' : '') },
388
- { label: 'status', value: (p) => (p.status_page_url ? 'yes' : '') }
458
+ { label: "slug", value: (p) => p.slug || p.id || "" },
459
+ { label: "name", value: (p) => p.name || "" },
460
+ { label: "hq", value: (p) => p.headquarters || "" },
461
+ { label: "datacenters", value: (p) => (p.datacenters || []).join(",") || "" },
462
+ { label: "privacy", value: (p) => (p.privacy_policy_url ? "yes" : "") },
463
+ { label: "tos", value: (p) => (p.terms_of_service_url ? "yes" : "") },
464
+ { label: "status", value: (p) => (p.status_page_url ? "yes" : "") },
389
465
  ]);
390
466
  });
391
467
  return 0;