@aaronjmars/openroutercli 0.2.2 → 0.3.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 +12 -1
- package/SKILL.md +13 -3
- package/package.json +1 -1
- package/src/api.js +13 -4
- package/src/args.js +2 -0
- package/src/cli.js +47 -6
- package/src/commands/containers.js +75 -0
- package/src/commands/data.js +376 -0
- package/src/commands/decisions.js +74 -0
- package/src/commands/files.js +40 -5
- package/src/commands/messages.js +28 -0
- package/src/commands/models.js +78 -13
- package/src/config.js +3 -0
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
<p align="center">
|
|
20
20
|
<strong>Every OpenRouter endpoint, on the command line - for humans and LLM agents</strong><br>
|
|
21
|
-
Browser-based OAuth login,
|
|
21
|
+
Browser-based OAuth login, inference, discovery, analytics, benchmarks, public datasets, Decisions, container files, account management, and a raw <code>request</code> escape hatch. <code>--json</code> on every command. Zero npm dependencies.
|
|
22
22
|
</p>
|
|
23
23
|
|
|
24
24
|
---
|
|
@@ -78,6 +78,10 @@ and run `openrouter login --management`.
|
|
|
78
78
|
| **Multi-format inference** | `chat` (OpenAI), `messages` (Anthropic), `responses` (OpenAI Responses) - same auth, same flags, same JSON contract. |
|
|
79
79
|
| **Embeddings + rerank + TTS + video** | `embed`, `rerank`, `speech`, `video {create,wait,download}` - async video jobs poll-until-done with `video wait <jobId>`. |
|
|
80
80
|
| **Model discovery with detail** | `models list` (filter, sort by price/context), `models show <id>` (full pricing breakdown - prompt, completion, cache r/w, reasoning, image, web search), `models endpoints <id> --sort throughput\|latency\|prompt\|completion\|uptime --best` for choosing the right provider variant. |
|
|
81
|
+
| **Benchmarks + rankings** | `benchmarks`, `classifications`, and `datasets {apps,daily,session-cost}` expose OpenRouter's current public benchmark and usage datasets. |
|
|
82
|
+
| **Management analytics** | `analytics meta` discovers fields; `analytics query` runs metrics/dimensions/time-range queries with a management key. |
|
|
83
|
+
| **Structured decisions** | `decisions` calls the alpha Decisions API for typed choice, score, and yes/no outputs. |
|
|
84
|
+
| **Hosted shell files** | `containers {list,get,download,promote}` retrieves and promotes files produced by OpenRouter's hosted shell tools. |
|
|
81
85
|
| **Spend + activity + generations** | `credits` for balance, `whoami` for daily/weekly/monthly usage + rate limit, `keys get <hash>` for per-key spend, `activity --api-key-hash <hash>` for daily aggregates, `generation <id> [--content]` for full per-request metadata + input/output. |
|
|
82
86
|
| **Account + governance** | `keys`, `guardrails` (allow/deny lists, USD limits, ZDR), `workspaces` (defaults + members), `org members`, `auth-code` to mint claim links. All require a management key. |
|
|
83
87
|
| **Raw escape hatch** | `openrouter request <METHOD> <path> --body @file.json --query k=v --header k:v` - talk to any current or future endpoint without waiting for a CLI release. |
|
|
@@ -163,6 +167,10 @@ Endpoint coverage map:
|
|
|
163
167
|
| `GET /key` | `openrouter whoami` |
|
|
164
168
|
| `GET /credits` | `openrouter credits` |
|
|
165
169
|
| `GET /activity` | `openrouter activity` |
|
|
170
|
+
| `GET /analytics/meta` / `POST /analytics/query` | `openrouter analytics {meta,query}` |
|
|
171
|
+
| `GET /benchmarks` | `openrouter benchmarks` |
|
|
172
|
+
| `GET /classifications/task` | `openrouter classifications` |
|
|
173
|
+
| `GET /datasets/app-rankings` / `GET /datasets/rankings-daily` / `GET /datasets/session-cost` | `openrouter datasets {apps,daily,session-cost}` |
|
|
166
174
|
| `GET /models` | `openrouter models list` |
|
|
167
175
|
| `GET /models/count` | `openrouter models count` |
|
|
168
176
|
| `GET /models/user` | `openrouter models user` |
|
|
@@ -180,6 +188,8 @@ Endpoint coverage map:
|
|
|
180
188
|
| `GET/POST/PATCH/DELETE /keys[/{hash}]` | `openrouter keys {list,get,create,update,delete}` |
|
|
181
189
|
| `GET/POST/PATCH/DELETE /guardrails[/{id}]` + assignments | `openrouter guardrails ...` |
|
|
182
190
|
| `GET/POST/PATCH/DELETE /workspaces[/{id}]` + members | `openrouter workspaces ...` |
|
|
191
|
+
| `POST /api/alpha/decisions` | `openrouter decisions` |
|
|
192
|
+
| `GET /containers/{id}/files[/{file}]` + content/promote | `openrouter containers ...` |
|
|
183
193
|
| `GET /organization/members` | `openrouter org members` |
|
|
184
194
|
| anything else | `openrouter request <METHOD> <path>` |
|
|
185
195
|
|
|
@@ -191,6 +201,7 @@ Endpoint coverage map:
|
|
|
191
201
|
| `--base-url <url>` | `OPENROUTER_BASE_URL` | API base (default `https://openrouter.ai/api/v1`) |
|
|
192
202
|
| `--referer <url>` | `OPENROUTER_REFERER` | `HTTP-Referer` header (your app URL) |
|
|
193
203
|
| `--title <name>` | `OPENROUTER_TITLE` | `X-Title` header (your app name; appears on openrouter.ai) |
|
|
204
|
+
| `--categories <csv>` | `OPENROUTER_CATEGORIES` | `X-OpenRouter-Categories` attribution header |
|
|
194
205
|
| `--json` | - | JSON output, no streaming, no color |
|
|
195
206
|
| `-q, --quiet` | - | Suppress informational stderr |
|
|
196
207
|
| `-V, --version` | - | Print the version |
|
package/SKILL.md
CHANGED
|
@@ -24,6 +24,9 @@ TRIGGER when the user asks to:
|
|
|
24
24
|
- create / list / disable / delete OpenRouter API keys programmatically
|
|
25
25
|
- manage BYOK provider integrations, guardrails, workspaces, files, presets, or
|
|
26
26
|
organization members
|
|
27
|
+
- inspect benchmarks, task classifications, and public usage datasets
|
|
28
|
+
- query management analytics
|
|
29
|
+
- submit structured Decisions requests or retrieve hosted-container files
|
|
27
30
|
- log in to OpenRouter from a fresh machine (OAuth PKCE in the browser)
|
|
28
31
|
|
|
29
32
|
SKIP when the user is already using the OpenAI / Anthropic / Cohere SDKs
|
|
@@ -76,8 +79,8 @@ command automatically.
|
|
|
76
79
|
|
|
77
80
|
| Slot | Used by | How to obtain |
|
|
78
81
|
| --- | --- | --- |
|
|
79
|
-
| **User key** | `chat`, `messages`, `responses`, `embed`, `rerank`, `speech`, `transcribe`, `image`, `video`, `files`, `presets`, `generation`, `credits`, `whoami` | OAuth (`openrouter login`) or paste from dashboard |
|
|
80
|
-
| **Management key** | `keys`, `byok`, `guardrails`, `workspaces`, `activity`, `org members`, `auth-code` | Dashboard only - <https://openrouter.ai/settings/provisioning-keys>. Cannot be obtained via OAuth. Save with `openrouter login --management`. |
|
|
82
|
+
| **User key** | `chat`, `messages`, `responses`, `embed`, `rerank`, `speech`, `transcribe`, `image`, `video`, `files`, `presets`, `generation`, `credits`, `whoami`, `benchmarks`, `classifications`, `datasets`, `decisions`, `containers` | OAuth (`openrouter login`) or paste from dashboard |
|
|
83
|
+
| **Management key** | `keys`, `byok`, `guardrails`, `workspaces`, `activity`, `analytics`, `org members`, `auth-code` | Dashboard only - <https://openrouter.ai/settings/provisioning-keys>. Cannot be obtained via OAuth. Save with `openrouter login --management`. |
|
|
81
84
|
|
|
82
85
|
You can store both - they live side by side in the config file. `--key sk-or-...`
|
|
83
86
|
always wins over both. Inference commands prefer the user key; management
|
|
@@ -203,6 +206,12 @@ openrouter models parameters openai/gpt-4o --provider openai
|
|
|
203
206
|
openrouter models endpoints anthropic/claude-sonnet-4.5 --sort throughput --best
|
|
204
207
|
openrouter models endpoints openai/gpt-4o-mini --sort latency
|
|
205
208
|
openrouter models endpoints openai/gpt-4o-mini --sort prompt
|
|
209
|
+
openrouter benchmarks --task-type coding --max-results 20
|
|
210
|
+
openrouter classifications --window 7d
|
|
211
|
+
openrouter datasets daily --period week --category programming
|
|
212
|
+
openrouter analytics meta
|
|
213
|
+
openrouter decisions --model typesafe/jev-1.13 --state '...' --questions @questions.json
|
|
214
|
+
openrouter containers list <container-id>
|
|
206
215
|
|
|
207
216
|
# Supporting metadata
|
|
208
217
|
openrouter providers # all providers
|
|
@@ -384,7 +393,8 @@ openrouter --json keys get <hash> | jq '.data | {usage, usage_daily, limit_remai
|
|
|
384
393
|
| `-k, --key` | `OPENROUTER_API_KEY` (alias `OPENROUTER_KEY`) / `OPENROUTER_MANAGEMENT_KEY` | from config |
|
|
385
394
|
| `--base-url` | `OPENROUTER_BASE_URL` | `https://openrouter.ai/api/v1` |
|
|
386
395
|
| `--referer` | `OPENROUTER_REFERER` | `https://github.com/aaronjmars/openroutercli` |
|
|
387
|
-
| `--title` | `OPENROUTER_TITLE` | `
|
|
396
|
+
| `--title` | `OPENROUTER_TITLE` | `X-OpenRouter-Title` app display name |
|
|
397
|
+
| `--categories` | `OPENROUTER_CATEGORIES` | `X-OpenRouter-Categories` attribution |
|
|
388
398
|
| `--json` | - | off |
|
|
389
399
|
| `-q, --quiet` | - | off |
|
|
390
400
|
| `-V, --version` | - | prints version, exits |
|
package/package.json
CHANGED
package/src/api.js
CHANGED
|
@@ -10,12 +10,14 @@ export class APIError extends Error {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
function buildHeaders({ apiKey, referer, title, extra }) {
|
|
13
|
+
function buildHeaders({ apiKey, referer, title, categories, extra }) {
|
|
14
14
|
const headers = {
|
|
15
15
|
Accept: "application/json",
|
|
16
16
|
"HTTP-Referer": referer,
|
|
17
17
|
"X-Title": title,
|
|
18
|
+
"X-OpenRouter-Title": title,
|
|
18
19
|
};
|
|
20
|
+
if (categories) headers["X-OpenRouter-Categories"] = categories;
|
|
19
21
|
if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
|
|
20
22
|
return { ...headers, ...(extra || {}) };
|
|
21
23
|
}
|
|
@@ -25,6 +27,11 @@ function joinUrl(base, path) {
|
|
|
25
27
|
return base.replace(/\/$/, "") + (path.startsWith("/") ? path : "/" + path);
|
|
26
28
|
}
|
|
27
29
|
|
|
30
|
+
function joinOriginPath(base, rootPath, path) {
|
|
31
|
+
const origin = new URL(base).origin;
|
|
32
|
+
return joinUrl(origin + rootPath, path);
|
|
33
|
+
}
|
|
34
|
+
|
|
28
35
|
async function parseError(res) {
|
|
29
36
|
const text = await res.text();
|
|
30
37
|
let body = text;
|
|
@@ -53,13 +60,15 @@ export async function api(method, path, opts = {}) {
|
|
|
53
60
|
throw e;
|
|
54
61
|
}
|
|
55
62
|
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
63
|
+
const requestUrl = opts.rootPath
|
|
64
|
+
? joinOriginPath(auth.baseUrl, opts.rootPath, path)
|
|
65
|
+
: joinUrl(auth.baseUrl, path);
|
|
66
|
+
const url = requestUrl + (opts.query ? "?" + new URLSearchParams(opts.query).toString() : "");
|
|
59
67
|
const headers = buildHeaders({
|
|
60
68
|
apiKey: auth.apiKey,
|
|
61
69
|
referer: auth.referer,
|
|
62
70
|
title: auth.title,
|
|
71
|
+
categories: auth.categories,
|
|
63
72
|
extra: opts.headers,
|
|
64
73
|
});
|
|
65
74
|
|
package/src/args.js
CHANGED
|
@@ -7,6 +7,7 @@ const GLOBAL_OPTIONS = {
|
|
|
7
7
|
"base-url": { type: "string" },
|
|
8
8
|
referer: { type: "string" },
|
|
9
9
|
title: { type: "string" },
|
|
10
|
+
categories: { type: "string" },
|
|
10
11
|
json: { type: "boolean" },
|
|
11
12
|
quiet: { type: "boolean", short: "q" },
|
|
12
13
|
help: { type: "boolean", short: "h" },
|
|
@@ -52,6 +53,7 @@ export function authFromValues(values) {
|
|
|
52
53
|
if (values["base-url"]) out.baseUrl = values["base-url"];
|
|
53
54
|
if (values.referer) out.referer = values.referer;
|
|
54
55
|
if (values.title) out.title = values.title;
|
|
56
|
+
if (values.categories) out.categories = values.categories;
|
|
55
57
|
return out;
|
|
56
58
|
}
|
|
57
59
|
|
package/src/cli.js
CHANGED
|
@@ -19,6 +19,14 @@ import { requestCommand } from "./commands/request.js";
|
|
|
19
19
|
import { guardrailsCommand } from "./commands/guardrails.js";
|
|
20
20
|
import { workspacesCommand } from "./commands/workspaces.js";
|
|
21
21
|
import { orgCommand, zdrCommand, authCodeCommand } from "./commands/misc.js";
|
|
22
|
+
import {
|
|
23
|
+
analyticsCommand,
|
|
24
|
+
benchmarksCommand,
|
|
25
|
+
classificationsCommand,
|
|
26
|
+
datasetsCommand,
|
|
27
|
+
} from "./commands/data.js";
|
|
28
|
+
import { decisionsCommand } from "./commands/decisions.js";
|
|
29
|
+
import { containersCommand } from "./commands/containers.js";
|
|
22
30
|
import { DEFAULT_BASE_URL } from "./config.js";
|
|
23
31
|
import { readFileSync } from "node:fs";
|
|
24
32
|
import { fileURLToPath } from "node:url";
|
|
@@ -58,6 +66,13 @@ const COMMANDS = {
|
|
|
58
66
|
org: orgCommand,
|
|
59
67
|
zdr: zdrCommand,
|
|
60
68
|
"auth-code": authCodeCommand,
|
|
69
|
+
analytics: analyticsCommand,
|
|
70
|
+
benchmarks: benchmarksCommand,
|
|
71
|
+
classifications: classificationsCommand,
|
|
72
|
+
datasets: datasetsCommand,
|
|
73
|
+
decisions: decisionsCommand,
|
|
74
|
+
decision: decisionsCommand,
|
|
75
|
+
containers: containersCommand,
|
|
61
76
|
request: requestCommand,
|
|
62
77
|
};
|
|
63
78
|
|
|
@@ -97,6 +112,12 @@ Discovery:
|
|
|
97
112
|
generation <id> [--content] Generation metadata or content
|
|
98
113
|
credits Remaining credits
|
|
99
114
|
activity Usage activity (management key)
|
|
115
|
+
benchmarks [options] Unified benchmark rankings
|
|
116
|
+
classifications [options] Task classification market share
|
|
117
|
+
datasets <sub> Public usage datasets
|
|
118
|
+
decisions Structured Decisions API (alpha)
|
|
119
|
+
containers <sub> Hosted shell output files
|
|
120
|
+
files <sub> Workspace files
|
|
100
121
|
zdr Preview Zero-Data-Retention impact
|
|
101
122
|
|
|
102
123
|
Management (require a management key):
|
|
@@ -104,7 +125,7 @@ Management (require a management key):
|
|
|
104
125
|
byok <sub> list / get / create / update / delete (provider integrations)
|
|
105
126
|
guardrails <sub> list / get / create / update / delete / assignments
|
|
106
127
|
workspaces <sub> list / get / create / update / delete / add-members / remove-members
|
|
107
|
-
|
|
128
|
+
analytics <sub> meta / query (management key)
|
|
108
129
|
org members List organization members
|
|
109
130
|
auth-code Mint a PKCE authorization code so a user can claim a key
|
|
110
131
|
request <METHOD> <path> Raw authenticated request to any endpoint
|
|
@@ -114,6 +135,7 @@ Global options (work with all commands):
|
|
|
114
135
|
--base-url <url> Override API base URL (default: ${DEFAULT_BASE_URL})
|
|
115
136
|
--referer <url> HTTP-Referer header (set as your app's URL)
|
|
116
137
|
--title <name> X-Title header (your app name; appears on openrouter.ai)
|
|
138
|
+
--categories <csv> X-OpenRouter-Categories attribution (e.g. cli-agent)
|
|
117
139
|
--json Output JSON (also disables streaming, color, and prompts)
|
|
118
140
|
-q, --quiet Suppress informational stderr messages
|
|
119
141
|
-V, --version Print the version
|
|
@@ -124,7 +146,8 @@ Environment:
|
|
|
124
146
|
OPENROUTER_MANAGEMENT_KEY Default management/provisioning key
|
|
125
147
|
OPENROUTER_BASE_URL Default base URL
|
|
126
148
|
OPENROUTER_REFERER Default HTTP-Referer
|
|
127
|
-
OPENROUTER_TITLE Default X-Title
|
|
149
|
+
OPENROUTER_TITLE Default X-Title / X-OpenRouter-Title
|
|
150
|
+
OPENROUTER_CATEGORIES Default X-OpenRouter-Categories
|
|
128
151
|
NO_COLOR Disable ANSI colors (alias: OPENROUTER_NO_COLOR)
|
|
129
152
|
OPENROUTER_DEBUG=1 Print stack traces on error
|
|
130
153
|
|
|
@@ -140,9 +163,18 @@ Version: ${VERSION}
|
|
|
140
163
|
`;
|
|
141
164
|
|
|
142
165
|
function preParseGlobals(argv) {
|
|
143
|
-
//
|
|
144
|
-
//
|
|
166
|
+
// Global flags work in any position. Value-taking globals are moved after
|
|
167
|
+
// the command so `openrouter --key ... chat ...` still dispatches correctly.
|
|
145
168
|
const out = [];
|
|
169
|
+
const globalTail = [];
|
|
170
|
+
const valueGlobals = new Set([
|
|
171
|
+
"--key",
|
|
172
|
+
"-k",
|
|
173
|
+
"--base-url",
|
|
174
|
+
"--referer",
|
|
175
|
+
"--title",
|
|
176
|
+
"--categories",
|
|
177
|
+
]);
|
|
146
178
|
let json = false;
|
|
147
179
|
let quiet = false;
|
|
148
180
|
let help = false;
|
|
@@ -152,12 +184,21 @@ function preParseGlobals(argv) {
|
|
|
152
184
|
if (a === "--json") json = true;
|
|
153
185
|
else if (a === "-q" || a === "--quiet") quiet = true;
|
|
154
186
|
else if (a === "-V" || a === "--version") version = true;
|
|
155
|
-
else if (a
|
|
187
|
+
else if (valueGlobals.has(a)) {
|
|
188
|
+
globalTail.push(a);
|
|
189
|
+
if (i + 1 < argv.length) globalTail.push(argv[++i]);
|
|
190
|
+
} else if (
|
|
191
|
+
["--key", "--base-url", "--referer", "--title", "--categories"].some((flag) =>
|
|
192
|
+
a.startsWith(`${flag}=`),
|
|
193
|
+
)
|
|
194
|
+
) {
|
|
195
|
+
globalTail.push(a);
|
|
196
|
+
} else if (a === "-h" || a === "--help") {
|
|
156
197
|
help = true;
|
|
157
198
|
out.push(a); // forward so subcommand help can also pick it up
|
|
158
199
|
} else out.push(a);
|
|
159
200
|
}
|
|
160
|
-
return { argv: out, json, quiet, help, version };
|
|
201
|
+
return { argv: [...out, ...globalTail], json, quiet, help, version };
|
|
161
202
|
}
|
|
162
203
|
|
|
163
204
|
export async function run(argv) {
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { parseArgs, authFromValues, numberOption } from "../args.js";
|
|
2
|
+
import { api } from "../api.js";
|
|
3
|
+
import { printResult, writeBinaryOutput } from "../output.js";
|
|
4
|
+
|
|
5
|
+
const HELP = `Usage: openrouter containers <subcommand> [options]
|
|
6
|
+
|
|
7
|
+
Inspect files produced by OpenRouter's hosted shell/batch tools.
|
|
8
|
+
|
|
9
|
+
Subcommands:
|
|
10
|
+
list <container-id> [--limit <n>] [--after <file-id>]
|
|
11
|
+
get <container-id> <file-id>
|
|
12
|
+
download <container-id> <file-id> [-o file]
|
|
13
|
+
promote <container-id> <file-id> Promote into workspace Files
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
function ids(positionals) {
|
|
17
|
+
if (positionals.length < 2) throw new Error("container-id and file-id required");
|
|
18
|
+
return positionals.slice(0, 2).map(encodeURIComponent);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function containersCommand(argv) {
|
|
22
|
+
const sub = argv[0];
|
|
23
|
+
const rest = argv.slice(1);
|
|
24
|
+
if (!sub || sub === "help" || sub === "-h" || sub === "--help") {
|
|
25
|
+
process.stdout.write(HELP);
|
|
26
|
+
return sub ? 0 : 1;
|
|
27
|
+
}
|
|
28
|
+
if (rest.includes("-h") || rest.includes("--help")) {
|
|
29
|
+
process.stdout.write(HELP);
|
|
30
|
+
return 0;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (sub === "list") {
|
|
34
|
+
const { values, positionals } = parseArgs(rest, {
|
|
35
|
+
limit: { type: "string" },
|
|
36
|
+
after: { type: "string" },
|
|
37
|
+
});
|
|
38
|
+
if (!positionals[0]) throw new Error("container-id required");
|
|
39
|
+
const query = {};
|
|
40
|
+
if (values.limit !== undefined) query.limit = numberOption(values.limit, "--limit");
|
|
41
|
+
if (values.after) query.after = values.after;
|
|
42
|
+
const data = await api("GET", `/containers/${encodeURIComponent(positionals[0])}/files`, {
|
|
43
|
+
auth: authFromValues(values),
|
|
44
|
+
query,
|
|
45
|
+
});
|
|
46
|
+
printResult(data);
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (sub === "get" || sub === "download" || sub === "promote") {
|
|
51
|
+
const { values, positionals } = parseArgs(rest, {
|
|
52
|
+
out: { type: "string", short: "o" },
|
|
53
|
+
});
|
|
54
|
+
const [containerId, fileId] = ids(positionals);
|
|
55
|
+
const path = `/containers/${containerId}/files/${fileId}`;
|
|
56
|
+
if (sub === "get") {
|
|
57
|
+
const data = await api("GET", path, { auth: authFromValues(values) });
|
|
58
|
+
printResult(data);
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
if (sub === "promote") {
|
|
62
|
+
const data = await api("POST", `${path}/promote`, { auth: authFromValues(values) });
|
|
63
|
+
printResult(data);
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
const bytes = await api("GET", `${path}/content`, {
|
|
67
|
+
auth: authFromValues(values),
|
|
68
|
+
binary: true,
|
|
69
|
+
});
|
|
70
|
+
await writeBinaryOutput(bytes, values.out || positionals[1]);
|
|
71
|
+
return 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
throw new Error(`Unknown containers subcommand: ${sub}`);
|
|
75
|
+
}
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import { parseArgs, authFromValues, numberOption } from "../args.js";
|
|
2
|
+
import { api } from "../api.js";
|
|
3
|
+
import { outln, printResult, table } from "../output.js";
|
|
4
|
+
|
|
5
|
+
async function loadJson(value, flag) {
|
|
6
|
+
if (value == null) return undefined;
|
|
7
|
+
const text = value.startsWith("@")
|
|
8
|
+
? await (async () => {
|
|
9
|
+
const { readFile } = await import("node:fs/promises");
|
|
10
|
+
return readFile(value.slice(1), "utf8");
|
|
11
|
+
})()
|
|
12
|
+
: value;
|
|
13
|
+
try {
|
|
14
|
+
return JSON.parse(text);
|
|
15
|
+
} catch (err) {
|
|
16
|
+
throw new Error(`Invalid JSON for ${flag}: ${err.message}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function add(query, key, value) {
|
|
21
|
+
if (value !== undefined) query[key] = value;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function addNumber(query, key, value, flag) {
|
|
25
|
+
if (value !== undefined) query[key] = numberOption(value, flag);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const BENCHMARK_HELP = `Usage: openrouter benchmarks [options]
|
|
29
|
+
|
|
30
|
+
List OpenRouter's unified benchmark data. Supports Artificial Analysis, Design
|
|
31
|
+
Arena, OpenRouter evaluations, and search benchmarks.
|
|
32
|
+
|
|
33
|
+
Options:
|
|
34
|
+
--source <name> artificial-analysis | design-arena
|
|
35
|
+
--task-type <type> coding | intelligence | agentic | search
|
|
36
|
+
--benchmark-type <type> Exact OpenRouter benchmark (e.g. search_widesearch)
|
|
37
|
+
--include-run-config Include published search benchmark run config
|
|
38
|
+
--search-engine <name> Filter search benchmarks by engine
|
|
39
|
+
--search-surface <name> server-tool | openai | anthropic
|
|
40
|
+
--arena <name> models | builders | agents
|
|
41
|
+
--category <name> Design Arena category
|
|
42
|
+
--max-results <n>
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
export async function benchmarksCommand(argv) {
|
|
46
|
+
const { values } = parseArgs(argv, {
|
|
47
|
+
source: { type: "string" },
|
|
48
|
+
"task-type": { type: "string" },
|
|
49
|
+
"benchmark-type": { type: "string" },
|
|
50
|
+
"include-run-config": { type: "boolean" },
|
|
51
|
+
"search-engine": { type: "string" },
|
|
52
|
+
"search-surface": { type: "string" },
|
|
53
|
+
arena: { type: "string" },
|
|
54
|
+
category: { type: "string" },
|
|
55
|
+
"max-results": { type: "string" },
|
|
56
|
+
});
|
|
57
|
+
if (values.help) {
|
|
58
|
+
process.stdout.write(BENCHMARK_HELP);
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
const query = {};
|
|
62
|
+
add(query, "source", values.source);
|
|
63
|
+
add(query, "task_type", values["task-type"]);
|
|
64
|
+
add(query, "benchmark_type", values["benchmark-type"]);
|
|
65
|
+
if (values["include-run-config"]) query.include_run_config = "true";
|
|
66
|
+
add(query, "search_engine", values["search-engine"]);
|
|
67
|
+
add(query, "search_surface", values["search-surface"]);
|
|
68
|
+
add(query, "arena", values.arena);
|
|
69
|
+
add(query, "category", values.category);
|
|
70
|
+
addNumber(query, "max_results", values["max-results"], "--max-results");
|
|
71
|
+
const data = await api("GET", "/benchmarks", {
|
|
72
|
+
auth: authFromValues(values),
|
|
73
|
+
query,
|
|
74
|
+
});
|
|
75
|
+
printResult(data, () => {
|
|
76
|
+
const rows = data.data || [];
|
|
77
|
+
table(rows, [
|
|
78
|
+
{ label: "model", value: (r) => r.display_name || r.model_permaslug || r.model || "" },
|
|
79
|
+
{ label: "source", value: (r) => r.source || "" },
|
|
80
|
+
{
|
|
81
|
+
label: "score",
|
|
82
|
+
value: (r) =>
|
|
83
|
+
r.primary_score ??
|
|
84
|
+
r.intelligence_index ??
|
|
85
|
+
r.coding_index ??
|
|
86
|
+
r.agentic_index ??
|
|
87
|
+
r.elo ??
|
|
88
|
+
"",
|
|
89
|
+
},
|
|
90
|
+
{ label: "benchmark", value: (r) => r.benchmark_type || r.category || "" },
|
|
91
|
+
]);
|
|
92
|
+
});
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const CLASSIFICATIONS_HELP = `Usage: openrouter classifications [options]
|
|
97
|
+
|
|
98
|
+
Show task-classification market share over the trailing window.
|
|
99
|
+
|
|
100
|
+
Options:
|
|
101
|
+
--window <window> Currently only 7d (default: 7d)
|
|
102
|
+
`;
|
|
103
|
+
|
|
104
|
+
export async function classificationsCommand(argv) {
|
|
105
|
+
const { values } = parseArgs(argv, { window: { type: "string" } });
|
|
106
|
+
if (values.help) {
|
|
107
|
+
process.stdout.write(CLASSIFICATIONS_HELP);
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
110
|
+
const query = {};
|
|
111
|
+
add(query, "window", values.window);
|
|
112
|
+
const data = await api("GET", "/classifications/task", {
|
|
113
|
+
auth: authFromValues(values),
|
|
114
|
+
query,
|
|
115
|
+
});
|
|
116
|
+
printResult(data, () => {
|
|
117
|
+
const rows = data.data?.classifications || [];
|
|
118
|
+
table(rows, [
|
|
119
|
+
{ label: "tag", value: (r) => r.tag || "" },
|
|
120
|
+
{ label: "category", value: (r) => r.display_name || "" },
|
|
121
|
+
{ label: "macro", value: (r) => r.macro_category || "" },
|
|
122
|
+
{ label: "usage", value: (r) => r.usage_share ?? "" },
|
|
123
|
+
{ label: "tokens", value: (r) => r.token_share ?? "" },
|
|
124
|
+
]);
|
|
125
|
+
});
|
|
126
|
+
return 0;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const DATASETS_HELP = `Usage: openrouter datasets <subcommand> [options]
|
|
130
|
+
|
|
131
|
+
Public OpenRouter usage datasets.
|
|
132
|
+
|
|
133
|
+
Subcommands:
|
|
134
|
+
apps [options] Top public apps by token usage
|
|
135
|
+
daily [options] Daily/weekly/monthly model rankings
|
|
136
|
+
session-cost [options] Cost per session by harness and model
|
|
137
|
+
|
|
138
|
+
apps options:
|
|
139
|
+
--category <name> --subcategory <name> --sort popular|trending
|
|
140
|
+
--start-date <date> --end-date <date> --limit <n> --offset <n>
|
|
141
|
+
|
|
142
|
+
daily options:
|
|
143
|
+
--start-date <date> --end-date <date> --period day|week|month
|
|
144
|
+
--modality <name> --context-bucket <bucket> --category <name>
|
|
145
|
+
--language-type natural|programming
|
|
146
|
+
|
|
147
|
+
session-cost options:
|
|
148
|
+
--app-slug <slug> --model <id> --turn-range <range> --limit <n> --offset <n>
|
|
149
|
+
`;
|
|
150
|
+
|
|
151
|
+
function printDataset(data, columns) {
|
|
152
|
+
printResult(data, () => table(data.data || [], columns));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export async function datasetsCommand(argv) {
|
|
156
|
+
const sub = argv[0] && !argv[0].startsWith("-") ? argv[0] : "apps";
|
|
157
|
+
const rest = sub === argv[0] ? argv.slice(1) : argv;
|
|
158
|
+
if (!argv.length || sub === "help" || sub === "-h" || sub === "--help") {
|
|
159
|
+
process.stdout.write(DATASETS_HELP);
|
|
160
|
+
return argv.length ? 0 : 1;
|
|
161
|
+
}
|
|
162
|
+
if (rest.includes("-h") || rest.includes("--help")) {
|
|
163
|
+
process.stdout.write(DATASETS_HELP);
|
|
164
|
+
return 0;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (sub === "apps" || sub === "app-rankings") {
|
|
168
|
+
const { values } = parseArgs(rest, {
|
|
169
|
+
category: { type: "string" },
|
|
170
|
+
subcategory: { type: "string" },
|
|
171
|
+
sort: { type: "string" },
|
|
172
|
+
"start-date": { type: "string" },
|
|
173
|
+
"end-date": { type: "string" },
|
|
174
|
+
limit: { type: "string" },
|
|
175
|
+
offset: { type: "string" },
|
|
176
|
+
});
|
|
177
|
+
const query = {};
|
|
178
|
+
add(query, "category", values.category);
|
|
179
|
+
add(query, "subcategory", values.subcategory);
|
|
180
|
+
add(query, "sort", values.sort);
|
|
181
|
+
add(query, "start_date", values["start-date"]);
|
|
182
|
+
add(query, "end_date", values["end-date"]);
|
|
183
|
+
addNumber(query, "limit", values.limit, "--limit");
|
|
184
|
+
addNumber(query, "offset", values.offset, "--offset");
|
|
185
|
+
const data = await api("GET", "/datasets/app-rankings", {
|
|
186
|
+
auth: authFromValues(values),
|
|
187
|
+
query,
|
|
188
|
+
});
|
|
189
|
+
printDataset(data, [
|
|
190
|
+
{ label: "rank", value: (r) => r.rank ?? "" },
|
|
191
|
+
{ label: "app", value: (r) => r.app_name || r.app_slug || "" },
|
|
192
|
+
{ label: "requests", value: (r) => r.total_requests ?? "" },
|
|
193
|
+
{ label: "tokens", value: (r) => r.total_tokens ?? "" },
|
|
194
|
+
]);
|
|
195
|
+
return 0;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (sub === "daily" || sub === "rankings" || sub === "rankings-daily") {
|
|
199
|
+
const { values } = parseArgs(rest, {
|
|
200
|
+
"start-date": { type: "string" },
|
|
201
|
+
"end-date": { type: "string" },
|
|
202
|
+
period: { type: "string" },
|
|
203
|
+
modality: { type: "string" },
|
|
204
|
+
"context-bucket": { type: "string" },
|
|
205
|
+
category: { type: "string" },
|
|
206
|
+
"language-type": { type: "string" },
|
|
207
|
+
});
|
|
208
|
+
const query = {};
|
|
209
|
+
add(query, "start_date", values["start-date"]);
|
|
210
|
+
add(query, "end_date", values["end-date"]);
|
|
211
|
+
add(query, "period", values.period);
|
|
212
|
+
add(query, "modality", values.modality);
|
|
213
|
+
add(query, "context_bucket", values["context-bucket"]);
|
|
214
|
+
add(query, "category", values.category);
|
|
215
|
+
add(query, "language_type", values["language-type"]);
|
|
216
|
+
const data = await api("GET", "/datasets/rankings-daily", {
|
|
217
|
+
auth: authFromValues(values),
|
|
218
|
+
query,
|
|
219
|
+
});
|
|
220
|
+
printDataset(data, [
|
|
221
|
+
{ label: "date", value: (r) => r.date || "" },
|
|
222
|
+
{ label: "model", value: (r) => r.model_permaslug || r.model || "" },
|
|
223
|
+
{ label: "tokens", value: (r) => r.total_tokens ?? "" },
|
|
224
|
+
]);
|
|
225
|
+
return 0;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (sub === "session-cost" || sub === "sessions") {
|
|
229
|
+
const { values } = parseArgs(rest, {
|
|
230
|
+
"app-slug": { type: "string" },
|
|
231
|
+
model: { type: "string" },
|
|
232
|
+
"turn-range": { type: "string" },
|
|
233
|
+
limit: { type: "string" },
|
|
234
|
+
offset: { type: "string" },
|
|
235
|
+
});
|
|
236
|
+
const query = {};
|
|
237
|
+
add(query, "app_slug", values["app-slug"]);
|
|
238
|
+
add(query, "model", values.model);
|
|
239
|
+
add(query, "turn_range", values["turn-range"]);
|
|
240
|
+
addNumber(query, "limit", values.limit, "--limit");
|
|
241
|
+
addNumber(query, "offset", values.offset, "--offset");
|
|
242
|
+
const data = await api("GET", "/datasets/session-cost", {
|
|
243
|
+
auth: authFromValues(values),
|
|
244
|
+
query,
|
|
245
|
+
});
|
|
246
|
+
printDataset(data, [
|
|
247
|
+
{ label: "app", value: (r) => r.app_name || r.app_slug || "" },
|
|
248
|
+
{ label: "model", value: (r) => r.model_permaslug || r.model || "" },
|
|
249
|
+
{ label: "turns", value: (r) => r.turn_range || r.turns || "" },
|
|
250
|
+
{
|
|
251
|
+
label: "median $/session",
|
|
252
|
+
value: (r) => r.median_session_cost_usd ?? r.cost ?? r.total_cost ?? "",
|
|
253
|
+
},
|
|
254
|
+
]);
|
|
255
|
+
return 0;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
throw new Error(`Unknown datasets subcommand: ${sub}`);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const ANALYTICS_HELP = `Usage: openrouter analytics <subcommand> [options]
|
|
262
|
+
|
|
263
|
+
Management-key analytics. Use the meta subcommand to discover valid metrics,
|
|
264
|
+
dimensions, operators, and granularities before querying.
|
|
265
|
+
|
|
266
|
+
Subcommands:
|
|
267
|
+
meta List available analytics fields
|
|
268
|
+
query [options] Run an analytics query
|
|
269
|
+
|
|
270
|
+
query options:
|
|
271
|
+
--metrics <name> Required; repeat or pass comma-separated values
|
|
272
|
+
--dimensions <name> Repeat or pass comma-separated values
|
|
273
|
+
--filter <json> Filter object; repeatable or use @file.json
|
|
274
|
+
--granularity <name> --group-limit <n> --limit <n>
|
|
275
|
+
--start <iso> --end <iso>
|
|
276
|
+
--order-by <json> --classifier-dimensions <json>
|
|
277
|
+
--classifier-filters <json> --body <json|@file>
|
|
278
|
+
`;
|
|
279
|
+
|
|
280
|
+
function splitValues(values) {
|
|
281
|
+
return (values || []).flatMap((v) =>
|
|
282
|
+
v
|
|
283
|
+
.split(",")
|
|
284
|
+
.map((x) => x.trim())
|
|
285
|
+
.filter(Boolean),
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export async function analyticsCommand(argv) {
|
|
290
|
+
const sub = argv[0] && !argv[0].startsWith("-") ? argv[0] : "meta";
|
|
291
|
+
const rest = sub === argv[0] ? argv.slice(1) : argv;
|
|
292
|
+
if (!argv.length || sub === "help" || sub === "-h" || sub === "--help") {
|
|
293
|
+
process.stdout.write(ANALYTICS_HELP);
|
|
294
|
+
return argv.length ? 0 : 1;
|
|
295
|
+
}
|
|
296
|
+
if (rest.includes("-h") || rest.includes("--help")) {
|
|
297
|
+
process.stdout.write(ANALYTICS_HELP);
|
|
298
|
+
return 0;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (sub === "meta") {
|
|
302
|
+
const { values } = parseArgs(rest, {});
|
|
303
|
+
const data = await api("GET", "/analytics/meta", {
|
|
304
|
+
auth: authFromValues(values),
|
|
305
|
+
requiresManagement: true,
|
|
306
|
+
});
|
|
307
|
+
printResult(data);
|
|
308
|
+
return 0;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (sub === "query") {
|
|
312
|
+
const { values } = parseArgs(rest, {
|
|
313
|
+
metrics: { type: "string", multiple: true },
|
|
314
|
+
dimensions: { type: "string", multiple: true },
|
|
315
|
+
filter: { type: "string", multiple: true },
|
|
316
|
+
granularity: { type: "string" },
|
|
317
|
+
"group-limit": { type: "string" },
|
|
318
|
+
limit: { type: "string" },
|
|
319
|
+
start: { type: "string" },
|
|
320
|
+
end: { type: "string" },
|
|
321
|
+
"order-by": { type: "string" },
|
|
322
|
+
"classifier-dimensions": { type: "string" },
|
|
323
|
+
"classifier-filters": { type: "string" },
|
|
324
|
+
body: { type: "string" },
|
|
325
|
+
});
|
|
326
|
+
let body = values.body ? await loadJson(values.body, "--body") : {};
|
|
327
|
+
if (!values.body) {
|
|
328
|
+
const metrics = splitValues(values.metrics);
|
|
329
|
+
if (!metrics.length) throw new Error("--metrics is required");
|
|
330
|
+
body.metrics = metrics;
|
|
331
|
+
const dimensions = splitValues(values.dimensions);
|
|
332
|
+
if (dimensions.length) body.dimensions = dimensions;
|
|
333
|
+
if (values.filter)
|
|
334
|
+
body.filters = await Promise.all(values.filter.map((v) => loadJson(v, "--filter")));
|
|
335
|
+
if (values.granularity) body.granularity = values.granularity;
|
|
336
|
+
addNumber(body, "group_limit", values["group-limit"], "--group-limit");
|
|
337
|
+
addNumber(body, "limit", values.limit, "--limit");
|
|
338
|
+
if (values.start || values.end) {
|
|
339
|
+
body.time_range = {};
|
|
340
|
+
add(body.time_range, "start", values.start);
|
|
341
|
+
add(body.time_range, "end", values.end);
|
|
342
|
+
}
|
|
343
|
+
if (values["order-by"]) body.order_by = await loadJson(values["order-by"], "--order-by");
|
|
344
|
+
if (values["classifier-dimensions"])
|
|
345
|
+
body.classifier_dimensions = await loadJson(
|
|
346
|
+
values["classifier-dimensions"],
|
|
347
|
+
"--classifier-dimensions",
|
|
348
|
+
);
|
|
349
|
+
if (values["classifier-filters"])
|
|
350
|
+
body.classifier_filters = await loadJson(
|
|
351
|
+
values["classifier-filters"],
|
|
352
|
+
"--classifier-filters",
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
if (!Array.isArray(body.metrics) || body.metrics.length === 0)
|
|
356
|
+
throw new Error("Analytics body must include a non-empty metrics array.");
|
|
357
|
+
const data = await api("POST", "/analytics/query", {
|
|
358
|
+
auth: authFromValues(values),
|
|
359
|
+
requiresManagement: true,
|
|
360
|
+
body,
|
|
361
|
+
});
|
|
362
|
+
printResult(data, () => {
|
|
363
|
+
const result = data.data || {};
|
|
364
|
+
const rows = result.data || [];
|
|
365
|
+
if (!rows.length) {
|
|
366
|
+
outln("(no rows)");
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
const columns = Object.keys(rows[0]).map((key) => ({ label: key, value: (row) => row[key] }));
|
|
370
|
+
table(rows, columns);
|
|
371
|
+
});
|
|
372
|
+
return 0;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
throw new Error(`Unknown analytics subcommand: ${sub}`);
|
|
376
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { parseArgs, authFromValues } from "../args.js";
|
|
2
|
+
import { api } from "../api.js";
|
|
3
|
+
import { printResult } from "../output.js";
|
|
4
|
+
|
|
5
|
+
const HELP = `Usage: openrouter decisions [options]
|
|
6
|
+
|
|
7
|
+
Submit a structured Decisions request (alpha). The API is designed for typed
|
|
8
|
+
choice, score, and yes/no decisions, such as routing or classification.
|
|
9
|
+
|
|
10
|
+
Options:
|
|
11
|
+
-m, --model <id> Decisions model id (required without --body)
|
|
12
|
+
--state <json|text> State to evaluate (required without --body)
|
|
13
|
+
--questions <json> Questions object or @questions.json
|
|
14
|
+
--body <json|@file> Fully-formed request body
|
|
15
|
+
--extra <json> Extra fields merged into the request
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
async function loadJson(value, flag) {
|
|
19
|
+
if (value == null) return undefined;
|
|
20
|
+
const text = value.startsWith("@")
|
|
21
|
+
? await (async () => {
|
|
22
|
+
const { readFile } = await import("node:fs/promises");
|
|
23
|
+
return readFile(value.slice(1), "utf8");
|
|
24
|
+
})()
|
|
25
|
+
: value;
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(text);
|
|
28
|
+
} catch (err) {
|
|
29
|
+
throw new Error(`Invalid JSON for ${flag}: ${err.message}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function loadState(value) {
|
|
34
|
+
if (value == null) return undefined;
|
|
35
|
+
if (value.startsWith("@")) return loadJson(value, "--state");
|
|
36
|
+
try {
|
|
37
|
+
return JSON.parse(value);
|
|
38
|
+
} catch {
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function decisionsCommand(argv) {
|
|
44
|
+
const { values } = parseArgs(argv, {
|
|
45
|
+
model: { type: "string", short: "m" },
|
|
46
|
+
state: { type: "string" },
|
|
47
|
+
questions: { type: "string" },
|
|
48
|
+
body: { type: "string" },
|
|
49
|
+
extra: { type: "string" },
|
|
50
|
+
});
|
|
51
|
+
if (values.help) {
|
|
52
|
+
process.stdout.write(HELP);
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
let body = values.body ? await loadJson(values.body, "--body") : null;
|
|
56
|
+
if (!body) {
|
|
57
|
+
if (!values.model) throw new Error("--model is required");
|
|
58
|
+
if (values.state === undefined) throw new Error("--state is required");
|
|
59
|
+
if (!values.questions) throw new Error("--questions is required");
|
|
60
|
+
body = {
|
|
61
|
+
model: values.model,
|
|
62
|
+
state: await loadState(values.state),
|
|
63
|
+
questions: await loadJson(values.questions, "--questions"),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (values.extra) Object.assign(body, await loadJson(values.extra, "--extra"));
|
|
67
|
+
const data = await api("POST", "/decisions", {
|
|
68
|
+
rootPath: "/api/alpha",
|
|
69
|
+
auth: authFromValues(values),
|
|
70
|
+
body,
|
|
71
|
+
});
|
|
72
|
+
printResult(data);
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
package/src/commands/files.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parseArgs, authFromValues } from "../args.js";
|
|
1
|
+
import { parseArgs, authFromValues, numberOption } from "../args.js";
|
|
2
2
|
import { api } from "../api.js";
|
|
3
3
|
import { outln, printResult, table, writeBinaryOutput } from "../output.js";
|
|
4
4
|
|
|
@@ -15,8 +15,22 @@ Subcommands:
|
|
|
15
15
|
|
|
16
16
|
upload options:
|
|
17
17
|
--purpose <p> Purpose tag for the file (e.g. assistants, user_data)
|
|
18
|
+
--workspace <id> Workspace UUID (defaults to the key's workspace)
|
|
19
|
+
--provider <slug> Store/read via a BYOK provider
|
|
18
20
|
`;
|
|
19
21
|
|
|
22
|
+
const FILE_SCOPE = {
|
|
23
|
+
workspace: { type: "string" },
|
|
24
|
+
provider: { type: "string" },
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function scopeQuery(values) {
|
|
28
|
+
const query = {};
|
|
29
|
+
if (values.workspace) query.workspace_id = values.workspace;
|
|
30
|
+
if (values.provider) query.provider = values.provider;
|
|
31
|
+
return Object.keys(query).length ? query : undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
20
34
|
export async function filesCommand(argv) {
|
|
21
35
|
const sub = argv[0];
|
|
22
36
|
const rest = argv.slice(1);
|
|
@@ -30,8 +44,23 @@ export async function filesCommand(argv) {
|
|
|
30
44
|
}
|
|
31
45
|
|
|
32
46
|
if (sub === "list") {
|
|
33
|
-
const { values } = parseArgs(rest, {
|
|
34
|
-
|
|
47
|
+
const { values } = parseArgs(rest, {
|
|
48
|
+
...FILE_SCOPE,
|
|
49
|
+
limit: { type: "string" },
|
|
50
|
+
cursor: { type: "string" },
|
|
51
|
+
after: { type: "string" },
|
|
52
|
+
"after-id": { type: "string" },
|
|
53
|
+
"before-id": { type: "string" },
|
|
54
|
+
order: { type: "string" },
|
|
55
|
+
});
|
|
56
|
+
const query = scopeQuery(values);
|
|
57
|
+
if (values.limit !== undefined) query.limit = numberOption(values.limit, "--limit");
|
|
58
|
+
if (values.cursor) query.cursor = values.cursor;
|
|
59
|
+
if (values.after) query.after = values.after;
|
|
60
|
+
if (values["after-id"]) query.after_id = values["after-id"];
|
|
61
|
+
if (values["before-id"]) query.before_id = values["before-id"];
|
|
62
|
+
if (values.order) query.order = values.order;
|
|
63
|
+
const data = await api("GET", "/files", { auth: authFromValues(values), query });
|
|
35
64
|
printResult(data, () => {
|
|
36
65
|
const rows = data.data || [];
|
|
37
66
|
table(rows, [
|
|
@@ -45,10 +74,11 @@ export async function filesCommand(argv) {
|
|
|
45
74
|
}
|
|
46
75
|
|
|
47
76
|
if (sub === "get") {
|
|
48
|
-
const { values, positionals } = parseArgs(rest,
|
|
77
|
+
const { values, positionals } = parseArgs(rest, FILE_SCOPE);
|
|
49
78
|
if (!positionals[0]) throw new Error("id required");
|
|
50
79
|
const data = await api("GET", `/files/${encodeURIComponent(positionals[0])}`, {
|
|
51
80
|
auth: authFromValues(values),
|
|
81
|
+
query: scopeQuery(values),
|
|
52
82
|
});
|
|
53
83
|
printResult(data);
|
|
54
84
|
return 0;
|
|
@@ -56,6 +86,7 @@ export async function filesCommand(argv) {
|
|
|
56
86
|
|
|
57
87
|
if (sub === "upload") {
|
|
58
88
|
const { values, positionals } = parseArgs(rest, {
|
|
89
|
+
...FILE_SCOPE,
|
|
59
90
|
purpose: { type: "string" },
|
|
60
91
|
});
|
|
61
92
|
const path = positionals[0];
|
|
@@ -69,6 +100,7 @@ export async function filesCommand(argv) {
|
|
|
69
100
|
const data = await api("POST", "/files", {
|
|
70
101
|
auth: authFromValues(values),
|
|
71
102
|
body: form,
|
|
103
|
+
query: scopeQuery(values),
|
|
72
104
|
});
|
|
73
105
|
printResult(data);
|
|
74
106
|
return 0;
|
|
@@ -76,12 +108,14 @@ export async function filesCommand(argv) {
|
|
|
76
108
|
|
|
77
109
|
if (sub === "download") {
|
|
78
110
|
const { values, positionals } = parseArgs(rest, {
|
|
111
|
+
...FILE_SCOPE,
|
|
79
112
|
out: { type: "string", short: "o" },
|
|
80
113
|
});
|
|
81
114
|
if (!positionals[0]) throw new Error("id required");
|
|
82
115
|
const bytes = await api("GET", `/files/${encodeURIComponent(positionals[0])}/content`, {
|
|
83
116
|
auth: authFromValues(values),
|
|
84
117
|
binary: true,
|
|
118
|
+
query: scopeQuery(values),
|
|
85
119
|
});
|
|
86
120
|
const out = values.out || positionals[0];
|
|
87
121
|
await writeBinaryOutput(bytes, out);
|
|
@@ -89,10 +123,11 @@ export async function filesCommand(argv) {
|
|
|
89
123
|
}
|
|
90
124
|
|
|
91
125
|
if (sub === "delete") {
|
|
92
|
-
const { values, positionals } = parseArgs(rest,
|
|
126
|
+
const { values, positionals } = parseArgs(rest, FILE_SCOPE);
|
|
93
127
|
if (!positionals[0]) throw new Error("id required");
|
|
94
128
|
const data = await api("DELETE", `/files/${encodeURIComponent(positionals[0])}`, {
|
|
95
129
|
auth: authFromValues(values),
|
|
130
|
+
query: scopeQuery(values),
|
|
96
131
|
});
|
|
97
132
|
printResult(data, () => outln("deleted"));
|
|
98
133
|
return 0;
|
package/src/commands/messages.js
CHANGED
|
@@ -37,15 +37,23 @@ Options:
|
|
|
37
37
|
-m, --model <id> Model id (required)
|
|
38
38
|
-s, --instructions <t> System / instructions
|
|
39
39
|
--max-tokens <n> Sent as max_output_tokens
|
|
40
|
+
--max-tool-calls <n>
|
|
40
41
|
--temperature <n>
|
|
41
42
|
--top-p <n>
|
|
42
43
|
--seed <n>
|
|
43
44
|
--reasoning <effort> none|minimal|low|medium|high|xhigh|max
|
|
45
|
+
--models <csv> Fallback models
|
|
46
|
+
--provider <json> Provider routing options
|
|
47
|
+
--plugins <json> Plugins array
|
|
48
|
+
--metadata <json> Metadata object
|
|
49
|
+
--parallel-tools Enable parallel tool calls
|
|
44
50
|
--tool <json|@file> Tool definition (repeatable)
|
|
45
51
|
--tool-choice <v> auto | none | required | <tool name>
|
|
46
52
|
--include <csv> Extra output fields to include
|
|
47
53
|
--store Persist the response server-side
|
|
48
54
|
--previous-response-id <id> Continue a stored response
|
|
55
|
+
--background Run as a background response
|
|
56
|
+
--extra <json|@file> Extra fields merged into the request body
|
|
49
57
|
--stream Stream tokens (default when TTY)
|
|
50
58
|
--no-stream Disable streaming
|
|
51
59
|
--raw Print full JSON response
|
|
@@ -167,15 +175,23 @@ export async function responsesCommand(argv) {
|
|
|
167
175
|
model: { type: "string", short: "m" },
|
|
168
176
|
instructions: { type: "string", short: "s" },
|
|
169
177
|
"max-tokens": { type: "string" },
|
|
178
|
+
"max-tool-calls": { type: "string" },
|
|
170
179
|
temperature: { type: "string" },
|
|
171
180
|
"top-p": { type: "string" },
|
|
172
181
|
seed: { type: "string" },
|
|
173
182
|
reasoning: { type: "string" },
|
|
183
|
+
models: { type: "string" },
|
|
184
|
+
provider: { type: "string" },
|
|
185
|
+
plugins: { type: "string" },
|
|
186
|
+
metadata: { type: "string" },
|
|
187
|
+
"parallel-tools": { type: "boolean" },
|
|
174
188
|
tool: { type: "string", multiple: true },
|
|
175
189
|
"tool-choice": { type: "string" },
|
|
176
190
|
include: { type: "string" },
|
|
177
191
|
store: { type: "boolean" },
|
|
178
192
|
"previous-response-id": { type: "string" },
|
|
193
|
+
background: { type: "boolean" },
|
|
194
|
+
extra: { type: "string" },
|
|
179
195
|
stream: { type: "boolean" },
|
|
180
196
|
"no-stream": { type: "boolean" },
|
|
181
197
|
raw: { type: "boolean" },
|
|
@@ -193,11 +209,21 @@ export async function responsesCommand(argv) {
|
|
|
193
209
|
if (values.instructions) body.instructions = values.instructions;
|
|
194
210
|
applyNumeric(body, values, {
|
|
195
211
|
"max-tokens": "max_output_tokens",
|
|
212
|
+
"max-tool-calls": "max_tool_calls",
|
|
196
213
|
temperature: "temperature",
|
|
197
214
|
"top-p": "top_p",
|
|
198
215
|
seed: "seed",
|
|
199
216
|
});
|
|
200
217
|
if (values.reasoning) body.reasoning = { effort: values.reasoning };
|
|
218
|
+
if (values.models)
|
|
219
|
+
body.models = values.models
|
|
220
|
+
.split(",")
|
|
221
|
+
.map((s) => s.trim())
|
|
222
|
+
.filter(Boolean);
|
|
223
|
+
if (values.provider) body.provider = await loadBody(values.provider);
|
|
224
|
+
if (values.plugins) body.plugins = await loadBody(values.plugins);
|
|
225
|
+
if (values.metadata) body.metadata = await loadBody(values.metadata);
|
|
226
|
+
if (values["parallel-tools"]) body.parallel_tool_calls = true;
|
|
201
227
|
if (values.tool && values.tool.length) {
|
|
202
228
|
body.tools = [];
|
|
203
229
|
for (const t of values.tool) body.tools.push(await loadBody(t));
|
|
@@ -210,6 +236,8 @@ export async function responsesCommand(argv) {
|
|
|
210
236
|
if (values.include) body.include = values.include.split(",").map((s) => s.trim());
|
|
211
237
|
if (values.store) body.store = true;
|
|
212
238
|
if (values["previous-response-id"]) body.previous_response_id = values["previous-response-id"];
|
|
239
|
+
if (values.background) body.background = true;
|
|
240
|
+
if (values.extra) Object.assign(body, await loadBody(values.extra));
|
|
213
241
|
}
|
|
214
242
|
|
|
215
243
|
if (shouldStream(values)) {
|
package/src/commands/models.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parseArgs, authFromValues } from "../args.js";
|
|
1
|
+
import { parseArgs, authFromValues, numberOption } from "../args.js";
|
|
2
2
|
import { api } from "../api.js";
|
|
3
3
|
import { c, isJsonMode, outln, pricePerMillion, printResult, table } from "../output.js";
|
|
4
4
|
|
|
@@ -29,9 +29,20 @@ Options for list:
|
|
|
29
29
|
--category <name> programming|roleplay|marketing|marketing/seo|
|
|
30
30
|
technology|science|translation|legal|finance|
|
|
31
31
|
health|trivia|academia
|
|
32
|
+
--q <text> Server-side search by model name or slug
|
|
32
33
|
--supported <param> Filter by supported parameter (e.g. tools)
|
|
33
34
|
--input-modalities <csv> text,image,audio,file (or "all")
|
|
34
|
-
--output-modalities <csv> text,image,audio,
|
|
35
|
+
--output-modalities <csv> text,image,embeddings,audio,video,rerank,
|
|
36
|
+
decisions,speech,transcription (or "all")
|
|
37
|
+
--context <tokens> Minimum context length
|
|
38
|
+
--min-price <$/M> Minimum prompt price
|
|
39
|
+
--max-price <$/M> Maximum prompt price
|
|
40
|
+
--arch <family> Model architecture/family
|
|
41
|
+
--model-authors <csv> Model author slugs
|
|
42
|
+
--providers <csv> Hosting provider names
|
|
43
|
+
--distillable <true|false> Filter by distillation capability
|
|
44
|
+
--zdr Only models with ZDR endpoints
|
|
45
|
+
--region <region> Regional endpoint, currently eu
|
|
35
46
|
--order <sort> Server-side sort: most-popular|newest|top-weekly|
|
|
36
47
|
pricing-low-to-high|pricing-high-to-low|
|
|
37
48
|
context-high-to-low|throughput-high-to-low|
|
|
@@ -45,14 +56,71 @@ Options for list:
|
|
|
45
56
|
// Server-side filters shared by `list` and `user`.
|
|
46
57
|
function listQuery(values) {
|
|
47
58
|
const query = {};
|
|
59
|
+
if (values.q) query.q = values.q;
|
|
48
60
|
if (values.category) query.category = values.category;
|
|
49
61
|
if (values.supported) query.supported_parameters = values.supported;
|
|
50
62
|
if (values["input-modalities"]) query.input_modalities = values["input-modalities"];
|
|
51
63
|
if (values["output-modalities"]) query.output_modalities = values["output-modalities"];
|
|
52
64
|
if (values.order) query.sort = values.order;
|
|
65
|
+
const numeric = [
|
|
66
|
+
["context", "context"],
|
|
67
|
+
["min-price", "min_price"],
|
|
68
|
+
["max-price", "max_price"],
|
|
69
|
+
["min-output-price", "min_output_price"],
|
|
70
|
+
["max-output-price", "max_output_price"],
|
|
71
|
+
["min-age-days", "min_age_days"],
|
|
72
|
+
["max-age-days", "max_age_days"],
|
|
73
|
+
["min-intelligence-index", "min_intelligence_index"],
|
|
74
|
+
["max-intelligence-index", "max_intelligence_index"],
|
|
75
|
+
["min-coding-index", "min_coding_index"],
|
|
76
|
+
["max-coding-index", "max_coding_index"],
|
|
77
|
+
["min-agentic-index", "min_agentic_index"],
|
|
78
|
+
["max-agentic-index", "max_agentic_index"],
|
|
79
|
+
["min-tool-success-rate", "min_tool_success_rate"],
|
|
80
|
+
["max-tool-success-rate", "max_tool_success_rate"],
|
|
81
|
+
];
|
|
82
|
+
for (const [flag, key] of numeric) {
|
|
83
|
+
if (values[flag] !== undefined) query[key] = numberOption(values[flag], `--${flag}`);
|
|
84
|
+
}
|
|
85
|
+
if (values.arch) query.arch = values.arch;
|
|
86
|
+
if (values["model-authors"]) query.model_authors = values["model-authors"];
|
|
87
|
+
if (values.providers) query.providers = values.providers;
|
|
88
|
+
if (values.distillable !== undefined) query.distillable = values.distillable;
|
|
89
|
+
if (values.zdr) query.zdr = "true";
|
|
90
|
+
if (values.region) query.region = values.region;
|
|
53
91
|
return query;
|
|
54
92
|
}
|
|
55
93
|
|
|
94
|
+
const LIST_OPTIONS = {
|
|
95
|
+
q: { type: "string" },
|
|
96
|
+
category: { type: "string" },
|
|
97
|
+
supported: { type: "string" },
|
|
98
|
+
"input-modalities": { type: "string" },
|
|
99
|
+
"output-modalities": { type: "string" },
|
|
100
|
+
order: { type: "string" },
|
|
101
|
+
context: { type: "string" },
|
|
102
|
+
"min-price": { type: "string" },
|
|
103
|
+
"max-price": { type: "string" },
|
|
104
|
+
"min-output-price": { type: "string" },
|
|
105
|
+
"max-output-price": { type: "string" },
|
|
106
|
+
arch: { type: "string" },
|
|
107
|
+
"model-authors": { type: "string" },
|
|
108
|
+
providers: { type: "string" },
|
|
109
|
+
distillable: { type: "string" },
|
|
110
|
+
zdr: { type: "boolean" },
|
|
111
|
+
region: { type: "string" },
|
|
112
|
+
"min-age-days": { type: "string" },
|
|
113
|
+
"max-age-days": { type: "string" },
|
|
114
|
+
"min-intelligence-index": { type: "string" },
|
|
115
|
+
"max-intelligence-index": { type: "string" },
|
|
116
|
+
"min-coding-index": { type: "string" },
|
|
117
|
+
"max-coding-index": { type: "string" },
|
|
118
|
+
"min-agentic-index": { type: "string" },
|
|
119
|
+
"max-agentic-index": { type: "string" },
|
|
120
|
+
"min-tool-success-rate": { type: "string" },
|
|
121
|
+
"max-tool-success-rate": { type: "string" },
|
|
122
|
+
};
|
|
123
|
+
|
|
56
124
|
function listFormatter(data) {
|
|
57
125
|
const rows = data.data || [];
|
|
58
126
|
table(rows.slice(0, 200), [
|
|
@@ -306,12 +374,8 @@ export async function modelsCommand(argv) {
|
|
|
306
374
|
|
|
307
375
|
if (sub === "user") {
|
|
308
376
|
const { values } = parseArgs(rest, {
|
|
377
|
+
...LIST_OPTIONS,
|
|
309
378
|
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" },
|
|
315
379
|
});
|
|
316
380
|
if (values.help) {
|
|
317
381
|
process.stdout.write(
|
|
@@ -357,9 +421,14 @@ export async function modelsCommand(argv) {
|
|
|
357
421
|
}
|
|
358
422
|
|
|
359
423
|
if (sub === "count") {
|
|
360
|
-
const { values } = parseArgs(rest, {
|
|
424
|
+
const { values } = parseArgs(rest, {
|
|
425
|
+
"output-modalities": { type: "string" },
|
|
426
|
+
});
|
|
427
|
+
const query = {};
|
|
428
|
+
if (values["output-modalities"]) query.output_modalities = values["output-modalities"];
|
|
361
429
|
const data = await api("GET", "/models/count", {
|
|
362
430
|
auth: authFromValues(values),
|
|
431
|
+
query,
|
|
363
432
|
requireAuth: false,
|
|
364
433
|
});
|
|
365
434
|
printResult(data, () => outln(JSON.stringify(data)));
|
|
@@ -367,11 +436,7 @@ export async function modelsCommand(argv) {
|
|
|
367
436
|
}
|
|
368
437
|
|
|
369
438
|
const { values } = parseArgs(rest, {
|
|
370
|
-
|
|
371
|
-
supported: { type: "string" },
|
|
372
|
-
"input-modalities": { type: "string" },
|
|
373
|
-
"output-modalities": { type: "string" },
|
|
374
|
-
order: { type: "string" },
|
|
439
|
+
...LIST_OPTIONS,
|
|
375
440
|
filter: { type: "string" },
|
|
376
441
|
free: { type: "boolean" },
|
|
377
442
|
sort: { type: "string" },
|
package/src/config.js
CHANGED
|
@@ -53,11 +53,14 @@ export async function resolveAuth(opts = {}) {
|
|
|
53
53
|
cfg.referer ||
|
|
54
54
|
"https://github.com/aaronjmars/openroutercli";
|
|
55
55
|
const title = opts.title || process.env.OPENROUTER_TITLE || cfg.title || "openrouter-cli";
|
|
56
|
+
const categories =
|
|
57
|
+
opts.categories || process.env.OPENROUTER_CATEGORIES || cfg.categories || undefined;
|
|
56
58
|
return {
|
|
57
59
|
apiKey,
|
|
58
60
|
baseUrl,
|
|
59
61
|
referer,
|
|
60
62
|
title,
|
|
63
|
+
categories,
|
|
61
64
|
hasManagementKey: !!mgmtKey,
|
|
62
65
|
hasUserKey: !!userKey,
|
|
63
66
|
};
|