Skip to Content
FeaturesAPI Keys

API Keys

API keys let your applications connect to Foir. A key is one of three kinds, and you choose the kind when you make it: publishable, server or admin. Foir holds the key to what that kind may hold and give. Credentials says which one to use where.

Overview

Every request to the Foir API requires an API key. A key belongs to one project, or for an admin key to the workspace itself, and carries the permissions that decide what a caller may do through it.

Key Types

The key’s prefix says its kind.

KindPrefixUse forWhat it does
Publishablefoir_pub_Your app: a browser, a mobile app, anythingA visitor gets only what the key’s second list names, published content only. A signed-in person gets what their role gives as well
Serverfoir_srv_The server that renders your app’s pagesThe same as a publishable key. It may also say who and where its visitor is, and be the ceiling for a signed-in person who reads every owner’s records
Adminfoir_adm_A machine of your own: a sync job, a pipeline, a tool. Never your appDoes what it holds, including what only an admin key may hold. It gives nobody anything, nobody signs in through it, and it expires

The credential your own logic uses is not a key: an operation’s endpoint calls Foir with the dispatch token Foir hands it for each run, carrying the operation’s declared grants. So your app never needs an admin key. See App architecture.

A publishable key is safe to include in browser code, mobile apps, and any client-side application. What a visitor may do with one is exactly what the key gives (A key’s two lists), and it returns only published content, unless the key is a preview environment’s own and holds drafts:read (see Reading draft content).

It can hold writes: records:write, files:write, users:write and operations:execute:<operation> may all be held by a publishable key. Holding one gives it to nobody. It puts that part of the API on the key, where a signed-in person whose role grants it can use it. A visitor may be given a read, the create of one model (records:create:<model>), one operation to run (operations:execute:<operation>) and the writing of a note (notes:create), each named on the key’s second list, and never an update, a delete or a publish.

The users permissions are the exception: neither users:read nor users:write ever reaches a signed-out visitor or a signed-in person, whatever the key holds. Every form of them reads or changes somebody other than the caller, and users:read lists the project’s users with their email addresses. A person reads and changes their own account as themselves, with no users permission at all. Anything your app does with other people’s accounts runs in an operation that declares what it needs.

What a publishable key may hold is a fixed list (Key Permissions), and anything else is refused when the key is made, with the reason. That includes every owner’s rows (records:read.all, files:read.all), the project’s secrets and events, the organization registry, the keys themselves (apikeys:read, apikeys:write), operations:write, records:attribute, and any wildcard.

A server key is for a server that renders your pages. It gives a visitor exactly what a publishable key gives, and holds what one holds. It holds two things more: visitors:forward, so that it can say who and where the visitor it is calling for is, and records:read.all, so that it can be the ceiling for a signed-in person whose role lets them read every owner’s records. It never gives either to a visitor. It is shown once, is refused from a browser, and never expires.

An admin key is a machine’s own, never your app’s, and must never reach a browser or client-side code. It does what it holds: it can create, update, delete and publish content, and may hold what only an admin key may, such as files:read.all or a wildcard. Nobody signs in through one, and it gives nobody anything. It expires: 90 days unless you say otherwise, a year at most, and it is renewed with the same secret (An admin key expires). The API refuses a server key or an admin key on any request that carries a browser Origin / Sec-Fetch-Site.

Every key is created inside a project and serves that project alone — a deploy that reads two projects holds two keys, and no header can steer one at a project it was not issued for. A key can name the organization it acts in for one request with X-Org-Id — see Selecting an Organization.

A key can also be confined to one organization. Confinement is a property of the key row itself, not something a header asks for, and it changes four things:

  • The key reads that organization’s rows, those of the organizations beneath it and the project-shared tier. It writes only its own organization’s rows, and the organization-owned records that organization owns. It cannot reach a sibling.
  • It cannot name a different organization with X-Org-Id, or reach one by its address with X-Org-Url. A project-scoped key chooses per request; a confined key has already chosen, permanently.
  • Its cached responses are partitioned on the organization, so two confined keys in one project can never be served each other’s bodies.
  • If the organization is suspended, the key stops authenticating with it.

Confinement is set when the key is minted (in the console under Reach, or from the CLI, config or API) and cannot be changed afterwards. The rules it follows are the organization rules; see Organizations.

A Key’s Two Lists

