Skip to main content
Version: Dev

CLI Reference

The aisix binary runs the AISIX gateway and provides commands for working with open-source AISIX gateway configuration. Use validate to check a declarative resources.yaml file and export to convert resources in an existing etcd store into that format. Both commands run without starting gateway listeners.

Usage: aisix --config <CONFIG>
aisix <COMMAND>
CommandPurpose
aisix --config <CONFIG>Start the gateway with the given startup configuration file. See the Startup Configuration Reference.
aisix validate --resources <FILE>Check a resources file without starting the gateway.
aisix export --etcd <ENDPOINT> [-o <FILE>]Export resources from an open-source AISIX gateway's etcd store as a loadable resources file.

When running the official container image, invoke the binary directly:

docker run --rm --entrypoint /usr/local/bin/aisix ghcr.io/api7/aisix:dev --help

Validate a Resources File​

aisix validate reads a resources file the way the gateway does and runs its entries through the loader the gateway uses for etcd and files alike, without starting any listener: ${VAR} interpolation, the id checks, the lenient read schema, and the typed decode. See Loading, Errors, and Reload. Use it as a pre-check before a boot or a reload, or as a CI gate on configuration changes.

aisix validate --resources resources.yaml
OptionRequiredDescription
--resources <FILE>YesPath to the resources file to validate.

${VAR} references in the file resolve against the environment of the validate process itself. Run the command with the same variables the gateway will receive, or validation fails on the unresolved references.

validate is stricter than a running gateway about entries. The gateway drops an entry it rejects and serves the rest of the file; validate exits non-zero when any entry is rejected, including an entry under a collection name the gateway does not know. A field the loader does not define does not fail validation: validate prints it as a warning, and the gateway ignores it.

After the file loads, validate reports two guardrail conditions before the configuration reaches a running gateway.

The first is a guardrail nothing attaches. It loads, it is counted in the resource total, and it inspects no traffic, because a guardrail's scope is its attachments and nothing else. That is a valid state rather than an error — the model or route it was scoped to may have been removed from the file — so validate names such rows on standard error and still exits 0.

The second is an enabled row that cannot run. validate builds every enabled guardrail, even one with no attachment, and catches an invalid regular expression, an unknown detector, or a custom script with a syntax error before deployment. A running gateway builds only guardrails reached through enabled attachments. If one of those guardrails cannot build, the gateway skips it, serves without its screening, and reports it in GET /status/config.

Exit Codes​

Exit codeMeaning
0Every entry loads and every enabled guardrail can run. A summary is printed to standard output, possibly alongside warnings on standard error for ignored fields and for enabled guardrails that nothing attaches.
Non-zeroThe file cannot be read as entries, an entry is rejected, or a guardrail loads but cannot run. The report is printed to standard error.

On success:

OK: resources.yaml loaded 3 resource(s)

A guardrail nothing attaches is reported without changing the exit code:

resources file resources.yaml: 1 enabled guardrail(s) have no attachment and inspect no traffic:
- guardrails ("no-secrets"): add a guardrail_attachments entry to put it in force
OK: resources.yaml loaded 4 resource(s)

A field the loader does not define is reported as a warning, also without changing the exit code:

resources file resources.yaml: warning: /aisix/provider_keys/0b6f3c1e-2f0a-4c5e-9d55-7d1a8b0c2e11: fields this gateway does not define are ignored: api_bsae
OK: resources.yaml loaded 3 resource(s)

When the file cannot be read as entries, every such problem is reported together, identified by collection and position:

