@aaronjmars/openroutercli 0.1.4 → 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.
package/src/cli.js CHANGED
@@ -1,32 +1,31 @@
1
- import { setJsonMode, setQuiet, c, outln } from './output.js';
2
- import { loginCommand, logoutCommand } from './commands/login.js';
3
- import { whoamiCommand, creditsCommand, activityCommand } from './commands/account.js';
4
- import { modelsCommand, providersCommand } from './commands/models.js';
5
- import { chatCommand, completeCommand } from './commands/chat.js';
6
- import { embedCommand } from './commands/embed.js';
7
- import { rerankCommand } from './commands/rerank.js';
8
- import { speechCommand } from './commands/speech.js';
9
- import { videoCommand } from './commands/video.js';
10
- import { messagesCommand, responsesCommand } from './commands/messages.js';
11
- import { generationCommand } from './commands/generation.js';
12
- import { keysCommand } from './commands/keys.js';
13
- import { requestCommand } from './commands/request.js';
14
- import { guardrailsCommand } from './commands/guardrails.js';
15
- import { workspacesCommand } from './commands/workspaces.js';
16
- import { orgCommand, zdrCommand, authCodeCommand } from './commands/misc.js';
17
- import { DEFAULT_BASE_URL } from './config.js';
18
- import { readFileSync } from 'node:fs';
19
- import { fileURLToPath } from 'node:url';
20
- import { dirname, join } from 'node:path';
21
-
22
- const VERSION = (() => {
23
- try {
24
- const pkgPath = join(dirname(fileURLToPath(import.meta.url)), '..', 'package.json');
25
- return JSON.parse(readFileSync(pkgPath, 'utf8')).version;
26
- } catch {
27
- return 'unknown';
28
- }
29
- })();
1
+ import { setJsonMode, setQuiet, outln } from "./output.js";
2
+ import { loginCommand, logoutCommand } from "./commands/login.js";
3
+ import { whoamiCommand, creditsCommand, activityCommand } from "./commands/account.js";
4
+ import { modelsCommand, providersCommand } from "./commands/models.js";
5
+ import { chatCommand, completeCommand } from "./commands/chat.js";
6
+ import { embedCommand } from "./commands/embed.js";
7
+ import { rerankCommand } from "./commands/rerank.js";
8
+ import { speechCommand } from "./commands/speech.js";
9
+ import { transcribeCommand } from "./commands/transcribe.js";
10
+ import { videoCommand } from "./commands/video.js";
11
+ import { imageCommand } from "./commands/image.js";
12
+ import { messagesCommand, responsesCommand } from "./commands/messages.js";
13
+ import { generationCommand } from "./commands/generation.js";
14
+ import { keysCommand } from "./commands/keys.js";
15
+ import { byokCommand } from "./commands/byok.js";
16
+ import { filesCommand } from "./commands/files.js";
17
+ import { presetsCommand } from "./commands/presets.js";
18
+ import { requestCommand } from "./commands/request.js";
19
+ import { guardrailsCommand } from "./commands/guardrails.js";
20
+ import { workspacesCommand } from "./commands/workspaces.js";
21
+ import { orgCommand, zdrCommand, authCodeCommand } from "./commands/misc.js";
22
+ import { DEFAULT_BASE_URL } from "./config.js";
23
+ import { readFileSync } from "node:fs";
24
+ import { fileURLToPath } from "node:url";
25
+ import { dirname, join } from "node:path";
26
+
27
+ const pkgPath = join(dirname(fileURLToPath(import.meta.url)), "..", "package.json");
28
+ const VERSION = JSON.parse(readFileSync(pkgPath, "utf8")).version;
30
29
 