Every key carries two lists, and they answer different questions.

  • What it holds (grants). For a publishable or a server key, the most a signed-in person may do through the key, and the part of the API the key is offered: a field the key does not hold is not in the schema it is served. An admin key acts with all of it.
  • What it gives (baseline_grants). What a caller gets through a publishable or a server key with nobody signed in: a visitor. It is also what a signed-in person may do beneath their role. An admin key gives nobody anything, and its second list is always empty.

Foir fills nothing in. A key gives only what its second list names. A publishable key that holds records:read and gives nothing is a key no visitor can read with: a visitor’s request is refused, and a signed-in person has what their role gives and nothing beneath it. A script that mints a publishable key with a read and no second list gets exactly that key.

The console’s key editor shows both lists. On a new publishable or server key the second list begins as what the key holds that may be given, its reads and the sign-in a visitor needs, ticked and editable. So the usual case, a visitor reads what the key reads, is one you can see and change before the key exists. A key made by the API, the CLI or foir.config.ts begins with exactly what you send.

An empty second list is never silent:

  • Creating or editing a key answers with notices: sentences saying that the key gives a visitor nothing, or that it holds reads that are given to nobody. The CLI prints them, and --json carries them beside the key.
  • The keys list says “Gives a visitor nothing” beside such a key, and the editor says it before you save.
  • whoami asked with the key and no user token lists what a visitor may do, and names the list that decides it.
  • A refused request says so. Where a visitor asks for something the key holds and does not give, the refusal names the permission and adds that the key holds it and gives it to nobody who is not signed in.

Both lists are written in the names of the permission catalogue, the same names a role is written in: records:read, records:write, files:read, search:read. An admin key may hold a read at a wider reach (records:read.all reads every user’s records) and a wildcard (records:*, or *). A publishable key may hold neither. A server key may hold records:read.all and no wildcard. Every permission a key of each kind may hold and give, with what it does, is on Key permissions, which the key editor’s boxes are built from.

Keys that existed before the two lists keep what they gave. Each was written once with the lists its scopes meant, so nothing a visitor could do through an existing key changed.

Names a key is not written with

A key is written by these two lists and by nothing else. A write that names what a key holds as scopes, or part of what it gives as anonymous_scopes, is refused, and the refusal names the list to send. A name that is not a permission in the catalogue is refused too, and where it is a name a permission had before the catalogue, the refusal says what it is written as now.

Reading draft content

To read draft / unpublished content, give the preview environment, the deployment your team reviews drafts on, its own public key holding drafts:read, and pass preview: true on the query (or select the draft schema, content and design tokens for the whole request with the X-Foir-Schema-Channel: draft request header). The key your production app ships does not hold drafts:read, so it keeps reading published content. Anyone who can load the preview environment reads your drafts, so keep it where your team works. Without drafts:read, preview: true is rejected with a permission error. See Preview Mode Access.

In the console

Seeing a project’s keys needs apikeys:read in that project, and creating, rotating and revoking them needs apikeys:write. Project managers and workspace owners hold both through their roles. Without apikeys:read the API keys screen is not offered, and the platform refuses to list or read the project’s keys, because every key’s name, prefix, scopes and reach describe a credential.

Creating a Key

  1. Open Settings > API keys
  2. Click Create API Key
  3. Fill in the form:
    • Name — something descriptive (e.g., “Production Frontend”, “CRM Sync”)
    • What the key is for: publishable, server or admin. None is chosen for you, and it cannot be changed afterwards
    • What this key holds — tick the permissions the key needs. Every permission a key of that type may hold is offered
    • What anyone can do without signing in (a publishable or a server key): the key’s second list. An admin key has none, because it gives nobody anything. The list begins as what you ticked above; untick anything that should take a sign-in. An empty list says what it means before you create the key
  4. Click Create
  5. Copy the key immediately — it is only shown once

Scopes and Permissions

What a key may hold, and what a publishable or a server key may give, is the generated Key Permissions page: every permission, by the kind of key and by which of its two lists it goes on, each with the permission catalogue’s own sentence. It is emitted from the list the platform checks a key against, and the key editor offers exactly its rows, so this page keeps no table of its own that could fall behind.

A few things its rows do not say:

  • The organization permissions are the provisioning surface on its own. A key minted with organizations:create, organizations:write, orgsettings:write and organizations:delete and nothing else can make and manage organizations and cannot touch the project’s content, settings, locales or publishing.
  • Some permissions are an admin key’s alone. A publishable key is made to sit in a browser bundle, so the platform refuses it every owner’s rows (records:read.all, files:read.all), the project’s secrets, the organization registry and the keys themselves, and says why. A server key is refused the same, except records:read.all. drafts:read is not one of them: it belongs on a preview environment’s own publishable key (Reading draft content).
  • A permission may name one model or one operation, written after a second colon (records:create:<model>, operations:execute:<operation>). To bound everything a key does to a set of models, use the model selector.

