Skip to Content
CLI ReferenceOverview

Foir CLI

The Foir CLI (foir) is a command-line interface for the Foir platform. It provides resource-oriented CRUD commands across the entire platform, composable output modes for scripting, and supports both OAuth and API key authentication.

Installation

# Install globally npm install -g @foir/cli # Or use with npx (no installation required) npx @foir/cli # Or add as a dev dependency npm install -D @foir/cli

Quick Start

1. Authenticate

foir login

This opens your browser for OAuth authentication. After logging in, credentials are stored locally in ~/.foir/. On a machine with no local browser (SSH, container, CI), foir login automatically switches to a short-code device flow you can approve from any device — see Authentication for the available flags.

2. Select a Project

foir select-project

Choose your tenant and project from the interactive menu. This stores the project context in .foir/project.json relative to your repository root, with a publishable key for the project that holds no scopes: commands act as your signed-in session, not as that key.

3. Start Using the CLI

# List records for a model foir records list page # Create a record foir records create page --data '{"title":"Hello World","slug":"hello-world"}' # Get a record by natural key foir records get page hello-world # Search across all content foir search "hello" --models page,blog-post

Generated command inputs

The generated command reference lists the contract’s enum names. Enum flags accept those exact names or their declared numbers; unknown values are refused before a request is sent. Repeatable flags keep every value, in order.

Bytes fields accept base64. For credentials and binary content, use the field’s file or stdin option so the value does not enter shell history or process arguments:

foir x-generated configs write-credential --config-key my-config --value-file ./credential.bin foir x-generated configs write-credential --config-key my-config --value-stdin < ./credential.bin

File and stdin inputs contain raw bytes, including zero bytes and non-UTF-8 content. Choose one input source per field. The CLI prints the procedure’s response, without echoing the supplied bytes.

Authentication

Foir CLI supports two authentication modes.

Interactive (OAuth)

For local development, authenticate through your browser:

foir login # Authenticate via browser foir whoami # Check current auth status foir select-project # Choose a project foir logout # End the session and clear stored credentials

By default foir login runs the browser (PKCE) flow, opening a local callback in your browser. Two flags cover environments without a local browser:

# Device flow: print a short code and a URL to approve on any device. # Auto-selected when no local browser is detected (SSH, containers, CI). foir login --device # Paste a one-time code back into the terminal instead of using a # local browser callback. foir login --no-browser

If the loopback callback can’t start, foir login falls back to the device flow automatically.

Signed in, the CLI acts as you: every command holds what your roles give you and nothing else, is refused in the platform’s words where they do not, and is recorded against you. Selecting a project remembers where you are working and makes no API key. foir mcp connects an agent the same way.

Headless (API Key)

For CI/CD pipelines, scripts, and automated workflows, set the FOIR_API_KEY environment variable:

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

When FOIR_API_KEY is set, the CLI skips the OAuth flow entirely and authenticates directly with the API key.

The key is one you made for the job, with the grants it needs: foir api-keys create, or the console. The CLI never mints one for itself.

Project Selection and Profiles

After logging in, you must select a project. The CLI saves profiles, bookmarks for the projects you work in, so you can move between them without re-authenticating.

A profile is a personal shortcut. When one config is deployed to a staging and a production project, declare them in the config as named projects instead: the CLI then refuses to guess which one a command means, and refuses a push that would land in the wrong one.

Saving a Profile

foir select-project --save-as client-a foir select-project --save-as client-b

Using Profiles

# Use a specific profile for a command foir records list page --profile client-a # Or set a default profile foir profiles default client-b # List all saved profiles foir profiles list # Show details of the active profile foir profiles show

Targeting One Project, For One Command

A profile is saved state. To run a single command against a project without changing anything saved, name the project by id:

# Find the ids you can reach foir projects list # Act in that project, once. Nothing on disk changes. foir users list --project-id prj_7hb2wi9 foir records list page --project-id prj_7hb2wi9 # Two projects in one script, no state to save or restore for p in prj_7hb2wi9 prj_k3m8qz1; do foir models list --project-id "$p" --json done

--project-id resolves the project’s workspace for you, at the cost of one lookup. Pass --tenant-id <id> alongside it to skip that lookup — useful in a tight loop, or for a project the lookup cannot see.

An API key says its own scope. A key bound to a project acts in that project, and with FOIR_API_KEY set the platform refuses a --project-id that names another, naming both. An admin key made for a workspace itself is bound to no project, so --project-id says which of the workspace’s projects a command acts in:

FOIR_API_KEY="$WORKSPACE_ADMIN_KEY" foir export postgres --project-id "$p" --out "./backups/$p.tar.gz"

Project Resolution Order

When the directory’s foir.config.ts declares named projects, the project is the one --project <name> or FOIR_PROJECT=<name> selects, and nothing else. There is no default: a command that resolves a target without a selection refuses and lists the declared names, on a terminal and in CI alike. --project-id, --tenant-id, --profile and their variables are refused there, because each would name a project around the declaration.

