Skip to main content

API Keys

Personal API keys let command-line tools and editor integrations call CoderFlow as you. They are different from AI provider API keys: AI provider keys let agents call Claude, Codex, Gemini, Bob, Grok, or Kimi, while personal API keys authenticate you to the CoderFlow server.

Use personal API keys for:

  • The CoderFlow CLI
  • The VS Code extension
  • Scripts that call CoderFlow HTTP endpoints
  • MCP clients (Claude Code, Claude Desktop / Cowork, GitHub Copilot) connecting to the MCP Server

How API Keys Work​

An API key is tied to one CoderFlow user account. Requests send the key as a Bearer token:

curl -H "Authorization: Bearer pc_your_key" \
"$CODERFLOW_URL/auth/me"

After the server validates the key, CoderFlow resolves permissions from the user's roles and access bindings, the same way it does for a browser session. If the user loses access to an environment, the API key loses that access too.

A key can also be restricted to reading, or to a few named tasks, and can be given an expiry. A third kind of restricted key, the server link key, is created only when you connect a Portal server to this server. Restrictions only narrow what the user can already do; a key never has more access than its owner.

API keys are shown only when they are created. Existing keys can be listed by name, access, creation time, last-used time, expiry, and the last four characters (key_hint), but the secret value is not returned again.

The server stores a SHA-256 hash of each full key and its last four characters (key_hint) in api-keys.json in the server data directory. It does not retain the full key. Copy the key when it is created and keep it in your client or secret manager. Listing keys returns the hint, never the hash or full key.

Upgrade and rollback​

On the first host-server start after upgrading, CoderFlow automatically migrates existing API keys to hashed storage. Existing clients keep using the same keys; no user action or opt-in is needed, and there is no opt-out. App Servers inside task containers read the host snapshot without migrating or writing it.

If migration cannot read or write the file, the server logs a warning containing only an error code and continues starting. Readable existing keys still work; migration is retried on the next save or host start. A malformed or unreadable store is left unchanged and must be repaired before its keys can be used. Malformed individual records are skipped and removed from the file on the next write, so valid records remain usable.

Before upgrading, back up the server data folder, including api-keys.json (see Backup and Recovery). To roll back, stop the server, restore the pre-upgrade backup of the data folder, then reinstall the previous version. Hashes cannot be converted back to full keys, so reinstalling the previous version alone does not restore API-key compatibility. Keys created since the backup must be issued again; other changes made since the backup are also lost when it is restored. There is no downgrade command and CoderFlow does not keep a separate copy of the full keys.

Manage Keys in Profile Settings​

Open your account menu, choose Profile Settings, and select the Security tab. The API keys section lists your keys with what each may do, when it was created and last used, when it expires, and its last four characters.

To create a key, click Create API key and fill in:

  • Name — what uses the key, such as "QAQE integration" or "Build server".
  • Expires — 7 days, 30 days, 90 days (the default), 1 year, No expiry, or Custom date.
  • Custom expiry date — the last day the key works, when Expires is Custom date.
  • Access — Full access, Read-only, or Selected tasks only. See Restrict a Key.
  • Task IDs — for Selected tasks only, up to 20 task IDs separated by commas or spaces. A task ID is the last part of the task page URL.
  • Allowed actions — for Selected tasks only: Read the task, Send follow-ups, or both.

Click Create key. The new key is shown once, with a Copy button. Copy it before you click Done or leave the tab; it cannot be shown again.

To revoke a key, click Revoke beside it and confirm. Anything using the key stops working immediately. Revoking one key leaves your other keys, such as your CLI and VS Code keys, working.

Key Expiry​

A key with an expiry stops authenticating at that time, and requests with it receive 401 Invalid API key. Expired keys stay in your list, marked Expired, until you revoke them. Create a new key to replace an expired one.

Keys created by coder login, coder login --sso, and VS Code sign-in, and keys created before expiry was available, do not expire. Prefer an expiry for keys used by automation or other servers.

Restrict a Key​

AccessWhat the key can do
Full accessEverything you can do, including the CLI, VS Code, MCP, terminals and editors. This is what coder login creates.
Read-onlyGET requests for tasks, environments, templates, your work list, your own API keys, and /auth/me. Only actions that need view permission are allowed, so it cannot start, stop, change or follow up tasks. It never reaches App Servers, editors, the designers, compile jobs, or deploy and sync streams, which run work when opened.
Selected tasks onlyOnly the tasks you list. Read the task allows GET /tasks/<task ID>, GET /tasks/<task ID>/results and GET /tasks/<task ID>/follow-up-queue. Send follow-ups allows POST /tasks/<task ID>/follow-up. GET /auth/me also works. Nothing else does: no other task, no task list, no new tasks, and no views of related tasks such as /relationships. The task record it reads leaves out other tasks' queued updates.

Restricted keys cannot use the MCP Server, WebSockets (terminals, editors, live App Server connections), or create or revoke API keys. A request outside the key's access receives 403 with "code": "api_key_scope_denied".

A task-limited key is the right choice for an integration that only follows up one task: if it leaks, it can only read that task and send it instructions. See REST API for the calls.

When IT requests on another CoderFlow server (a Portal server) launch tasks on this one, each person connects their own account and allows it on a consent page here (see Connected Servers). Allow creates a server link key for that person, which this server gives to the Portal server. You can't create one by hand, and POST /api-keys refuses the scope.

In Profile Settings → Security → API keys, the key is listed as Server link: followed by the Portal server's name, such as Server link: Billing Portal, with a Server link badge and the line Starts and reads IT request tasks in followed by its environments. It expires a year after it was created. Each person has at most one per Portal server: connecting again replaces it. If the Portal server is no longer allowed here, the key is listed as Server link: a Portal server no longer allowed here.

