Skip to Content
Getting Started

Getting Started

From nothing to reading your own data in your own application, without leaving the terminal.

Every step below is a command. There is a console and it is where you will do most content work day to day, but nothing on this page requires clicking in it — a person following along and an agent doing it for you take the same path.

Prerequisites

  • A Foir account
  • Node.js 22.18 or later

Step 1: Install the CLI

npm install -g @foir/cli

Or run it without installing, which is what CI usually does:

npx @foir/cli --version

Step 2: Sign in

foir login

That opens a browser. For an SSH session, a container or CI where no local browser exists, use the device flow — it prints a short code you approve on any device, and it is selected automatically when no browser is detected:

foir login --device

foir login --no-browser is the third option: authenticate by pasting a one-time code back into the terminal, with no local callback listener.

For unattended CI, skip login entirely and export a key instead:

export FOIR_API_KEY=foir_adm_...

See CLI Overview for authentication and project profiles.

Step 3: Create a project

A project is one isolated space — its own content, users, API keys and domains. Projects live in a workspace, and one account can hold many.

If your account has no workspace yet, make one. It starts on Free, with no card, and comes with a project:

foir workspaces create --name "My Studio" --select

In a workspace you already have, create a project instead:

foir projects create --name "My App" --select

--select makes the project the CLI’s active one, so every command after this one targets it. If you already have a project, pick it instead:

foir select-project

Step 4: Describe your data, and push it

Your models live in a foir.config.ts you commit. This is the part worth doing in code rather than in the console: it is reviewable, it is the same in every environment, and it is how you get the schema back if you lose it.

// foir.config.ts import { defineConfig, defineModel } from '@foir/cli/configs'; export default defineConfig({ key: 'my-app', name: 'My App', models: [ defineModel({ key: 'page', name: 'Page', pluralName: 'Pages', config: { publishing: true, versioning: true }, fields: [ { key: 'title', type: 'text', label: 'Title', required: true }, { key: 'body', type: 'prose', label: 'Body' }, ], }), ], });
foir push --dry-run # what would change, and what it would cost you foir push # apply it

Always read the dry run first. It names every model, field and resource the push would create, change or remove, and what removing one would do to the records under it. See Config as Code and Push & Remove.

Step 5: Create an API key

Your application reads through a key, not through your login.

foir api-keys create --name "Frontend" --kind publishable \ --grants records:read --baseline-grants records:read --all-models

--grants is what the key holds. --baseline-grants is what it gives a visitor with nobody signed in, and nothing is filled in: leave it off and no visitor can read with the key, which the command tells you. --all-models lets the key read the records of every model, those you add later among them. Name the models instead with --allowed-models. A key given neither reads no model’s records.

  • Publishable keys (foir_pub_) are embeddable in client-side code and read published content. This is the right default for a storefront or a web app.
  • Server keys (foir_srv_) are for the server that renders your app’s pages. One gives a visitor what a publishable key gives, and is never sent to a browser.
  • Admin keys (foir_adm_) are for a machine of your own writing to Foir (an integration sync, a CI seed, your back-office tooling), never for your app. An admin key expires, after 90 days unless you say otherwise, and foir api-keys renew keeps it with the same secret. A publishable key can hold a write scope; it acts only for a signed-in user, or for a scope you have opened to anonymous callers. Your app’s own logic runs in an operation: see App architecture.

The kind is --kind, and nothing is assumed. A key made without one is refused and told the three. You choose what a key is for, and the platform holds it to that: see Credentials.

You can also declare a key in your config with kind: 'publishable' and push it, which is the reproducible route and writes the value straight to your .env.

The raw key is printed once. Copy it now — it cannot be retrieved later.

# .env.local FOIR_API_KEY=foir_pub_abc123...

See API Keys for the full scope list.

Step 6: Create a record

foir records create page \ --natural-key home \ --data '{"title":"Home"}' \ --message "first page"

page has publishing: true in the config above, so that created an unpublished draft.

Versioning and publishing are two different switches, and it is publishing that decides draftness. Versioning keeps a history of what a record has been; publishing decides whether what you just wrote is live yet. A model can have either without the other.

Publish it:

VERSION=$(foir records create page --natural-key about \ --data '{"title":"About"}' --json | jq -r '.version.id') foir records publish "$VERSION"

For a model with publishing: false, a create is immediately readable and there is nothing to publish.

An AI agent connected over MCP does the same thing with foir_create_record — same platform, same authorization, no shell.

Step 7: Generate types

npm install -D @foir/cli @foir/sdk npx foir types --out src/foir.generated.ts

This writes one module holding your interfaces, the selection tree behind each operation, and the schema version they came from. Commit it. It is a build input, and CI should not need a network call to your project to build.

It is read through the session you signed in with, and describes the project’s whole surface. To generate exactly what your app’s key is served, name that key: npx foir types --api-key-id <id> --out src/foir.generated.ts (foir api-keys list shows the ids). Its scopes, the models it is restricted to and the organization it is confined to shape the module, and its secret never leaves the platform.

A field added to a model does not appear in your responses on the next request — it appears on your next foir types plus a deploy. That is deliberate, and it is explained in Generating Types.

Step 8: Read it from your application

import { createFoirClient } from '@foir/sdk/data'; import * as generated from './foir.generated'; const foir = createFoirClient({ apiUrl: 'https://api.foir.dev', apiKey: process.env.FOIR_API_KEY!, generated, }); const page = await foir.page.findUnique({ naturalKey: 'home' }); console.log(page?.title);

No .graphql files, no codegen step of your own, and no graphql dependency in your bundle. The document is printed from the selection tree your project published, and page is fully typed from the module you just generated.

The full client surface is in The Data Client. If you would rather send GraphQL yourself, the endpoint is POST https://api.foir.dev/graphql with an x-api-key header — see GraphQL API.

Next Steps

Learn the Features

  • Models — How data is structured
  • Records — Creating, versioning, and publishing data
  • Field Types — Available field types
  • Variants — Serve different content to different audiences

Automate

Define as Code

Common Issues

“API key or a signed-in person’s token required”

The data API reads the key from the x-api-key header. createFoirClient sets it for you from apiKey; if you are sending GraphQL by hand, set it yourself.

FOIR_API_URL configures the CLI and defaults to https://rpc.foir.io. It is not the data-plane host, which is https://api.foir.dev. Setting one where the other belongs is the usual cause of a key that “does not work”.

“Record not found”

  1. Check the record is published — a draft is invisible to your app’s key
  2. Verify the naturalKey matches
  3. To read drafts, use a key with drafts:read and pass preview: true. That key is a preview environment’s own key, separate from the one your production app ships; see Step 5 and Preview Mode Access

Reading and fixing content from the terminal

foir records list page foir records get page home

records save replaces the record wholesale. It is not a patch: the data you send becomes the record, and anything you leave out is dropped. Sending only title to the page model defined above would delete body, and nothing would warn you.

So read, edit, write back — and read with --resolved, because a plain get on a model with versioning returns the parent row rather than the resolved content:

foir records get page home --resolved --json \ | jq '.data | .title = "Home, corrected"' \ | foir records save page <id>

records save reads its payload from stdin when you give it no --data, which is what makes the pipe work.

Last updated on