Skip to content

Commit 49f2f8f

Browse files
akxueclaude
andcommitted
docs: document deployment API key lifecycle and reserved env vars
Explain that each deployment mints its own deployment-scoped KERNEL_API_KEY, that KERNEL_API_KEY and ENTRYPOINT_RELPATH are reserved (user-supplied values are overridden), and how a superseded deployment's key is drained after in-flight invocations complete. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent a358df4 commit 49f2f8f

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎apps/deploy.mdx‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,31 @@ kernel deploy my_app.py --env-file .env
6565
```
6666
</CodeGroup>
6767

68+
### Reserved environment variables
69+
70+
Kernel injects a few environment variables into every deployment and its invocations. These names are **reserved** — if you set them via `--env` or `--env-file`, Kernel overrides your value, so setting them has no effect:
71+
72+
- `KERNEL_API_KEY` — each deployment is given its own deployment-scoped API key at deploy time (see [Deployment API keys](/info/api-keys#deployment-api-keys)). The SDKs read this from the environment by default, so your app is already authenticated as itself. Passing your own `KERNEL_API_KEY` does **not** replace it.
73+
- `ENTRYPOINT_RELPATH` — set by the platform to locate your entrypoint.
74+
75+
If your app needs a different, long-lived key (for example an org- or project-scoped key), pass it under a **non-reserved** name and read it explicitly:
76+
77+
<CodeGroup>
78+
```python Python
79+
import os
80+
from kernel import Kernel
81+
82+
# Use your own key from a non-reserved var instead of the injected deployment key.
83+
client = Kernel(api_key=os.environ["MY_KERNEL_API_KEY"])
84+
```
85+
86+
```typescript TypeScript
87+
import Kernel from '@onkernel/sdk';
88+
89+
const client = new Kernel({ apiKey: process.env.MY_KERNEL_API_KEY });
90+
```
91+
</CodeGroup>
92+
6893
## Deployment notes
6994

7095
- **The dependency manifest (`package.json` for JS/TS, `pyproject.toml` for Python) must be present in the root directory of your project.**

‎info/api-keys.mdx‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ func main() {
8888
```
8989
</CodeGroup>
9090

91+
## Deployment API keys
92+
93+
When you deploy an app, Kernel mints a **deployment-scoped API key** for that deployment and injects it into the deployment (and every invocation it runs) as the `KERNEL_API_KEY` environment variable. Because the SDKs read `KERNEL_API_KEY` from the environment by default, your app can call the Kernel API as itself without you managing a key.
94+
95+
Key points about deployment keys:
96+
97+
- **One key per deployment.** Each deploy (including a redeploy of the same app) mints a fresh deployment key. `KERNEL_API_KEY` is a [reserved environment variable](/apps/deploy#reserved-environment-variables) — a value you supply at deploy time is overridden by the injected key. To use your own long-lived key, pass it under a non-reserved name.
98+
- **Lifecycle tied to the deployment.** A deployment key stays valid while its deployment is active. When you redeploy, the new deployment supersedes the old one, and the old deployment's key is released once it is no longer needed — that is, once the superseded deployment is stopped **and** no invocation is still running on it.
99+
- **In-flight invocations are drained, not cut off.** If an invocation is still running on a deployment that gets superseded, its key is kept valid until that invocation completes; the key is released right after. An idle redeploy (nothing in flight) releases the old key immediately. In the rare case where an invocation's workflow terminates without releasing the key, a background sweep releases it after a grace period (~95 minutes). You do not need to manage any of this — it is automatic.
100+
101+
If you need a credential whose lifetime you control (for CI, a persistent backend, or sharing across deployments), create an org- or project-scoped key as described below and reference it explicitly rather than relying on the injected `KERNEL_API_KEY`.
102+
91103
## List and inspect API keys
92104

93105
List keys to audit what exists. List and retrieve responses include `masked_key`, `project_id`, `project_name`, `created_by`, and expiry metadata, but they don't include the plaintext key.

0 commit comments

Comments
 (0)