flapii CLI
flapii is the command-line client for flAPI's config service (/api/v1/_config/*). It inspects and changes a running flapi server: endpoints, SQL templates, caches, schema, log level and metrics, without a restart.
There are two commands, and both come from one package:
| Command | What it is | Talks to |
|---|---|---|
flapi | The server. Also validates configs, packs bundles, refreshes caches once, installs extensions. See Server CLI. | Your config files and DuckDB |
flapii | A client for the server's config service. | A running flapi over HTTP |
Installation
pip install flapi-io # installs both `flapi` and `flapii`
flapi --help
flapii --help
Or try it without installing:
uvx --from flapi-io flapii --help
flapi-iois the only package. There is no separateflapiipackage on PyPI.flapiiships only in the wheel. The GitHub release archives (flapi-linux-amd64.tar.gz, ...) and the Docker images carry theflapiserver, notflapii.flapii --versionprints the CLI's own version, which differs from the server's;flapii healthshowsserver.version.
Talking to a server
1. Start the server with the config service
The config service is off by default. In a first terminal, turn it on and give it a token:
flapi -c flapi.yaml --config-service --config-service-token demo-token-0123456789
The server also reads the token from FLAPI_CONFIG_SERVICE_TOKEN. Without either, it generates one and prints it in its startup banner.
2. Point flapii at it
In a second terminal:
export FLAPI_CONFIG_SERVICE_TOKEN=demo-token-0123456789
export FLAPI_BASE_URL=http://localhost:8080 # change the port if you used -p
flapii ping
✔ ✓ Connected to flapi server
Name: my-flapi-project
Base URL: http://localhost:8080
Every config-service route except health needs the token. flapii health works without it.
Where flapii gets the token
First match wins:
-t,--config-service-token <token>- the environment variable
FLAPI_CONFIG_SERVICE_TOKEN --auth-token <token>- the environment variable
FLAPI_TOKEN
The environment variable beats --auth-token (it is the default value of -t), so with FLAPI_CONFIG_SERVICE_TOKEN exported, --auth-token is ignored. Use -t to override. flapii sends the token as both Authorization: Bearer and X-Config-Token, and never reads it from a file.
Where flapii gets the URL
First match wins:
-u,--base-url <url>FLAPI_BASE_URL, thenFLAPI_URLcli.http.base-urlin aflapi.yamlflapii finds: the file given by-c,--config, else$FLAPI_CONFIG, elseflapi.yamlin the current directory or a parent, else~/.config/flapii/flapi.yamlhttp://localhost:8080
Keep a default URL in the per-user file, not in your project's flapi.yaml; the server warns about a cli: key in its own config (Unknown top-level configuration key `cli` is ignored):
cli:
http:
base-url: http://localhost:8080
timeout-seconds: 30
flapii only reaches that file when there is no flapi.yaml in the current directory or its parents. ~/.flapi/config.json holds only the Gemini key of the endpoint wizard; flapii reads no URL or token from it.
Global options
| Option | Description | Default / env |
|---|---|---|
-c, --config <path> | A flapi.yaml to read cli.http.* defaults from | $FLAPI_CONFIG, then search |
-u, --base-url <url> | Server URL | FLAPI_BASE_URL, FLAPI_URL |
-t, --config-service-token <token> | Config-service token | FLAPI_CONFIG_SERVICE_TOKEN |
--auth-token <token> | Fallback token | FLAPI_TOKEN |
--timeout <seconds> | Request timeout | 10, FLAPI_TIMEOUT |
--retries <count> | Retries, for reads only | 2, FLAPI_RETRIES |
--insecure | Skip TLS certificate verification | off |
-o, --output <format> | json or table | json |
--json-style <style> | camel or hyphen (keys as the YAML spells them, url-path) | camel |
--debug-http | Log requests, token masked | off |
-q, --quiet | Drop progress lines | off |
-y, --yes | Assume yes for confirmations | off |
Commands
project init: scaffold a project
Runs locally and needs no server:
flapii project init demo
You get demo/flapi.yaml, an endpoint GET /sample (sqls/sample.yaml + sqls/sample.sql) over data/sample.csv, and common/auth.yaml / common/rate-limit.yaml to include later.
| Option | Effect |
|---|---|
-f, --force | Overwrite existing files. Without it, existing files are skipped, so rerunning is safe. |
--skip-validation | Skip the check at the end |
--no-examples, --advanced | Listed by --help, not implemented: the output is the same as without them |
--ai | Not implemented: prints "AI-assisted project initialization coming soon!" and scaffolds the standard project |
It exits 0 on success, 2 on a permission error, 3 when the error message contains "Invalid", and 1 on anything else, including an invalid project name given as the argument.
endpoints
flapii endpoints list -o table
flapii endpoints get /sample # the parsed config, defaults included
flapii endpoints parameters /sample -o table
When a GET and a POST share a path, pick one with --method POST; the same option exists on update, delete, validate, reload and the template and cache commands.
Create one from a file. Write drafts outside the project, so the server does not load a half-written file:
flapii endpoints validate /by-category --file ../drafts/by-category.yaml
flapii endpoints create --file ../drafts/by-category.yaml
flapii templates update /by-category --file ../drafts/by_category.sql
endpoints validatesends the YAML to the server, which parses it as it would at startup. The argument is the URL path; the YAML comes from--file. Without--fileit waits for YAML on stdin.createwritessqls/by-category.yamlon the server's disk and registers the endpoint at once;templates updatewrites the SQL file. Between the two, requests to the new endpoint fail with500.--filetakes YAML or JSON;--stdinreads the payload from a pipe.
Update, reload, delete:
flapii endpoints update /by-category --file ../drafts/by-category.yaml
flapii endpoints reload /sample # re-read a hand-edited YAML
flapii endpoints reload --file sqls/cheap.yaml # load a new hand-written file
flapii endpoints delete /cheap --force
- flAPI re-reads a SQL template on the next request, so a template edit (or a
git pull) is live at once. An endpoint YAML is read only at startup and on reload. - A file the server never loaded needs
reload --file;reload /cheapanswers404 Endpoint not found. deletewithout--force(or the global--yes) stops with exit code1. It removes the YAML; the SQL file stays.updatereplaces the endpoint's whole config and writes its YAML file, patching in place where it can.
flapii endpoints wizard creates an endpoint interactively (--ai asks Gemini to draft it, with the key from FLAPI_GEMINI_KEY; --output-file writes the YAML instead). Not for scripts.
templates
flapii templates list
flapii templates get /by-category
flapii templates expand /by-category --params '{"category":"toys"}'
flapii templates test /by-category --params '{"category":"toys"}'
expandrenders the template without running it and shows which values flAPI binds as prepared-statement parameters. It runs no validators.--cacheexpands the cache populate template instead, with the live watermark.testvalidates the parameters, runs the query and returns the rows. A failure exits1with the reason ([400] Bad Request: Parameter validation failed, or the DuckDB error).--params-file <file>reads the JSON from a file.templates updatechecks the Mustache syntax before writing; a broken template is refused.
See SQL Templating for what the bindings mean.
cache
The scaffold from project init has no cache. The examples below assume a cached endpoint GET /products with cache.table: products_cache and a ducklake: block with alias: cache in flapi.yaml; Caching Setup shows how to add one.
flapii cache list # every endpoint; use the JSON, the table view shows N/A
flapii cache get /products
flapii cache refresh /products # refresh now
flapii cache refresh /products --full # drop the table, erase the watermark, rebuild
flapii cache audit /products -o table # refresh history, newest first
flapii cache gc /products # expire snapshots under the retention policy
Also there: cache template / cache update-template (the populate SQL), cache update (the cache block), cache compact (DuckLake compaction now) and cache drop-table <table> (an orphaned cache table). On an endpoint without a cache, refresh exits 1 with [400] Bad Request: Cache is not enabled for this endpoint. flapii takes the path as an argument; --endpoint belongs to the server's one-shot flapi cache refresh.
schema
The cache connection and products_cache table below are the DuckLake alias and cache table from the cache example.
flapii schema connections
flapii schema tables --connection cache
flapii schema get | jq '.cache.tables.products_cache.columns | keys'
flapii schema refresh
--connection filters by attached database name: the DuckLake alias or a database a connection's init attaches. A connection that only holds a file path attaches nothing and lists no tables. The --connection, --table and --database options of schema get filter nothing in v26.11.25; filter with jq.
config
flapii config log-level set debug # resets on server restart
flapii config log-level get
flapii config log-level list # debug, info, warning (or warn), error
flapii config env # whitelisted environment variables and whether they are set
flapii config show # flapii's own resolved settings (URL, output, ...)
flapii config validate # LOCAL check of endpoint YAML files
log-level getreports what the lastsetstored, not what the server started with.config validateis local. It reads the endpoint files undertemplate.pathof the nearestflapi.yaml(or--dir,--file) and checks a few keys. It does not contact the server and does not check templates. For a real check useflapi --validate-config(see Server CLI) orendpoints validate --fileagainst a server.
metrics, health, ping
flapii -o table metrics # per-endpoint counts and latencies, cache states
flapii metrics -e /sample # one route or MCP tool
flapii health # needs no token
flapii ping
Counts run since server start. The metrics are JSON behind the config token (GET /api/v1/_config/metrics); there is no Prometheus endpoint. For traces, see Observability.
mcp
flapii mcp tools list, flapii mcp resources list and flapii mcp prompts list (and get <name>) show the mcp-tool, mcp-resource and mcp-prompt blocks your endpoint YAMLs declare.
Output for scripts
-o json(the default) or-o table. It is a global option, so it works on any command (flapii -o table metrics).- Progress lines go to stderr, the JSON to stdout, so
jqworks:flapii endpoints list | jq -r 'keys[]'. -qdrops the progress lines; a failure still prints one line.
Exit codes
0 on success, 1 on any failure: an HTTP error, an unreachable server, a failed validation or test, an unknown command or option. (project init adds 2 for a permission error and 3 for an error whose message contains "Invalid".) The message says which:
| Message | Meaning |
|---|---|
The config service needs a token. ... No token was sent (HTTP 401). | flapii found no token |
The config service rejected the token flapii sent. | the token differs from the server's |
Cannot reach flAPI at http://localhost:8080. Is it running? | wrong URL, or no server |
The config service may be disabled on this server. (with a 404) | server started without --config-service |
Request timed out after 10s; the server may still be working | raise --timeout; a refresh keeps running |
A CI job
Three stages, each catching what the one before cannot:
#!/usr/bin/env bash
set -euo pipefail
cd demo
# 1. Parse every YAML and template. Opens no data source.
flapi -c flapi.yaml --validate-config
# 2. Start a throwaway server with the config service on a spare port.
export FLAPI_CONFIG_SERVICE_TOKEN=$(openssl rand -hex 32)
export FLAPI_BASE_URL=http://localhost:18080
flapi -c flapi.yaml -p 18080 --config-service > server.log 2>&1 &
SERVER=$!
trap 'kill $SERVER' EXIT
until curl -sf "$FLAPI_BASE_URL/health/live" > /dev/null; do sleep 0.5; done
# 3a. Run each endpoint's query against real data, with fixture params.
flapii -q templates test /sample --params '{"id": 1}' > /dev/null
flapii -q templates test /by-category --params '{"category": "toys"}' > /dev/null
# 3b. Or bind-check the SQL without running it (?validate_only=1).
# The slug of /by-category is -by~1category: '/' becomes '-', a literal '-' becomes '~1'.
curl -sf -X POST -H "X-Config-Token: $FLAPI_CONFIG_SERVICE_TOKEN" \
-d '{"parameters": {"category": "toys"}}' \
"$FLAPI_BASE_URL/api/v1/_config/endpoints/-by~1category/template/expand?validate_only=1" \
| jq -e '.valid'
--validate-configopens no data source and runs no SQL, so a misspelled column passes it.templates testexits1on a validation or SQL error.validate_onlyanswers200either way, so check.valid(asjq -edoes). Add&target=cacheto check a cache's populate template the same way.
As a GitHub Actions job:
name: Validate flAPI configuration
on: [push, pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: pip install flapi-io # installs both flapi and flapii
- run: bash ci.sh
The config service in production
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, and nothing goes back to git.
Keep git as the source of truth: try changes with the config service on a laptop or in staging, copy what works into the repository, and deploy production from git (or a packed binary). In production, leave --config-service off, or use it read-only (metrics, cache refresh, cache audit). Details and the security rules are in Configuration Service.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
flapii: command not found | Installed from a release archive or Docker image | pip install flapi-io |
[404] Not Found with "The config service may be disabled" | Server started without --config-service | Restart with --config-service --config-service-token <t> |
No token was sent (HTTP 401) | flapii has no token | Export FLAPI_CONFIG_SERVICE_TOKEN, or pass -t |
rejected the token flapii sent | Token differs from the server's | Use the token from the server's command line or banner |
--auth-token seems ignored | FLAPI_CONFIG_SERVICE_TOKEN is exported and wins | Pass -t <token> |
Cannot reach flAPI at http://localhost:8080 | Wrong port or host | -u http://host:port or FLAPI_BASE_URL |
endpoints validate hangs | No --file, so it waits for YAML on stdin | Pass --file <yaml> |
A new endpoint answers 500 | Created, template not uploaded yet | flapii templates update <path> --file <sql> |
| A YAML edit has no effect | Endpoint YAML is read only at startup and on reload | flapii endpoints reload <path>; new files: --file |
error: unknown option '--endpoint' | --endpoint belongs to the server's flapi cache refresh | flapii cache refresh <path> |
log-level get says info on a warning server | get reports the last set | set once to align |
[DEP0169] DeprecationWarning: url.parse() on stderr | Printed by a library inside the pip-installed flapii | Harmless |
Next steps
- Server CLI: the
flapibinary's flags and subcommands - Configuration Service: what the API does, and running it in production
- Config Service REST API: the HTTP routes behind each command
- SQL Templating: what
templates expandshows
The upstream guide is docs/guides/cli.md.