A server link key can only:

  • start tasks for IT requests in its environments, while the Portal server is still allowed to use them (checked on every request). A task it starts can carry only a name, instructions, files and whether it is shared, and must name the IT request it is for;
  • read one task by its ID (GET /tasks/<task ID> and GET /tasks/<task ID>/results), when the task is in one of its environments and you may view it;
  • read GET /auth/me, and revoke itself.

It can't list tasks, send follow-ups, use the MCP Server, WebSockets, App Servers or editors, or reach anything else. Your own permissions still apply.

To disconnect a Portal server from this side, click Revoke beside the key and confirm: that server can no longer start or read IT request tasks as you. To restore it, connect again from that server. Disconnecting on the Portal server also revokes the key here, when this server can be reached. An administrator removing the Portal server, or one of its environments, under Server Settings → Connected servers → Allowed Portal servers revokes the keys it affects.

Create a Key with the CLI​

For most users, coder login is the easiest way to create and store a key.

coder login

Enter your username and password. The server creates a key named CLI Access and the CLI stores it in the active profile or CLI configuration.

When SSO is enabled, use:

coder login --sso

The CLI displays a verification code, opens the browser when possible, and polls the server until the OIDC login is approved. On approval, the server creates an API key and the CLI stores it in the active profile.

There is no separate coder login --api-key flow in the current CLI. If an administrator or script gives you an existing key, add it to the active profile:

coder profile set apiKey pc_your_key

For one-off automation, you can also pass a key through the environment:

CODER_API_KEY=pc_your_key coder list

Use a Key in VS Code​

The VS Code extension uses the same API-key authentication path as the CLI. Open the CoderFlow Profile Manager from the extension and choose one of these flows:

  • Enter a server URL and username/password. The extension calls the CLI login endpoint, receives a generated API key, and stores it in the selected profile.
  • Choose Sign in with SSO when OIDC is enabled. The extension opens the browser, waits for approval, and stores the returned API key.
  • Paste an existing key into the profile when you already have one.

The extension also has a workspace setting named profoundCoder.apiKey. CLI profile configuration takes priority when both are present.

Create and Revoke Keys by API​

The server exposes self-service API-key endpoints for the authenticated user:

ActionEndpointNotes
List your keysGET /api-keysReturns key IDs, names, creation time (created_at), last-used time (last_used_at), expiry (expires_at, expired), access (scope), and the last four characters (key_hint). Secret values are omitted.
Create a keyPOST /api-keysBody fields are below. The secret key is returned once.
Delete a keyDELETE /api-keys/:idRevokes one of your own keys immediately.

POST /api-keys accepts:

FieldNotes
nameRequired, at most 100 characters.
expires_in_daysOptional whole number from 1 to 3650.
expires_atOptional ISO 8601 date and time in the future, at most 3650 days ahead. Send this or expires_in_days, not both. Omit both for a key that does not expire.
scopeOptional. Omit it, or send { "access": "full" }, for full access. { "access": "read_only" } for a read-only key. { "access": "tasks", "task_ids": ["<task ID>"], "actions": ["read", "follow_up"] } for a task-limited key; actions defaults to both. You must be able to view every listed task.

For example, a key that can only follow up one task for 30 days:

curl -X POST "$CODERFLOW_URL/api-keys" \
-H "Authorization: Bearer $CODER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name":"QAQE integration","expires_in_days":30,
"scope":{"access":"tasks","task_ids":["<task ID>"],"actions":["follow_up"]}}'

The response's apiKey object includes key (shown only this once), expires_at and scope. Invalid settings return 400 with a code such as invalid_api_key_scope, invalid_api_key_expiry or api_key_task_unavailable.

These endpoints require either a browser session or a full-access API key. Read-only keys can list keys; no restricted key can create or delete them. The endpoints do not let a user list or revoke another user's keys.

Rotate a Key​

Rotate keys when a device is replaced, a secret may have leaked, or you want to retire old automation credentials.

  1. Create a new key in Profile Settings → Security → API keys, or with coder login, coder login --sso, the VS Code Profile Manager, or POST /api-keys.
  2. Update the CLI profile, VS Code profile, script secret, or CI variable that uses the old key.
  3. Test the new key with coder list or GET /auth/me.
  4. Revoke the old key with Revoke in Profile Settings, or with DELETE /api-keys/:id.

A key stops working when it is revoked, when it expires, or when the user account it belongs to is deleted.

Security Practices​

  • Treat API keys like passwords. Store them in the CLI profile, VS Code profile, or a secret manager, not in source control.
  • Use one key per device or automation workflow so rotation has a small blast radius.
  • Give keys used by automation or other servers an expiry and the narrowest access that works: Read-only, or Selected tasks only.
  • Prefer SSO login for humans when your server requires centralized identity. The SSO flow still produces an API key for non-browser requests.
  • Review stale keys by last-used time and delete keys that are no longer needed.
  • Keep the server data directory protected. Personal API keys are server-side credentials.

Troubleshooting​

Invalid API key

The key was revoked, expired, mistyped, or belongs to a deleted user. Re-run coder login, refresh the VS Code profile, or update the stored key.

403 with "code": "api_key_scope_denied"

The key is restricted, and the request is outside its access. Check the key's access in Profile Settings → Security → API keys, and create a key with the access the request needs. Restricted keys never work with MCP or WebSockets.

Forbidden after authentication succeeds

The key is valid, but the user does not have the required permission. Ask an administrator to review the user's teams and access bindings. See Permissions.

Confusing personal keys with AI provider keys

Personal API keys authenticate you to CoderFlow. AI provider keys are configured under provider authentication settings and are injected into task containers so agents can call model providers.