routerbase-models-cli 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 RouterBase contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # RouterBase Models CLI
2
+
3
+ [RouterBase](https://routerbase.com) lets developers call many AI models through one OpenAI-compatible API. This CLI lists model ids from the RouterBase `/models` endpoint so you can quickly find the model string to use in your app.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install -g routerbase-models-cli
9
+ ```
10
+
11
+ Or run it without installing:
12
+
13
+ ```bash
14
+ npx routerbase-models-cli
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```bash
20
+ export ROUTERBASE_API_KEY="sk-rb-..."
21
+
22
+ routerbase-models
23
+ routerbase-models --provider google
24
+ routerbase-models --provider openai --json
25
+ ```
26
+
27
+ Options:
28
+
29
+ - `--api-key <key>`: RouterBase API key. Defaults to `ROUTERBASE_API_KEY`.
30
+ - `--base-url <url>`: Defaults to `https://routerbase.com/v1`.
31
+ - `--provider <name>`: Filters ids that start with a provider prefix such as `google/`.
32
+ - `--json`: Prints the normalized model array as JSON.
33
+
34
+ ## JavaScript
35
+
36
+ ```js
37
+ import { listRouterBaseModels } from "routerbase-models-cli";
38
+
39
+ const models = await listRouterBaseModels({
40
+ apiKey: process.env.ROUTERBASE_API_KEY
41
+ });
42
+
43
+ console.log(models.map((model) => model.id));
44
+ ```
45
+
46
+ ## Links
47
+
48
+ - [RouterBase](https://routerbase.com)
49
+ - [RouterBase docs](https://docs.routerbase.com/)
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { parseArgs } from "node:util";
4
+ import { formatModels, listRouterBaseModels } from "../src/index.js";
5
+
6
+ const usage = `Usage:
7
+ routerbase-models [--provider google] [--json]
8
+
9
+ Options:
10
+ --api-key <key> RouterBase API key. Defaults to ROUTERBASE_API_KEY.
11
+ --base-url <url> API base URL. Default: https://routerbase.com/v1
12
+ --provider <name> Filter model ids by provider prefix.
13
+ --json Print JSON.
14
+ --help Show this help text.
15
+ `;
16
+
17
+ const { values } = parseArgs({
18
+ options: {
19
+ "api-key": { type: "string" },
20
+ "base-url": { type: "string" },
21
+ provider: { type: "string" },
22
+ json: { type: "boolean", default: false },
23
+ help: { type: "boolean", short: "h", default: false }
24
+ }
25
+ });
26
+
27
+ if (values.help) {
28
+ console.log(usage);
29
+ process.exit(0);
30
+ }
31
+
32
+ try {
33
+ const models = await listRouterBaseModels({
34
+ apiKey: values["api-key"],
35
+ baseURL: values["base-url"],
36
+ provider: values.provider
37
+ });
38
+
39
+ console.log(values.json ? JSON.stringify(models, null, 2) : formatModels(models));
40
+ } catch (error) {
41
+ console.error(error.message);
42
+ process.exit(1);
43
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "routerbase-models-cli",
3
+ "version": "0.1.0",
4
+ "description": "A small CLI for listing RouterBase model ids from the OpenAI-compatible models endpoint.",
5
+ "type": "module",
6
+ "main": "./src/index.js",
7
+ "exports": {
8
+ ".": "./src/index.js"
9
+ },
10
+ "bin": {
11
+ "routerbase-models": "bin/routerbase-models.js"
12
+ },
13
+ "files": [
14
+ "bin",
15
+ "src",
16
+ "README.md",
17
+ "LICENSE"
18
+ ],
19
+ "scripts": {
20
+ "test": "node --test",
21
+ "pack:check": "npm pack --dry-run"
22
+ },
23
+ "keywords": [
24
+ "routerbase",
25
+ "models",
26
+ "cli",
27
+ "openai-compatible",
28
+ "llm",
29
+ "ai"
30
+ ],
31
+ "homepage": "https://routerbase.com",
32
+ "bugs": {
33
+ "url": "https://docs.routerbase.com/"
34
+ },
35
+ "license": "MIT",
36
+ "engines": {
37
+ "node": ">=18"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ }
42
+ }
package/src/index.js ADDED
@@ -0,0 +1,77 @@
1
+ export const ROUTERBASE_BASE_URL = "https://routerbase.com/v1";
2
+
3
+ function resolveBaseURL(baseURL = ROUTERBASE_BASE_URL) {
4
+ return baseURL.trim().replace(/\/+$/, "");
5
+ }
6
+
7
+ function readEnvApiKey() {
8
+ return globalThis.process?.env?.ROUTERBASE_API_KEY;
9
+ }
10
+
11
+ function normalizeModel(model) {
12
+ if (typeof model === "string") {
13
+ return { id: model };
14
+ }
15
+
16
+ if (!model || typeof model !== "object") {
17
+ return null;
18
+ }
19
+
20
+ const id = model.id ?? model.name ?? model.model;
21
+ return id ? { ...model, id } : null;
22
+ }
23
+
24
+ export function normalizeModelsResponse(body) {
25
+ const candidates = Array.isArray(body?.data)
26
+ ? body.data
27
+ : Array.isArray(body?.models)
28
+ ? body.models
29
+ : Array.isArray(body)
30
+ ? body
31
+ : [];
32
+
33
+ return candidates.map(normalizeModel).filter(Boolean);
34
+ }
35
+
36
+ export function filterModelsByProvider(models, provider) {
37
+ if (!provider) {
38
+ return models;
39
+ }
40
+
41
+ const prefix = provider.endsWith("/") ? provider : `${provider}/`;
42
+ return models.filter((model) => model.id.startsWith(prefix));
43
+ }
44
+
45
+ export async function listRouterBaseModels(options = {}) {
46
+ const apiKey = options.apiKey ?? readEnvApiKey();
47
+
48
+ if (!apiKey) {
49
+ throw new Error(
50
+ "RouterBase API key is required. Pass apiKey or set ROUTERBASE_API_KEY."
51
+ );
52
+ }
53
+
54
+ const fetchImpl = options.fetchImpl ?? globalThis.fetch;
55
+
56
+ if (typeof fetchImpl !== "function") {
57
+ throw new Error("A fetch implementation is required. Use Node.js 18+.");
58
+ }
59
+
60
+ const response = await fetchImpl(`${resolveBaseURL(options.baseURL)}/models`, {
61
+ headers: {
62
+ Authorization: `Bearer ${apiKey}`
63
+ }
64
+ });
65
+ const body = await response.json();
66
+
67
+ if (!response.ok) {
68
+ const detail = body.error?.message ?? body.msg ?? JSON.stringify(body);
69
+ throw new Error(`RouterBase models request failed (${response.status}): ${detail}`);
70
+ }
71
+
72
+ return filterModelsByProvider(normalizeModelsResponse(body), options.provider);
73
+ }
74
+
75
+ export function formatModels(models) {
76
+ return models.map((model) => model.id).sort().join("\n");
77
+ }