@foldrun/core 24.12.0 → 25.0.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.
@@ -50,7 +50,7 @@ export function approveLinkToken(tenant, workspace, runId, link) {
50
50
  * install's public origin. `decision=reject` pre-selects; a GET never
51
51
  * decides. */
52
52
  export function approveLinkPath(tenant, workspace, runId, link) {
53
- return `/api/approve/${tenant}/${workspace}/${runId}?token=${approveLinkToken(tenant, workspace, runId, link)}`;
53
+ return `/v1/approve/${tenant}/${workspace}/${runId}?token=${approveLinkToken(tenant, workspace, runId, link)}`;
54
54
  }
55
55
  const same = (a, b) => a.length === b.length && crypto.timingSafeEqual(Buffer.from(a), Buffer.from(b));
56
56
  /**
@@ -419,7 +419,7 @@ const PROTECTED_BASH = [
419
419
  * A web address, which names a place on a server rather than in the workspace.
420
420
  *
421
421
  * The protected-path patterns match a bare `runs/`, so an agent calling the
422
- * platform's own API — `curl https://…/api/workspaces/x/runs/<id>` — was told
422
+ * platform's own API — `curl https://…/v1/workspaces/x/runs/<id>` — was told
423
423
  * it was reading the run journal. The weekly retros read their week through
424
424
  * that API and were refused on 9 Oct 2026. Only http(s): a `file://` URL is a
425
425
  * path, and stays checked.
@@ -111,6 +111,10 @@ export declare const DEPLOY_BLOCK_MODES: readonly ["none", "secrets", "security"
111
111
  export type DeployBlockMode = (typeof DEPLOY_BLOCK_MODES)[number];
112
112
  /** The workspace's own AGENTS.md, else the account's, else none. */
113
113
  export declare function deployBlockMode(files: DeployFile[], accountKeys: Record<string, unknown>): DeployBlockMode;
114
+ /** Own keys off on this platform (models.byok, 22 Nov 2026): every
115
+ * `provider:` in the files is a refusal — nothing deploys that would run on
116
+ * an endpoint the platform does not meter. Nothing where they are allowed. */
117
+ export declare function ownKeyBlockers(tenant: string, files: DeployFile[]): DeployIssue[];
114
118
  /** The findings `mode` turns into refusals, as deploy issues. */
115
119
  export declare function deployBlockers(files: DeployFile[], mode: DeployBlockMode, options?: ScanOptions): DeployIssue[];
116
120
  export declare function deployWarnings(files: DeployFile[]): DeployIssue[];
@@ -43,6 +43,7 @@ import { languageProblem } from "./language.js";
43
43
  import { localeProblems } from "./locale.js";
44
44
  import { entriesNoFollow } from "./paths.js";
45
45
  import { filterIgnored, findingFingerprint, ruleForWhere, scanFiles, scanRule, STRICT_FRONTMATTER_PATH } from "./scan.js";
46
+ import { platform } from "./platform.js";
46
47
  /** Directories a deploy never reads out of a source tree. */
47
48
  // `.cache` is what a run's tools leave in an agent's folder (HOME is that
48
49
  // folder): logs and font caches, never authored.
@@ -311,6 +312,17 @@ function blockersFor(tenant, given) {
311
312
  .map(([n]) => n);
312
313
  return deployBlockers(files, mode, { accountNetwork: account.network, outwardTools });
313
314
  }
315
+ /** Own keys off on this platform (models.byok, 22 Nov 2026): every
316
+ * `provider:` in the files is a refusal — nothing deploys that would run on
317
+ * an endpoint the platform does not meter. Nothing where they are allowed. */
318
+ export function ownKeyBlockers(tenant, files) {
319
+ if (platform.ownModelKeys?.(tenant) ?? true)
320
+ return [];
321
+ return scanFiles(files, { only: ["config/own-model-key"], ownModelKeys: false }).map((f) => ({
322
+ where: `${f.file}${f.line ? `:${f.line}` : ""}`,
323
+ message: `${f.message} [${f.rule}]`,
324
+ }));
325
+ }
314
326
  /** The findings `mode` turns into refusals, as deploy issues. */
315
327
  export function deployBlockers(files, mode, options = {}) {
316
328
  if (mode === "none")
@@ -777,7 +789,7 @@ export function planDeploy(tenant, workspace, files, opts = {}) {
777
789
  // deploy_block: (FOL-58) turns the scanner's findings into refusals —
778
790
  // scanned with what the Checks page passes too: the account's network:
779
791
  // and the library's outward tools (Codex review).
780
- issues: [...deployIssues(files), ...blockersFor(tenant, files)],
792
+ issues: [...deployIssues(files), ...blockersFor(tenant, files), ...ownKeyBlockers(tenant, files)],
781
793
  warnings: deployWarnings(files),
782
794
  blockedBy: runsInFlight(tenant, workspace),
783
795
  };
@@ -8,11 +8,12 @@ export declare function hostEnvAllowed(name: string): boolean;
8
8
  export declare function hostSafeEnv(from?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
9
9
  /**
10
10
  * Where this install's own API answers, for a step to call: `FOLDRUN_API_URL`
11
- * when the operator set it, else `FOLDRUN_PUBLIC_URL` + `/api`. Undefined on a
12
- * laptop with neither.
11
+ * when the operator set it, else the API host (`FOLDRUN_PUBLIC_API_URL`) or
12
+ * the install's own address (`FOLDRUN_PUBLIC_URL`), + `/v1` (23 Nov 2026:
13
+ * every route is /v1). Undefined on a laptop with none.
13
14
  *
14
15
  * A desk that reads its own run history used to write the host into its
15
- * files (`https://dev.foldrun.io/api`), so the same workspace pointed at the
16
+ * files (`https://dev.foldrun.io/api`, an address since retired), so the same workspace pointed at the
16
17
  * wrong server the day it moved. Now a script reads `$FOLDRUN_API_URL` and an
17
18
  * `apis:` entry writes `base: ${FOLDRUN_API_URL}`.
18
19
  */
@@ -53,11 +53,12 @@ export function hostSafeEnv(from = process.env) {
53
53
  }
54
54
  /**
55
55
  * Where this install's own API answers, for a step to call: `FOLDRUN_API_URL`
56
- * when the operator set it, else `FOLDRUN_PUBLIC_URL` + `/api`. Undefined on a
57
- * laptop with neither.
56
+ * when the operator set it, else the API host (`FOLDRUN_PUBLIC_API_URL`) or
57
+ * the install's own address (`FOLDRUN_PUBLIC_URL`), + `/v1` (23 Nov 2026:
58
+ * every route is /v1). Undefined on a laptop with none.
58
59
  *
59
60
  * A desk that reads its own run history used to write the host into its
60
- * files (`https://dev.foldrun.io/api`), so the same workspace pointed at the
61
+ * files (`https://dev.foldrun.io/api`, an address since retired), so the same workspace pointed at the
61
62
  * wrong server the day it moved. Now a script reads `$FOLDRUN_API_URL` and an
62
63
  * `apis:` entry writes `base: ${FOLDRUN_API_URL}`.
63
64
  */
@@ -65,8 +66,8 @@ export function platformApiUrl(from = process.env) {
65
66
  const explicit = from.FOLDRUN_API_URL?.trim();
66
67
  if (explicit)
67
68
  return explicit.replace(/\/+$/, "");
68
- const origin = from.FOLDRUN_PUBLIC_URL?.trim();
69
- return origin ? `${origin.replace(/\/+$/, "")}/api` : undefined;
69
+ const origin = from.FOLDRUN_PUBLIC_API_URL?.trim() || from.FOLDRUN_PUBLIC_URL?.trim();
70
+ return origin ? `${origin.replace(/\/+$/, "")}/v1` : undefined;
70
71
  }
71
72
  /** The install's own addresses an `apis:` base may name. Not secrets: they
72
73
  * are printed in the prompt as the tool's base URL. */
package/dist/src/mail.js CHANGED
@@ -157,7 +157,7 @@ export function unsubscribeLinks(claim, now = Date.now()) {
157
157
  if (!base)
158
158
  return null;
159
159
  const token = encodeURIComponent(unsubscribeToken(claim, now));
160
- return { page: `${base}/unsubscribe?token=${token}`, oneClick: `${base}/api/unsubscribe?token=${token}` };
160
+ return { page: `${base}/unsubscribe?token=${token}`, oneClick: `${base}/v1/unsubscribe?token=${token}` };
161
161
  }
162
162
  /** The RFC 8058 pair, for a mail whose category may be turned off. */
163
163
  export function unsubscribeHeaders(claim, now = Date.now()) {
@@ -12,6 +12,9 @@ export declare function credentialLine(c: ModelCredential): {
12
12
  type: "info" | "error";
13
13
  text: string;
14
14
  };
15
+ /** Why a step or a call that names its own model endpoint (`provider:`)
16
+ * is refused where a platform admin turned own keys off (models.byok). */
17
+ export declare const OWN_KEYS_OFF = "this platform runs every model call on foldrun's models, so an agent or project cannot name its own model endpoint \u2014 remove `provider:` from the agent or AGENTS.md (a platform admin can allow own keys: setting models.byok)";
15
18
  /** The account vault names the account's own model key lives under. */
16
19
  export declare const ACCOUNT_MODEL_SECRETS: {
17
20
  readonly provider: "FOLDRUN_MODEL_PROVIDER";
@@ -24,9 +27,8 @@ export declare const ACCOUNT_MODEL_SECRETS: {
24
27
  * reader (getSecret without a workspace). */
25
28
  export declare function accountModelBlock(read: (name: string) => string | null): Record<string, unknown> | undefined;
26
29
  /** A Claude login token (`claude setup-token`, sk-ant-oat…), not an API key.
27
- * Anthropic's terms do not let a third-party product run customers on
28
- * claude.ai logins, so on a hosted platform only the operator's own
29
- * accounts may; a customer's key must be an API key. */
30
+ * An account may set one as its model key — its own claude.ai subscription —
31
+ * the same as any provider key. */
30
32
  export declare function isClaudeLoginToken(value: string | null | undefined): boolean;
31
33
  /**
32
34
  * The variables a step's own model call is made with: the credential, the
@@ -60,9 +60,12 @@ export function credentialLine(c) {
60
60
  //
61
61
  // An account brings its own model key without writing a provider: block:
62
62
  // three secrets in the ACCOUNT vault (set from Settings → Models, the API's
63
- // /api/account/model, or `foldrun account model set`). A provider: block at any
63
+ // /v1/account/model, or `foldrun account model set`). A provider: block at any
64
64
  // level still wins; this is what a step falls to when none names one, before
65
65
  // the platform's own credential.
66
+ /** Why a step or a call that names its own model endpoint (`provider:`)
67
+ * is refused where a platform admin turned own keys off (models.byok). */
68
+ export const OWN_KEYS_OFF = "this platform runs every model call on foldrun's models, so an agent or project cannot name its own model endpoint — remove `provider:` from the agent or AGENTS.md (a platform admin can allow own keys: setting models.byok)";
66
69
  /** The account vault names the account's own model key lives under. */
67
70
  export const ACCOUNT_MODEL_SECRETS = {
68
71
  provider: "FOLDRUN_MODEL_PROVIDER",
@@ -90,9 +93,8 @@ export function accountModelBlock(read) {
90
93
  return block;
91
94
  }
92
95
  /** A Claude login token (`claude setup-token`, sk-ant-oat…), not an API key.
93
- * Anthropic's terms do not let a third-party product run customers on
94
- * claude.ai logins, so on a hosted platform only the operator's own
95
- * accounts may; a customer's key must be an API key. */
96
+ * An account may set one as its model key — its own claude.ai subscription —
97
+ * the same as any provider key. */
96
98
  export function isClaudeLoginToken(value) {
97
99
  return typeof value === "string" && /^sk-ant-oat\d*-/.test(value.trim());
98
100
  }
@@ -9,7 +9,7 @@ import { accountDir, workspaceDir, parseProvider, providerEnvFor } from "./store
9
9
  import { readAgentsMd } from "./runner.js";
10
10
  import { getSecret } from "./secrets.js";
11
11
  import { platform, hostUrlProblem } from "./platform.js";
12
- import { accountModelBlock, isClaudeLoginToken } from "./model-credential.js";
12
+ import { accountModelBlock, OWN_KEYS_OFF } from "./model-credential.js";
13
13
  import { providerPreset } from "./providers.js";
14
14
  import { startTranslator, translatorSpecFor } from "./translator.js";
15
15
  import { supplyProviderBlock } from "./model-supply.js";
@@ -32,8 +32,15 @@ export const NO_MODEL_KEY = "no model key: this account runs on its own API key,
32
32
  * it, so a judge or a draft works on any key a run works on (FOL-16).
33
33
  */
34
34
  export function accountModelEnv(tenant, workspace, platformEnv) {
35
- const written = readAgentsMd(workspaceDir(tenant, workspace))?.data?.provider ??
35
+ const writtenBlock = readAgentsMd(workspaceDir(tenant, workspace))?.data?.provider ??
36
36
  readAgentsMd(accountDir(tenant))?.data?.provider;
37
+ // Own keys as the platform admin allows them (models.byok), as a step
38
+ // takes them (runner.ts): off, a written block is refused and the stored
39
+ // key never read.
40
+ const ownKeys = platform.ownModelKeys?.(tenant) ?? true;
41
+ if (writtenBlock && !ownKeys)
42
+ throw new ModelKeyError(OWN_KEYS_OFF, 403);
43
+ const written = writtenBlock;
37
44
  // foldrun's models, the same rung a step takes (runner.ts agentContext):
38
45
  // after the written blocks, before the account's stored key; chosen but
39
46
  // refused fails here, never onto the stored key or the operator's.
@@ -60,7 +67,7 @@ export function accountModelEnv(tenant, workspace, platformEnv) {
60
67
  tenant,
61
68
  };
62
69
  }
63
- const raw = written ?? accountModelBlock((name) => getSecret(tenant, name)?.value ?? null);
70
+ const raw = written ?? (ownKeys ? accountModelBlock((name) => getSecret(tenant, name)?.value ?? null) : undefined);
64
71
  const spec = parseProvider(raw);
65
72
  if (!spec?.baseUrl) {
66
73
  if (!platform.platformKeyAllowed(tenant))
@@ -78,9 +85,6 @@ export function accountModelEnv(tenant, workspace, platformEnv) {
78
85
  const token = sub(spec.token);
79
86
  if (token.includes("${"))
80
87
  throw new ModelKeyError("the provider's token secret is not set — `foldrun secrets` sets it", 422);
81
- if (!platform.platformKeyAllowed(tenant) && isClaudeLoginToken(token)) {
82
- throw new ModelKeyError("model key: a Claude login token (sk-ant-oat…) cannot be used here — use an API key from your provider", 422);
83
- }
84
88
  const headers = Object.fromEntries(Object.entries(spec.headers).map(([k, v]) => [k, sub(v)]));
85
89
  const preset = providerPreset(spec.name);
86
90
  return {
@@ -8,7 +8,7 @@
8
8
  //
9
9
  // The roles:
10
10
  // client an agent reaches Google, Slack, a bank — foldrun holds the token
11
- // server an AI app signs in to /api/mcp — foldrun issues the token
11
+ // server an AI app signs in to /v1/mcp — foldrun issues the token
12
12
  const core = (file, test) => ({ repo: "foldrun-core", file, test });
13
13
  const platform = (file, test) => ({ repo: "foldrun-platform", file, test });
14
14
  const web = (file, test) => ({ repo: "foldrun-web", file, test });
@@ -110,10 +110,10 @@ export const OAUTH_CAPABILITIES = [
110
110
  id: "client.ciba", role: "client", title: "Client-initiated backchannel authentication", spec: "OpenID CIBA",
111
111
  status: "not-needed", note: "No provider an agent needs uses it.",
112
112
  },
113
- // ------------------------------------------------------------ server (/api/mcp)
113
+ // ------------------------------------------------------------ server (/v1/mcp)
114
114
  {
115
115
  id: "server.authorization-code-pkce", role: "server", title: "Authorization code with PKCE (S256)", spec: "OAuth 2.1, MCP authorization",
116
- status: "supported", note: "How claude.ai and other AI apps sign in to /api/mcp.",
116
+ status: "supported", note: "How claude.ai and other AI apps sign in to /v1/mcp.",
117
117
  proof: [web("tests/mcp-oauth.test.ts", "the code: PKCE, once, for its own app and redirect"), web("tests/mcp-sdk-oauth.test.ts", "the MCP SDK: 401 → discovery → registration")],
118
118
  },
119
119
  {
@@ -138,8 +138,8 @@ export const OAUTH_CAPABILITIES = [
138
138
  },
139
139
  {
140
140
  id: "server.resource-indicators", role: "server", title: "Resource indicators", spec: "RFC 8707",
141
- status: "supported", note: "Tokens are bound to /api/mcp.",
142
- proof: [web("tests/mcp-oauth.test.ts", "the access token opens /api/mcp and its tools")],
141
+ status: "supported", note: "Tokens are bound to /v1/mcp.",
142
+ proof: [web("tests/mcp-oauth.test.ts", "the access token opens /v1/mcp and its tools")],
143
143
  },
144
144
  {
145
145
  id: "server.iss-parameter", role: "server", title: "Issuer in the authorization response", spec: "RFC 9207",
@@ -148,7 +148,7 @@ export const OAUTH_CAPABILITIES = [
148
148
  },
149
149
  {
150
150
  id: "server.revocation", role: "server", title: "Revocation endpoint", spec: "RFC 7009",
151
- status: "supported", note: "`POST /api/mcp/oauth/revoke`: an app ends its own connection.",
151
+ status: "supported", note: "`POST /v1/mcp/oauth/revoke`: an app ends its own connection.",
152
152
  proof: [web("tests/mcp-oauth.test.ts", "revocation (RFC 7009): advertised")],
153
153
  },
154
154
  {
@@ -159,6 +159,13 @@ export interface PlatformHooks {
159
159
  * operator's accounts do so; every customer brings their own API key.
160
160
  * Default: yes — a laptop or a self-hosted install is its own operator. */
161
161
  platformKeyAllowed(tenant: string): boolean;
162
+ /** May this account's steps run on a model key or endpoint of its own —
163
+ * the account's stored key (Settings → Models) or a `provider:` block in
164
+ * its files (BYOK)? A platform admin decides, for the whole install
165
+ * (setting models.byok, 22 Nov 2026: off unless turned on). No: a stored
166
+ * key is never used, and a step whose files name a provider: is refused
167
+ * before it starts. Absent: yes — a laptop runs on what it is given. */
168
+ ownModelKeys?(tenant: string): boolean;
162
169
  /** foldrun's models (3 Nov 2026): whether this account chose to run on
163
170
  * the platform's own key for a provider, and whether it can now. Asked
164
171
  * only where no provider: block of the account's own says otherwise.
@@ -18,6 +18,7 @@
18
18
  // It reads the same provider block a run reads, resolved the same way, so a
19
19
  // pass here means a run would reach the same place with the same key.
20
20
  import { accountModelBlock } from "./model-credential.js";
21
+ import { platform } from "./platform.js";
21
22
  import fs from "node:fs";
22
23
  import path from "node:path";
23
24
  import { configMatter } from "./matter.js";
@@ -187,6 +188,10 @@ function frontmatterOf(file) {
187
188
  export function providersInUse(tenant) {
188
189
  const out = [];
189
190
  const seen = new Set();
191
+ // Own keys off on this platform (models.byok): nothing of the account's
192
+ // is used, so nothing is probed (or spent) on its behalf.
193
+ if (!(platform.ownModelKeys?.(tenant) ?? true))
194
+ return out;
190
195
  const add = (raw, workspace, declaredIn) => {
191
196
  const spec = parseProvider(raw);
192
197
  if (!spec || !spec.baseUrl)
@@ -522,7 +522,7 @@ export declare function userAgentDrift(ua: string | undefined, chrome: string |
522
522
  * `check` prints these as warnings and the deploy reports them beside its
523
523
  * outward-gate warnings. `opts.chrome` / `opts.chromium`: the runner image's
524
524
  * Google Chrome and Playwright Chromium versions, when known
525
- * (FOLDRUN_RUNNER_ENGINES on the platform, /api/version from the CLI); an
525
+ * (FOLDRUN_RUNNER_ENGINES on the platform, /v1/version from the CLI); an
526
526
  * engine whose version is unknown is not compared.
527
527
  */
528
528
  export declare function webWarnings(front: Record<string, unknown>, opts?: {
@@ -1151,7 +1151,7 @@ export function userAgentDrift(ua, chrome, where, browser = "Chrome") {
1151
1151
  * `check` prints these as warnings and the deploy reports them beside its
1152
1152
  * outward-gate warnings. `opts.chrome` / `opts.chromium`: the runner image's
1153
1153
  * Google Chrome and Playwright Chromium versions, when known
1154
- * (FOLDRUN_RUNNER_ENGINES on the platform, /api/version from the CLI); an
1154
+ * (FOLDRUN_RUNNER_ENGINES on the platform, /v1/version from the CLI); an
1155
1155
  * engine whose version is unknown is not compared.
1156
1156
  */
1157
1157
  export function webWarnings(front, opts = {}) {
@@ -22,7 +22,7 @@ import { eventUrl } from "./webhook.js";
22
22
  import { runStepInContainer, resolveResources, memoryGiB, heldCores, killRunSandboxes, classDisk } from "./run-container.js";
23
23
  import { readResources, hasOverride, anyMemoryMi } from "./resources.js";
24
24
  import { hostSafeEnv, platformApiUrl } from "./host-env.js";
25
- import { resolveModelCredential, credentialLine, accountModelBlock, isClaudeLoginToken, isModelEnvName, DECLARED_ENV_PREFIX } from "./model-credential.js";
25
+ import { resolveModelCredential, credentialLine, accountModelBlock, isModelEnvName, DECLARED_ENV_PREFIX, OWN_KEYS_OFF } from "./model-credential.js";
26
26
  import { parseJudge } from "./judge-verdict.js";
27
27
  import { validateSchema, describeSchemaErrors, looksLikeSchema } from "./json-schema.js";
28
28
  import { EGRESS_ENV, MODEL_KEY_NAME, addGrant, grantModelKey, hostOf, placeholderNames, proxyModelEnv, unsubstitute } from "./egress.js";
@@ -1303,18 +1303,29 @@ grantsOnly = false) {
1303
1303
  // agent's own block wins over the workspace's, like everything else here.
1304
1304
  // Then the account's own model key (Settings → Models), when it set one:
1305
1305
  // an account that brings its key need not write a block anywhere.
1306
- const fileBlock = front.provider ?? workspaceFrontmatter(agentDir, tenant).provider;
1306
+ const writtenBlock = front.provider ?? workspaceFrontmatter(agentDir, tenant).provider;
1307
+ // Own keys (BYOK) as the platform admin allows them (models.byok): off,
1308
+ // a written provider: block refuses the step and a stored key is never
1309
+ // read — every call goes through foldrun's models.
1310
+ const ownKeys = platform.ownModelKeys?.(tenant) ?? true;
1311
+ const fileBlock = ownKeys ? writtenBlock : undefined;
1307
1312
  // foldrun's models (3 Nov 2026): an account that chose the platform's key
1308
1313
  // for a provider runs on it here, between its written blocks (which still
1309
1314
  // win) and its stored key. Chosen but not to be had now — refused, and
1310
1315
  // the step fails with why (runStep); it never falls to the stored key.
1311
- const supply = fileBlock ? { kind: "none" } : platform.modelSupply?.(tenant) ?? { kind: "none" };
1316
+ const supply = fileBlock
1317
+ ? { kind: "none" }
1318
+ : writtenBlock
1319
+ ? { kind: "refused", reason: OWN_KEYS_OFF }
1320
+ : platform.modelSupply?.(tenant) ?? { kind: "none" };
1312
1321
  const providerBlock = fileBlock ??
1313
1322
  (supply.kind === "foldrun"
1314
1323
  ? supplyProviderBlock(supply.provider, supply.tiers, supply.via)
1315
1324
  : supply.kind === "refused"
1316
1325
  ? undefined
1317
- : accountModelBlock((name) => getSecret(tenant, name)?.value ?? null));
1326
+ : ownKeys
1327
+ ? accountModelBlock((name) => getSecret(tenant, name)?.value ?? null)
1328
+ : undefined);
1318
1329
  let providerEnv = {};
1319
1330
  let providerLabel = null;
1320
1331
  // Secret values pulled into the provider block, name → value. Kept apart
@@ -2458,7 +2469,7 @@ conversation) {
2458
2469
  // Chosen, but not to be had now: failed with why, before a sandbox —
2459
2470
  // never onto the account's stored key or the operator's.
2460
2471
  if (supply.kind === "refused") {
2461
- push("error", `foldrun's models: ${supply.reason} — or switch this account back to its own key (Settings → Models, \`foldrun account model use own\`)`);
2472
+ push("error", platform.ownModelKeys?.(tenant) ?? true ? `foldrun's models: ${supply.reason} — or switch this account back to its own key (Settings → Models, \`foldrun account model use own\`)` : `foldrun's models: ${supply.reason}`);
2462
2473
  step.status = "failed";
2463
2474
  save();
2464
2475
  return;
@@ -2483,7 +2494,6 @@ conversation) {
2483
2494
  // before a sandbox is rented, with what to do about it — not run on the
2484
2495
  // operator's key, and not failed later by a provider.
2485
2496
  if (!platform.platformKeyAllowed(tenant)) {
2486
- const own = Object.values(providerSecrets).concat(Object.values(providerEnv));
2487
2497
  if (primaryOnPlatform) {
2488
2498
  push("error", `no model key: this account runs on its own API key, and none is set. Add one in Settings → Models ` +
2489
2499
  `(or \`foldrun account model set <provider> --key …\`), or write a provider: block in AGENTS.md`);
@@ -2491,12 +2501,6 @@ conversation) {
2491
2501
  save();
2492
2502
  return;
2493
2503
  }
2494
- if (own.some((v) => isClaudeLoginToken(v))) {
2495
- push("error", "model key: a Claude login token (sk-ant-oat…) cannot be used here — use an API key from your provider");
2496
- step.status = "failed";
2497
- save();
2498
- return;
2499
- }
2500
2504
  }
2501
2505
  // A step in core's own Docker container (self-hosting) has no machine
2502
2506
  // login to fall back to: with no credential at all it could only fail at
@@ -59,6 +59,11 @@ export interface ScanOptions {
59
59
  model: string;
60
60
  on: string;
61
61
  } | null;
62
+ /** May this account's files name their own model endpoint (`provider:`)?
63
+ * False where a platform admin turned own keys off (models.byok): each
64
+ * one is config/own-model-key, an error, so the deploy is refused.
65
+ * Absent (the CLI offline, a laptop): yes. */
66
+ ownModelKeys?: boolean;
62
67
  }
63
68
  export declare const OWASP_URL = "https://genai.owasp.org/resource/owasp-top-10-for-agentic-applications-for-2026";
64
69
  export declare const SCAN_RULES: readonly ScanRule[];
package/dist/src/scan.js CHANGED
@@ -260,6 +260,15 @@ export const SCAN_RULES = [
260
260
  "The step still runs, at the nearest level the model has, and the step's log says so. Write the level it has, or choose " +
261
261
  "a provider whose model has the one you want (Settings → Models).",
262
262
  },
263
+ {
264
+ id: "config/own-model-key",
265
+ category: "config",
266
+ level: "error",
267
+ title: "A model endpoint of its own, where this platform runs every call on its own models",
268
+ help: "This platform's admin turned own model keys off (setting models.byok), so every model call goes through foldrun's models. " +
269
+ "An agent's or a project's `provider:` block names an endpoint and key of its own, which would run unmetered. Remove the " +
270
+ "block: the agent then runs on the account's choice in Settings → Models.",
271
+ },
263
272
  {
264
273
  id: "config/output-fitted",
265
274
  category: "config",
@@ -1236,6 +1245,19 @@ export function scanFiles(files, options = {}) {
1236
1245
  // A workspace that names its own provider: does not run on the account's
1237
1246
  // choice, so the account's models say nothing about its efforts.
1238
1247
  const ownWorkspaceProvider = Boolean(workspaceMd && frontOf(workspaceMd.content, "AGENTS.md")?.provider);
1248
+ // Own keys off on this platform (models.byok): every provider: is refused.
1249
+ if (options.ownModelKeys === false) {
1250
+ const lineOf = (content) => {
1251
+ const i = content.split("\n").findIndex((l) => /^provider\s*:/.test(l));
1252
+ return i >= 0 ? i + 1 : 1;
1253
+ };
1254
+ const say = (file, content) => push("config/own-model-key", file, lineOf(content), `config/own-model-key ${file}`, "provider: names a model endpoint of its own, and this platform runs every model call on its own models (own keys are off) — remove it; the agent runs on the account's choice in Settings → Models.");
1255
+ for (const a of agents)
1256
+ if (a.data.provider)
1257
+ say(a.file, files.find((f) => f.path === a.file)?.content ?? "");
1258
+ if (workspaceMd && ownWorkspaceProvider)
1259
+ say(workspaceMd.path, workspaceMd.content);
1260
+ }
1239
1261
  if (options.effortRunsAs && !ownWorkspaceProvider)
1240
1262
  scanEfforts(agents, flows, options.effortRunsAs, push);
1241
1263
  if (options.outputCeiling && !ownWorkspaceProvider)
@@ -340,8 +340,8 @@ on a server, use the HTTP API — every route takes the same API key
340
340
  session, and refuses without one.
341
341
 
342
342
  \`\`\`sh
343
- export FOLDRUN_TOKEN=... FOLDRUN_URL=https://your-server WS=my-workspace
344
- api() { p=$1; shift; curl -sS -H "authorization: Bearer $FOLDRUN_TOKEN" "$FOLDRUN_URL/api/$p" "$@"; }
343
+ export FOLDRUN_TOKEN=... FOLDRUN_URL=https://your-api-server WS=my-workspace
344
+ api() { p=$1; shift; curl -sS -H "authorization: Bearer $FOLDRUN_TOKEN" "$FOLDRUN_URL/v1/$p" "$@"; }
345
345
 
346
346
  api workspaces/$WS/runs # recent runs, newest first
347
347
  api workspaces/$WS/runs/<id> # the full trail of one
@@ -349,7 +349,7 @@ api workspaces/$WS/runs/<id>/stream # follow a live one (SSE)
349
349
  api workspaces/$WS/flows/<flow>/run -X POST # start one
350
350
  \`\`\`
351
351
 
352
- All of it, \`/api/workspaces/<workspace>\` unless noted:
352
+ All of it, \`/v1/workspaces/<workspace>\` unless noted:
353
353
 
354
354
  | Route | Methods | For |
355
355
  |---|---|---|
@@ -385,21 +385,21 @@ All of it, \`/api/workspaces/<workspace>\` unless noted:
385
385
  | \`/check\` | GET | what \`foldrun check\` says about the deployed copy, as findings with rule ids (\`?security=1\`) |
386
386
  | \`/assistant\` | POST | ask the assistant, or have it write agents, flows, tools and skills — from the docs only; proposals come back, nothing is written |
387
387
 
388
- Account-level, outside \`/workspaces\`: \`/api/secrets\`, \`/api/keys\`, \`/api/schedule\`,
389
- \`/api/approvals\`, \`/api/issues\` (what went wrong, open until resolved), \`/api/usage\`, \`/api/library/<kind>\`, \`/api/team\`, \`/api/billing\`,
390
- \`/api/me/notifications\` (what mail you get; a key acts for whoever minted it),
391
- \`/api/me/inbox\` (what waits on you: gates, questions, issues, proposed fixes, your failed runs),
392
- \`/api/mcp\` (this account as MCP tools for an AI app such as Claude Desktop or Cursor — an API key; \`foldrun mcp\` serves the same over stdio, \`foldrun docs mcp\`),
393
- \`/api/account/backups\` (snapshots, restore requests), \`/api/me/onboarding\` (getting started),
394
- \`/api/healthz\` and \`/api/version\` (open), \`/api/changelog\` (release notes)
395
- and \`/api/metrics\` (Prometheus). Outside \`/api\`: \`/a2a/<account>/<ws>/flows/<flow>\`
388
+ Account-level, outside \`/workspaces\`: \`/v1/secrets\`, \`/v1/keys\`, \`/v1/schedule\`,
389
+ \`/v1/approvals\`, \`/v1/issues\` (what went wrong, open until resolved), \`/v1/account/usage\`, \`/v1/library/<kind>\`, \`/v1/team\`, \`/v1/billing\`,
390
+ \`/v1/me/notifications\` (what mail you get; a key acts for whoever minted it),
391
+ \`/v1/me/inbox\` (what waits on you: gates, questions, issues, proposed fixes, your failed runs),
392
+ \`/v1/mcp\` (this account as MCP tools for an AI app such as Claude Desktop or Cursor — an API key; \`foldrun mcp\` serves the same over stdio, \`foldrun docs mcp\`),
393
+ \`/v1/account/backups\` (snapshots, restore requests), \`/v1/me/onboarding\` (getting started),
394
+ \`/v1/healthz\` and \`/v1/version\` (open), \`/v1/changelog\` (release notes)
395
+ and \`/v1/metrics\` (Prometheus). Outside \`/v1\`: \`/a2a/<account>/<ws>/flows/<flow>\`
396
396
  (a published flow's agent card and A2A 1.0 JSON-RPC endpoint — an A2A key only, \`foldrun docs a2a\`).
397
397
 
398
398
  Every call answers — and the CLI sends — \`Foldrun-Version: YYYY-MM-DD\` (dated API
399
399
  versions; an account pin in Settings → API keys → API), \`X-RateLimit-*\` headers (a \`429\`
400
400
  carries \`Retry-After\`), and writes that start work take an \`Idempotency-Key\`
401
401
  (a retry with the same key replays the first answer). The whole surface as
402
- OpenAPI 3.1: \`/api/openapi.json\` (open), or \`foldrun api spec --out openapi.json\`.
402
+ OpenAPI 3.1: \`/v1/openapi.json\` (open), or \`foldrun api spec --out openapi.json\`.
403
403
 
404
404
  Debugging a failed run is usually: \`runs\` to find it, \`runs/<id>\` to read which
405
405
  step failed and what it cost, fix the markdown, \`deploy\`, then \`rerun\`.
@@ -504,7 +504,7 @@ secrets: [CRM_TOKEN] # keys the agent uses itself; a tool's own come with
504
504
  limits: {web.search: 40, crm: 20, calls: 300} # per step; a call past a limit is refused, never run
505
505
  network: [api.example.com] # sites its sandbox may reach, added to the trusted list; open | trusted | none
506
506
  timezone: Australia/Sydney # the calendar it works to — IANA name or UTC+10
507
- provider: {} # BYOK for this agent; account-wide: \`foldrun account model set\`
507
+ provider: {} # BYOK for this agent, where the platform allows own keys (models.byok); account-wide: \`foldrun account model set\`
508
508
  permissionMode: plan # plan first, act once approved
509
509
  runtime: # only if scripts need packages
510
510
  packages: [requests]
package/dist/src/store.js CHANGED
@@ -2515,7 +2515,7 @@ export function writeWorkspaceFile(tenant, workspace, rel, content, meta = {}) {
2515
2515
  // recursive, so until 30 Oct 2026 a write to a name that did not exist
2516
2516
  // created that workspace — with workspace:write alone, past the
2517
2517
  // workspace:manage role and the plan's workspace count that POST
2518
- // /api/workspaces, deploy and import apply. Those create through
2518
+ // /v1/workspaces, deploy and import apply. Those create through
2519
2519
  // saveWorkspace / applyImport, not through here.
2520
2520
  if (!fs.existsSync(dir))
2521
2521
  throw Object.assign(new Error(`project ${workspace} not found`), { status: 404 });
@@ -75,7 +75,7 @@ export function webhookToken(tenant, workspace, flow) {
75
75
  return crypto.createHmac("sha256", installKey()).update(identity).digest("hex").slice(0, 32);
76
76
  }
77
77
  export function webhookPath(tenant, workspace, flow) {
78
- return `/api/hooks/${tenant}/${workspace}/${flow}?token=${webhookToken(tenant, workspace, flow)}`;
78
+ return `/v1/hooks/${tenant}/${workspace}/${flow}?token=${webhookToken(tenant, workspace, flow)}`;
79
79
  }
80
80
  // ---------- one-click approval ----------
81
81
  /**
@@ -119,7 +119,7 @@ export function eventToken(tenant, workspace, runId, gate) {
119
119
  * knows its origin, a path otherwise. With `gate`, that step's own URL
120
120
  * (`&step=<index>`); the route finds the park's moment on the record. */
121
121
  export function eventUrl(tenant, workspace, runId, gate) {
122
- const p = `/api/events/${tenant}/${workspace}/${runId}?token=${eventToken(tenant, workspace, runId, gate)}${gate ? `&step=${gate.step}` : ""}`;
122
+ const p = `/v1/events/${tenant}/${workspace}/${runId}?token=${eventToken(tenant, workspace, runId, gate)}${gate ? `&step=${gate.step}` : ""}`;
123
123
  const base = publicUrl();
124
124
  return base ? `${base}${p}` : p;
125
125
  }
@@ -31,7 +31,11 @@ export function checkOptions(tenant, workspace) {
31
31
  // AGENTS.md, or the older project.md, as the runner reads it (Codex review).
32
32
  const accountKeys = readAgentsMdKeys(accountDir(tenant));
33
33
  const accountNetwork = accountKeys.network;
34
- return { outwardTools, accountNetwork, ...effortCheck(tenant, accountKeys.provider) };
34
+ // Own keys as the platform admin set them (models.byok): off, a provider:
35
+ // in these files is an error, so the deploy, a save and the Checks page
36
+ // all refuse it as the runner would.
37
+ const ownModelKeys = platform.ownModelKeys?.(tenant) ?? true;
38
+ return { outwardTools, accountNetwork, ...effortCheck(tenant, accountKeys.provider), ...(ownModelKeys ? {} : { ownModelKeys: false }) };
35
39
  }
36
40
  /**
37
41
  * What an effort level runs at on the account's choice, for
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foldrun/core",
3
- "version": "24.12.0",
3
+ "version": "25.0.0",
4
4
  "description": "Agents are just folders. The format, the runner, the checks.",
5
5
  "license": "FSL-1.1-ALv2",
6
6
  "type": "module",
package/src/approvals.ts CHANGED
@@ -107,7 +107,7 @@ export function approveLinkPath(
107
107
  runId: string,
108
108
  link: { step: number; expiresAt: number; approver?: string | null },
109
109
  ): string {
110
- return `/api/approve/${tenant}/${workspace}/${runId}?token=${approveLinkToken(tenant, workspace, runId, link)}`;
110
+ return `/v1/approve/${tenant}/${workspace}/${runId}?token=${approveLinkToken(tenant, workspace, runId, link)}`;
111
111
  }
112
112
 
113
113
  const same = (a: string, b: string) => a.length === b.length && crypto.timingSafeEqual(Buffer.from(a), Buffer.from(b));
package/src/confine.ts CHANGED
@@ -480,7 +480,7 @@ const PROTECTED_BASH: { re: RegExp; writeOnly: boolean; reason: string }[] = [
480
480
  * A web address, which names a place on a server rather than in the workspace.
481
481
  *
482
482
  * The protected-path patterns match a bare `runs/`, so an agent calling the
483
- * platform's own API — `curl https://…/api/workspaces/x/runs/<id>` — was told
483
+ * platform's own API — `curl https://…/v1/workspaces/x/runs/<id>` — was told
484
484
  * it was reading the run journal. The weekly retros read their week through
485
485
  * that API and were refused on 9 Oct 2026. Only http(s): a `file://` URL is a
486
486
  * path, and stays checked.
package/src/deploy.ts CHANGED
@@ -57,6 +57,7 @@ import { languageProblem } from "./language.ts";
57
57
  import { localeProblems } from "./locale.ts";
58
58
  import { entriesNoFollow } from "./paths.ts";
59
59
  import { filterIgnored, findingFingerprint, ruleForWhere, scanFiles, scanRule, STRICT_FRONTMATTER_PATH, type ScanFinding, type ScanOptions } from "./scan.ts";
60
+ import { platform } from "./platform.ts";
60
61
 
61
62
  /** Directories a deploy never reads out of a source tree. */
62
63
  // `.cache` is what a run's tools leave in an agent's folder (HOME is that
@@ -372,6 +373,17 @@ function blockersFor(tenant: string, given: DeployFile[]): DeployIssue[] {
372
373
  return deployBlockers(files, mode, { accountNetwork: account.network, outwardTools });
373
374
  }
374
375
 
376
+ /** Own keys off on this platform (models.byok, 22 Nov 2026): every
377
+ * `provider:` in the files is a refusal — nothing deploys that would run on
378
+ * an endpoint the platform does not meter. Nothing where they are allowed. */
379
+ export function ownKeyBlockers(tenant: string, files: DeployFile[]): DeployIssue[] {
380
+ if (platform.ownModelKeys?.(tenant) ?? true) return [];
381
+ return scanFiles(files, { only: ["config/own-model-key"], ownModelKeys: false }).map((f) => ({
382
+ where: `${f.file}${f.line ? `:${f.line}` : ""}`,
383
+ message: `${f.message} [${f.rule}]`,
384
+ }));
385
+ }
386
+
375
387
  /** The findings `mode` turns into refusals, as deploy issues. */
376
388
  export function deployBlockers(files: DeployFile[], mode: DeployBlockMode, options: ScanOptions = {}): DeployIssue[] {
377
389
  if (mode === "none") return [];
@@ -783,7 +795,7 @@ export function planDeploy(tenant: string, workspace: string, files: DeployFile[
783
795
  // deploy_block: (FOL-58) turns the scanner's findings into refusals —
784
796
  // scanned with what the Checks page passes too: the account's network:
785
797
  // and the library's outward tools (Codex review).
786
- issues: [...deployIssues(files), ...blockersFor(tenant, files)],
798
+ issues: [...deployIssues(files), ...blockersFor(tenant, files), ...ownKeyBlockers(tenant, files)],
787
799
  warnings: deployWarnings(files),
788
800
  blockedBy: runsInFlight(tenant, workspace),
789
801
  };
package/src/host-env.ts CHANGED
@@ -57,19 +57,20 @@ export function hostSafeEnv(from: NodeJS.ProcessEnv = process.env): NodeJS.Proce
57
57
 
58
58
  /**
59
59
  * Where this install's own API answers, for a step to call: `FOLDRUN_API_URL`
60
- * when the operator set it, else `FOLDRUN_PUBLIC_URL` + `/api`. Undefined on a
61
- * laptop with neither.
60
+ * when the operator set it, else the API host (`FOLDRUN_PUBLIC_API_URL`) or
61
+ * the install's own address (`FOLDRUN_PUBLIC_URL`), + `/v1` (23 Nov 2026:
62
+ * every route is /v1). Undefined on a laptop with none.
62
63
  *
63
64
  * A desk that reads its own run history used to write the host into its
64
- * files (`https://dev.foldrun.io/api`), so the same workspace pointed at the
65
+ * files (`https://dev.foldrun.io/api`, an address since retired), so the same workspace pointed at the
65
66
  * wrong server the day it moved. Now a script reads `$FOLDRUN_API_URL` and an
66
67
  * `apis:` entry writes `base: ${FOLDRUN_API_URL}`.
67
68
  */
68
69
  export function platformApiUrl(from: NodeJS.ProcessEnv = process.env): string | undefined {
69
70
  const explicit = from.FOLDRUN_API_URL?.trim();
70
71
  if (explicit) return explicit.replace(/\/+$/, "");
71
- const origin = from.FOLDRUN_PUBLIC_URL?.trim();
72
- return origin ? `${origin.replace(/\/+$/, "")}/api` : undefined;
72
+ const origin = from.FOLDRUN_PUBLIC_API_URL?.trim() || from.FOLDRUN_PUBLIC_URL?.trim();
73
+ return origin ? `${origin.replace(/\/+$/, "")}/v1` : undefined;
73
74
  }
74
75
 
75
76
  /** The install's own addresses an `apis:` base may name. Not secrets: they
package/src/mail.ts CHANGED
@@ -197,7 +197,7 @@ export function unsubscribeLinks(claim: Omit<UnsubscribeClaim, "expiresAt">, now
197
197
  const base = publicUrl();
198
198
  if (!base) return null;
199
199
  const token = encodeURIComponent(unsubscribeToken(claim, now));
200
- return { page: `${base}/unsubscribe?token=${token}`, oneClick: `${base}/api/unsubscribe?token=${token}` };
200
+ return { page: `${base}/unsubscribe?token=${token}`, oneClick: `${base}/v1/unsubscribe?token=${token}` };
201
201
  }
202
202
 
203
203
  /** The RFC 8058 pair, for a mail whose category may be turned off. */
@@ -75,10 +75,15 @@ export function credentialLine(c: ModelCredential): { type: "info" | "error"; te
75
75
  //
76
76
  // An account brings its own model key without writing a provider: block:
77
77
  // three secrets in the ACCOUNT vault (set from Settings → Models, the API's
78
- // /api/account/model, or `foldrun account model set`). A provider: block at any
78
+ // /v1/account/model, or `foldrun account model set`). A provider: block at any
79
79
  // level still wins; this is what a step falls to when none names one, before
80
80
  // the platform's own credential.
81
81
 
82
+ /** Why a step or a call that names its own model endpoint (`provider:`)
83
+ * is refused where a platform admin turned own keys off (models.byok). */
84
+ export const OWN_KEYS_OFF =
85
+ "this platform runs every model call on foldrun's models, so an agent or project cannot name its own model endpoint — remove `provider:` from the agent or AGENTS.md (a platform admin can allow own keys: setting models.byok)";
86
+
82
87
  /** The account vault names the account's own model key lives under. */
83
88
  export const ACCOUNT_MODEL_SECRETS = {
84
89
  provider: "FOLDRUN_MODEL_PROVIDER",
@@ -104,9 +109,8 @@ export function accountModelBlock(read: (name: string) => string | null): Record
104
109
  }
105
110
 
106
111
  /** A Claude login token (`claude setup-token`, sk-ant-oat…), not an API key.
107
- * Anthropic's terms do not let a third-party product run customers on
108
- * claude.ai logins, so on a hosted platform only the operator's own
109
- * accounts may; a customer's key must be an API key. */
112
+ * An account may set one as its model key — its own claude.ai subscription —
113
+ * the same as any provider key. */
110
114
  export function isClaudeLoginToken(value: string | null | undefined): boolean {
111
115
  return typeof value === "string" && /^sk-ant-oat\d*-/.test(value.trim());
112
116
  }
package/src/model-env.ts CHANGED
@@ -10,7 +10,7 @@ import { accountDir, workspaceDir, parseProvider, providerEnvFor } from "./store
10
10
  import { readAgentsMd } from "./runner.ts";
11
11
  import { getSecret } from "./secrets.ts";
12
12
  import { platform, hostUrlProblem } from "./platform.ts";
13
- import { accountModelBlock, isClaudeLoginToken } from "./model-credential.ts";
13
+ import { accountModelBlock, OWN_KEYS_OFF } from "./model-credential.ts";
14
14
  import { providerPreset } from "./providers.ts";
15
15
  import { startTranslator, translatorSpecFor, type TranslatorSpec } from "./translator.ts";
16
16
  import { supplyProviderBlock, type SupplyAnswer } from "./model-supply.ts";
@@ -50,9 +50,15 @@ export function accountModelEnv(
50
50
  translator: TranslatorSpec | null;
51
51
  tenant?: string;
52
52
  } {
53
- const written =
53
+ const writtenBlock =
54
54
  (readAgentsMd(workspaceDir(tenant, workspace))?.data?.provider as Record<string, unknown> | undefined) ??
55
55
  (readAgentsMd(accountDir(tenant))?.data?.provider as Record<string, unknown> | undefined);
56
+ // Own keys as the platform admin allows them (models.byok), as a step
57
+ // takes them (runner.ts): off, a written block is refused and the stored
58
+ // key never read.
59
+ const ownKeys = platform.ownModelKeys?.(tenant) ?? true;
60
+ if (writtenBlock && !ownKeys) throw new ModelKeyError(OWN_KEYS_OFF, 403);
61
+ const written = writtenBlock;
56
62
  // foldrun's models, the same rung a step takes (runner.ts agentContext):
57
63
  // after the written blocks, before the account's stored key; chosen but
58
64
  // refused fails here, never onto the stored key or the operator's.
@@ -78,7 +84,7 @@ export function accountModelEnv(
78
84
  tenant,
79
85
  };
80
86
  }
81
- const raw = written ?? accountModelBlock((name) => getSecret(tenant, name)?.value ?? null);
87
+ const raw = written ?? (ownKeys ? accountModelBlock((name) => getSecret(tenant, name)?.value ?? null) : undefined);
82
88
  const spec = parseProvider(raw);
83
89
  if (!spec?.baseUrl) {
84
90
  if (!platform.platformKeyAllowed(tenant)) throw new ModelKeyError(NO_MODEL_KEY);
@@ -94,9 +100,6 @@ export function accountModelEnv(
94
100
  text.replace(/\$\{([A-Z][A-Z0-9_]*)\}/g, (whole, name) => getSecret(tenant, name, workspace)?.value ?? whole);
95
101
  const token = sub(spec.token);
96
102
  if (token.includes("${")) throw new ModelKeyError("the provider's token secret is not set — `foldrun secrets` sets it", 422);
97
- if (!platform.platformKeyAllowed(tenant) && isClaudeLoginToken(token)) {
98
- throw new ModelKeyError("model key: a Claude login token (sk-ant-oat…) cannot be used here — use an API key from your provider", 422);
99
- }
100
103
  const headers = Object.fromEntries(Object.entries(spec.headers).map(([k, v]) => [k, sub(v)]));
101
104
  const preset = providerPreset(spec.name);
102
105
  return {
@@ -8,7 +8,7 @@
8
8
  //
9
9
  // The roles:
10
10
  // client an agent reaches Google, Slack, a bank — foldrun holds the token
11
- // server an AI app signs in to /api/mcp — foldrun issues the token
11
+ // server an AI app signs in to /v1/mcp — foldrun issues the token
12
12
 
13
13
  export type OAuthRole = "client" | "server";
14
14
  export type OAuthStatus = "supported" | "planned" | "refused" | "not-needed";
@@ -136,10 +136,10 @@ export const OAUTH_CAPABILITIES: OAuthCapability[] = [
136
136
  id: "client.ciba", role: "client", title: "Client-initiated backchannel authentication", spec: "OpenID CIBA",
137
137
  status: "not-needed", note: "No provider an agent needs uses it.",
138
138
  },
139
- // ------------------------------------------------------------ server (/api/mcp)
139
+ // ------------------------------------------------------------ server (/v1/mcp)
140
140
  {
141
141
  id: "server.authorization-code-pkce", role: "server", title: "Authorization code with PKCE (S256)", spec: "OAuth 2.1, MCP authorization",
142
- status: "supported", note: "How claude.ai and other AI apps sign in to /api/mcp.",
142
+ status: "supported", note: "How claude.ai and other AI apps sign in to /v1/mcp.",
143
143
  proof: [web("tests/mcp-oauth.test.ts", "the code: PKCE, once, for its own app and redirect"), web("tests/mcp-sdk-oauth.test.ts", "the MCP SDK: 401 → discovery → registration")],
144
144
  },
145
145
  {
@@ -164,8 +164,8 @@ export const OAUTH_CAPABILITIES: OAuthCapability[] = [
164
164
  },
165
165
  {
166
166
  id: "server.resource-indicators", role: "server", title: "Resource indicators", spec: "RFC 8707",
167
- status: "supported", note: "Tokens are bound to /api/mcp.",
168
- proof: [web("tests/mcp-oauth.test.ts", "the access token opens /api/mcp and its tools")],
167
+ status: "supported", note: "Tokens are bound to /v1/mcp.",
168
+ proof: [web("tests/mcp-oauth.test.ts", "the access token opens /v1/mcp and its tools")],
169
169
  },
170
170
  {
171
171
  id: "server.iss-parameter", role: "server", title: "Issuer in the authorization response", spec: "RFC 9207",
@@ -174,7 +174,7 @@ export const OAUTH_CAPABILITIES: OAuthCapability[] = [
174
174
  },
175
175
  {
176
176
  id: "server.revocation", role: "server", title: "Revocation endpoint", spec: "RFC 7009",
177
- status: "supported", note: "`POST /api/mcp/oauth/revoke`: an app ends its own connection.",
177
+ status: "supported", note: "`POST /v1/mcp/oauth/revoke`: an app ends its own connection.",
178
178
  proof: [web("tests/mcp-oauth.test.ts", "revocation (RFC 7009): advertised")],
179
179
  },
180
180
  {
package/src/platform.ts CHANGED
@@ -165,6 +165,13 @@ export interface PlatformHooks {
165
165
  * operator's accounts do so; every customer brings their own API key.
166
166
  * Default: yes — a laptop or a self-hosted install is its own operator. */
167
167
  platformKeyAllowed(tenant: string): boolean;
168
+ /** May this account's steps run on a model key or endpoint of its own —
169
+ * the account's stored key (Settings → Models) or a `provider:` block in
170
+ * its files (BYOK)? A platform admin decides, for the whole install
171
+ * (setting models.byok, 22 Nov 2026: off unless turned on). No: a stored
172
+ * key is never used, and a step whose files name a provider: is refused
173
+ * before it starts. Absent: yes — a laptop runs on what it is given. */
174
+ ownModelKeys?(tenant: string): boolean;
168
175
  /** foldrun's models (3 Nov 2026): whether this account chose to run on
169
176
  * the platform's own key for a provider, and whether it can now. Asked
170
177
  * only where no provider: block of the account's own says otherwise.
@@ -19,6 +19,7 @@
19
19
  // pass here means a run would reach the same place with the same key.
20
20
 
21
21
  import { accountModelBlock } from "./model-credential.ts";
22
+ import { platform } from "./platform.ts";
22
23
  import fs from "node:fs";
23
24
  import path from "node:path";
24
25
  import { configMatter } from "./matter.ts";
@@ -224,6 +225,9 @@ function frontmatterOf(file: string): Record<string, unknown> {
224
225
  export function providersInUse(tenant: string): ProviderInUse[] {
225
226
  const out: ProviderInUse[] = [];
226
227
  const seen = new Set<string>();
228
+ // Own keys off on this platform (models.byok): nothing of the account's
229
+ // is used, so nothing is probed (or spent) on its behalf.
230
+ if (!(platform.ownModelKeys?.(tenant) ?? true)) return out;
227
231
 
228
232
  const add = (raw: unknown, workspace: string | null, declaredIn: string) => {
229
233
  const spec = parseProvider(raw);
package/src/providers.ts CHANGED
@@ -1470,7 +1470,7 @@ export function userAgentDrift(ua: string | undefined, chrome: string | null | u
1470
1470
  * `check` prints these as warnings and the deploy reports them beside its
1471
1471
  * outward-gate warnings. `opts.chrome` / `opts.chromium`: the runner image's
1472
1472
  * Google Chrome and Playwright Chromium versions, when known
1473
- * (FOLDRUN_RUNNER_ENGINES on the platform, /api/version from the CLI); an
1473
+ * (FOLDRUN_RUNNER_ENGINES on the platform, /v1/version from the CLI); an
1474
1474
  * engine whose version is unknown is not compared.
1475
1475
  */
1476
1476
  export function webWarnings(front: Record<string, unknown>, opts: { chrome?: string | null; chromium?: string | null } = {}): string[] {
package/src/runner.ts CHANGED
@@ -24,7 +24,7 @@ import { eventUrl } from "./webhook.ts";
24
24
  import { runStepInContainer, resolveResources, memoryGiB, heldCores, killRunSandboxes, classDisk, type StepTiming } from "./run-container.ts";
25
25
  import { readResources, hasOverride, anyMemoryMi } from "./resources.ts";
26
26
  import { hostSafeEnv, platformApiUrl } from "./host-env.ts";
27
- import { resolveModelCredential, credentialLine, accountModelBlock, isClaudeLoginToken, isModelEnvName, DECLARED_ENV_PREFIX } from "./model-credential.ts";
27
+ import { resolveModelCredential, credentialLine, accountModelBlock, isModelEnvName, DECLARED_ENV_PREFIX, OWN_KEYS_OFF } from "./model-credential.ts";
28
28
  import { parseJudge } from "./judge-verdict.ts";
29
29
  import { validateSchema, describeSchemaErrors, looksLikeSchema } from "./json-schema.ts";
30
30
  import { EGRESS_ENV, MODEL_KEY_NAME, addGrant, grantModelKey, hostOf, placeholderNames, proxyModelEnv, unsubstitute, type EgressGrant } from "./egress.ts";
@@ -1453,20 +1453,31 @@ export function agentContext(
1453
1453
  // agent's own block wins over the workspace's, like everything else here.
1454
1454
  // Then the account's own model key (Settings → Models), when it set one:
1455
1455
  // an account that brings its key need not write a block anywhere.
1456
- const fileBlock =
1456
+ const writtenBlock =
1457
1457
  (front.provider as Record<string, unknown> | undefined) ?? workspaceFrontmatter(agentDir, tenant).provider;
1458
+ // Own keys (BYOK) as the platform admin allows them (models.byok): off,
1459
+ // a written provider: block refuses the step and a stored key is never
1460
+ // read — every call goes through foldrun's models.
1461
+ const ownKeys = platform.ownModelKeys?.(tenant) ?? true;
1462
+ const fileBlock = ownKeys ? writtenBlock : undefined;
1458
1463
  // foldrun's models (3 Nov 2026): an account that chose the platform's key
1459
1464
  // for a provider runs on it here, between its written blocks (which still
1460
1465
  // win) and its stored key. Chosen but not to be had now — refused, and
1461
1466
  // the step fails with why (runStep); it never falls to the stored key.
1462
- const supply: SupplyAnswer = fileBlock ? { kind: "none" } : platform.modelSupply?.(tenant) ?? { kind: "none" };
1467
+ const supply: SupplyAnswer = fileBlock
1468
+ ? { kind: "none" }
1469
+ : writtenBlock
1470
+ ? { kind: "refused", reason: OWN_KEYS_OFF }
1471
+ : platform.modelSupply?.(tenant) ?? { kind: "none" };
1463
1472
  const providerBlock =
1464
1473
  fileBlock ??
1465
1474
  (supply.kind === "foldrun"
1466
1475
  ? supplyProviderBlock(supply.provider, supply.tiers, supply.via)
1467
1476
  : supply.kind === "refused"
1468
1477
  ? undefined
1469
- : accountModelBlock((name) => getSecret(tenant, name)?.value ?? null));
1478
+ : ownKeys
1479
+ ? accountModelBlock((name) => getSecret(tenant, name)?.value ?? null)
1480
+ : undefined);
1470
1481
  let providerEnv: Record<string, string> = {};
1471
1482
  let providerLabel: string | null = null;
1472
1483
  // Secret values pulled into the provider block, name → value. Kept apart
@@ -2658,7 +2669,7 @@ async function runStepBody(
2658
2669
  // Chosen, but not to be had now: failed with why, before a sandbox —
2659
2670
  // never onto the account's stored key or the operator's.
2660
2671
  if (supply.kind === "refused") {
2661
- push("error", `foldrun's models: ${supply.reason} — or switch this account back to its own key (Settings → Models, \`foldrun account model use own\`)`);
2672
+ push("error", platform.ownModelKeys?.(tenant) ?? true ? `foldrun's models: ${supply.reason} — or switch this account back to its own key (Settings → Models, \`foldrun account model use own\`)` : `foldrun's models: ${supply.reason}`);
2662
2673
  step.status = "failed";
2663
2674
  save();
2664
2675
  return;
@@ -2683,7 +2694,6 @@ async function runStepBody(
2683
2694
  // before a sandbox is rented, with what to do about it — not run on the
2684
2695
  // operator's key, and not failed later by a provider.
2685
2696
  if (!platform.platformKeyAllowed(tenant)) {
2686
- const own = Object.values(providerSecrets).concat(Object.values(providerEnv));
2687
2697
  if (primaryOnPlatform) {
2688
2698
  push(
2689
2699
  "error",
@@ -2694,12 +2704,6 @@ async function runStepBody(
2694
2704
  save();
2695
2705
  return;
2696
2706
  }
2697
- if (own.some((v) => isClaudeLoginToken(v))) {
2698
- push("error", "model key: a Claude login token (sk-ant-oat…) cannot be used here — use an API key from your provider");
2699
- step.status = "failed";
2700
- save();
2701
- return;
2702
- }
2703
2707
  }
2704
2708
  // A step in core's own Docker container (self-hosting) has no machine
2705
2709
  // login to fall back to: with no credential at all it could only fail at
package/src/scan.ts CHANGED
@@ -95,6 +95,11 @@ export interface ScanOptions {
95
95
  * (a `model:` word or id) — the price list's ceiling on foldrun's
96
96
  * models — or null when that is not known here. */
97
97
  outputCeiling?: (model: string) => { ceiling: number; model: string; on: string } | null;
98
+ /** May this account's files name their own model endpoint (`provider:`)?
99
+ * False where a platform admin turned own keys off (models.byok): each
100
+ * one is config/own-model-key, an error, so the deploy is refused.
101
+ * Absent (the CLI offline, a laptop): yes. */
102
+ ownModelKeys?: boolean;
98
103
  }
99
104
 
100
105
  export const OWASP_URL = "https://genai.owasp.org/resource/owasp-top-10-for-agentic-applications-for-2026";
@@ -343,6 +348,16 @@ export const SCAN_RULES: readonly ScanRule[] = [
343
348
  "The step still runs, at the nearest level the model has, and the step's log says so. Write the level it has, or choose " +
344
349
  "a provider whose model has the one you want (Settings → Models).",
345
350
  },
351
+ {
352
+ id: "config/own-model-key",
353
+ category: "config",
354
+ level: "error",
355
+ title: "A model endpoint of its own, where this platform runs every call on its own models",
356
+ help:
357
+ "This platform's admin turned own model keys off (setting models.byok), so every model call goes through foldrun's models. " +
358
+ "An agent's or a project's `provider:` block names an endpoint and key of its own, which would run unmetered. Remove the " +
359
+ "block: the agent then runs on the account's choice in Settings → Models.",
360
+ },
346
361
  {
347
362
  id: "config/output-fitted",
348
363
  category: "config",
@@ -1368,6 +1383,17 @@ export function scanFiles(files: ScanFile[], options: ScanOptions = {}): ScanFin
1368
1383
  // A workspace that names its own provider: does not run on the account's
1369
1384
  // choice, so the account's models say nothing about its efforts.
1370
1385
  const ownWorkspaceProvider = Boolean(workspaceMd && frontOf(workspaceMd.content, "AGENTS.md")?.provider);
1386
+ // Own keys off on this platform (models.byok): every provider: is refused.
1387
+ if (options.ownModelKeys === false) {
1388
+ const lineOf = (content: string) => {
1389
+ const i = content.split("\n").findIndex((l) => /^provider\s*:/.test(l));
1390
+ return i >= 0 ? i + 1 : 1;
1391
+ };
1392
+ const say = (file: string, content: string) =>
1393
+ push("config/own-model-key", file, lineOf(content), `config/own-model-key ${file}`, "provider: names a model endpoint of its own, and this platform runs every model call on its own models (own keys are off) — remove it; the agent runs on the account's choice in Settings → Models.");
1394
+ for (const a of agents) if (a.data.provider) say(a.file, files.find((f) => f.path === a.file)?.content ?? "");
1395
+ if (workspaceMd && ownWorkspaceProvider) say(workspaceMd.path, workspaceMd.content);
1396
+ }
1371
1397
  if (options.effortRunsAs && !ownWorkspaceProvider) scanEfforts(agents, flows, options.effortRunsAs, push);
1372
1398
  if (options.outputCeiling && !ownWorkspaceProvider) scanOutputs(agents, flows, options.outputCeiling, push);
1373
1399
  for (const m of more.values()) {
package/src/starter.ts CHANGED
@@ -356,8 +356,8 @@ on a server, use the HTTP API — every route takes the same API key
356
356
  session, and refuses without one.
357
357
 
358
358
  \`\`\`sh
359
- export FOLDRUN_TOKEN=... FOLDRUN_URL=https://your-server WS=my-workspace
360
- api() { p=$1; shift; curl -sS -H "authorization: Bearer $FOLDRUN_TOKEN" "$FOLDRUN_URL/api/$p" "$@"; }
359
+ export FOLDRUN_TOKEN=... FOLDRUN_URL=https://your-api-server WS=my-workspace
360
+ api() { p=$1; shift; curl -sS -H "authorization: Bearer $FOLDRUN_TOKEN" "$FOLDRUN_URL/v1/$p" "$@"; }
361
361
 
362
362
  api workspaces/$WS/runs # recent runs, newest first
363
363
  api workspaces/$WS/runs/<id> # the full trail of one
@@ -365,7 +365,7 @@ api workspaces/$WS/runs/<id>/stream # follow a live one (SSE)
365
365
  api workspaces/$WS/flows/<flow>/run -X POST # start one
366
366
  \`\`\`
367
367
 
368
- All of it, \`/api/workspaces/<workspace>\` unless noted:
368
+ All of it, \`/v1/workspaces/<workspace>\` unless noted:
369
369
 
370
370
  | Route | Methods | For |
371
371
  |---|---|---|
@@ -401,21 +401,21 @@ All of it, \`/api/workspaces/<workspace>\` unless noted:
401
401
  | \`/check\` | GET | what \`foldrun check\` says about the deployed copy, as findings with rule ids (\`?security=1\`) |
402
402
  | \`/assistant\` | POST | ask the assistant, or have it write agents, flows, tools and skills — from the docs only; proposals come back, nothing is written |
403
403
 
404
- Account-level, outside \`/workspaces\`: \`/api/secrets\`, \`/api/keys\`, \`/api/schedule\`,
405
- \`/api/approvals\`, \`/api/issues\` (what went wrong, open until resolved), \`/api/usage\`, \`/api/library/<kind>\`, \`/api/team\`, \`/api/billing\`,
406
- \`/api/me/notifications\` (what mail you get; a key acts for whoever minted it),
407
- \`/api/me/inbox\` (what waits on you: gates, questions, issues, proposed fixes, your failed runs),
408
- \`/api/mcp\` (this account as MCP tools for an AI app such as Claude Desktop or Cursor — an API key; \`foldrun mcp\` serves the same over stdio, \`foldrun docs mcp\`),
409
- \`/api/account/backups\` (snapshots, restore requests), \`/api/me/onboarding\` (getting started),
410
- \`/api/healthz\` and \`/api/version\` (open), \`/api/changelog\` (release notes)
411
- and \`/api/metrics\` (Prometheus). Outside \`/api\`: \`/a2a/<account>/<ws>/flows/<flow>\`
404
+ Account-level, outside \`/workspaces\`: \`/v1/secrets\`, \`/v1/keys\`, \`/v1/schedule\`,
405
+ \`/v1/approvals\`, \`/v1/issues\` (what went wrong, open until resolved), \`/v1/account/usage\`, \`/v1/library/<kind>\`, \`/v1/team\`, \`/v1/billing\`,
406
+ \`/v1/me/notifications\` (what mail you get; a key acts for whoever minted it),
407
+ \`/v1/me/inbox\` (what waits on you: gates, questions, issues, proposed fixes, your failed runs),
408
+ \`/v1/mcp\` (this account as MCP tools for an AI app such as Claude Desktop or Cursor — an API key; \`foldrun mcp\` serves the same over stdio, \`foldrun docs mcp\`),
409
+ \`/v1/account/backups\` (snapshots, restore requests), \`/v1/me/onboarding\` (getting started),
410
+ \`/v1/healthz\` and \`/v1/version\` (open), \`/v1/changelog\` (release notes)
411
+ and \`/v1/metrics\` (Prometheus). Outside \`/v1\`: \`/a2a/<account>/<ws>/flows/<flow>\`
412
412
  (a published flow's agent card and A2A 1.0 JSON-RPC endpoint — an A2A key only, \`foldrun docs a2a\`).
413
413
 
414
414
  Every call answers — and the CLI sends — \`Foldrun-Version: YYYY-MM-DD\` (dated API
415
415
  versions; an account pin in Settings → API keys → API), \`X-RateLimit-*\` headers (a \`429\`
416
416
  carries \`Retry-After\`), and writes that start work take an \`Idempotency-Key\`
417
417
  (a retry with the same key replays the first answer). The whole surface as
418
- OpenAPI 3.1: \`/api/openapi.json\` (open), or \`foldrun api spec --out openapi.json\`.
418
+ OpenAPI 3.1: \`/v1/openapi.json\` (open), or \`foldrun api spec --out openapi.json\`.
419
419
 
420
420
  Debugging a failed run is usually: \`runs\` to find it, \`runs/<id>\` to read which
421
421
  step failed and what it cost, fix the markdown, \`deploy\`, then \`rerun\`.
@@ -520,7 +520,7 @@ secrets: [CRM_TOKEN] # keys the agent uses itself; a tool's own come with
520
520
  limits: {web.search: 40, crm: 20, calls: 300} # per step; a call past a limit is refused, never run
521
521
  network: [api.example.com] # sites its sandbox may reach, added to the trusted list; open | trusted | none
522
522
  timezone: Australia/Sydney # the calendar it works to — IANA name or UTC+10
523
- provider: {} # BYOK for this agent; account-wide: \`foldrun account model set\`
523
+ provider: {} # BYOK for this agent, where the platform allows own keys (models.byok); account-wide: \`foldrun account model set\`
524
524
  permissionMode: plan # plan first, act once approved
525
525
  runtime: # only if scripts need packages
526
526
  packages: [requests]
package/src/store.ts CHANGED
@@ -3017,7 +3017,7 @@ export function writeWorkspaceFile(
3017
3017
  // recursive, so until 30 Oct 2026 a write to a name that did not exist
3018
3018
  // created that workspace — with workspace:write alone, past the
3019
3019
  // workspace:manage role and the plan's workspace count that POST
3020
- // /api/workspaces, deploy and import apply. Those create through
3020
+ // /v1/workspaces, deploy and import apply. Those create through
3021
3021
  // saveWorkspace / applyImport, not through here.
3022
3022
  if (!fs.existsSync(dir)) throw Object.assign(new Error(`project ${workspace} not found`), { status: 404 });
3023
3023
  const p = path.join(dir, assertEditablePath(rel));
package/src/webhook.ts CHANGED
@@ -93,7 +93,7 @@ export function webhookToken(tenant: string, workspace: string, flow: string): s
93
93
  }
94
94
 
95
95
  export function webhookPath(tenant: string, workspace: string, flow: string): string {
96
- return `/api/hooks/${tenant}/${workspace}/${flow}?token=${webhookToken(tenant, workspace, flow)}`;
96
+ return `/v1/hooks/${tenant}/${workspace}/${flow}?token=${webhookToken(tenant, workspace, flow)}`;
97
97
  }
98
98
 
99
99
  // ---------- one-click approval ----------
@@ -149,7 +149,7 @@ export function eventToken(tenant: string, workspace: string, runId: string, gat
149
149
  * knows its origin, a path otherwise. With `gate`, that step's own URL
150
150
  * (`&step=<index>`); the route finds the park's moment on the record. */
151
151
  export function eventUrl(tenant: string, workspace: string, runId: string, gate?: EventGate): string {
152
- const p = `/api/events/${tenant}/${workspace}/${runId}?token=${eventToken(tenant, workspace, runId, gate)}${gate ? `&step=${gate.step}` : ""}`;
152
+ const p = `/v1/events/${tenant}/${workspace}/${runId}?token=${eventToken(tenant, workspace, runId, gate)}${gate ? `&step=${gate.step}` : ""}`;
153
153
  const base = publicUrl();
154
154
  return base ? `${base}${p}` : p;
155
155
  }
@@ -37,7 +37,11 @@ export function checkOptions(tenant: string, workspace: string): ScanOptions {
37
37
  // AGENTS.md, or the older project.md, as the runner reads it (Codex review).
38
38
  const accountKeys = readAgentsMdKeys(accountDir(tenant));
39
39
  const accountNetwork = accountKeys.network;
40
- return { outwardTools, accountNetwork, ...effortCheck(tenant, accountKeys.provider) };
40
+ // Own keys as the platform admin set them (models.byok): off, a provider:
41
+ // in these files is an error, so the deploy, a save and the Checks page
42
+ // all refuse it as the runner would.
43
+ const ownModelKeys = platform.ownModelKeys?.(tenant) ?? true;
44
+ return { outwardTools, accountNetwork, ...effortCheck(tenant, accountKeys.provider), ...(ownModelKeys ? {} : { ownModelKeys: false }) };
41
45
  }
42
46
 
43
47
  /**