From 841f1d21ce36ea6504ac220ddc4deb1999fe1f66 Mon Sep 17 00:00:00 2001 From: Charan Rathore <180254320+charan-rathore@users.noreply.github.com> Date: Sun, 18 Oct 2026 02:51:51 +0530 Subject: [PATCH 1/3] Read the CLI-written CPK_INTELLIGENCE_API_KEY as the Intelligence key fallback The CopilotKit CLI saves the runtime key as CPK_INTELLIGENCE_API_KEY, while the server only read INTELLIGENCE_API_KEY. A deployment that ran the CLI without setup-learning.ts refused to boot with a missing INTELLIGENCE_API_KEY error until the key was copied by hand. Fall back to CPK_INTELLIGENCE_API_KEY when INTELLIGENCE_API_KEY is unset, keeping the unprefixed variable authoritative when both are present. Closes #800 Signed-off-by: Charan Rathore <180254320+charan-rathore@users.noreply.github.com> --- server/src/config.ts | 6 +++++- server/tests/config.test.ts | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/server/src/config.ts b/server/src/config.ts index df9f2b036..633203b79 100644 --- a/server/src/config.ts +++ b/server/src/config.ts @@ -949,7 +949,11 @@ function runtimeCapabilities(environment: Environment): RuntimeCapabilities { const settings = { apiUrl: url(environment, "INTELLIGENCE_API_URL"), gatewayWsUrl: url(environment, "INTELLIGENCE_GATEWAY_WS_URL"), - apiKey: optional(environment, "INTELLIGENCE_API_KEY"), + // The CopilotKit CLI writes the runtime key as CPK_INTELLIGENCE_API_KEY; setup-learning.ts + // copies it across, but a deployment that ran only the CLI would otherwise refuse to boot. + apiKey: + optional(environment, "INTELLIGENCE_API_KEY") ?? + optional(environment, "CPK_INTELLIGENCE_API_KEY"), licenseToken: optional(environment, "COPILOTKIT_LICENSE_TOKEN"), }; diff --git a/server/tests/config.test.ts b/server/tests/config.test.ts index 7e5b1ddbe..e9db37d1d 100644 --- a/server/tests/config.test.ts +++ b/server/tests/config.test.ts @@ -117,6 +117,27 @@ describe("deployment configuration", () => { ); }); + test("reads the CLI-written CPK_INTELLIGENCE_API_KEY when INTELLIGENCE_API_KEY is unset", () => { + const environment: Record = { + ...baseEnvironment, + }; + delete environment.INTELLIGENCE_API_KEY; + environment.CPK_INTELLIGENCE_API_KEY = "cpk-cli-written"; + + const config = loadConfig(environment); + + expect(config.runtime.intelligence.apiKey).toBe("cpk-cli-written"); + }); + + test("prefers INTELLIGENCE_API_KEY over CPK_INTELLIGENCE_API_KEY when both are set", () => { + const config = loadConfig({ + ...baseEnvironment, + CPK_INTELLIGENCE_API_KEY: "cpk-cli-written", + }); + + expect(config.runtime.intelligence.apiKey).toBe("tenant-api-key"); + }); + test("starts without COPILOTKIT_LICENSE_TOKEN, because managed Intelligence no longer issues one", () => { const environment: Record = { ...baseEnvironment, From 0341f6e0bc14c606382003a9ed58792cdc5052e2 Mon Sep 17 00:00:00 2001 From: Charan Rathore <180254320+charan-rathore@users.noreply.github.com> Date: Sun, 18 Oct 2026 03:04:42 +0530 Subject: [PATCH 2/3] Sync the CLI-key setup guidance with the CPK_INTELLIGENCE_API_KEY fallback Signed-off-by: Charan Rathore <180254320+charan-rathore@users.noreply.github.com> --- .env.example | 2 +- prompt.txt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index acc971401..68f8f4f26 100644 --- a/.env.example +++ b/.env.example @@ -131,7 +131,7 @@ INTELLIGENCE_GATEWAY_WS_URL=wss://realtime.intelligence.copilotkit.ai # npx --yes copilotkit@latest project select # writes the cpk-... key to .env as CPK_INTELLIGENCE_API_KEY # bun scripts/setup-learning.ts # copies it here, as INTELLIGENCE_API_KEY # -# The server reads only INTELLIGENCE_API_KEY, so a key left as CPK_INTELLIGENCE_API_KEY is not seen. +# The server reads INTELLIGENCE_API_KEY first and falls back to CPK_INTELLIGENCE_API_KEY, so the CLI-written key works as written. # # The runtime key is also under "API Keys" in your project at https://intelligence.copilotkit.ai INTELLIGENCE_API_KEY= diff --git a/prompt.txt b/prompt.txt index aedf0bfa6..8c4710645 100644 --- a/prompt.txt +++ b/prompt.txt @@ -103,9 +103,9 @@ OpenBot root where `.env` is: npx copilotkit@latest local connect --approve-connection `local connect` writes INTELLIGENCE_API_URL, INTELLIGENCE_GATEWAY_WS_URL and -CPK_INTELLIGENCE_API_KEY to `.env`. OpenBot reads the first two as they are but takes its project -key only from INTELLIGENCE_API_KEY, so copy the `cpk-...` value of CPK_INTELLIGENCE_API_KEY into -INTELLIGENCE_API_KEY before `bash scripts/start.sh`. The local licence lasts 30 days; +CPK_INTELLIGENCE_API_KEY to `.env`. OpenBot reads the first two as they are and falls back to +CPK_INTELLIGENCE_API_KEY for its project key, so `bash scripts/start.sh` works as written; set +INTELLIGENCE_API_KEY only when it should differ from the CLI-written key. The local licence lasts 30 days; `npx copilotkit@latest local renew` renews it as often as needed while the account is in good standing. Skip the managed `project select` and setup-learning commands on this path. From 41773cc1120a76d8b25772513d6c8623187e139c Mon Sep 17 00:00:00 2001 From: Charan Rathore <180254320+charan-rathore@users.noreply.github.com> Date: Sun, 18 Oct 2026 03:13:08 +0530 Subject: [PATCH 3/3] Sync the README local-connect guidance with the key fallback Signed-off-by: Charan Rathore <180254320+charan-rathore@users.noreply.github.com> --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5586fbec8..174686cd1 100644 --- a/README.md +++ b/README.md @@ -138,12 +138,12 @@ not a production installation. Run its `npx copilotkit@latest local connect` from the OpenBot root, where `.env` is. That command writes `INTELLIGENCE_API_URL`, `INTELLIGENCE_GATEWAY_WS_URL` and -`CPK_INTELLIGENCE_API_KEY` to `.env`. OpenBot reads the first two as they are, but takes its project -key only from `INTELLIGENCE_API_KEY` and refuses to start without it, so copy the `cpk-...` value -across before `bash scripts/start.sh`: +`CPK_INTELLIGENCE_API_KEY` to `.env`. OpenBot reads the first two as they are and falls back to +`CPK_INTELLIGENCE_API_KEY` for its project key, so `bash scripts/start.sh` works as written. Set +`INTELLIGENCE_API_KEY` only when it should differ from the CLI-written key: ```sh -INTELLIGENCE_API_KEY=cpk-... # the value of CPK_INTELLIGENCE_API_KEY +INTELLIGENCE_API_KEY=cpk-... # overrides CPK_INTELLIGENCE_API_KEY ``` To give the Bots a Learning container on that stack, see