31
30
  const COMMANDS = {
32
31
  login: loginCommand,
@@ -42,20 +41,27 @@ const COMMANDS = {
42
41
  rerank: rerankCommand,
43
42
  speech: speechCommand,
44
43
  tts: speechCommand,
44
+ transcribe: transcribeCommand,
45
+ stt: transcribeCommand,
45
46
  video: videoCommand,
47
+ image: imageCommand,
48
+ images: imageCommand,
46
49
  messages: messagesCommand,
47
50
  responses: responsesCommand,
48
51
  generation: generationCommand,
52
+ presets: presetsCommand,
49
53
  keys: keysCommand,
54
+ byok: byokCommand,
55
+ files: filesCommand,
50
56
  guardrails: guardrailsCommand,
51
57
  workspaces: workspacesCommand,
52
58
  org: orgCommand,
53
59
  zdr: zdrCommand,
54
- 'auth-code': authCodeCommand,
55
- request: requestCommand
60
+ "auth-code": authCodeCommand,
61
+ request: requestCommand,
56
62
  };
57
63
 
58
- const HELP = `openrouter — CLI for the OpenRouter API
64
+ const HELP = `openrouter - CLI for the OpenRouter API
59
65
 
60
66
  Usage:
61
67
  openrouter <command> [options]
@@ -75,15 +81,19 @@ Inference:
75
81
  embed [text...] Embeddings
76
82
  rerank --query --doc Reranking
77
83
  speech [text...] Text to speech (audio out)
84
+ transcribe <file> Speech to text (audio in). Alias: stt
78
85
  video <sub> Video generation jobs (create / get / wait / download / models)
86
+ image <sub> Image generation (create / models / endpoints). Alias: images
79
87
 
80
88
  Discovery:
81
- models [list|show|endpoints|count|user] List models, full model detail,
82
- provider variants, count, or your
83
- workspace-filtered set
89
+ models [list|show|endpoints|parameters|count|user] List models, full model
90
+ detail, provider variants, param
91
+ analytics, count, or your set
84
92
  embed models List embedding models
85
93
  video models List video generation models
94
+ image models List image generation models
86
95
  providers List providers (with HQ + datacenters)
96
+ presets <sub> list / get / versions (saved config profiles)
87
97
  generation <id> [--content] Generation metadata or content
88
98
  credits Remaining credits
89
99
  activity Usage activity (management key)
@@ -91,8 +101,10 @@ Discovery:
91
101
 
92
102
  Management (require a management key):
93
103
  keys <sub> list / get / create / update / delete
104
+ byok <sub> list / get / create / update / delete (provider integrations)
94
105
  guardrails <sub> list / get / create / update / delete / assignments
95
106
  workspaces <sub> list / get / create / update / delete / add-members / remove-members
107
+ files <sub> list / get / upload / download / delete
96
108
  org members List organization members
97
109
  auth-code Mint a PKCE authorization code so a user can claim a key
98
110
  request <METHOD> <path> Raw authenticated request to any endpoint
@@ -104,20 +116,21 @@ Global options (work with all commands):
104
116
  --title <name> X-Title header (your app name; appears on openrouter.ai)
105
117
  --json Output JSON (also disables streaming, color, and prompts)
106
118
  -q, --quiet Suppress informational stderr messages
119
+ -V, --version Print the version
107
120
  -h, --help Show help (use \`openrouter <command> --help\` for command-specific help)
108
121
 
109
122
  Environment:
110
- OPENROUTER_API_KEY Default user key
123
+ OPENROUTER_API_KEY Default user key (alias: OPENROUTER_KEY)
111
124
  OPENROUTER_MANAGEMENT_KEY Default management/provisioning key
112
125
  OPENROUTER_BASE_URL Default base URL
113
126
  OPENROUTER_REFERER Default HTTP-Referer
114
127
  OPENROUTER_TITLE Default X-Title
115
- NO_COLOR Disable ANSI colors
128
+ NO_COLOR Disable ANSI colors (alias: OPENROUTER_NO_COLOR)
116
129
  OPENROUTER_DEBUG=1 Print stack traces on error
117
130
 
118
131
  Examples:
119
132
  openrouter login
120
- openrouter chat "Hello, world" -m anthropic/claude-3.5-sonnet
133
+ openrouter chat "Hello, world" -m anthropic/claude-sonnet-4.5
121
134
  echo "summarize this" | openrouter chat -m openai/gpt-4o-mini --no-stream
122
135
  openrouter models --filter claude --json
123
136
  openrouter embed -m openai/text-embedding-3-small "hello" "world"
@@ -127,7 +140,8 @@ Version: ${VERSION}
127
140
  `;
128
141
 
129
142
  function preParseGlobals(argv) {
130
- // Pull global flags out of any position so they work before or after the subcommand.
143
+ // --json/--quiet/--version work in any position; the rest are merged
144
+ // per-command in args.js.
131
145
  const out = [];
132
146
  let json = false;
133
147
  let quiet = false;
@@ -135,10 +149,10 @@ function preParseGlobals(argv) {
135
149
  let version = false;
136
150
  for (let i = 0; i < argv.length; i++) {
137
151
  const a = argv[i];
138
- if (a === '--json') json = true;
139
- else if (a === '-q' || a === '--quiet') quiet = true;
140
- else if (a === '-V' || a === '--version') version = true;
141
- else if (a === '-h' || a === '--help') {
152
+ if (a === "--json") json = true;
153
+ else if (a === "-q" || a === "--quiet") quiet = true;
154
+ else if (a === "-V" || a === "--version") version = true;
155
+ else if (a === "-h" || a === "--help") {
142
156
  help = true;
143
157
  out.push(a); // forward so subcommand help can also pick it up
144
158
  } else out.push(a);
@@ -167,10 +181,10 @@ export async function run(argv) {
167
181
  if (!handler) {
168
182
  process.stderr.write(`Unknown command: ${cmd}\n\n`);
169
183
  process.stdout.write(HELP);
170
- process.exit(1);
184
+ return safeExit(1);
171
185
  }
172
186
  const code = await handler(rest);
173
- if (typeof code === 'number') await safeExit(code);
187
+ if (typeof code === "number") await safeExit(code);
174
188
  }
175
189
 
176
190
  function safeExit(code) {
@@ -187,7 +201,7 @@ function safeExit(code) {
187
201
  for (const stream of [process.stdout, process.stderr]) {
188
202
  if (stream && stream.writableLength > 0) {
189
203
  pending++;
190
- stream.write('', done);
204
+ stream.write("", done);
191
205
  }
192
206
  }
193
207
  if (pending === 0) {
@@ -1,11 +1,11 @@
1
- import { parseArgs, authFromValues } from '../args.js';
2
- import { api, APIError } from '../api.js';
3
- import { resolveAuth } from '../config.js';
4
- import { c, isJsonMode, outln, printJSON, printResult, table } from '../output.js';
1
+ import { parseArgs, authFromValues } from "../args.js";
2
+ import { api, APIError } from "../api.js";
3
+ import { resolveAuth } from "../config.js";
4
+ import { c, isJsonMode, outln, printJSON, printResult, table } from "../output.js";
5
5
 
6
6
  async function fetchKey(authOpts, requiresManagement = false) {
7
7
  try {
8
- return await api('GET', '/key', { auth: authOpts, requiresManagement });
8
+ return await api("GET", "/key", { auth: authOpts, requiresManagement });
9
9
  } catch (err) {
10
10
  if (err instanceof APIError) return { error: err.message };
11
11
  throw err;
@@ -15,41 +15,43 @@ async function fetchKey(authOpts, requiresManagement = false) {
15
15
  function renderKey(label, data) {
16
16
  outln(c.bold(label));
17
17
  if (!data) {
18
- outln(c.dim(' (not configured)'));
18
+ outln(c.dim(" (not configured)"));
19
19
  return;
20
20
  }
21
21
  if (data.error) {
22
- outln(' ' + c.red(data.error));
22
+ outln(" " + c.red(data.error));
23
23
  return;
24
24
  }
25
25
  const d = data.data || data;
26
- outln(` label: ${d.label ?? ''}`);
26
+ outln(` label: ${d.label ?? ""}`);
27
27
  outln(` is_management_key: ${d.is_management_key ?? false}`);
28
28
  outln(` is_free_tier: ${d.is_free_tier}`);
29
- outln(` limit: ${d.limit ?? 'unlimited'}`);
30
- outln(` limit_remaining: ${d.limit_remaining ?? '-'}`);
31
- outln(` limit_reset: ${d.limit_reset ?? '-'}`);
32
- outln(` usage (total): ${d.usage ?? '-'}`);
29
+ outln(` limit: ${d.limit ?? "unlimited"}`);
30
+ outln(` limit_remaining: ${d.limit_remaining ?? "-"}`);
31
+ outln(` limit_reset: ${d.limit_reset ?? "-"}`);
32
+ outln(` usage (total): ${d.usage ?? "-"}`);
33
33
  if (d.usage_daily != null) outln(` usage_daily: ${d.usage_daily}`);
34
34
  if (d.usage_weekly != null) outln(` usage_weekly: ${d.usage_weekly}`);
35
35
  if (d.usage_monthly != null) outln(` usage_monthly: ${d.usage_monthly}`);
36
36
  if (d.byok_usage != null) outln(` byok_usage: ${d.byok_usage}`);
37
- outln(` expires_at: ${d.expires_at ?? '-'}`);
37
+ outln(` expires_at: ${d.expires_at ?? "-"}`);
38
38
  if (d.rate_limit) {
39
- outln(` rate_limit: ${d.rate_limit.requests ?? '?'} req / ${d.rate_limit.interval ?? '?'}`);
39
+ outln(
40
+ ` rate_limit: ${d.rate_limit.requests ?? "?"} req / ${d.rate_limit.interval ?? "?"}`,
41
+ );
40
42
  }
41
43
  }
42
44
 
43
45
  export async function whoamiCommand(argv) {
44
46
  const { values } = parseArgs(argv, {
45
- management: { type: 'boolean' }
47
+ management: { type: "boolean" },
46
48
  });
47
49
  if (values.help) {
48
50
  process.stdout.write(
49
- 'Usage: openrouter whoami [--management]\n\n' +
50
- 'Show the API key(s) currently configured. By default shows both the user\n' +
51
- 'key and the management key (if set). With --management, shows only the\n' +
52
- 'management key.\n'
51
+ "Usage: openrouter whoami [--management]\n\n" +
52
+ "Show the API key(s) currently configured. By default shows both the user\n" +
53
+ "key and the management key (if set). With --management, shows only the\n" +
54
+ "management key.\n",
53
55
  );
54
56
  return 0;
55
57
  }
@@ -59,42 +61,48 @@ export async function whoamiCommand(argv) {
59
61
 
60
62
  // If --key is supplied, query just that key.
61
63
  if (authOpts.key) {
62
- const data = await fetchKey(authOpts);
63
- printResult(data, () => renderKey('API key (--key override)', data));
64
+ const data = await api("GET", "/key", { auth: authOpts });
65
+ printResult(data, () => renderKey("API key (--key override)", data));
64
66
  return 0;
65
67
  }
66
68
 
67
69
  if (values.management) {
68
- const data = resolved.hasManagementKey ? await fetchKey(authOpts, true) : null;
70
+ const data = resolved.hasManagementKey
71
+ ? await api("GET", "/key", { auth: authOpts, requiresManagement: true })
72
+ : null;
69
73
  if (isJsonMode()) printJSON({ management: data });
70
- else renderKey('Management key', data);
74
+ else renderKey("Management key", data);
71
75
  return 0;
72
76
  }
73
77
 
74
- // Both
78
+ // Probing both slots: one slot failing is normal (a user key is rejected by
79
+ // the management-scoped probe and vice versa), so report per slot and only
80
+ // fail when every configured key errored.
75
81
  const userData = resolved.hasUserKey ? await fetchKey(authOpts, false) : null;
76
82
  const mgmtData = resolved.hasManagementKey ? await fetchKey(authOpts, true) : null;
83
+ const probed = [userData, mgmtData].filter(Boolean);
84
+ const code = probed.length && probed.every((d) => d.error) ? 2 : 0;
77
85
 
78
86
  if (isJsonMode()) {
79
87
  printJSON({ user: userData, management: mgmtData });
80
- return 0;
88
+ return code;
81
89
  }
82
- renderKey('User key', userData);
83
- outln('');
84
- renderKey('Management key', mgmtData);
85
- return 0;
90
+ renderKey("User key", userData);
91
+ outln("");
92
+ renderKey("Management key", mgmtData);
93
+ return code;
86
94
  }
87
95
 
88
96
  export async function creditsCommand(argv) {
89
97
  const { values } = parseArgs(argv, {});
90
98
  if (values.help) {
91
- process.stdout.write('Usage: openrouter credits\n\nShow remaining credits.\n');
99
+ process.stdout.write("Usage: openrouter credits\n\nShow remaining credits.\n");
92
100
  return 0;
93
101
  }
94
- const data = await api('GET', '/credits', { auth: authFromValues(values) });
102
+ const data = await api("GET", "/credits", { auth: authFromValues(values) });
95
103
  printResult(data, () => {
96
104
  const d = data.data || data;
97
- outln(c.bold('Credits'));
105
+ outln(c.bold("Credits"));
98
106
  for (const [k, v] of Object.entries(d)) outln(` ${k}: ${v}`);
99
107
  });
100
108
  return 0;
@@ -102,37 +110,37 @@ export async function creditsCommand(argv) {
102
110
 
103
111
  export async function activityCommand(argv) {
104
112
  const { values } = parseArgs(argv, {
105
- date: { type: 'string' },
106
- 'api-key-hash': { type: 'string' },
107
- 'user-id': { type: 'string' }
113
+ date: { type: "string" },
114
+ "api-key-hash": { type: "string" },
115
+ "user-id": { type: "string" },
108
116
  });
109
117
  if (values.help) {
110
118
  process.stdout.write(
111
- `Usage: openrouter activity [options]\n\nGet usage activity grouped by endpoint.\n\nOptions:\n --date <YYYY-MM-DD> UTC date in last 30 days\n --api-key-hash <hash> Filter by API key SHA-256 hash\n --user-id <id> Filter by org member user ID\n`
119
+ `Usage: openrouter activity [options]\n\nGet usage activity grouped by endpoint.\n\nOptions:\n --date <YYYY-MM-DD> UTC date in last 30 days\n --api-key-hash <hash> Filter by API key SHA-256 hash\n --user-id <id> Filter by org member user ID\n`,
112
120
  );
113
121
  return 0;
114
122
  }
115
123
  const query = {};
116
124
  if (values.date) query.date = values.date;
117
- if (values['api-key-hash']) query.api_key_hash = values['api-key-hash'];
118
- if (values['user-id']) query.user_id = values['user-id'];
119
- const data = await api('GET', '/activity', {
125
+ if (values["api-key-hash"]) query.api_key_hash = values["api-key-hash"];
126
+ if (values["user-id"]) query.user_id = values["user-id"];
127
+ const data = await api("GET", "/activity", {
120
128
  auth: authFromValues(values),
121
129
  requiresManagement: true,
122
- query
130
+ query,
123
131
  });
124
132
  printResult(data, () => {
125
133
  const rows = data.data || [];
126
134
  if (!rows.length) {
127
- outln(c.dim('(no activity)'));
135
+ outln(c.dim("(no activity)"));
128
136
  return;
129
137
  }
130
138
  table(rows, [
131
- { label: 'date', value: (r) => r.date || r.day || '' },
132
- { label: 'model', value: (r) => r.model || r.model_permaslug || '' },
133
- { label: 'requests', value: (r) => r.requests ?? r.request_count ?? '' },
134
- { label: 'tokens', value: (r) => r.tokens ?? r.total_tokens ?? '' },
135
- { label: 'cost', value: (r) => r.usage ?? r.cost ?? '' }
139
+ { label: "date", value: (r) => r.date || r.day || "" },
140
+ { label: "model", value: (r) => r.model || r.model_permaslug || "" },
141
+ { label: "requests", value: (r) => r.requests ?? r.request_count ?? "" },
142
+ { label: "tokens", value: (r) => r.tokens ?? r.total_tokens ?? "" },
143
+ { label: "cost", value: (r) => r.usage ?? r.cost ?? "" },
136
144
  ]);
137
145
  });
138
146
  return 0;
@@ -0,0 +1,153 @@
1
+ import { parseArgs, authFromValues } from "../args.js";
2
+ import { api } from "../api.js";
3
+ import { outln, printResult, table } from "../output.js";
4
+
5
+ const HELP = `Usage: openrouter byok <subcommand> [options]
6
+
7
+ Manage BYOK (bring-your-own-key) provider integrations (requires a provisioning/management key).
8
+
9
+ Subcommands:
10
+ list List integrations
11
+ get <id> Get a single integration
12
+ create [options] Create an integration
13
+ update <id> [options] Update an integration
14
+ delete <id> Delete an integration
15
+
16
+ create options:
17
+ --provider <slug> Provider slug (required)
18
+ --api-key <key> Provider secret key (required)
19
+ --name <text>
20
+ --allowed-models <csv>
21
+ --allowed-hashes <csv>
22
+ --allowed-users <csv>
23
+ --disabled / --enabled
24
+ --fallback / --no-fallback
25
+
26
+ update options:
27
+ --provider <slug>
28
+ --api-key <key>
29
+ --name <text>
30
+ --allowed-models <csv>
31
+ --allowed-hashes <csv>
32
+ --allowed-users <csv>
33
+ --disabled / --enabled
34
+ --fallback / --no-fallback
35
+ `;
36
+
37
+ const WRITE_OPTIONS = {
38
+ provider: { type: "string" },
39
+ "api-key": { type: "string" },
40
+ name: { type: "string" },
41
+ "allowed-models": { type: "string" },
42
+ "allowed-hashes": { type: "string" },
43
+ "allowed-users": { type: "string" },
44
+ disabled: { type: "boolean" },
45
+ enabled: { type: "boolean" },
46
+ fallback: { type: "boolean" },
47
+ "no-fallback": { type: "boolean" },
48
+ };
49
+
50
+ function csvOption(value) {
51
+ return value.split(",").map((s) => s.trim());
52
+ }
53
+
54
+ export async function byokCommand(argv) {
55
+ const sub = argv[0];
56
+ const rest = argv.slice(1);
57
+ if (!sub || sub === "-h" || sub === "--help" || sub === "help") {
58
+ process.stdout.write(HELP);
59
+ return sub ? 0 : 1;
60
+ }
61
+
62
+ if (rest.includes("-h") || rest.includes("--help")) {
63
+ process.stdout.write(HELP);
64
+ return 0;
65
+ }
66
+
67
+ if (sub === "list") {
68
+ const { values } = parseArgs(rest, {});
69
+ const data = await api("GET", "/byok", {
70
+ auth: authFromValues(values),
71
+ requiresManagement: true,
72
+ });
73
+ printResult(data, () => {
74
+ const rows = data.data || [];
75
+ table(rows, [
76
+ { label: "id", value: (b) => b.id || "" },
77
+ { label: "provider", value: (b) => b.provider || "" },
78
+ { label: "name", value: (b) => b.name || "" },
79
+ { label: "disabled", value: (b) => (b.disabled ? "yes" : "") },
80
+ ]);
81
+ });
82
+ return 0;
83
+ }
84
+
85
+ if (sub === "get") {
86
+ const { values, positionals } = parseArgs(rest, {});
87
+ if (!positionals[0]) throw new Error("id required");
88
+ const data = await api("GET", `/byok/${encodeURIComponent(positionals[0])}`, {
89
+ auth: authFromValues(values),
90
+ requiresManagement: true,
91
+ });
92
+ printResult(data);
93
+ return 0;
94
+ }
95
+
96
+ if (sub === "create") {
97
+ const { values } = parseArgs(rest, WRITE_OPTIONS);
98
+ if (!values.provider) throw new Error("--provider required");
99
+ if (!values["api-key"]) throw new Error("--api-key required");
100
+ const body = { provider: values.provider, key: values["api-key"] };
101
+ if (values.name) body.name = values.name;
102
+ if (values["allowed-models"]) body.allowed_models = csvOption(values["allowed-models"]);
103
+ if (values["allowed-hashes"]) body.allowed_api_key_hashes = csvOption(values["allowed-hashes"]);
104
+ if (values["allowed-users"]) body.allowed_user_ids = csvOption(values["allowed-users"]);
105
+ if (values.disabled) body.disabled = true;
106
+ if (values.enabled) body.disabled = false;
107
+ if (values.fallback) body.is_fallback = true;
108
+ if (values["no-fallback"]) body.is_fallback = false;
109
+ const data = await api("POST", "/byok", {
110
+ auth: authFromValues(values),
111
+ requiresManagement: true,
112
+ body,
113
+ });
114
+ printResult(data);
115
+ return 0;
116
+ }
117
+
118
+ if (sub === "update") {
119
+ const { values, positionals } = parseArgs(rest, WRITE_OPTIONS);
120
+ if (!positionals[0]) throw new Error("id required");
121
+ const body = {};
122
+ if (values.provider) body.provider = values.provider;
123
+ if (values["api-key"]) body.key = values["api-key"];
124
+ if (values.name) body.name = values.name;
125
+ if (values["allowed-models"]) body.allowed_models = csvOption(values["allowed-models"]);
126
+ if (values["allowed-hashes"]) body.allowed_api_key_hashes = csvOption(values["allowed-hashes"]);
127
+ if (values["allowed-users"]) body.allowed_user_ids = csvOption(values["allowed-users"]);
128
+ if (values.disabled) body.disabled = true;
129
+ if (values.enabled) body.disabled = false;
130
+ if (values.fallback) body.is_fallback = true;
131
+ if (values["no-fallback"]) body.is_fallback = false;
132
+ const data = await api("PATCH", `/byok/${encodeURIComponent(positionals[0])}`, {
133
+ auth: authFromValues(values),
134
+ requiresManagement: true,
135
+ body,
136
+ });
137
+ printResult(data);
138
+ return 0;
139
+ }
140
+
141
+ if (sub === "delete") {
142
+ const { values, positionals } = parseArgs(rest, {});
143
+ if (!positionals[0]) throw new Error("id required");
144
+ const data = await api("DELETE", `/byok/${encodeURIComponent(positionals[0])}`, {
145
+ auth: authFromValues(values),
146
+ requiresManagement: true,
147
+ });
148
+ printResult(data, () => outln("deleted"));
149
+ return 0;
150
+ }
151
+
152
+ throw new Error(`Unknown byok subcommand: ${sub}`);
153
+ }