Skip to content

CLI Reference

tollbooth provides a CLI for managing your gateway.

Generate a tollbooth.config.yaml interactively.

Terminal window
tollbooth init

Walks you through setting up wallets, upstreams, and routes with prompts.

Generate a config from an existing OpenAPI spec:

Terminal window
tollbooth init --from openapi spec.yaml

This reads the OpenAPI spec and creates route entries for each endpoint with default pricing.


Start the gateway.

Terminal window
tollbooth start [--config=path]
FlagDefaultDescription
--configtollbooth.config.yamlPath to the config file
Terminal window
# Start with default config location
tollbooth start
# Start with a custom config path
tollbooth start --config=examples/tollbooth.config.dev.yaml

On startup, tollbooth:

  1. Loads and validates the config
  2. Resolves environment variables
  3. Loads hook modules (if any)
  4. Starts the HTTP server
  5. Registers the /.well-known/x402 discovery endpoint (if gateway.discovery is true)

Start the gateway in development mode with watch.

Terminal window
tollbooth dev [--config=path]
FlagDefaultDescription
--configtollbooth.config.yamlPath to the config file

Same as start but with file watching enabled — the gateway restarts when your config or hook files change.


Validate a config file without starting the gateway.

Terminal window
tollbooth validate [--config=path]
FlagDefaultDescription
--configtollbooth.config.yamlPath to the config file

Outputs:

✅ Config is valid
2 upstream(s), 5 route(s)

Or on error:

❌ Invalid "price" value in route "GET /data"

Use this in CI to catch config errors before deployment.


Show the help message with all available commands.

Terminal window
tollbooth help
⛩️ tollbooth — Turn any API into a paid x402 API
Usage:
tollbooth init Generate a config file interactively
tollbooth init --from openapi <path> Generate config from an OpenAPI spec
tollbooth start [--config=path] Start the gateway
tollbooth dev [--config=path] Start in dev mode (with watch)
tollbooth validate [--config=path] Validate config without starting
tollbooth help Show this help message

You can also use tollbooth as a library:

import { createGateway, loadConfig } from "x402-tollbooth";
const config = loadConfig("./tollbooth.config.yaml");
const gateway = createGateway(config);
await gateway.start();

The TollboothGateway interface:

interface TollboothGateway {
start(): Promise<void>;
stop(): Promise<void>;
readonly port: number;
readonly config: TollboothConfig;
}

Next: Configuration Reference →