# API keys The CLI, the SDKs and the HTTP API use an API key. A key can do everything in its workspace, so keep it private. To let a sandbox use your Anthropic key without holding it, see [Secrets](https://fdtn.dev/docs/secrets.md). ## 1. Create a key 1. Sign in at [compute.fdtn.dev](https://compute.fdtn.dev) and open **API keys**. 2. Click create. Enter a name (1 to 64 characters) and an expiry: **Never**, **In 30 days** or **In 90 days**. 3. Optional: select **Use as my default key**. The Home page then shows it in code examples, only to you. 4. Copy the key. The page shows it once. | Format | `fdtn_` and 40 letters or digits (45 characters) | |---|---| | Scope | One workspace, full access | | Our storage | A hash only. A default key is kept encrypted, readable only by its creator. | | Members | Owners and admins can always create keys. A workspace can stop members from creating keys, or set a longest expiry for them. | ## 2. Store the key The CLI and the SDKs use the first key they find: | Order | Place | Use it for | |---|---|---| | 1 | `api_key=` (Python), `apiKey` (TypeScript) | Your own secret store (SDKs only) | | 2 | `FDTN_API_KEY` | Servers, CI and containers | | 3 | `~/.fdtn/key` | Your own computer | ### On your computer ```bash $ fdtn auth # paste the key; it does not show or go into shell history $ fdtn auth --replace # save a new key, also when a working key is saved $ fdtn auth < key.txt # read the key from a file or pipe; no check with the service ``` `fdtn auth` checks the key and saves it in `~/.fdtn/key` (mode 600). The CLI and the SDKs refuse a key file that other users can read or own; the error shows the fix. ### On a server or in CI Put the key in your secret store and expose it as `FDTN_API_KEY`. It wins over the saved file. CI setup: [Run CI](https://fdtn.dev/docs/ci.md). ```bash $ export FDTN_API_KEY=fdtn_... ``` ### In code Python (key.py): ```python import os from fdtn import Sandbox # Reads FDTN_API_KEY or ~/.fdtn/key by itself: sbx = Sandbox.create("base") sbx.kill() # Or pass a key from your own secret store: sbx = Sandbox.create("base", api_key=os.environ["MY_FDTN_KEY"]) sbx.kill() ``` TypeScript (key.mjs): ```typescript import { Sandbox } from '@fdtn/sdk' // Reads FDTN_API_KEY or ~/.fdtn/key by itself: let sbx = await Sandbox.create('base') await sbx.kill() // Or pass a key from your own secret store: sbx = await Sandbox.create('base', { apiKey: process.env.MY_FDTN_KEY }) await sbx.kill() ``` curl (terminal): ```bash $ curl -s https://api.sbx.fdtn.dev/v2/sandboxes \ -H "X-API-Key: $FDTN_API_KEY" ``` - The HTTP API reads the key from the `X-API-Key` header ([HTTP API](https://fdtn.dev/docs/api.md)). - The SDKs never put the key in a URL, a log line or an error. A key they found by themselves goes only to `sbx.fdtn.dev` or your `FDTN_DOMAIN`. - Never put a key in a web page. Call the SDK from your server. ## Rotate a key 1. On **API keys**, open the key's menu and click **Rotate**. 2. Copy the new secret. The name and expiry stay the same. 3. Update every place that uses the key: `fdtn auth --replace` on each computer, and each secret store. The old secret stops at once. Calls that use it fail until you update them. ## Revoke or delete a key - **Revoke** stops the key at once; the next request gets `401`. Running sandboxes keep running. - **Delete** works only on a revoked or expired key. It removes the key from the list. The activity log keeps its events. - Owners and admins see all key changes on the **Key history** tab. ## Keep keys safe - Never paste a key into a chat, issue, email or agent prompt. Give agents the key through `FDTN_API_KEY` or `~/.fdtn/key`. - Never commit a key. - Use one key per computer or system, so you can revoke one place only. - Give CI keys an expiry. - Never send a key to support. `fdtn doctor` shows only its source and length. ## Next - [**Security and isolation**: Isolation and secrets.](https://fdtn.dev/docs/security.md) - [**Troubleshooting**: Fix key and network errors.](https://fdtn.dev/docs/troubleshooting.md) - [**CLI reference**: The main commands and their options.](https://fdtn.dev/docs/cli.md) Source: https://fdtn.dev/docs/keys/