foldrun 20.6.0 → 20.7.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/bin/foldrun.mjs +3 -1
- package/docs/a2a.md +1 -1
- package/docs/api.md +3 -4
- package/docs/checks.md +2 -1
- package/docs/cli.md +0 -3
- package/docs/mcp.md +2 -2
- package/package.json +1 -1
- package/src/commands.mjs +96 -3
- package/docs/claude-code.md +0 -180
package/bin/foldrun.mjs
CHANGED
|
@@ -307,6 +307,7 @@ Signing in
|
|
|
307
307
|
foldrun keys create <label> --a2a --to <ws> --flows a,b a key for an OUTSIDE agent: it opens /a2a for those published flows and no /api route (--max-tasks N open at once, default 10; --expires); shown once
|
|
308
308
|
foldrun keys set <id> --sonnet openai/gpt-6 which model a gateway key runs each Claude Code tier on (--opus, --haiku; - clears one, --clear all)
|
|
309
309
|
foldrun keys create <label> --gateway --cap <usd> [--daily <usd>] a key for a CODING agent (Claude Code: ANTHROPIC_BASE_URL + this key) — it spends the account's credits on foldrun's models through the gateway, up to its own limits, and opens no /api route; an admin of every workspace; shown once
|
|
310
|
+
foldrun keys create laptop --gateway --cap 20 --claude-code the same, and Claude Code is set up on this machine: the URL and key go into its settings
|
|
310
311
|
foldrun a2a ls --to <ws> what a workspace serves over A2A: each flow's a2a:, card and endpoint URLs, its A2A keys (admins), recent tasks and the key that asked (--json)
|
|
311
312
|
foldrun a2a publish <flow> set a2a: publish: true in the flow (--to <ws>: the deployed copy, an admin's) — --name, --description, --example "…" (repeatable), --public-card | --private-card; diff, checked, --dry-run
|
|
312
313
|
foldrun a2a publish <flow> --clear-name | --clear-description | --clear-examples drop the card's name, description or examples (also on unpublish)
|
|
@@ -458,6 +459,7 @@ Options
|
|
|
458
459
|
--gateway keys create: a gateway key for Claude Code — with --cap <usd> (in all) and/or --daily <usd> (per UTC day)
|
|
459
460
|
--cap <usd>, --daily <usd> keys create --gateway: the key's own spending limits, $0.01–$100000
|
|
460
461
|
--login keys create --gateway: on the operator's Claude login instead (the operator's own accounts; not metered, no limits)
|
|
462
|
+
--claude-code keys create --gateway: also write the gateway URL and the key into Claude Code's settings (~/.claude/settings.json, or $CLAUDE_CONFIG_DIR) — nothing to copy
|
|
461
463
|
--opus, --sonnet, --haiku <model> keys set <id>: which model that Claude Code tier runs on with a gateway key (e.g. openai/gpt-6; - clears it)
|
|
462
464
|
--key-env <NAME> a2a call, a2a status, a2a cancel, a2a card: the environment variable holding the A2A key (default FOLDRUN_A2A_KEY) — a key is never taken on the command line
|
|
463
465
|
--card <url> a2a status, a2a cancel: the agent card of the agent that holds the task
|
|
@@ -503,7 +505,7 @@ if (!command || command === "--help" || command === "-h") {
|
|
|
503
505
|
// `--value` as the account's argument and stored an empty secret; `--force
|
|
504
506
|
// ./dir` swallowed the directory. A flag followed by another flag is also
|
|
505
507
|
// boolean, so an unlisted switch at least does not eat its neighbour.
|
|
506
|
-
const BOOLEAN_FLAGS = new Set(["read-only", "account", "follow", "force", "oauth2", "wait", "watch", "print", "dry-run", "help", "no-browser", "local", "test", "flat", "yes", "platform", "json", "forever", "all", "check", "new-client", "quiet", "off", "can-ask", "preview", "csv", "failed", "starter", "history", "list", "library", "clear", "security", "changed", "write-baseline", "no-baseline", "rules", "calls", "tree", "tool-error", "stop", "last", "no-pkce", "generate-key", "device", "write", "dpop", "export", "isolated", "no-wait", "dismissed", "unread", "team", "started", "mine", "none", "a2a", "gateway", "login", "unreachable", "public-card", "private-card", "return-immediately", "online", "overwrite", "no-send", "event-wait", "with-client", "use", "clear-name", "clear-description", "clear-examples", "clear-accept-risk", "clear-address", "clear-email", "clear-abn", "no-task", "empty"]);
|
|
508
|
+
const BOOLEAN_FLAGS = new Set(["read-only", "account", "follow", "force", "oauth2", "wait", "watch", "print", "dry-run", "help", "no-browser", "local", "test", "flat", "yes", "platform", "json", "forever", "all", "check", "new-client", "quiet", "off", "can-ask", "preview", "csv", "failed", "starter", "history", "list", "library", "clear", "security", "changed", "write-baseline", "no-baseline", "rules", "calls", "tree", "tool-error", "stop", "last", "no-pkce", "generate-key", "device", "write", "dpop", "export", "isolated", "no-wait", "dismissed", "unread", "team", "started", "mine", "none", "a2a", "gateway", "claude-code", "login", "unreachable", "public-card", "private-card", "return-immediately", "online", "overwrite", "no-send", "event-wait", "with-client", "use", "clear-name", "clear-description", "clear-examples", "clear-accept-risk", "clear-address", "clear-email", "clear-abn", "no-task", "empty"]);
|
|
507
509
|
// Flags said more than once collect into a list: `--tag a --tag b`.
|
|
508
510
|
const REPEATABLE = new Set(["tag", "expect", "header", "site", "add", "remove", "rule", "authorize-param", "example", "accept-risk"]);
|
|
509
511
|
// `--wait` is a switch everywhere but `flow add <flow> wait`, where it takes
|
package/docs/a2a.md
CHANGED
|
@@ -198,7 +198,7 @@ the flow's page and `foldrun a2a card` show them whole.
|
|
|
198
198
|
| `POST /a2a/<account>/<ws>/flows/<flow>` | the JSON-RPC endpoint |
|
|
199
199
|
| `GET /a2a/<account>/<ws>` | the flows this key may call here, each with its card and endpoint — a convenience index, not an A2A operation |
|
|
200
200
|
|
|
201
|
-
Every call sends the key as `Authorization: Bearer
|
|
201
|
+
Every call sends the key as `Authorization: Bearer fr_a2a_…` and the protocol
|
|
202
202
|
version as `A2A-Version: 1.0` (or `?A2A-Version=1.0`). A request without the
|
|
203
203
|
header is A2A 0.3, which is not served: it is answered
|
|
204
204
|
`VersionNotSupportedError` (`-32009`). A session cookie never opens `/a2a`.
|
package/docs/api.md
CHANGED
|
@@ -367,8 +367,7 @@ Reads return which secrets exist, never their values.
|
|
|
367
367
|
|
|
368
368
|
| Route | Methods | |
|
|
369
369
|
|---|---|---|
|
|
370
|
-
| `/api/keys` | GET, POST, DELETE | API keys — an admin's (`keys:manage`) to list, mint and revoke; any key may revoke itself (DELETE with its own `id`, audited as self — what `foldrun logout` does). POST `label`, `role` (viewer \| editor \| admin, never above your own, default editor), `workspaces` (names, or `null` for all — never wider than your own scope); `expires` (`30d`, `90d`, `365d`, any number of days up to 3650, or `never` — the default; anything else is a 400, never a key that lives forever); returns `{ ok, key, id, prefix, role, workspaces, expiresAt }`. POST `{ purpose: "a2a", workspace, flows, maxTasks?, label?, expires? }` mints an A2A key instead: for an outside agent, it opens `/a2a/<account>/<workspace>/…` for the named flows (each must say `a2a: { publish: true }` when the key is minted — a flow not published is refused, 400 — and still say it on every call) and every `/api` route refuses it (403); `maxTasks` (1–100, default 10) caps its tasks open at once; it answers `{ ok, key, id, prefix, purpose, workspace, flows, maxTasks, role, workspaces, expiresAt }`, and rotating one keeps the tasks it made, and the key is shown once.
|
|
371
|
-
| `/api/keys/<id>` | PATCH | a gateway key's model map: `{ models: { opus?, sonnet?, haiku? } }` — which model each Claude Code tier runs on with that key (`provider/model` such as `openai/gpt-6`, or a known prefix), each on foldrun's price list; a login gateway key maps to Claude models only; `{ models: null }` clears it. Answers `{ ok, id, models }`. `keys:manage` and an admin of every workspace; any other key is 400. The gateway reads the change within its 10 s key cache. Audited as `apikey.models`. The same `models` may be given when minting (`POST /api/keys { purpose: "gateway", models }`) |
|
|
370
|
+
| `/api/keys` | GET, POST, DELETE | API keys — an admin's (`keys:manage`) to list, mint and revoke; any key may revoke itself (DELETE with its own `id`, audited as self — what `foldrun logout` does). POST `label`, `role` (viewer \| editor \| admin, never above your own, default editor), `workspaces` (names, or `null` for all — never wider than your own scope); `expires` (`30d`, `90d`, `365d`, any number of days up to 3650, or `never` — the default; anything else is a 400, never a key that lives forever); returns `{ ok, key, id, prefix, role, workspaces, expiresAt }`. A key's prefix says what it is: `fr_api_` an API key, `fr_a2a_` an A2A key (`fr_dep_` is reserved for deploy keys); keys minted before 11 Nov 2026 start `mda_` (or `mdk_`) and keep working — a key is looked up by its hash, never its prefix, and `prefix` is its first 12 characters. POST `{ purpose: "a2a", workspace, flows, maxTasks?, label?, expires? }` mints an A2A key instead: for an outside agent, it opens `/a2a/<account>/<workspace>/…` for the named flows (each must say `a2a: { publish: true }` when the key is minted — a flow not published is refused, 400 — and still say it on every call) and every `/api` route refuses it (403); `maxTasks` (1–100, default 10) caps its tasks open at once; it answers `{ ok, key, id, prefix, purpose, workspace, flows, maxTasks, role, workspaces, expiresAt }`, and rotating one keeps the tasks it made, and the key is shown once. GET lists each key with `createdAt`, `createdBy`, `expiresAt`, `lastUsedAt`, `lastIp` and `replacedBy` (the id of the key a rotation replaced it with; `null` until then) — the last-use pair written at most once a minute per key, the address cut to its /24 (IPv4) or /48 (IPv6). A key past its `expiresAt` is refused with 401 `API key expired on <date>`; the owner is emailed seven days before. Mint, revoke and rotate are written to the audit log. POST with `workspace` or `access` is refused (400): those minted deploy keys for the platform's own git, which went on 17 Oct 2026 — a deploy key minted before is refused everywhere (403). A key for one workspace is `workspaces: ["<ws>"]`. DELETE `id`. `?tenant=` / body `tenant` is read only on an install with no users yet (first-run bootstrap), and there, when the install has a setup token (`FOLDRUN_SETUP_TOKEN`, written by the self-hosting installer), only with that token in `X-Foldrun-Setup-Token` |
|
|
372
371
|
| `/api/keys/<id>/rotate` | POST | a new key with the old one's label, role, workspaces and deploy scope — and, when it had an end, the same lifetime from today — returned once like a mint (`{ ok, key, id, prefix, role, workspaces, expiresAt, replaced: { id, endsAt } }`). `grace`: `0` (default — the old key is revoked at once), or a duration up to `7d` such as `1h` or `24h`, during which the old key still works and after which it is refused as expired. A key is rotated once: rotating a key already replaced is 409 `this key was already rotated to <prefix>…; rotate that one` — and someone who lost the new key's secret rotates the NEW key, which mints another and ends the lost one (rotating the old one again would leave the lost key working). Two rotations of one key at once mint one key. `keys:manage`; a key outside the caller's scope is 404 — except that a key `foldrun login` minted may rotate **itself**, whatever its role: same label, role, workspaces and 90-day lifetime from today, the old key ending 10 minutes later (`grace` is not read). A retry with the old key inside those 10 minutes — the CLI lost the answer, or could not store it — rotates that replacement instead, when nobody has used it and it is at least 30 seconds old (a younger one is a 409: another command may have just stored it). That is how the CLI renews its sign-in; any other key rotating itself still needs `keys:manage`. Audited as `apikey.rotated` (`self: true` for a self-rotation). A `foldrun login` key stays one only when it renews itself or its own person rotates it, signed in; rotated by any other caller the new key is an ordinary one |
|
|
373
372
|
| `/api/team` | GET, POST | members with their roles and workspace scope; mint an invite (a session, or the person's own `foldrun login` key, which invites no admin) — `role` (viewer \| editor \| admin, default editor), `workspaces` (names, or omit for all), `email` (only that address can accept it; sent through the account's `RESEND_API_KEY` unless `send: false`). An invite works **once**, for seven days, and a newer invite to the same address revokes the older ones still pending. Returns `id`, `path` (the invite's relative URL, shown only here), `expires`, `sent` and any `sendError` either way; the full link is in the mail. Links made before 29 Oct 2026 (`inv1`–`inv3`) are refused |
|
|
374
373
|
| `/api/team/invites?all=1` | GET | the account's invites, newest first — pending ones unless `all=1` (then accepted, revoked and expired too): `{ invites: [{ id, email, role, workspaces, invitedBy, createdAt, expiresAt, status }] }`, `email` `null` for a link anyone may use, `workspaces` `null` for all, `status` `pending` \| `accepted` \| `revoked` \| `expired`. Never the link. `team:manage` — an admin key included; a caller scoped to some workspaces sees only the invites inside its scope |
|
|
@@ -541,7 +540,7 @@ signed-in person, never by a key — mints an ordinary API key at their role.
|
|
|
541
540
|
|
|
542
541
|
## A2A — outside agents calling a published flow
|
|
543
542
|
|
|
544
|
-
Outside `/api`, and opened only by an **A2A key** (`Authorization: Bearer
|
|
543
|
+
Outside `/api`, and opened only by an **A2A key** (`Authorization: Bearer fr_a2a_…`,
|
|
545
544
|
minted with `POST /api/keys { purpose: "a2a", … }`) — never a session, never an
|
|
546
545
|
API key. They speak [A2A 1.0](a2a) over JSON-RPC 2.0, not this API: no
|
|
547
546
|
`Foldrun-Version` (the route answers `A2A-Version: 1.0` instead, and a call
|
|
@@ -560,7 +559,7 @@ published, is `404` like one that does not exist.
|
|
|
560
559
|
|
|
561
560
|
The platform as an [MCP server](mcp) for claude.ai, Claude Code, Claude
|
|
562
561
|
Desktop, Cursor, Codex and any other MCP client. An **API key**
|
|
563
|
-
(`Authorization: Bearer
|
|
562
|
+
(`Authorization: Bearer fr_api_…`) or an AI app's **OAuth access token** (below)
|
|
564
563
|
opens it — never a session cookie, never an A2A key — and every tool is a call
|
|
565
564
|
to one of the routes above, made with that credential, so it answers what the
|
|
566
565
|
route would: its role, its workspaces and every refusal hold. MCP's Streamable HTTP transport, stateless: one JSON-RPC 2.0
|
package/docs/checks.md
CHANGED
|
@@ -196,7 +196,8 @@ The OWASP ids are from the
|
|
|
196
196
|
|
|
197
197
|
*warn · ASI03.* A credential is written into a file: an Anthropic, OpenAI,
|
|
198
198
|
AWS, GitHub, GitLab, Slack, Google, Stripe, SendGrid, Twilio, Telegram, npm,
|
|
199
|
-
Hugging Face, Linear, DigitalOcean, Shopify or
|
|
199
|
+
Hugging Face, Linear, DigitalOcean, Shopify, Resend or foldrun key (`fr_api_`, `fr_gw_`,
|
|
200
|
+
`fr_a2a_`, `fr_dep_`, and the older `mda_`/`mdk_`), a JSON web token,
|
|
200
201
|
a private key, a webhook URL that carries its own secret, a password inside a
|
|
201
202
|
URL, or a field named like a credential (`api_key:`, `token:`, `password=`)
|
|
202
203
|
holding a literal value that looks random. Everything in a workspace is
|
package/docs/cli.md
CHANGED
|
@@ -209,8 +209,6 @@ claude.ai or Claude Code there, nor any MCP configuration on disk.
|
|
|
209
209
|
| `foldrun keys ls` | the account's API keys, each with its role and scope, when it was created, when it was last used and from where (a /24 or /48), and when it expires; a key `foldrun login` minted is tagged `CLI sign-in · renews itself` (revoke it to sign that machine out) — also `create <label>` (`--expires 30d\|90d\|365d\|never`), `rotate <id>` and `revoke <id>` |
|
|
210
210
|
| `foldrun keys rotate <id>` | a new key with the old one's label, role, workspaces and deploy scope, printed once; the old key is revoked at once (asks first; `--yes` on a pipe), or keeps working for `--grace 1h` / `24h` while you swap the new one in. A key already rotated is refused (409) and the command names the key that replaced it — rotate that one, also if its secret was lost; `keys ls` shows `rotated → <id>`. The owner is emailed a week before any key expires |
|
|
211
211
|
| `foldrun keys create <label> --a2a --to <ws> --flows a,b` | a key for an outside agent ([A2A](a2a.md)): it opens `/a2a/<account>/<ws>/…` — the agent card and JSON-RPC endpoint of those flows, each published with `a2a:` (a flow not published when the key is minted is refused: publish first) — and no `/api` route. `--max-tasks <n>` caps the tasks it may have open at once (1–100, default 10); `--expires` as for any key. Printed once; `keys ls` shows it as `A2A · <ws> · <flows>`. `POST /api/keys { purpose: "a2a", workspace, flows, maxTasks }`, an admin's |
|
|
212
|
-
| `foldrun keys create <label> --gateway --cap <usd>` | a gateway key for a coding agent ([Claude Code](claude-code.md)): `ANTHROPIC_BASE_URL` + this key run Claude Code on the account's credits, through foldrun's gateway, and it opens no `/api` route. `--cap` (USD in all) and/or `--daily` (USD per UTC day) — at least one, $0.01–$100,000; `--expires` as for any key. Printed once with the two `export` lines; `keys ls` shows it as `gateway · Claude Code · $spent of $cap · $today of $daily today`. `POST /api/keys { purpose: "gateway", capUsd, dailyUsd }`, an admin of every workspace |
|
|
213
|
-
| `foldrun keys set <id> --sonnet <model>` | a gateway key's model map: which model each Claude Code tier runs on with that key (`--opus`, `--sonnet`, `--haiku`, each `provider/model` such as `openai/gpt-6`; `-` clears one, `--clear` all). The tiers named change, the rest stay. `keys ls` shows the map. `PATCH /api/keys/<id> { models }`, an admin of every workspace |
|
|
214
212
|
| `foldrun a2a ls --to <ws>` | what a workspace serves over A2A (`GET /api/workspaces/<ws>/a2a`): every flow that says `a2a:`, published or not, with its public/private card and its card and endpoint URLs; the workspace's A2A keys (an admin's view; `null` otherwise); and the newest tasks — state, flow, run, and `A2A · <key label>`; then, under **Secret and code**, every agent that holds a secret and can run code, accepted or not, with the `--accept-risk` line that accepts it. `--json` prints the answer as it came |
|
|
215
213
|
| `foldrun a2a publish <flow>` | sets `a2a: { publish: true }` in the flow, keeping the rest of its block: `--name`, `--description`, `--example "…"` (repeatable — the card's examples), `--public-card` (the card is readable without a key; calling never is) or `--private-card`. Checked with core's `a2a:` rules before anything is written; shows the diff, `--dry-run` writes nothing. Without `--to` it edits this folder (`deploy` ships it); `--to <workspace>` sends the flow page's `PATCH …/flows/<flow> { a2a, expect }` — an admin's, the platform refuses an editor — and prints the card URL. A caller also needs an A2A key that names the flow |
|
|
216
214
|
| `foldrun a2a unpublish <flow>` | `a2a: publish: false` — no outside agent may call it, whatever keys name it; the rest of `a2a:` stays for the next publish. `--to`, `--dry-run` as for `publish` |
|
|
@@ -316,7 +314,6 @@ claude.ai or Claude Code there, nor any MCP configuration on disk.
|
|
|
316
314
|
| `--expires <span>` | `keys create`: when it stops working — `30d`, `90d` (the default, as in the dashboard; before CLI 15.0.0 the default was never), `365d` or `never`; `--forever` is `never` |
|
|
317
315
|
| `--grace <span>` | `keys rotate`: keep the old key working for `1h` or `24h` (default `0`: revoked now) |
|
|
318
316
|
| `--a2a` | `keys create`: an A2A key for an outside agent, with `--to <workspace>`, `--flows a,b` and optionally `--max-tasks <n>` |
|
|
319
|
-
| `--gateway` | `keys create`: a gateway key for Claude Code, with `--cap <usd>` and/or `--daily <usd>` — or `--login` (the operator's Claude login, on the operator's own accounts; not metered, no limits) |
|
|
320
317
|
| `--key-env <NAME>` | `a2a call`, `a2a status`, `a2a cancel`, `a2a card`: the environment variable that holds the A2A key (default `FOLDRUN_A2A_KEY`) |
|
|
321
318
|
| `--card <url>` | `a2a status`, `a2a cancel`: the agent card of the agent that holds the task |
|
|
322
319
|
| `--force` | `deploy`: deploy while runs are in flight. `pull`, `storage get`: overwrite local files |
|
package/docs/mcp.md
CHANGED
|
@@ -71,7 +71,7 @@ Over HTTP, with a key from Settings → API keys:
|
|
|
71
71
|
|
|
72
72
|
```sh
|
|
73
73
|
claude mcp add --transport http foldrun https://<your platform>/api/mcp \
|
|
74
|
-
--header "Authorization: Bearer
|
|
74
|
+
--header "Authorization: Bearer fr_api_..."
|
|
75
75
|
```
|
|
76
76
|
|
|
77
77
|
Settings → API keys → **Connect an AI app (MCP)** shows this install's
|
|
@@ -165,7 +165,7 @@ that act are not offered, and a call to one is refused:
|
|
|
165
165
|
|
|
166
166
|
```sh
|
|
167
167
|
claude mcp add foldrun -- foldrun mcp --read-only
|
|
168
|
-
claude mcp add --transport http foldrun "https://<your platform>/api/mcp?readonly=1" --header "Authorization: Bearer
|
|
168
|
+
claude mcp add --transport http foldrun "https://<your platform>/api/mcp?readonly=1" --header "Authorization: Bearer fr_api_..."
|
|
169
169
|
```
|
|
170
170
|
|
|
171
171
|
A viewer's key is the stronger version of the same: read-only by role,
|
package/package.json
CHANGED
package/src/commands.mjs
CHANGED
|
@@ -4697,6 +4697,7 @@ async function doctor(flags) {
|
|
|
4697
4697
|
* keys create <label> --a2a --to <ws> --flows a,b [--max-tasks N] a key for an outside agent: /a2a only
|
|
4698
4698
|
* keys create <label> --gateway --cap <usd> [--daily <usd>] a coding agent's key (Claude Code): the gateway only
|
|
4699
4699
|
* keys create <label> --gateway --login on the operator's Claude login (its own accounts): not metered
|
|
4700
|
+
* keys create <label> --gateway --cap <usd> --claude-code …and write it into Claude Code's settings
|
|
4700
4701
|
* keys set <id> --opus|--sonnet|--haiku <provider/model> which model each Claude Code tier runs on (a gateway key; `-` clears one, --clear all)
|
|
4701
4702
|
* keys rotate <id> [--grace 1h] a new key, same label/role/scope; the old
|
|
4702
4703
|
* one ends now, or when the grace runs out.
|
|
@@ -4744,6 +4745,7 @@ async function keysCmd(positional, flags) {
|
|
|
4744
4745
|
if (verb === "create" || verb === "new") {
|
|
4745
4746
|
if (!arg) throw new Error("what is the key for? foldrun keys create <label>");
|
|
4746
4747
|
if (flags.a2a === true && flags.gateway === true) throw new Error("--a2a or --gateway, not both");
|
|
4748
|
+
if (flags["claude-code"] === true && flags.gateway !== true) throw new Error("--claude-code goes with --gateway: only a gateway key runs Claude Code");
|
|
4747
4749
|
if (flags.a2a === true) return keysCreateA2a(url, arg, flags);
|
|
4748
4750
|
if (flags.gateway === true) return keysCreateGateway(url, arg, flags);
|
|
4749
4751
|
const body = { label: arg };
|
|
@@ -4905,6 +4907,9 @@ async function keysCreateGateway(url, label, flags) {
|
|
|
4905
4907
|
const capUsd = flags.login === true ? undefined : usdFlag(flags.cap, "--cap");
|
|
4906
4908
|
const dailyUsd = flags.login === true ? undefined : usdFlag(flags.daily, "--daily");
|
|
4907
4909
|
if (flags.login !== true && capUsd === undefined && dailyUsd === undefined) throw new Error("a gateway key needs a limit of its own: --cap <usd> in all, or --daily <usd> per UTC day (or both) — or --login, on an account the operator's Claude login is for");
|
|
4910
|
+
// --claude-code: read Claude Code's settings BEFORE minting, so a file we
|
|
4911
|
+
// could not safely rewrite stops here with nothing made.
|
|
4912
|
+
const claude = flags["claude-code"] === true ? preflightClaudeSettings() : null;
|
|
4908
4913
|
const body = { label, purpose: "gateway" };
|
|
4909
4914
|
if (flags.login === true) body.credential = "login";
|
|
4910
4915
|
if (capUsd !== undefined) body.capUsd = capUsd;
|
|
@@ -4918,9 +4923,27 @@ async function keysCreateGateway(url, label, flags) {
|
|
|
4918
4923
|
if (made.key == null) return lostSecret(made.id);
|
|
4919
4924
|
console.log(` ${made.key}\n`);
|
|
4920
4925
|
const base = made.gatewayUrl ?? "<the gateway URL — not set on this platform yet>";
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4926
|
+
// Written from the file as it is NOW, not as it was before the request,
|
|
4927
|
+
// so a change made meanwhile is kept. A write that fails after the key
|
|
4928
|
+
// exists says so and falls back to the lines to copy.
|
|
4929
|
+
/** @type {{ file: string, dropped: string[], backup: string | null } | null} */
|
|
4930
|
+
let done = null;
|
|
4931
|
+
if (claude && made.gatewayUrl) {
|
|
4932
|
+
try { done = writeClaudeSettings(readClaudeSettings(), made.gatewayUrl, made.key); }
|
|
4933
|
+
catch (e) { console.log(` ${c.yellow(`The key was made, but Claude Code's settings were not written: ${e.message}`)}\n`); }
|
|
4934
|
+
}
|
|
4935
|
+
if (done) {
|
|
4936
|
+
console.log(` ${c.green("✓")} ${c.dim("Claude Code now runs on it — written to")} ${done.file}`);
|
|
4937
|
+
console.log(` ${c.dim(`env: ANTHROPIC_BASE_URL=${made.gatewayUrl}, ANTHROPIC_AUTH_TOKEN=<this key>`)}`);
|
|
4938
|
+
if (done.dropped.length) console.log(` ${c.dim(`removed from that env block: ${done.dropped.join(", ")} (it would have competed with the key)`)}`);
|
|
4939
|
+
if (done.backup) console.log(` ${c.dim(`the file as it was: ${done.backup}`)}`);
|
|
4940
|
+
console.log(` ${c.dim("Start a new claude session; /status shows the gateway. Claude Desktop is set in its own Developer → Configure Third-Party Inference.")}\n`);
|
|
4941
|
+
} else {
|
|
4942
|
+
if (claude && !made.gatewayUrl) console.log(` ${c.yellow("This platform has no gateway URL yet, so Claude Code's settings were not written.")}\n`);
|
|
4943
|
+
console.log(` ${c.dim("Shown once. Point Claude Code at it:")}\n`);
|
|
4944
|
+
console.log(` export ANTHROPIC_BASE_URL=${base}`);
|
|
4945
|
+
console.log(` export ANTHROPIC_API_KEY=<key>\n`);
|
|
4946
|
+
}
|
|
4924
4947
|
// A login key is not metered: there is no spend for `keys ls` to show.
|
|
4925
4948
|
const after = made.credential === "login"
|
|
4926
4949
|
? `It opens the gateway only and runs on the operator's Claude login, not metered — it shares that subscription's weekly cap with the desks. \`foldrun keys revoke ${made.id}\` ends it.`
|
|
@@ -4929,6 +4952,76 @@ async function keysCreateGateway(url, label, flags) {
|
|
|
4929
4952
|
return 0;
|
|
4930
4953
|
}
|
|
4931
4954
|
|
|
4955
|
+
/** Claude Code's user settings: $CLAUDE_CONFIG_DIR/settings.json, else
|
|
4956
|
+
* ~/.claude/settings.json (%USERPROFILE%\.claude on Windows). Its env block
|
|
4957
|
+
* reaches the CLI, the IDE extensions' sessions and background agents. */
|
|
4958
|
+
function claudeSettingsFile() {
|
|
4959
|
+
const dir = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), ".claude");
|
|
4960
|
+
return path.join(dir, "settings.json");
|
|
4961
|
+
}
|
|
4962
|
+
|
|
4963
|
+
/** Read Claude Code's settings for `keys create --gateway --claude-code`,
|
|
4964
|
+
* refusing anything we could not rewrite without losing what is there: a
|
|
4965
|
+
* file that is not a JSON object, or an env that is not one. */
|
|
4966
|
+
function readClaudeSettings() {
|
|
4967
|
+
const file = claudeSettingsFile();
|
|
4968
|
+
/** @type {string | null} */
|
|
4969
|
+
let text = null;
|
|
4970
|
+
try { text = fs.readFileSync(file, "utf8"); } catch (e) { if (e.code !== "ENOENT") throw new Error(`cannot read ${file}: ${e.message}`); }
|
|
4971
|
+
/** @type {any} */
|
|
4972
|
+
let settings = {};
|
|
4973
|
+
if (text !== null && text.trim()) {
|
|
4974
|
+
try { settings = JSON.parse(text); } catch { throw new Error(`${file} is not valid JSON, so it was left alone — fix the file, or leave out --claude-code and set the two lines by hand`); }
|
|
4975
|
+
}
|
|
4976
|
+
if (!settings || typeof settings !== "object" || Array.isArray(settings)) throw new Error(`${file} is not a JSON object, so it was left alone`);
|
|
4977
|
+
if (settings.env !== undefined && (!settings.env || typeof settings.env !== "object" || Array.isArray(settings.env))) throw new Error(`${file} has an "env" that is not an object, so it was left alone`);
|
|
4978
|
+
return { file, text, settings };
|
|
4979
|
+
}
|
|
4980
|
+
|
|
4981
|
+
/** Before a key is made: the settings can be read and rewritten — the
|
|
4982
|
+
* folder exists or can be made, and a file can be written in it. Anything
|
|
4983
|
+
* else stops here, with no key made. */
|
|
4984
|
+
function preflightClaudeSettings() {
|
|
4985
|
+
try {
|
|
4986
|
+
const found = readClaudeSettings();
|
|
4987
|
+
fs.mkdirSync(path.dirname(found.file), { recursive: true, mode: 0o700 });
|
|
4988
|
+
const probe = `${found.file}.${process.pid}.probe`;
|
|
4989
|
+
fs.writeFileSync(probe, "", { mode: 0o600 });
|
|
4990
|
+
fs.rmSync(probe, { force: true });
|
|
4991
|
+
if (found.text !== null) fs.accessSync(found.file, fs.constants.W_OK);
|
|
4992
|
+
return found;
|
|
4993
|
+
} catch (e) {
|
|
4994
|
+
throw new Error(`${e.message} — no key was made`);
|
|
4995
|
+
}
|
|
4996
|
+
}
|
|
4997
|
+
|
|
4998
|
+
/** Put the gateway URL and key into Claude Code's env block, keeping every
|
|
4999
|
+
* other setting. ANTHROPIC_AUTH_TOKEN (a Bearer) wins over a saved Claude
|
|
5000
|
+
* login with no prompt; an ANTHROPIC_API_KEY in the same block would compete
|
|
5001
|
+
* with it, so it goes. The old file is kept beside it, the new one is
|
|
5002
|
+
* written whole (a temp file, then a rename) and readable only by you. */
|
|
5003
|
+
function writeClaudeSettings({ file, text, settings }, baseUrl, key) {
|
|
5004
|
+
const env = { ...(settings.env ?? {}) };
|
|
5005
|
+
const dropped = ["ANTHROPIC_API_KEY"].filter((k) => k in env);
|
|
5006
|
+
for (const k of dropped) delete env[k];
|
|
5007
|
+
env.ANTHROPIC_BASE_URL = baseUrl;
|
|
5008
|
+
env.ANTHROPIC_AUTH_TOKEN = key;
|
|
5009
|
+
const next = { ...settings, env };
|
|
5010
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
5011
|
+
/** @type {string | null} */
|
|
5012
|
+
let backup = null;
|
|
5013
|
+
if (text !== null) {
|
|
5014
|
+
backup = `${file}.before-foldrun`;
|
|
5015
|
+
fs.writeFileSync(backup, text, { mode: 0o600 });
|
|
5016
|
+
try { fs.chmodSync(backup, 0o600); } catch { /* Windows: no modes */ }
|
|
5017
|
+
}
|
|
5018
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
5019
|
+
fs.writeFileSync(tmp, JSON.stringify(next, null, 2) + "\n", { mode: 0o600 });
|
|
5020
|
+
fs.renameSync(tmp, file);
|
|
5021
|
+
try { fs.chmodSync(file, 0o600); } catch { /* Windows: no modes */ }
|
|
5022
|
+
return { file, dropped, backup };
|
|
5023
|
+
}
|
|
5024
|
+
|
|
4932
5025
|
/** A retried mint or rotate is answered from the first call, and the server
|
|
4933
5026
|
* never stores a key's secret — so a retry after a lost answer has none. */
|
|
4934
5027
|
function lostSecret(id) {
|
package/docs/claude-code.md
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
# Claude Code on foldrun's models
|
|
2
|
-
|
|
3
|
-
Claude Code — and any tool that takes an Anthropic base URL and key — can run
|
|
4
|
-
on your foldrun account's credits instead of an Anthropic account of your
|
|
5
|
-
own. You mint a **gateway key**, point the tool at foldrun's gateway, and
|
|
6
|
-
every call is billed to the account at foldrun's price list, up to the key's
|
|
7
|
-
own limits.
|
|
8
|
-
|
|
9
|
-
```sh
|
|
10
|
-
export ANTHROPIC_BASE_URL=https://<the gateway URL> # Settings → API keys shows it
|
|
11
|
-
export ANTHROPIC_API_KEY=mda_… # the gateway key
|
|
12
|
-
claude
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
`ANTHROPIC_AUTH_TOKEN` works in place of `ANTHROPIC_API_KEY` (it is sent as
|
|
16
|
-
`Authorization: Bearer`). This is on the hosted platform only; a self-hosted
|
|
17
|
-
install has no gateway.
|
|
18
|
-
|
|
19
|
-
## Minting a gateway key
|
|
20
|
-
|
|
21
|
-
On **Settings → API keys**, pick **Gateway key — Claude Code** as the kind,
|
|
22
|
-
or from a terminal:
|
|
23
|
-
|
|
24
|
-
```sh
|
|
25
|
-
foldrun keys create laptop --gateway --cap 20 --daily 5
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
- **A limit of its own is required:** `--cap` (USD, in all) or `--daily`
|
|
29
|
-
(USD, per UTC day), or both — from $0.01 to $100,000.
|
|
30
|
-
Limits are in dollars charged — what the account pays at foldrun's price
|
|
31
|
-
list — and so is the spend `keys ls` shows. Each call is kept at the
|
|
32
|
-
margin it was charged at, so a margin changed later re-prices nothing.
|
|
33
|
-
- **Who may mint one:** an admin of every workspace. The key spends the
|
|
34
|
-
whole account's balance, so a workspace-scoped admin cannot.
|
|
35
|
-
- **What it opens:** the gateway only. Every `/api` route refuses it (403),
|
|
36
|
-
so it cannot read a workspace, start a run or mint a key. An account API
|
|
37
|
-
key is refused by the gateway the same way.
|
|
38
|
-
- **Shown once**, like every key. `foldrun keys ls` (and the Settings list)
|
|
39
|
-
shows what it has spent against each limit; `rotate` keeps its limits, and
|
|
40
|
-
the new key's spend starts afresh; `revoke` ends it at once.
|
|
41
|
-
|
|
42
|
-
The API is `POST /api/keys { purpose: "gateway", capUsd?, dailyUsd?, label?, expires? }`
|
|
43
|
-
([API](api.md)).
|
|
44
|
-
|
|
45
|
-
## On the operator's Claude login
|
|
46
|
-
|
|
47
|
-
An account the operator allows its own model credential — the one its desks
|
|
48
|
-
run on — may mint a gateway key on the operator's Claude login instead:
|
|
49
|
-
|
|
50
|
-
```sh
|
|
51
|
-
foldrun keys create mine --gateway --login
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
or **Runs on → The operator's Claude login** on Settings → API keys (shown
|
|
55
|
-
only on such an account). Such a key:
|
|
56
|
-
|
|
57
|
-
- sends the operator's Claude login to Anthropic, read fresh on every call,
|
|
58
|
-
so the platform's token refresh reaches it with no restart;
|
|
59
|
-
- is **not metered or billed** and takes no `--cap` or `--daily` — the
|
|
60
|
-
login is a flat-rate subscription, so there is no dollar figure to hold;
|
|
61
|
-
- shares that subscription's weekly cap with the account's desks: a long
|
|
62
|
-
coding session can leave the desks out of their window until it resets;
|
|
63
|
-
- opens nothing once the account is no longer allowed the credential: the
|
|
64
|
-
gateway asks on every call.
|
|
65
|
-
|
|
66
|
-
It is for the operator's own use. A subscription's terms are its owner's to
|
|
67
|
-
keep; foldrun's models (the rest of this page) are what to give anyone else.
|
|
68
|
-
|
|
69
|
-
## Other providers' models
|
|
70
|
-
|
|
71
|
-
The same key reaches OpenAI's, Gemini's, DeepSeek's, Kimi's, Z.ai's (GLM),
|
|
72
|
-
Alibaba's (Qwen), MiniMax's and Xiaomi's (MiMo) models: name one, and the
|
|
73
|
-
gateway sends it to that provider on foldrun's models (billed at its price,
|
|
74
|
-
under the same limits).
|
|
75
|
-
|
|
76
|
-
```sh
|
|
77
|
-
claude --model deepseek/deepseek-v4 # or /model deepseek/deepseek-v4 in a session
|
|
78
|
-
claude --model kimi/kimi-k3
|
|
79
|
-
claude --model openai/gpt-6 # or gpt-6
|
|
80
|
-
claude --model gemini/gemini-3-pro # or gemini-3-pro
|
|
81
|
-
claude --model glm-5.3 # Z.ai
|
|
82
|
-
claude --model qwen3.8-max # Alibaba
|
|
83
|
-
claude --model MiniMax-M3 # MiniMax
|
|
84
|
-
claude --model mimo-v2.6-pro # Xiaomi
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
- **Choosing a provider.** `provider/model` always works (`anthropic/`,
|
|
88
|
-
`openai/`, `gemini/`, `deepseek/`, `kimi/`, `zai/`, `qwen/`, `minimax/`,
|
|
89
|
-
`mimo/`). A bare name with a known prefix works too: `gpt-…`, `gemini-…`,
|
|
90
|
-
`deepseek-…`, `kimi-…`, `glm-…`, `qwen…`, `minimax-…`, `mimo-…`, or
|
|
91
|
-
`claude-…` for Anthropic. Anything else goes to Anthropic.
|
|
92
|
-
- **How each is reached.** DeepSeek, Kimi, Z.ai, Qwen, MiniMax and MiMo speak
|
|
93
|
-
Anthropic's format and are sent as they are, less what each one's API does
|
|
94
|
-
not document (context editing, Claude's tool search, `service_tier`;
|
|
95
|
-
`thinking` in the words each one takes). OpenAI (Responses API) and Gemini (Chat Completions) are
|
|
96
|
-
translated both ways, by the same translator runs use.
|
|
97
|
-
- Tools work on all of them.
|
|
98
|
-
- Gemini's thought signatures are kept between your calls (in the
|
|
99
|
-
platform's cache, per account, for two hours), so a multi-turn tool loop
|
|
100
|
-
works on Gemini too.
|
|
101
|
-
- Translation drops prompt caching, thinking where the provider has none,
|
|
102
|
-
and Anthropic's server tools (web search, web fetch).
|
|
103
|
-
- **What Claude Code sends.** It sends the name you give it unchanged.
|
|
104
|
-
Claude Code's own `/model` list shows Claude models only, so type the name.
|
|
105
|
-
Each provider gets only the request fields its API takes; the rest are
|
|
106
|
-
dropped.
|
|
107
|
-
- **Token counts.** A provider with no token-count route gets an estimate
|
|
108
|
-
(marked `x-foldrun-estimate: 1`).
|
|
109
|
-
- **What Claude Code can't know.** For non-Claude models it shows the wrong
|
|
110
|
-
cost and context size. The charge is foldrun's.
|
|
111
|
-
- **What isn't offered.** A login gateway key stays Claude-only.
|
|
112
|
-
|
|
113
|
-
## Run Claude Code's own tiers on other models
|
|
114
|
-
|
|
115
|
-
Claude Code's `/model` list shows Claude's tiers alone. A gateway key can map
|
|
116
|
-
each tier to any model foldrun offers, so picking Sonnet in `/model` (or
|
|
117
|
-
`--model sonnet`) runs, say, GPT — with no setting in Claude Code at all:
|
|
118
|
-
|
|
119
|
-
```sh
|
|
120
|
-
foldrun keys set <id> --sonnet openai/gpt-6 --haiku deepseek/deepseek-v4
|
|
121
|
-
foldrun keys set <id> --haiku - # Haiku back to Claude
|
|
122
|
-
foldrun keys set <id> --clear # every tier as Claude Code names it
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
On Settings → API keys, a gateway key's **Models** button does the same, and
|
|
126
|
-
the row shows what each tier runs on. A mapped model must be on foldrun's
|
|
127
|
-
price list; a login gateway key maps to Claude models only. The gateway reads a
|
|
128
|
-
change within 10 seconds. API: `PATCH /api/keys/<id> { models }`, or `models`
|
|
129
|
-
when minting.
|
|
130
|
-
|
|
131
|
-
## What the gateway serves
|
|
132
|
-
|
|
133
|
-
| Route | |
|
|
134
|
-
|---|---|
|
|
135
|
-
| `POST /v1/messages` | metered, streamed or not |
|
|
136
|
-
| `POST /v1/messages/count_tokens` | free |
|
|
137
|
-
| `GET /v1/models` | free |
|
|
138
|
-
|
|
139
|
-
Anything else is a 404; a query string (`/v1/models?after_id=…`) goes on as
|
|
140
|
-
it came. Anthropic's models only. Your key never reaches
|
|
141
|
-
Anthropic: the gateway sends the call with the platform's own key, and only
|
|
142
|
-
the headers Anthropic's API reads (`anthropic-version`, `anthropic-beta`,
|
|
143
|
-
`content-type`, `accept`).
|
|
144
|
-
|
|
145
|
-
## Limits and refusals
|
|
146
|
-
|
|
147
|
-
Each call is checked the way a run's call on foldrun's models is
|
|
148
|
-
([budgets and billing](budgets-and-billing.md)):
|
|
149
|
-
|
|
150
|
-
- the account must have credit, and foldrun's models must be on for it;
|
|
151
|
-
- the model must be on the price list;
|
|
152
|
-
- the call is held at the most it could cost (its input, and every output
|
|
153
|
-
token it may ask for) against the account's daily limit **and** the key's
|
|
154
|
-
own limits, before it is sent — so calls at once cannot pass a limit
|
|
155
|
-
together, and a call that would pass one is refused, not cut off midway;
|
|
156
|
-
- it is charged what Anthropic reports it used, or its hold if no usage
|
|
157
|
-
came back (a reply cut short).
|
|
158
|
-
|
|
159
|
-
Because a call is held at its most, a key's limit needs room for the
|
|
160
|
-
calls Claude Code makes at once — a few dollars, not cents.
|
|
161
|
-
|
|
162
|
-
Request fields billed outside tokens are refused until they have a price:
|
|
163
|
-
server tools (web search, code execution), a one-hour prompt cache, a
|
|
164
|
-
priority tier.
|
|
165
|
-
|
|
166
|
-
A refusal comes back in Anthropic's own error shape, so Claude Code prints
|
|
167
|
-
the reason:
|
|
168
|
-
|
|
169
|
-
| Status | Why |
|
|
170
|
-
|---|---|
|
|
171
|
-
| `401` | no key, an unknown, revoked or expired key |
|
|
172
|
-
| `403` | not a gateway key; foldrun's models off for the account |
|
|
173
|
-
| `402` | out of credits; the key's limit or the account's daily limit has no room; a model with no price |
|
|
174
|
-
| `429` | the key's request rate (300 a minute) or its open calls (32 at once) — with `Retry-After`; waiting helps. Every route and every kind of key counts |
|
|
175
|
-
| `400` | a request field that is not offered (named in the message) |
|
|
176
|
-
|
|
177
|
-
A key that is revoked can still answer for up to 10 seconds: each gateway pod
|
|
178
|
-
caches a key for that long. A spent limit is a `402`, not a `429`: Claude Code retries a `429` for minutes,
|
|
179
|
-
and no retry makes room under a limit. A `429` from Anthropic itself comes
|
|
180
|
-
back as it was.
|