Restricting a Key’s Reach

Scopes control what kind of access a key has (read, write, execute). Two further selectors in the key form control which resources that access reaches: All or a choice, with a picker. For operations, all is the default. For models, a new key begins with none chosen, and every model is a choice you make. Use them to mint least-privilege keys for a frontend: the key exposes exactly the fields that application uses and nothing else.

Specific operations only

When a key holds operations:execute, an Operation Access selector appears:

  • All operations — the key can execute every operation in the project (today’s default, and the behavior of every key minted before this selector existed).
  • Specific operations only — pick the operations this key may execute. Under the hood the key’s operations:execute scope is replaced with one operations:execute:<operation-key> entry per selected operation.

An operation left off the list isn’t just denied — its execute<Op> mutation disappears from the schema the key sees, including introspection, so codegen against the key’s schema only ever sees what the key can call.

Two details to know:

  • The selector covers mutation-shaped operations (the execute<Op> surface). Query- and field-shaped operations are read surface and aren’t restricted per key.
  • cancelOperationExecution requires the unrestricted operations:execute scope — a key limited to specific operations can execute them but not cancel executions.

All models, or the models you choose

When a key holds anything that takes a model (records, search, rooms or presence), a Model Access selector appears. It is about the key’s reach, not a model’s access config, which declares record ownership.

  • All models: the key reaches every model its grants allow, models added later among them. A key reaches every model only when this is chosen.
  • Choose models: pick the models. The key’s record reads and writes, and per-model search, are bounded to that list: typed fields for other models disappear from the key’s schema and are refused if called. A key with no model chosen reads no model’s records. It keeps everything else it holds, such as running an operation or reading design tokens.

Both can be changed on the key later, and the change is live at once. In foir.config.ts they are allModels: true and allowedModels; on the CLI, --all-models and --allowed-models.

When a release removes the last model a key reads, the key loses that model’s name, so a model added later under the same key is not given to it. The key keeps its other grants. If records were all it reached, it is switched off as well. Either way, whoever made the key is emailed, or the workspace’s managers when its maker has no address. Open the key and choose its models again, or choose all models.

A model-restricted key deliberately loses the generic record fields — record, records, recordVersions, searchRecords, and batchRecordOperations — because those can reach any model. Use the typed per-model fields (page, createPage, searchPages, …) instead; a restricted frontend shouldn’t need the generic escape hatches.

Choosing specific models also removes the semantic-search permissions from the key. embeddings:read and embeddings:write are dropped rather than bounded, because the embeddings plane has no per-model form. A restricted key therefore cannot use the embeddings queries and mutations or the MCP semantic-search tools, whichever of those scopes it was granted. Per-model search still works: search:read is narrowed to the listed models, so searchPages and the other typed search fields keep answering for each listed model with embeddings enabled. A key holding the global * scope is not narrowed at all. See semantic search on a model-restricted key for each scope and field.

One organization only

A key can be confined to one organization of the project. In the console, choose the organization under Reach when creating the key; the section appears once the project has organizations, and a key is project wide unless you choose one. You can also mint one with foir api-keys create --confine-to-org <id>, with org on a key declared in foir.config.ts, or with orgId on the CreateApiKey RPC. The confinement is set once, when the key is created, and cannot be changed.

The keys list says where every key reaches: Project wide, or Confined to followed by the organization’s whole path, so two organizations with the same name read differently. The rotate and revoke confirmations name the key’s reach before you confirm.

A confined key reads its organization, every organization nested under it and the project-shared tier, and writes only into its own organization and the organization-owned records that organization owns. Four rules hold it in shape:

  • It must name at least one scope, because an empty scope set is the widest authority rather than the narrowest.
  • Its scopes are clamped to a subset of the key that mints it.
  • It cannot mint keys, and may not hold apikeys:read, apikeys:write, hooks:write or organizations:reach.
  • It is deleted with its organization, rather than surviving as a project-wide key.

An admin key made for a workspace itself cannot be confined to an organization. See which credential to hold where for how a product built on organizations uses the three kinds of credential.

Keys are managed at the project. While the console is standing in an organization it lists keys but offers no create, rotate or revoke, because the platform refuses every key-management write from a caller confined to an organization, and it links to the project’s API keys screen instead.

