Skip to Content
API ReferenceOverview

API Overview

The Foir API is a headless data platform with one execution surface: a GraphQL endpoint that queries content, manages records, uploads media, authenticates users, executes custom operations and streams changes.

What differs between clients is who writes the document. @foir/sdk/data generates it for you — typed, shaped by your API key, with no graphql package in your bundle. @foir/sdk/client and every other GraphQL client take a document you wrote. Both send it to the same endpoint, through the same executor, the same scope checks and the same response cache, so most apps use both.

Choosing an API Style compares the two properly.

Base URL

All API requests are made against:

https://api.foir.dev

Endpoints

EndpointMethodDescription
/graphqlPOSTGraphQL queries and mutations
/graphqlGETSchema introspection
/cdn/graphqlGETThe same reads, as a cacheable GET — see Response Caching
/graphiqlGETInteractive GraphQL explorer
/schemaGETFull schema definition
/graphql/wsGETWebSocket subscriptions (graphql-ws protocol)
/v1/manifestGETPer-caller surface descriptor — the models, fields, operations and selections your key may use
/v1/eventsGETCursor-resumable read of the project’s event log
/api/files/uploadPOSTFile upload (multipart/form-data)
/v1/email/unsubscribeGET, POSTRFC 8058 one-click email unsubscribe
/.well-known/openid-configurationGETSign-in discovery

The remaining non-GraphQL endpoints are covered in the REST Endpoints reference.

GraphQL

Your project’s schema is generated from your models, so every model you define becomes directly queryable and mutable.

  • Request exactly what you need — no over-fetching or under-fetching
  • Single request — fetch related records, resolved content, and metadata in one query
  • Strongly typed — your schema reflects your models, with full type safety
  • Introspectable — explore the API with GraphiQL or any GraphQL client

Anything the platform can do is reachable here, including subscriptions.

The data client

@foir/sdk/data writes the document for you. It generates a typed client from your project’s manifest, shaped by your API key — an operation your key cannot perform is not on the type at all.

const post = await foir.post.findUnique({ naturalKey: 'hello-world', include: { author: true }, omit: ['bodyRichtext'], });

No .graphql documents, no codegen pipeline, and no graphql package in your bundle. The trade is that the selection is resolved when you run foir types rather than at the call site: it returns every scalar on the model, and a field added upstream reaches you on your next regeneration. See Selection and Responses.

GraphiQL Explorer

Foir provides an interactive GraphiQL interface at:

https://api.foir.dev/graphiql

Use it to explore your schema, test queries, and view documentation for all available types and fields. Configure your API key in the headers panel.

Quick Start

1. Get an API Key

Create an API key in the Foir dashboard under Settings > API keys. For getting started, a publishable key (foir_pub_) that gives its reads is sufficient for read-only access to published content.

2. Fetch Content with curl

curl -X POST https://api.foir.dev/graphql \ -H "Content-Type: application/json" \ -H "x-api-key: foir_pub_..." \ -d '{ "query": "{ page(naturalKey: \"homepage\", locale: \"en-US\") { _id content } }" }'

Ask what your key can reach, which is also what foir types generates from:

curl -H "x-api-key: foir_pub_..." https://api.foir.dev/v1/manifest

3. Fetch Content with JavaScript

async function fetchPage(slug) { 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: ` query GetPage($slug: String!) { page(naturalKey: $slug, locale: "en-US") { _id content } } `, variables: { slug }, }), }); const { data, errors } = await response.json(); if (errors) throw new Error(errors[0].message); return data.page; }

4. Use with Apollo Client

import { ApolloClient, InMemoryCache, createHttpLink } from "@apollo/client"; const client = new ApolloClient({ link: createHttpLink({ uri: "https://api.foir.dev/graphql", headers: { "x-api-key": process.env.FOIR_API_KEY, }, }), cache: new InMemoryCache(), });

5. Or let the client write the document

npx foir types --out src/foir.generated.ts
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: 'homepage', locale: 'en-US' });

No documents to write, no codegen pipeline, no graphql dependency. See the SDK quickstart.

Authentication Summary

Requests carry an API key in the x-api-key header, except from an operation’s endpoint, which is described below. A key is one of three kinds, chosen when it is made and named by its prefix:

KindPrefixUse Case
Publishablefoir_pub_Frontend apps; a visitor does only what the key gives, and a signed-in user’s role adds the rest. Published content only, unless it is a preview environment’s own key holding drafts:read
Serverfoir_srv_The server that renders your app’s pages. Gives a visitor what a publishable key gives, and may say who and where its visitor is. Never a browser
Adminfoir_adm_A machine of your own (integration sync, CI seeds, config push, back-office tooling), never your app. Holds the permissions you give it, the management ones included. Nobody signs in through it, and it expires

For user-facing features, your app sends its publishable key (or its server key, from the server that renders its pages) with the user’s own JWT in the Authorization header. An operation’s endpoint calls with the dispatch token it was handed (X-Foir-Token) and no key. See App architecture for which credential belongs where.

See Authentication for full details on scopes, security, and user auth.

Rate Limiting

API requests are rate-limited per API key, at the ceiling your plan allows: from 10,000 per hour on Free and Entry to 5,000,000 on Enterprise, where a contract may set a higher one. Rate limit status is returned in response headers:

HeaderDescription
X-RateLimit-LimitMaximum requests per window
X-RateLimit-RemainingRemaining requests in current window
X-RateLimit-ResetUnix timestamp when the window resets

See Errors and Rate Limits for details on error handling and query complexity limits.

What’s Next

Last updated on