Skip to main content

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:

CommandWhat it isTalks to
flapiThe server. Also validates configs, packs bundles, refreshes caches once, installs extensions. See Server CLI.Your config files and DuckDB
flapiiA 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-io is the only package. There is no separate flapii package on PyPI.
  • flapii ships only in the wheel. The GitHub release archives (flapi-linux-amd64.tar.gz, ...) and the Docker images carry the flapi server, not flapii.
  • flapii --version prints the CLI's own version, which differs from the server's; flapii health shows server.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:

  1. -t, --config-service-token <token>
  2. the environment variable FLAPI_CONFIG_SERVICE_TOKEN
  3. --auth-token <token>
  4. 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:

  1. -u, --base-url <url>
  2. FLAPI_BASE_URL, then FLAPI_URL
  3. cli.http.base-url in a flapi.yaml flapii finds: the file given by -c, --config, else $FLAPI_CONFIG, else flapi.yaml in the current directory or a parent, else ~/.config/flapii/flapi.yaml
  4. http://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):

~/.config/flapii/flapi.yaml
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​

OptionDescriptionDefault / env
-c, --config <path>A flapi.yaml to read cli.http.* defaults from$FLAPI_CONFIG, then search
-u, --base-url <url>Server URLFLAPI_BASE_URL, FLAPI_URL
-t, --config-service-token <token>Config-service tokenFLAPI_CONFIG_SERVICE_TOKEN
--auth-token <token>Fallback tokenFLAPI_TOKEN
--timeout <seconds>Request timeout10, FLAPI_TIMEOUT
--retries <count>Retries, for reads only2, FLAPI_RETRIES
--insecureSkip TLS certificate verificationoff
-o, --output <format>json or tablejson
--json-style <style>camel or hyphen (keys as the YAML spells them, url-path)camel
--debug-httpLog requests, token maskedoff
-q, --quietDrop progress linesoff
-y, --yesAssume yes for confirmationsoff

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.

OptionEffect
-f, --forceOverwrite existing files. Without it, existing files are skipped, so rerunning is safe.
--skip-validationSkip the check at the end
--no-examples, --advancedListed by --help, not implemented: the output is the same as without them
--aiNot 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 validate sends 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 --file it waits for YAML on stdin.
  • create writes sqls/by-category.yaml on the server's disk and registers the endpoint at once; templates update writes the SQL file. Between the two, requests to the new endpoint fail with 500.
  • --file takes YAML or JSON; --stdin reads 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 /cheap answers 404 Endpoint not found.
  • delete without --force (or the global --yes) stops with exit code 1. It removes the YAML; the SQL file stays.
  • update replaces 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"}'
  • expand renders the template without running it and shows which values flAPI binds as prepared-statement parameters. It runs no validators. --cache expands the cache populate template instead, with the live watermark.
  • test validates the parameters, runs the query and returns the rows. A failure exits 1 with the reason ([400] Bad Request: Parameter validation failed, or the DuckDB error). --params-file <file> reads the JSON from a file.
  • templates update checks 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 get reports what the last set stored, not what the server started with.
  • config validate is local. It reads the endpoint files under template.path of the nearest flapi.yaml (or --dir, --file) and checks a few keys. It does not contact the server and does not check templates. For a real check use flapi --validate-config (see Server CLI) or endpoints validate --file against 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 jq works: flapii endpoints list | jq -r 'keys[]'.
  • -q drops 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:

MessageMeaning
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 workingraise --timeout; a refresh keeps running

A CI job​

Three stages, each catching what the one before cannot:

ci.sh
#!/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-config opens no data source and runs no SQL, so a misspelled column passes it.
  • templates test exits 1 on a validation or SQL error.
  • validate_only answers 200 either way, so check .valid (as jq -e does). Add &target=cache to check a cache's populate template the same way.

As a GitHub Actions job:

.github/workflows/flapi.yaml
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​

SymptomCauseFix
flapii: command not foundInstalled from a release archive or Docker imagepip install flapi-io
[404] Not Found with "The config service may be disabled"Server started without --config-serviceRestart with --config-service --config-service-token <t>
No token was sent (HTTP 401)flapii has no tokenExport FLAPI_CONFIG_SERVICE_TOKEN, or pass -t
rejected the token flapii sentToken differs from the server'sUse the token from the server's command line or banner
--auth-token seems ignoredFLAPI_CONFIG_SERVICE_TOKEN is exported and winsPass -t <token>
Cannot reach flAPI at http://localhost:8080Wrong port or host-u http://host:port or FLAPI_BASE_URL
endpoints validate hangsNo --file, so it waits for YAML on stdinPass --file <yaml>
A new endpoint answers 500Created, template not uploaded yetflapii templates update <path> --file <sql>
A YAML edit has no effectEndpoint YAML is read only at startup and on reloadflapii endpoints reload <path>; new files: --file
error: unknown option '--endpoint'--endpoint belongs to the server's flapi cache refreshflapii cache refresh <path>
log-level get says info on a warning serverget reports the last setset once to align
[DEP0169] DeprecationWarning: url.parse() on stderrPrinted by a library inside the pip-installed flapiiHarmless

Next steps​

The upstream guide is docs/guides/cli.md.

🍪 Cookie Settings