An organization’s keys

To see every key confined to an organization and to the organizations beneath it, open the organization from Organizations and choose the API keys tab. These are the keys that stop authenticating when that organization is suspended.

From the same tab, Revoke all live keys revokes every key confined to the organization and its descendants in one step. The button and the confirmation show how many keys it will revoke, and the confirmation names the organization’s path and asks for its name. Project-wide keys and the keys of other organizations, siblings included, are never touched. A key that is only switched off is revoked with the rest, and a key already revoked keeps its original revocation. Each revoked key is recorded on the audit trail as its own API_KEY_REVOKED event.

The revoke is all or nothing. When an admin key holding apikeys:write runs it, every key in the subtree must be within that key’s own authority; if any is broader, nothing is revoked and the refusal says how many keys were beyond it.

From the CLI or the API:

# The keys confined to one organization foir api-keys list --confined-to-org <orgId> # The keys confined to it and to every organization beneath it foir api-keys list --confined-to-org <orgId> --include-descendants # Revoke them all, after confirming the count foir api-keys revoke-confined <orgId>

On the ListApiKeys RPC, orgId restricts the list to one organization and includeDescendants: true widens it to the subtree; where: { orgId: { isNull: true } } lists the project-wide keys. RevokeOrganizationApiKeys takes the organization id and returns the keys it revoked. The count it will act on is ListApiKeys with the same orgId, includeDescendants: true and where: { revokedAt: { isNull: true } }.

What a Key Gives

A key’s second list is what anyone who comes through it may do: a caller with nobody signed in, and a signed-in person beneath their role. Only a publishable or a server key has one. It is how a storefront’s visitors read the catalogue, and how a guest checkout or a contact form reaches the platform without a server in front holding a key of its own.

A visitor may be given a read (records:read, search:read, files:read and the like), one model to submit into (records:create:<model>) and one operation to run (operations:execute:<operation>). No wildcard, and no update, delete or publish.

Set it in the key’s settings, in foir.config.ts as baselineGrants, or with the CLI:

foir api-keys create --name Storefront --kind publishable \ --grants records:read,search:read \ --baseline-grants records:read,search:read,operations:execute:checkout foir api-keys update <id> --baseline-grants records:read,records:create:enquiry

The list you send is the whole list. --baseline-grants "" leaves the key giving nothing, and the command prints what that means.

What Can Change on a Key

Some of a key is fixed when it is minted; the rest can be changed on the key itself, which keeps its id and its secret.

Fixed at creationChanged in place
The key’s kind (publishable, server or admin)Name
Whether it is a project’s key or the workspace’s ownSwitched on or off
The organization it is confined toWhat it holds
The config that provisioned itAllowed models and allowed file types
The secret (a new one only by rotating)What it gives
An admin key’s expiry, by renewing it

A change is live the moment it is saved. A credential is never held for a release, so a foir push that changes what a key gives says the change is live rather than listing it with the drafts. To change something in the left column, create a new key and revoke the old one.

An admin key expires

An admin key is a machine’s own, and a key nobody remembers is the one that leaks. So it lapses unless somebody renews it.

  • A new admin key is given 90 days unless you say otherwise, and a year at most.
  • Renewing moves the date and changes nothing else. The key keeps its secret, so whatever holds it keeps running.
  • The key’s owner and your workspace’s managers are told 14 days and 3 days before it lapses, in the console and by email, with when the key was last used.
  • A key that has lapsed is refused in its own words, saying when it expired. Renew it, or make another.

A publishable or a server key never expires, so that a lapsed key cannot take your app’s pages down. Revoke one when you no longer want it.

# 90 days, which is what an admin key is given when nothing is said foir api-keys create --name "Warehouse sync" --kind admin --grants records:read.all # Thirty days foir api-keys create --name "Migration" --kind admin --grants records:write --expires-in 30d # Another 90 days, with the same secret foir api-keys renew <id>

In foir.config.ts a declared admin key says how long it lives with expiresIn: '90d'. It is read when the key is made. A push never renews a key that exists, so a key is kept alive by somebody deciding to, and not by a pipeline that happens to run.

Rotating a Key

If a key is compromised or needs to be changed:

  1. Open Settings > API keys
  2. Find the key and click Rotate
  3. Copy the new key
  4. Update your application

