Concepts
Secrets
Official Kody doc
A secret is a credential stored on your Kody account, such as an API key, token,
or private key. Code never reads the value: a package declares a need in
kody.credentials, the owner maps it to a credential, and
credential(key).fetch() sends the value only at the network boundary. No API
returns a stored value; even the legacy
packageSecrets.get call
returns an opaque reference.
If a remote service echoes a value the gateway filled, echo redaction can redact strong values inside surrounding text. For short or repetitive values it redacts only standalone matches; a weak value embedded in longer text or returned as a JSON number in a full JSON response can remain visible. See Requests with credentials for the redaction rules.
Watch: Make your agent safe and autonomous for the locked Gmail drafts loop, written up in Gmail drafts without send.
The rule: there is no secret_get
The secrets capabilities are secretList, secretSet, secretSetMany,
resourceLock, secretDisconnect, secretDelete, and secretJwtSign. No
capability returns a secret value. secretList returns metadata only: names,
descriptions, approved hosts, expiry, remaining time to live, disconnected
(value cleared, row kept), and package_id for package-scoped secrets.
secretDisconnect clears the value but keeps the credential row, placement,
hosts, and grants so reconnect with secretSet restores the same record.
secretDelete removes the credential and every record of it. Explicit listing
includes caller-owned package-scoped metadata even from execute; using a package
secret still requires package context. Search does not return or rank those
rows. resourceLock({ kind: 'secret', name, package_id }) returns grant-status
metadata and an approval_url for the owner to click; it does not apply the
grant. External vaults use custom secret providers
(secretProvider* capabilities and vault-backed Keys).
Give the agent the secret's name rather than pasting its value into a prompt.
How code uses a secret
Declare the need, have the owner map it, and call the scoped client. Kody puts the value where the Key's placement says, on the final serialized request, and only for hosts you approved.
import { credential } from 'kody:runtime'
export default async function listRepos() {
const github = await credential('github')
const response = await github.fetch('https://api.github.com/user/repos')
return response.json()
}- Requests —
credential(key).fetch(url, init)sends HTTPS requests to the Key's approved hosts with the value in its configured header, Basic auth, or query parameter. On plainhttp://or an unapproved host the client throws and the value is never sent (client tests, host checks). A JSON body field, a URL path segment, or a request that needs several credentials goes through an approved request profile. SDKs that take a custom fetch getfetch: github.fetch. Vault items use vault-backed Keys the same way. - Basic auth from two values — set the Key's inject to
{ kind: 'basic', ... }, or approve a composition profile when the username and password are separate Keys. - Signing — a signing credential exposes
credential(key).sign(...), which returns a signature, never the key. See Signing. ThesecretJwtSigncapability also signs a JWT with a stored key and returns a sealed handle for the compact token, never the key or the token; it fills on theaudhost (orsend_to_host). See Signing JWTs with saved secrets (raw).
Legacy placeholder references, secretHeaders, and packageSecrets refs still
work during migration and warn at publish and runtime. See
Migrating from placeholders.
- Saving a token from a token exchange: a token response (
access_token,refresh_token,id_token) to a request Kody filled a credential into comes back as a sealed handle, good only in that run for up to an hour. To keep a long-lived one (Plaid'saccess_tokenfrom/item/public_token/exchange), pass it tosecretSet({ name, scope: 'user', sealed_token })in the same run. Kody opens it and saves the real token as a Key, never returned to code. The Key goes only to the token endpoint's host, the exact hosts approved on the credentials that minted it, and its JWT audience host, in a header or the body (never the URL). Saving over an existing Key keeps its narrower hosts and placement.secretSetrefuses a sealed token passed asvalue, one from another run, an expired one, and a signed JWT. Saving works from ad hoc execute (hosted,--local, or Open API with a run), not from package code: a package that holds a refresh token uses a login credential instead.
Two approvals, both yours
Saving a secret does not by itself let anything use it.
- Host approval decides which destinations a secret may be sent to. A secret
with an empty host allowlist sends nowhere, including from packages you wrote
yourself. Approve hosts on
/@<org-slug>/-/connect/secrets— one link can cover several secrets and several hosts at once. Hosts that are not valid hostname shapes (truncated tokens, paths, empty values) are flagged on that page and are not written to the allowlist. Kody never approves a host automatically; an ad hoc smoke test that happened to work does not widen the allowlist. - Package approval decides which saved packages may read and use a
user-scoped secret. Approval is checked against the stamped package — the
module that originated the call — so dependents statically import the owning
export instead of needing their own grant. Packages you authored and community
forks you adopted after reviewing the source get read/use automatically while
the secret's
allowed_packageslist is empty. A non-empty list is enforced for every package, including ones you authored or adopted. Unadopted forks need an explicit grant. Updating, disconnecting, or deleting a user secret from package code always needs the grant. Only the account owner can add a package to that grant on/@<slug>/-/secrets/user/:nameor/@<slug>/-/secrets/approve— a focused Allow page, the same spirit as host approval on/@<org-slug>/-/connect/secrets.resourceLock({ kind: 'secret', name, package_id })returns that approval URL for the owner to click; it does not changeallowed_packages. Send the link and wait. Removing a grant is also website-only.
Bulk approval URLs (/@<slug>/-/secrets/approve?package_id=…&names=a,b) let you
approve several pending secrets for one package in a click.
Publish and save warn when a package fills a user credential whose
allowed_packages list is non-empty and does not include that package, because
that use is denied at runtime. Approve the package or move the use into an
already-allowed package.
Scopes
- User secrets belong to the org they were saved in (your personal org or a
team org) and can be approved for any package.
useris a storage scope, not ownership by a person: in that org,credentialListandcredential(key).scopereport a user secret asorg. Only a personal credential granted to another org readspersonalthere. See Scope in code. - Package secrets belong to one saved package. They are package config,
keyed by the package id, and can be used only with package context.
secretListandpackageGetexpose their metadata withpackage_ideven outside an active package run. Search does not return or rank those references. To create or update one from execute, the Open API, orkody execute --local, passpackage_idtosecretSet(a saved package in this org); Kody applies the same permission check as the website. Details: Local CLI execute.
A Use collaborator running your package in your org uses your org's secrets and integrations under the same host and package allowlists — they still cannot read secret values. Details: Share a package.
OAuth access and refresh tokens are different: they live on the integration,
refresh inside credential(key).fetch on an OAuth need, and do not appear in
the secrets list. A pasted API key is a secret; a Slack login is an integration.
See Packages, integrations, and MCP servers.
Expiry
A secret can carry an expiry (expires_at). Expired secrets stay listed with
ttl_ms: 0, and Kody treats them as missing so it stops sending the value.
Agents prefilling /connect/secret-set can set expiresAt in the query string
so the person pastes the token without typing a date.
When a token is coarser than the job
Providers do not always offer the scope you want. Gmail has a send scope and no
drafts-only scope. When the token can do more than the job should, publish the
narrow behavior as a package, lock the package, and lock the integration to it.
After that, execute cannot borrow the token and a later publish cannot quietly
add a send path. Push changes to a branch and open a merge request for the owner
to merge on the website. See
Gmail drafts without send and
Lock an MCP server to a package for the same pattern
on connected tool servers.
Adding a secret
- Pasting a key or PAT: the agent sends you a prefilled
/connect/secret-setlink; you paste the value into the page, never into chat. URL shape and parameters: Ask the user to save a secret. - Building an integration around one or more secrets: Secret-backed integrations.
- Using a password-manager item without pasting it into Kody: Custom secret providers.
- A token that already exists inside trusted code (a key the package just
minted):
secretSetpersists it without returning it.
Renaming a secret
Rename a secret on its page on the website (edit Name and save), or rename a
user-scope secret with credentialUpdate and a new name. The secret keeps its
credential id and value, so grants, package credential mappings, read history,
and audit history stay attached, and the token does not need rotating. The
rename needs Write on the secret, is recorded as credential.renamed in the
audit log, and is refused when the name is taken in the same scope or uses
characters a credential name cannot use (allowed: letters, numbers, dots,
underscores, hyphens).
{
"operationId": "credentialUpdate",
"params": {
"credential_id": "cred_…",
"name": "kodyCloudflareWorkersAiToken"
}
}References by name do not follow the rename, and there is no alias for the old
name: call-map name picks, package and execute code that looks the secret up by
name (including legacy placeholders and secret mounts), and scripts keep
resolving the old name and fail until you update them. Needs mapped by
credential ID keep working. The credentialUpdate response returns
rename.known_references for the settings Kody stores by name (webhook
verification secrets, secret provider door keys). Kody does not index package or
execute source, so search your packages for the old name too. Send name on its
own call, not with provider, inject, or placement. OAuth connections and
MCP servers rename the same way; see
Renaming a credential.
Where to go next
- Credentials — every credential kind, scoped clients, and
kody.credentialsneeds. - Secrets and host approval — the MCP-level reference with the exact host, placement, and approval semantics.
- Custom secret providers — vault-backed Keys, account binding, and package grants. Watch: Kody secret providers: use password manager items without exposing them.
- Integration bootstrap — the sequence before a secret-backed package is saved.