resources file resources.yaml: 3 error(s):
- (file): unrecognized _format_version "1" (supported: "2")
- models[0]: `id` is required (the resource's UUID)
- provider_keys[0]: field `api_key`: environment variable `OPENAI_API_KEY` is unset or empty

An entry that the loader rejects is reported with its etcd key, the failure kind, and the reason:

resources file resources.yaml: 1 row(s) rejected:
- /aisix/models/6efd592d-a73b-473d-8e2c-e9e103692f92 (schema_failed): schema validation failed at `/timeout`: value is not of type "integer"

A guardrail that loads but cannot run is reported the same way, with the reason the row would be dropped. A custom script error carries the engine's own line and column:

resources file resources.yaml: 1 guardrail(s) load but cannot run:
- guardrails ("screen-with-my-service"): custom guardrail script does not compile: Error: unsupported keyword: export
at guardrail.js:12:3

Validate with the Container Image​

Without a local binary, run the same check through Docker. Mount the file and pass the environment variables it references:

docker run --rm \
-v "$(pwd)/resources.yaml:/etc/aisix/resources.yaml:ro" \
-e OPENAI_API_KEY \
-e CALLER_API_KEY_SHA256 \
--entrypoint /usr/local/bin/aisix \
ghcr.io/api7/aisix:dev \
validate --resources /etc/aisix/resources.yaml

Export Resources from etcd​

aisix export reads resources from an open-source AISIX gateway's etcd prefix and writes them to a declarative resources file. Use it to move an etcd-backed gateway to a resources file. This includes gateways whose resources were created through the gateway Admin API in earlier releases. The command can also create a reviewable backup of resources the gateway can load.

aisix export \
--etcd "http://127.0.0.1:2379" \
--output resources.yaml
OptionRequiredDescription
--etcd <ENDPOINT>Yesetcd endpoint to read. Repeat the option or provide a comma-separated list for multiple endpoints.
--prefix <PREFIX>NoKey prefix containing the resources. Defaults to /aisix, the gateway's default etcd.prefix.
-o, --output <FILE>NoWrite the YAML document to a file instead of standard output. On Unix, AISIX creates or resets the file with mode 0600.
--reveal-secretsNoWrite stored credentials inline instead of replacing them with environment-variable placeholders. The resulting output contains live secrets.

The export decodes the store with the same loader the running gateway uses and writes every entry the loader accepts as its etcd ID plus the document exactly as etcd stores it, with fields in alphabetical order. References stay as they are stored. A field the gateway does not define is left out of the entry and reported on standard error. A literal $ in a stored value is written as $$ so that it survives interpolation when the file loads.

The output carries every kind the gateway reads except budgets: provider_keys, models, api_keys, guardrails, guardrail_attachments, mcp_servers, mcp_policies, a2a_agents, cache_policies, observability_exporters, rate_limit_policies, oidc_providers, claim_mappings, passthrough_routes, mcp_auth_settings, teams, users, budget_policy, usage_accounting, and pricing, with the shared catalog's pricing documents under the global section. budgets are left out because the control plane writes a budget's exhausted state at run time and nothing clears it in file mode; when the store holds budgets, the command reports how many it left out on standard error.

When several pricing documents in one table carry the same key, only the one the gateway applies is exported: the row with the highest revision, then the highest ID. Each row left out is reported on standard error with the ID of the row that replaced it. In a resources file every row shares one revision, so writing all of them would let a different row win.

The shared pricing catalog is read only when --prefix is the bare base prefix, such as the default /aisix. With an environment prefix such as /aisix/<env_id>, the read does not reach <base>/global/, so the catalog is not exported, and the command warns about each model whose pricing_key matches no pricing or global.pricing document written to the file, saying whether it falls back to its inline cost or carries no price.

By default, stored credentials are replaced with ${VAR} placeholders named after the entry, such as ${AISIXSECRET_PROVIDER_KEY_OPENAI_PROD_API_KEY}. AISIX prints the placeholder names and their source fields to standard error. Set those variables in the gateway environment before loading the exported file.

caution

Use --reveal-secrets only for a controlled migration where plaintext credentials must remain in the file. Do not commit, publish, or copy that output to an unsecured location.

The command also warns about a reference to an ID that is not among the exported entries. It still writes the output for inspection, and exits non-zero when the file it wrote is incomplete or cannot load: the loader rejected an entry, which is then missing from the output, or a resource is stored under an ID that is not a lowercase hyphenated UUID, which a resources file does not accept. Validate the completed file before switching the gateway to it:

aisix validate --resources resources.yaml