Rotation is additive. The key keeps its scopes, model limits and organization, and the secret it had until now keeps working for 24 hours after the rotation, so you can deploy the new secret before the old one stops. To end the old secret sooner, retire it with foir api-keys retire-previous <id> once the new one is deployed. A key holds at most two secrets: rotating it again inside the 24 hours ends the older one at once. If the key is compromised, revoke it instead, which ends every secret it has immediately.

Revoking a Key

To permanently disable a key:

  1. Open Settings > API keys
  2. Find the key and click Revoke

A revoked key stops authenticating immediately, under every secret it has, and cannot be restored. Create a new key if needed. To stop a key without revoking it, switch it off from its settings; a switched-off key can be switched back on.

Using Keys in Requests

Include the key in the x-api-key header:

curl -X POST https://api.foir.dev/graphql \ -H "Content-Type: application/json" \ -H "x-api-key: foir_pub_..." \ -d '{"query": "{ pages(first: 10) { edges { node { _id } } } }"}'

In JavaScript:

const response = await fetch('https://api.foir.dev/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': process.env.FOIR_API_KEY, }, body: JSON.stringify({ query: `{ pages(first: 10) { edges { node { _id } } } }` }), });

Environment Variables

Store keys in environment variables, never in code:

# .env.local (do not commit this file) FOIR_PUBLIC_KEY=foir_pub_...

An admin key lives only in the environment of the machine, CI job or tool that holds it, never in your app’s. A server key lives only on the server that renders your pages.

The Foir CLI also uses the FOIR_API_KEY environment variable for headless authentication:

export FOIR_API_KEY=foir_adm_... foir records list page --json

Via the CLI

# List all API keys for the current project foir api-keys list # An admin key for a machine of your own (what it holds is comma-separated) foir api-keys create \ --name "CRM sync" --kind admin \ --grants records:read,records:write,files:read # The workspace's own admin key, bound to no project foir api-keys create \ --name "Provisioner" --kind admin --workspace \ --grants projects:write,usage:read # A publishable key a visitor can read with, and run one operation through foir api-keys create \ --name "Storefront" --kind publishable \ --grants records:read,search:read \ --baseline-grants records:read,search:read,operations:execute:checkout # A server key for the server that renders your pages foir api-keys create \ --name "Storefront server" --kind server \ --grants records:read,search:read,visitors:forward \ --baseline-grants records:read,search:read # Rotate a key (a new secret; the current one keeps working for 24 hours) foir api-keys rotate <id> # Renew an admin key for another 90 days, with the same secret foir api-keys renew <id> # Change what a key gives in place (an empty value leaves it giving nothing) foir api-keys update <id> --baseline-grants records:read,operations:execute:checkout # Retire the previous secret once the new one is deployed foir api-keys retire-previous <id> # Revoke a key (permanently disables it) foir api-keys revoke <id>

Rate Limits

Each API key has its own per-hour request budget. When exceeded, the API returns 429 Too Many Requests and the response carries a Retry-After header telling you how many seconds to wait.

  • Each key counts on its own, and the size of the budget comes from your workspace’s plan: every key in the workspace gets the same one, and it is not set per key.
  • The window is a sliding 60-minute window — bursts are flattened across the hour rather than refilling on a fixed cadence.
  • Every successful response includes X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset headers so you can pace your client.
  • A higher budget comes with a higher plan.

See Errors & Rate Limits for the full header reference and a recommended client retry/backoff pattern.

Best Practices

Do:

  • Use a publishable key for all client-side code (browsers, mobile apps).
  • Use a server key on the server that renders your pages, and nowhere else.
  • Store an admin key only in the environment of the machine, CI job or tool that holds it, one key per system.
  • Give each key the least it needs, in both lists: hold only what the application uses, and give a visitor only what a stranger should have — and use the operation and model selectors to bound a frontend key to exactly the fields it uses.
  • Use descriptive names so you can identify which application uses each key.
  • Rotate keys on a regular schedule, and revoke a key at once if it is compromised: a rotated key’s old secret keeps working for 24 hours.
  • Renew an admin key before it lapses if the system that holds it is still wanted, and let it lapse if it is not.
  • Give a preview deployment for your team its own publishable key with drafts:read (plus preview: true) when it needs unpublished content, and keep drafts:read off the key your production app ships.

Do not:

  • Commit keys to version control.
  • Use an admin key in your app, in the browser or on the server that renders your pages.
  • Sign people in through an admin key. It is refused.
  • Use one key everywhere — create separate keys per application and environment.
  • Grant more permissions than necessary.
Last updated on