Otherwise, the CLI resolves the project context in this order:

  1. --project-id <id> flag (with optional --tenant-id <id>)
  2. FOIR_PROJECT_ID environment variable (with optional FOIR_TENANT_ID)
  3. --profile <name> flag on the command
  4. FOIR_PROFILE environment variable
  5. Default profile (set via foir profiles default)
  6. .foir/project.json (created by foir select-project without --save-as)

Steps 1 and 2 never fall through. A project id that cannot be resolved is an error, not a reason to use the ambient context — running against a project you did not name is the failure the flag exists to remove.

The platform holds the other half of that rule. Every command says which workspace and project it is about, and one aimed at a project your account cannot open is refused there: it is never run in another project. The error names what the command was aimed at and why it was refused, and --json carries the same as error.refusedScope. foir projects list shows the projects you can open, and foir select-project aims the folder at one of them.

foir context show says which project a command would act in and how it was selected.

Global Options

Every command accepts these global options:

OptionDescription
--api-url <url>Override the API endpoint URL. Takes precedence over FOIR_API_URL
--jsonOutput as formatted JSON
--jsonlOutput as JSON Lines (one object per line)
--quietMinimal output (IDs only, one per line)
--project-id <id>Run this command against this project. Per-invocation: nothing saved changes
--tenant-id <id>Workspace of --project-id. Optional — supplying it skips the lookup
--org-id <id>Act in this organization for this command. - means the project itself. Per-invocation: nothing saved changes
--profile <name>Use a specific named profile
--project <name>Act in this named project from foir.config.ts. Required where named projects are declared
--allow-control-plane-mismatchAct in a named project from a control plane other than the one it declares
--draftServe this command the project’s draft definitions rather than the published ones. A key needs drafts:read

Every command is served the published definitions unless it asks for the draft. That holds for a signed-in session and a key alike, as it does for every other caller. A record saved without --draft is judged against the published schema, so a field you have pushed to a model and not yet published is refused until you publish the model, or save with --draft.

--project <name> names a named project, and only that. It once named a profile, and FOIR_PROJECT was the older spelling of FOIR_PROFILE. Both now select a project declared under projects in foir.config.ts, with no bridge: where no named projects are declared they are refused, with a message naming --profile <name> for a saved profile and --project-id <id> for a project.

Output Modes

Every command supports four output modes for different use cases:

FlagOutputUse Case
(default)Formatted tableHuman reading in the terminal
--jsonPretty-printed JSONDebugging, inspection, scripting
--jsonlOne JSON object per lineStreaming, log processing
--quietIDs only, one per linePiping to other commands

Examples

# Human-readable table (default) foir records list page # JSON for scripting foir records list page --json # Pipe IDs to another command foir records list page --quiet | head -5 # JSONL for streaming processing foir records list page --jsonl

Environment Variables

VariableDescriptionDefault
FOIR_API_KEYAPI key for headless authentication—
FOIR_API_URLOverride the API endpoint the CLI connects to. --api-url wins over it, so a repo whose .envrc exports this can still be pointed somewhere else for one commandhttps://rpc.foir.io
FOIR_STORAGE_URLOverride the storage endpoint URL. On 0.69.0 and earlier, set it to your API URL explicitlyThe resolved API URL, from 0.70.0
FOIR_PROJECT_IDProject to act in, same as --project-id—
FOIR_TENANT_IDWorkspace of FOIR_PROJECT_ID, same as --tenant-id—
FOIR_PROFILENamed profile to use, same as --profile—
FOIR_PROJECTNamed project to act in, same as --project. It no longer names a profile—

Input Methods

Commands that create or update resources accept data through three methods:

# Inline JSON with --data foir records create page --data '{"title":"Hello","slug":"hello"}' # From a JSON file with --file foir records create page --file record.json # Pipe from stdin cat record.json | foir records create page

Pass exactly one. --data together with --file is refused before anything is sent — it is not a precedence question, because two sources for one payload is a mistake rather than a preference, and guessing which one you meant is how the wrong data gets written. Give one, or pipe.

This holds for every command that takes a payload, in all eleven groups: records, models, operations, hooks, schedules, locales, configs, embeddings, variant-catalog, context-dimensions and auth-providers.

Filtering

foir records list supports a --filter option for querying. Pagination uses --first (page size) and --after (cursor) — see records.

# Filter with comparison operators foir records list page --filter "status=published" foir records list page --filter "createdAt>2025-01-01" foir records list page --filter "title~hello" # Combine multiple predicates (comma-separated) with pagination foir records list page --filter "status=published,createdAt>2025-01-01" --first 10

Repeated comparisons on the same field merge into one predicate — --filter "createdAt>2020,createdAt<2024" becomes a single range condition.

Filter Operators

SyntaxOperatorExample
=Equalsstatus=published
!=Not equalsstatus!=draft
>Greater thancreatedAt>2025-01-01
<Less thanprice<100
>=Greater or equalcount>=5
<=Less or equalcount<=10
~Contains (substring)title~hello

The ~ operator matches a substring. Leading and trailing % are stripped: title~%hello%, title~hello, and title~hello% all match the substring hello.

Next Steps

Last updated on