@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.
- package/README.md +4 -0
- package/bin/openrouter.js +3 -3
- package/package.json +7 -2
- package/src/api.js +36 -25
- package/src/args.js +17 -18
- package/src/cli.js +53 -35
- package/src/commands/account.js +45 -43
- package/src/commands/byok.js +153 -0
- package/src/commands/chat.js +228 -107
- package/src/commands/embed.js +31 -26
- package/src/commands/files.js +102 -0
- package/src/commands/generation.js +10 -10
- package/src/commands/guardrails.js +98 -79
- package/src/commands/image.js +149 -0
- package/src/commands/keys.js +61 -55
- package/src/commands/login.js +84 -88
- package/src/commands/messages.js +119 -55
- package/src/commands/misc.js +45 -45
- package/src/commands/models.js +215 -139
- package/src/commands/presets.js +93 -0
- package/src/commands/request.js +20 -20
- package/src/commands/rerank.js +33 -25
- package/src/commands/speech.js +16 -16
- package/src/commands/transcribe.js +62 -0
- package/src/commands/video.js +45 -42
- package/src/commands/workspaces.js +49 -45
- package/src/config.js +17 -23
- package/src/output.js +14 -27
package/src/commands/messages.js
CHANGED
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
authFromValues,
|
|
4
4
|
numberOption,
|
|
5
5
|
readStdinIfPiped,
|
|
6
|
-
shouldStream
|
|
7
|
-
} from
|
|
8
|
-
import { api, assertNoStreamError, sseStream } from
|
|
9
|
-
import { isJsonMode, out, outln, printJSON } from
|
|
6
|
+
shouldStream,
|
|
7
|
+
} from "../args.js";
|
|
8
|
+
import { api, assertNoStreamError, sseStream } from "../api.js";
|
|
9
|
+
import { c, isJsonMode, out, outln, printJSON } from "../output.js";
|
|
10
10
|
|
|
11
11
|
const HELP = `Usage: openrouter messages [prompt...] [options]
|
|
12
12
|
|
|
@@ -17,6 +17,12 @@ Options:
|
|
|
17
17
|
-s, --system <text> System prompt
|
|
18
18
|
--max-tokens <n> (default: 1024)
|
|
19
19
|
--temperature <n>
|
|
20
|
+
--top-p <n>
|
|
21
|
+
--top-k <n>
|
|
22
|
+
--stop <text> Stop sequence (repeatable via comma)
|
|
23
|
+
--thinking-budget <n> Enable extended thinking with a token budget
|
|
24
|
+
--tool <json|@file> Anthropic-shaped tool definition (repeatable)
|
|
25
|
+
--tool-choice <v> auto | any | <tool name>
|
|
20
26
|
--stream Stream tokens
|
|
21
27
|
--no-stream
|
|
22
28
|
--raw Print full JSON response
|
|
@@ -34,7 +40,12 @@ Options:
|
|
|
34
40
|
--temperature <n>
|
|
35
41
|
--top-p <n>
|
|
36
42
|
--seed <n>
|
|
37
|
-
--reasoning <effort> low
|
|
43
|
+
--reasoning <effort> none|minimal|low|medium|high|xhigh|max
|
|
44
|
+
--tool <json|@file> Tool definition (repeatable)
|
|
45
|
+
--tool-choice <v> auto | none | required | <tool name>
|
|
46
|
+
--include <csv> Extra output fields to include
|
|
47
|
+
--store Persist the response server-side
|
|
48
|
+
--previous-response-id <id> Continue a stored response
|
|
38
49
|
--stream Stream tokens (default when TTY)
|
|
39
50
|
--no-stream Disable streaming
|
|
40
51
|
--raw Print full JSON response
|
|
@@ -42,11 +53,11 @@ Options:
|
|
|
42
53
|
`;
|
|
43
54
|
|
|
44
55
|
async function resolvePrompt(values, positionals) {
|
|
45
|
-
if (!values.model) throw new Error(
|
|
46
|
-
let prompt = positionals.join(
|
|
56
|
+
if (!values.model) throw new Error("--model is required");
|
|
57
|
+
let prompt = positionals.join(" ").trim();
|
|
47
58
|
const piped = await readStdinIfPiped();
|
|
48
59
|
if (piped) prompt = prompt ? `${prompt}\n\n${piped}` : piped;
|
|
49
|
-
if (!prompt) throw new Error(
|
|
60
|
+
if (!prompt) throw new Error("No prompt.");
|
|
50
61
|
return prompt;
|
|
51
62
|
}
|
|
52
63
|
|
|
@@ -59,23 +70,29 @@ function applyNumeric(body, values, map) {
|
|
|
59
70
|
|
|
60
71
|
async function loadBody(value) {
|
|
61
72
|
if (!value) return null;
|
|
62
|
-
if (value.startsWith(
|
|
63
|
-
const { readFile } = await import(
|
|
64
|
-
return JSON.parse(await readFile(value.slice(1),
|
|
73
|
+
if (value.startsWith("@")) {
|
|
74
|
+
const { readFile } = await import("node:fs/promises");
|
|
75
|
+
return JSON.parse(await readFile(value.slice(1), "utf8"));
|
|
65
76
|
}
|
|
66
77
|
return JSON.parse(value);
|
|
67
78
|
}
|
|
68
79
|
|
|
69
80
|
export async function messagesCommand(argv) {
|
|
70
81
|
const { values, positionals } = parseArgs(argv, {
|
|
71
|
-
model: { type:
|
|
72
|
-
system: { type:
|
|
73
|
-
|
|
74
|
-
temperature: { type:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
82
|
+
model: { type: "string", short: "m" },
|
|
83
|
+
system: { type: "string", short: "s" },
|
|
84
|
+
"max-tokens": { type: "string" },
|
|
85
|
+
temperature: { type: "string" },
|
|
86
|
+
"top-p": { type: "string" },
|
|
87
|
+
"top-k": { type: "string" },
|
|
88
|
+
stop: { type: "string" },
|
|
89
|
+
"thinking-budget": { type: "string" },
|
|
90
|
+
tool: { type: "string", multiple: true },
|
|
91
|
+
"tool-choice": { type: "string" },
|
|
92
|
+
stream: { type: "boolean" },
|
|
93
|
+
"no-stream": { type: "boolean" },
|
|
94
|
+
raw: { type: "boolean" },
|
|
95
|
+
body: { type: "string" },
|
|
79
96
|
});
|
|
80
97
|
if (values.help) {
|
|
81
98
|
process.stdout.write(HELP);
|
|
@@ -87,58 +104,82 @@ export async function messagesCommand(argv) {
|
|
|
87
104
|
const prompt = await resolvePrompt(values, positionals);
|
|
88
105
|
body = {
|
|
89
106
|
model: values.model,
|
|
90
|
-
max_tokens: numberOption(values[
|
|
91
|
-
messages: [{ role:
|
|
107
|
+
max_tokens: numberOption(values["max-tokens"], "--max-tokens") ?? 1024,
|
|
108
|
+
messages: [{ role: "user", content: prompt }],
|
|
92
109
|
};
|
|
93
110
|
if (values.system) body.system = values.system;
|
|
94
|
-
applyNumeric(body, values, {
|
|
111
|
+
applyNumeric(body, values, {
|
|
112
|
+
temperature: "temperature",
|
|
113
|
+
"top-p": "top_p",
|
|
114
|
+
"top-k": "top_k",
|
|
115
|
+
});
|
|
116
|
+
if (values.stop) body.stop_sequences = values.stop.split(",");
|
|
117
|
+
const budget = numberOption(values["thinking-budget"], "--thinking-budget");
|
|
118
|
+
if (budget !== undefined) body.thinking = { type: "enabled", budget_tokens: budget };
|
|
119
|
+
if (values.tool && values.tool.length) {
|
|
120
|
+
body.tools = [];
|
|
121
|
+
for (const t of values.tool) body.tools.push(await loadBody(t));
|
|
122
|
+
}
|
|
123
|
+
if (values["tool-choice"]) {
|
|
124
|
+
const v = values["tool-choice"];
|
|
125
|
+
body.tool_choice = v === "auto" || v === "any" ? { type: v } : { type: "tool", name: v };
|
|
126
|
+
}
|
|
95
127
|
}
|
|
96
128
|
|
|
97
129
|
if (shouldStream(values)) {
|
|
98
130
|
body.stream = true;
|
|
99
|
-
const res = await api(
|
|
131
|
+
const res = await api("POST", "/messages", {
|
|
100
132
|
auth: authFromValues(values),
|
|
101
133
|
body,
|
|
102
134
|
raw: true,
|
|
103
|
-
headers: { Accept:
|
|
135
|
+
headers: { Accept: "text/event-stream" },
|
|
104
136
|
});
|
|
105
137
|
for await (const evt of sseStream(res)) {
|
|
106
138
|
assertNoStreamError(evt);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
out(
|
|
139
|
+
if (evt.type === "content_block_delta" && evt.delta) {
|
|
140
|
+
const d = evt.delta;
|
|
141
|
+
if (d.text) out(d.text);
|
|
142
|
+
// Extended-thinking and streamed tool-call args arrive as their own
|
|
143
|
+
// delta types; without these both were silently dropped.
|
|
144
|
+
else if (d.thinking && process.stdout.isTTY) out(c.dim(d.thinking));
|
|
145
|
+
else if (d.partial_json) out(d.partial_json);
|
|
110
146
|
}
|
|
111
147
|
}
|
|
112
|
-
if (process.stdout.isTTY) out(
|
|
148
|
+
if (process.stdout.isTTY) out("\n");
|
|
113
149
|
return 0;
|
|
114
150
|
}
|
|
115
151
|
|
|
116
|
-
const data = await api(
|
|
152
|
+
const data = await api("POST", "/messages", {
|
|
117
153
|
auth: authFromValues(values),
|
|
118
|
-
body
|
|
154
|
+
body,
|
|
119
155
|
});
|
|
120
156
|
if (isJsonMode() || values.raw) {
|
|
121
157
|
printJSON(data);
|
|
122
158
|
} else {
|
|
123
159
|
const blocks = data.content || [];
|
|
124
|
-
for (const b of blocks) if (b.type ===
|
|
160
|
+
for (const b of blocks) if (b.type === "text") outln(b.text);
|
|
125
161
|
}
|
|
126
162
|
return 0;
|
|
127
163
|
}
|
|
128
164
|
|
|
129
165
|
export async function responsesCommand(argv) {
|
|
130
166
|
const { values, positionals } = parseArgs(argv, {
|
|
131
|
-
model: { type:
|
|
132
|
-
instructions: { type:
|
|
133
|
-
|
|
134
|
-
temperature: { type:
|
|
135
|
-
|
|
136
|
-
seed: { type:
|
|
137
|
-
reasoning: { type:
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
167
|
+
model: { type: "string", short: "m" },
|
|
168
|
+
instructions: { type: "string", short: "s" },
|
|
169
|
+
"max-tokens": { type: "string" },
|
|
170
|
+
temperature: { type: "string" },
|
|
171
|
+
"top-p": { type: "string" },
|
|
172
|
+
seed: { type: "string" },
|
|
173
|
+
reasoning: { type: "string" },
|
|
174
|
+
tool: { type: "string", multiple: true },
|
|
175
|
+
"tool-choice": { type: "string" },
|
|
176
|
+
include: { type: "string" },
|
|
177
|
+
store: { type: "boolean" },
|
|
178
|
+
"previous-response-id": { type: "string" },
|
|
179
|
+
stream: { type: "boolean" },
|
|
180
|
+
"no-stream": { type: "boolean" },
|
|
181
|
+
raw: { type: "boolean" },
|
|
182
|
+
body: { type: "string" },
|
|
142
183
|
});
|
|
143
184
|
if (values.help) {
|
|
144
185
|
process.stdout.write(HELP_RESPONSES);
|
|
@@ -151,44 +192,67 @@ export async function responsesCommand(argv) {
|
|
|
151
192
|
body = { model: values.model, input: prompt };
|
|
152
193
|
if (values.instructions) body.instructions = values.instructions;
|
|
153
194
|
applyNumeric(body, values, {
|
|
154
|
-
|
|
155
|
-
temperature:
|
|
156
|
-
|
|
157
|
-
seed:
|
|
195
|
+
"max-tokens": "max_output_tokens",
|
|
196
|
+
temperature: "temperature",
|
|
197
|
+
"top-p": "top_p",
|
|
198
|
+
seed: "seed",
|
|
158
199
|
});
|
|
159
200
|
if (values.reasoning) body.reasoning = { effort: values.reasoning };
|
|
201
|
+
if (values.tool && values.tool.length) {
|
|
202
|
+
body.tools = [];
|
|
203
|
+
for (const t of values.tool) body.tools.push(await loadBody(t));
|
|
204
|
+
}
|
|
205
|
+
if (values["tool-choice"]) {
|
|
206
|
+
const v = values["tool-choice"];
|
|
207
|
+
if (["auto", "none", "required"].includes(v)) body.tool_choice = v;
|
|
208
|
+
else body.tool_choice = { type: "function", name: v };
|
|
209
|
+
}
|
|
210
|
+
if (values.include) body.include = values.include.split(",").map((s) => s.trim());
|
|
211
|
+
if (values.store) body.store = true;
|
|
212
|
+
if (values["previous-response-id"]) body.previous_response_id = values["previous-response-id"];
|
|
160
213
|
}
|
|
161
214
|
|
|
162
215
|
if (shouldStream(values)) {
|
|
163
216
|
body.stream = true;
|
|
164
|
-
const res = await api(
|
|
217
|
+
const res = await api("POST", "/responses", {
|
|
165
218
|
auth: authFromValues(values),
|
|
166
219
|
body,
|
|
167
220
|
raw: true,
|
|
168
|
-
headers: { Accept:
|
|
221
|
+
headers: { Accept: "text/event-stream" },
|
|
169
222
|
});
|
|
170
223
|
for await (const evt of sseStream(res)) {
|
|
171
224
|
assertNoStreamError(evt);
|
|
172
|
-
if (evt.type && evt.type.endsWith(
|
|
225
|
+
if (evt.type && evt.type.endsWith("output_text.delta") && evt.delta) {
|
|
173
226
|
out(evt.delta);
|
|
227
|
+
} else if (
|
|
228
|
+
evt.type &&
|
|
229
|
+
(evt.type.endsWith("reasoning_summary_text.delta") ||
|
|
230
|
+
evt.type.endsWith("reasoning_text.delta")) &&
|
|
231
|
+
evt.delta &&
|
|
232
|
+
process.stdout.isTTY
|
|
233
|
+
) {
|
|
234
|
+
out(c.dim(evt.delta));
|
|
174
235
|
}
|
|
175
236
|
}
|
|
176
|
-
if (process.stdout.isTTY) out(
|
|
237
|
+
if (process.stdout.isTTY) out("\n");
|
|
177
238
|
return 0;
|
|
178
239
|
}
|
|
179
240
|
|
|
180
|
-
const data = await api(
|
|
241
|
+
const data = await api("POST", "/responses", {
|
|
181
242
|
auth: authFromValues(values),
|
|
182
|
-
body
|
|
243
|
+
body,
|
|
183
244
|
});
|
|
184
245
|
if (isJsonMode() || values.raw) {
|
|
185
246
|
printJSON(data);
|
|
186
247
|
} else {
|
|
187
248
|
const text =
|
|
188
249
|
data.output_text ||
|
|
189
|
-
(data.output &&
|
|
190
|
-
|
|
191
|
-
|
|
250
|
+
(data.output &&
|
|
251
|
+
data.output
|
|
252
|
+
.flatMap?.((o) =>
|
|
253
|
+
(o.content || []).filter((c) => c.type === "output_text").map((c) => c.text),
|
|
254
|
+
)
|
|
255
|
+
.join("\n"));
|
|
192
256
|
outln(text || JSON.stringify(data));
|
|
193
257
|
}
|
|
194
258
|
return 0;
|
package/src/commands/misc.js
CHANGED
|
@@ -3,32 +3,32 @@ import {
|
|
|
3
3
|
authFromValues,
|
|
4
4
|
numberOption,
|
|
5
5
|
PAGINATION_OPTIONS,
|
|
6
|
-
paginationQuery
|
|
7
|
-
} from
|
|
8
|
-
import { api } from
|
|
9
|
-
import { printResult, table } from
|
|
6
|
+
paginationQuery,
|
|
7
|
+
} from "../args.js";
|
|
8
|
+
import { api } from "../api.js";
|
|
9
|
+
import { printResult, table } from "../output.js";
|
|
10
10
|
|
|
11
11
|
async function orgMembersCommand(argv) {
|
|
12
12
|
const { values } = parseArgs(argv, PAGINATION_OPTIONS);
|
|
13
13
|
if (values.help) {
|
|
14
14
|
process.stdout.write(
|
|
15
|
-
|
|
15
|
+
"Usage: openrouter org members [--offset N] [--limit N]\n\nList organization members. Requires a management key.\n",
|
|
16
16
|
);
|
|
17
17
|
return 0;
|
|
18
18
|
}
|
|
19
19
|
const query = paginationQuery(values);
|
|
20
|
-
const data = await api(
|
|
20
|
+
const data = await api("GET", "/organization/members", {
|
|
21
21
|
auth: authFromValues(values),
|
|
22
22
|
requiresManagement: true,
|
|
23
|
-
query
|
|
23
|
+
query,
|
|
24
24
|
});
|
|
25
25
|
printResult(data, () => {
|
|
26
26
|
const rows = data.data || [];
|
|
27
27
|
table(rows, [
|
|
28
|
-
{ label:
|
|
29
|
-
{ label:
|
|
30
|
-
{ label:
|
|
31
|
-
{ label:
|
|
28
|
+
{ label: "user_id", value: (m) => m.user_id || m.id || "" },
|
|
29
|
+
{ label: "email", value: (m) => m.email || "" },
|
|
30
|
+
{ label: "role", value: (m) => m.role || "" },
|
|
31
|
+
{ label: "name", value: (m) => m.name || "" },
|
|
32
32
|
]);
|
|
33
33
|
});
|
|
34
34
|
return 0;
|
|
@@ -37,10 +37,10 @@ async function orgMembersCommand(argv) {
|
|
|
37
37
|
export async function orgCommand(argv) {
|
|
38
38
|
const sub = argv[0];
|
|
39
39
|
const rest = argv.slice(1);
|
|
40
|
-
if (sub ===
|
|
41
|
-
if (!sub || sub ===
|
|
40
|
+
if (sub === "members") return orgMembersCommand(rest);
|
|
41
|
+
if (!sub || sub === "-h" || sub === "--help" || sub === "help") {
|
|
42
42
|
process.stdout.write(
|
|
43
|
-
|
|
43
|
+
"Usage: openrouter org <subcommand>\n\nSubcommands:\n members List organization members (management key)\n",
|
|
44
44
|
);
|
|
45
45
|
return sub ? 0 : 1;
|
|
46
46
|
}
|
|
@@ -51,12 +51,12 @@ export async function zdrCommand(argv) {
|
|
|
51
51
|
const { values } = parseArgs(argv, {});
|
|
52
52
|
if (values.help) {
|
|
53
53
|
process.stdout.write(
|
|
54
|
-
|
|
54
|
+
"Usage: openrouter zdr\n\nPreview the impact of Zero Data Retention on the available endpoints.\n",
|
|
55
55
|
);
|
|
56
56
|
return 0;
|
|
57
57
|
}
|
|
58
|
-
const data = await api(
|
|
59
|
-
auth: authFromValues(values)
|
|
58
|
+
const data = await api("GET", "/endpoints/zdr", {
|
|
59
|
+
auth: authFromValues(values),
|
|
60
60
|
});
|
|
61
61
|
printResult(data);
|
|
62
62
|
return 0;
|
|
@@ -64,41 +64,41 @@ export async function zdrCommand(argv) {
|
|
|
64
64
|
|
|
65
65
|
export async function authCodeCommand(argv) {
|
|
66
66
|
const { values } = parseArgs(argv, {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
limit: { type:
|
|
73
|
-
|
|
67
|
+
"callback-url": { type: "string" },
|
|
68
|
+
"code-challenge": { type: "string" },
|
|
69
|
+
"code-challenge-method": { type: "string" },
|
|
70
|
+
"expires-at": { type: "string" },
|
|
71
|
+
"key-label": { type: "string" },
|
|
72
|
+
limit: { type: "string" },
|
|
73
|
+
"usage-limit-type": { type: "string" },
|
|
74
74
|
});
|
|
75
|
-
if (values.help || !values[
|
|
75
|
+
if (values.help || !values["callback-url"]) {
|
|
76
76
|
process.stdout.write(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
77
|
+
"Usage: openrouter auth-code --callback-url <url> [options]\n\n" +
|
|
78
|
+
"Mint a PKCE authorization code so a user can claim a key for your app.\n" +
|
|
79
|
+
"Requires a management key.\n\n" +
|
|
80
|
+
"Options:\n" +
|
|
81
|
+
" --callback-url <url> HTTPS URL on port 443 or 3000 (required)\n" +
|
|
82
|
+
" --code-challenge <s> PKCE challenge\n" +
|
|
83
|
+
" --code-challenge-method <m> S256 | plain\n" +
|
|
84
|
+
" --expires-at <iso> Optional ISO 8601 UTC expiry\n" +
|
|
85
|
+
" --key-label <text> Custom label for the resulting key\n" +
|
|
86
|
+
" --limit <usd> Credit limit\n" +
|
|
87
|
+
" --usage-limit-type <p> daily | weekly | monthly\n",
|
|
88
88
|
);
|
|
89
89
|
return values.help ? 0 : 1;
|
|
90
90
|
}
|
|
91
|
-
const body = { callback_url: values[
|
|
92
|
-
if (values[
|
|
93
|
-
if (values[
|
|
94
|
-
if (values[
|
|
95
|
-
if (values[
|
|
96
|
-
if (values.limit) body.limit = numberOption(values.limit,
|
|
97
|
-
if (values[
|
|
98
|
-
const data = await api(
|
|
91
|
+
const body = { callback_url: values["callback-url"] };
|
|
92
|
+
if (values["code-challenge"]) body.code_challenge = values["code-challenge"];
|
|
93
|
+
if (values["code-challenge-method"]) body.code_challenge_method = values["code-challenge-method"];
|
|
94
|
+
if (values["expires-at"]) body.expires_at = values["expires-at"];
|
|
95
|
+
if (values["key-label"]) body.key_label = values["key-label"];
|
|
96
|
+
if (values.limit) body.limit = numberOption(values.limit, "--limit");
|
|
97
|
+
if (values["usage-limit-type"]) body.usage_limit_type = values["usage-limit-type"];
|
|
98
|
+
const data = await api("POST", "/auth/keys/code", {
|
|
99
99
|
auth: authFromValues(values),
|
|
100
100
|
requiresManagement: true,
|
|
101
|
-
body
|
|
101
|
+
body,
|
|
102
102
|
});
|
|
103
103
|
printResult(data);
|
|
104
104
|
return 0;
|