Configuration Service
flAPI's configuration story has two layers:
- The
flapi.yamlfile — declarative configuration loaded at server start. Supports{{env.VAR}}substitution, hierarchical YAML, and modular includes. - The Configuration Service API — an optional HTTP API (
/api/v1/_config/*) the server exposes when started with--config-service. TheflapiiCLI is a thin client over this API and lets you inspect and modify configuration without restarting the server.
This page covers both layers.
Configuration Architecture
Hierarchical Configuration
Main Configuration File
flapi.yaml is the entry point. Canonical keys use kebab-case (project-name, project-description), with a few snake_case keys for DuckDB pass-through settings.
# flapi.yaml
project-name: my-api-project
project-description: Production API for customer data
# Template configuration
template:
path: './sqls'
environment-whitelist:
- '^FLAPI_.*'
- '^DB_.*'
- '^GOOGLE_.*'
# Include the connections: section of another file (path relative to this file, unquoted)
{{include:connections from config/connections.yaml}}
# DuckDB engine settings (snake_case keys pass through to DuckDB)
duckdb:
db_path: ./cache/flapi.db
access_mode: READ_WRITE
threads: 8
max_memory: 8GB
Modular Configuration with Includes
Break large configurations into modules. Includes are expanded as text before the YAML is parsed, so an include stands on its own line at the top level, and the included file carries its own top-level key:
config/connections.yaml:
connections:
bigquery-warehouse:
init: |
INSTALL bigquery FROM community;
LOAD bigquery;
ATTACH 'project={{env.GOOGLE_CLOUD_PROJECT}}' AS bq (TYPE bigquery, READ_ONLY);
properties:
dataset: analytics
postgres-db:
init: |
INSTALL postgres;
LOAD postgres;
CREATE OR REPLACE SECRET pg (TYPE postgres, HOST '{{env.DB_HOST}}', PORT 5432,
DATABASE '{{env.DB_NAME}}', USER '{{env.DB_USER}}', PASSWORD '{{env.DB_PASSWORD}}');
ATTACH '' AS pg (TYPE postgres, SECRET pg, READ_ONLY);
customers-parquet:
properties:
path: './data/customers.parquet'
{{include:connections from ...}} takes only the connections: key of that file; {{include from ...}} splices the whole file. An include in a value position (connections: {{include from ...}}) and a quoted path do not work.
Environment Variables
{{env.VAR}} substitution in YAML
flAPI substitutes {{env.VAR_NAME}} references at load time, in the main config, in endpoint files and in included files. The same form reads whitelisted variables inside SQL templates.
connections:
production-db:
properties:
host: '{{env.DB_HOST}}'
port: '5432'
username: '{{env.DB_USER}}'
password: '{{env.DB_PASSWORD}}'
{{env.VAR}} is the only supported form (spaces inside the braces are fine). ${VAR} is not supported and not warned about: it stays literal text. There is no default-value syntax: give a variable its value in the deployment environment. There is no built-in vault: or aws-secrets: resolver either: wire those secrets in via environment variables sourced from your deployment platform.
Environment Variable Whitelist
Control which variables are visible to templates:
template:
environment-whitelist:
- '^FLAPI_.*'
- '^DB_.*'
- '^GOOGLE_.*'
- '^AWS_.*'
- 'JWT_SECRET'
One whitelist governs every {{env.VAR_NAME}}: in SQL templates and in YAML files. An empty or missing whitelist allows none. In a YAML file an unlisted variable stops startup with an error naming it; in a SQL template it is simply not available. The whitelist must sit under template: in the main flapi.yaml.
Environment-aware includes
Vary the configuration by environment with a variable in the include path, or with an include condition:
# The variable must be whitelisted, like any other {{env.NAME}}.
# config/connections-<env>.yaml has the same shape as config/connections.yaml above.
{{include:connections from config/connections-{{env.FLAPI_ENV}}.yaml}}
# Include only when the variable is set and non-empty
{{include from config/overrides-dev.yaml if env.FLAPI_DEV}}
Then maintain config/connections-development.yaml, config/connections-staging.yaml, etc.
Configuration Validation
From the command line (server)
The server can validate and exit without starting:
./flapi --validate-config -c flapi.yaml
echo $? # 0 = valid, 1 = invalid
Use this in CI to fail builds on broken configuration.
flapii config validate is a local check
flapii config validate does not contact the server. It reads the endpoint YAML files under template.path of the nearest flapi.yaml (or --dir <dir>, --file <file>) and checks a few keys. Use it as a quick lint; flapi --validate-config is the real check. To validate one endpoint the way a running server would parse it, use flapii endpoints validate <path> --file <yaml> (see flapii CLI).
Real validation errors
An environment variable that is not whitelisted stops startup and --validate-config:
Configuration error: ... environment variable PG_PASSWORD referenced as {{env.NAME}} but not whitelisted.
Add a pattern matching it to `template.environment-whitelist` in the main configuration file; an empty or missing whitelist allows no variables.
A server: block is an error, because flAPI never had one:
flAPI has no `server:` block; it was never read, so anything set under it had no effect. Configure the HTTP server with the top-level `http-port` and `http-host` keys, or with --port/-p and --host, or the FLAPI_PORT and FLAPI_HOST environment variables.
environment-whitelist at the top level is an error too; it belongs under template:.
A missing template file:
ERROR: Template file does not exist: .../sqls/missing.sql
An unknown top-level key (such as cli:) is only a warning: Unknown top-level configuration key `cli` is ignored; nothing reads it.
Configuration Reference (abbreviated)
For the full set of keys, see docs/CONFIG_REFERENCE.md. Selected highlights:
# Project metadata
project-name: my-api-project
project-description: API for business intelligence
# SQL template root
template:
path: './sqls'
environment-whitelist:
- '^FLAPI_.*'
- '^DB_.*'
- '^GOOGLE_.*'
- '^JWT_SECRET$'
# DuckDB engine (snake_case pass-through)
duckdb:
db_path: ./cache/flapi.db
access_mode: READ_WRITE
threads: 8
max_memory: 8GB
# Data connections
connections:
bigquery-warehouse:
init: |
INSTALL bigquery FROM community;
LOAD bigquery;
ATTACH 'project={{env.GOOGLE_CLOUD_PROJECT}}' AS bq (TYPE bigquery, READ_ONLY);
properties:
dataset: analytics
postgres-db:
init: |
INSTALL postgres;
LOAD postgres;
CREATE OR REPLACE SECRET pg (TYPE postgres, HOST '{{env.DB_HOST}}', PORT 5432,
DATABASE '{{env.DB_NAME}}', USER '{{env.DB_USER}}', PASSWORD '{{env.DB_PASSWORD}}');
ATTACH '' AS pg (TYPE postgres, SECRET pg, READ_ONLY);
# Server (top-level keys; a `server:` block is an error)
http-port: 8080
http-host: 0.0.0.0
log-level: info # debug, info, warning (or warn), error
# Authentication (applies to every endpoint without its own auth: block)
auth:
enabled: true
type: bearer
jwt-secret: '{{env.JWT_SECRET}}'
roles: [admin, user]
# Global rate limiting
rate_limit:
enabled: true
max: 100 # requests per interval
interval: 60 # seconds
The Configuration Service API
The Configuration Service exposes runtime endpoints under /api/v1/_config/* for listing, inspecting, mutating, and reloading endpoints, templates, and caches.
Enable it
The API is off by default. Enable it on the server:
./flapi -c flapi.yaml \
--config-service \
--config-service-token "$FLAPI_CONFIG_SERVICE_TOKEN"
- If
--config-serviceis set without a token, the server generates a random one at startup and prints it in its startup banner. - The token can also be supplied via the
FLAPI_CONFIG_SERVICE_TOKENenvironment variable.
Authentication
Every request to /api/v1/_config/* must present the token in one of:
Authorization: Bearer <token>
or
X-Config-Token: <token>
Reload an endpoint without restart
The dedicated reload endpoint applies updated YAML or template changes:
POST /api/v1/_config/endpoints/{slug}/reload
This is what flapii endpoints reload <path> calls under the hood. What needs a reload and what does not:
- SQL templates are re-read on the next request, so a template edit (or a
git pull) is live at once. - Endpoint YAML is read only at startup and on reload. A file the server never loaded needs
flapii endpoints reload --file <yaml>. flapi.yamland connectioninitare read only at startup; secrets andATTACHes created byinitchange only with a restart.
The config service in production
What it changes. Every write (endpoints create/update/delete, templates update, cache update) changes the server's memory and its files on its own disk. So:
- In a container, the change is gone on the next restart unless
sqls/is a persistent volume. - With several replicas, only the one that answered changed.
- Nothing goes back to git.
Where it refuses. A packed binary answers 409 ("its configuration is read-only"). A template.path in remote storage (S3, GCS, ...) answers 501 for template writes. Updating an endpoint whose YAML uses {{include}} answers 409, because the update would flatten the include.
Recommendation. Keep git as the source of truth. Use the config service on a laptop and in staging to try changes, copy what works into the repository, and deploy production from git (or a packed binary). In production, leave --config-service off, or keep it for read-only use (metrics, cache refresh, cache audit).
Security.
/api/v1/_config/*is served on the same port as your API. If you enable it in production, block that prefix at your reverse proxy or load balancer for everyone but operators.- The token is the key to rewriting your API. Use 32+ random characters (
openssl rand -hex 32); startup warns below 16. Rotating it means restarting the server with the new token. - With
--config-service, the MCP server also offersflapi_*tools (list, create, update and delete endpoints, update templates, refresh caches). They need the same token. See MCP Config Tools.
For the full API surface (endpoints, templates, caches, schema, MCP, ping), see docs/CONFIG_SERVICE_API_REFERENCE.md and the flapii CLI overview.
Scaffolding a project
Use the CLI to scaffold a working flapi.yaml plus directory layout:
flapii project init my-first-api
Supported flags:
-f, --force— overwrite existing files--skip-validation— skip post-scaffold validation--no-examples,--advanced— listed by--helpbut not implemented: the output is the same as without them--ai— not implemented either: it prints "AI-assisted project initialization coming soon!" and scaffolds the standard project
project init runs locally and needs no server. It exits 0 on success, 2 on a permission error, 3 when the error message contains "Invalid", and 1 on anything else (an invalid project name given as the argument is 1).
There is no built-in --template <preset> switch. Pick a starter from the examples directory and copy the relevant flapi.yaml if you need a specific data-source preset.
Best Practices
Use includes for organization
# Good: modular and maintainable
{{include:connections from config/connections.yaml}}
{{include:auth from config/auth.yaml}}
# Bad: everything in one 1000-line file
Keep secrets out of YAML
# Good: secrets via environment
password: '{{env.DB_PASSWORD}}'
# Bad: hardcoded secret in version control
password: 'my-secret-password'
Validate before deploying
# Fast check, no server start
./flapi --validate-config -c flapi.yaml
# Parse one endpoint the way the running server would
flapii endpoints validate /customers --file sqls/customers.yaml
Troubleshooting
Configuration not loading
Error: Failed to load configuration file
ls -la flapi.yaml— does the file exist where the server runs?./flapi --validate-config -c flapi.yaml— exact parser error.- Check the working directory used by your process supervisor.
Environment variable not resolved
... environment variable DB_HOST referenced as {{env.NAME}} but not whitelisted.
- Add a pattern matching it under
template.environment-whitelistin the mainflapi.yaml. echo $DB_HOSTin the same shell (or service unit) that launchesflapi.- If the value arrives as literal
${DB_HOST}, the file uses${...}, which flAPI does not substitute. Write{{env.DB_HOST}}.
401 Unauthorized from the Configuration Service
The server received a request to /api/v1/_config/* without a valid token. Set FLAPI_CONFIG_SERVICE_TOKEN for both the server and flapii, or pass -t/--config-service-token explicitly.
Next Steps
- Configuration Guide: Complete configuration reference
- CLI Overview:
flapiiand theflapiserver CLI - VS Code Extension: Visual config editing (preview)
- Endpoints Overview: Configure API endpoints
- Connections Overview: Set up data sources
- Deployment Guide: Production deployment
- Authentication: Secure your configuration