Self-Hosting Variables
Payment wires: every paid endpoint accepts x402 and MPP (Machine Payments Protocol) on the same 402 - see Paying with x402 and Paying with MPP. Agent402 is the applied layer of Agentic Finance: agents that pay and get paid on their own.
The environment variables of a self-hosted instance, one row each with what it enables. Part of Self-Hosting.
Environment variables
Set these on your host. None are committed to the repo. This table is the common set: every variable the server reads, with its purpose and default, is in the generated configuration reference (see Configuration), and .env.example is a commented starting file.
| Variable | Required? | What it enables |
|---|---|---|
FREE_MODE |
No | Set true to serve all tools free (no paywall, no PoW gate) |
PORT |
No | HTTP listen port (default: 3000) |
BASE_URL |
For a public deployment | The public origin of your server, e.g. https://tools.example.com (default: http://127.0.0.1:<PORT>). Links, the resource URL in each 402, the discovery files and the canonical-host redirect are built from it |
TRUST_PROXY_HOPS |
Behind a proxy | How many reverse proxies in front of the server append X-Forwarded-For (default 0: the client address is the connection's, and a client-sent X-Forwarded-For is ignored). Set 1 behind a single edge proxy so per-client rate limits see the real client; the server logs a warning at boot while it is unset. Without it, every visitor behind the proxy reads as the proxy's one address and shares its rate limits |
WALLET_ADDRESS |
For paid mode | Your USDC receiving address (Base) |
WALLET_ENS |
No | ENS or Basename for display (e.g. agent402.base.eth) |
NETWORK |
For paid mode | Primary chain (default: base = Base mainnet; base-sepolia for testnet) |
PAYMENT_NETWORKS |
No | Comma-separated chains to accept (default: the primary network only), e.g. base,solana,polygon,arbitrum,stellar,algorand,monad,celo,avalanche,sei,optimism,arc,ink,robinhood; an extra EVM chain is paid to WALLET_ADDRESS; arc is configured only with CIRCLE_FACILITATOR_API_KEY set (which also adds it to a multi-chain list on its own) and ink only with INK_FACILITATOR_URL; Solana, Stellar and Algorand each need their own payTo (the next three rows) |
SOLANA_WALLET_ADDRESS |
With a Solana network in PAYMENT_NETWORKS |
Your USDC receiving address on Solana (base58). Unset, the server logs a boot warning and leaves the Solana option out of the 402s it sends |
STELLAR_WALLET_ADDRESS |
With stellar in PAYMENT_NETWORKS |
Your USDC receiving address on Stellar (public key, G...). Unset, the server logs a boot warning and leaves the Stellar option out of the 402s it sends |
ALGORAND_WALLET_ADDRESS |
With algorand in PAYMENT_NETWORKS |
Your USDC receiving address on Algorand. Unset, the server logs a boot warning and leaves the Algorand option out of the 402s it sends |
CDP_API_KEY_ID |
For paid mode (or FACILITATOR_URL) |
Coinbase CDP API key ID (facilitator auth) |
CDP_API_KEY_SECRET |
For paid mode (or FACILITATOR_URL) |
Coinbase CDP API secret |
FACILITATOR_URL |
No | Custom x402 facilitator URL for the primary network, used when the CDP keys are unset (the CDP keys take precedence). With neither, only NETWORK=base-sepolia boots, on the x402.org testnet facilitator |
POW_SECRET |
For PoW tier | HMAC secret for signing PoW challenges |
BRAVE_API_KEY |
No | Enables search-kit tools (Web, News, Images) |
BRAVE_ANSWERS_API_KEY |
No | Distinct Brave subscription token for the answer tool; falls back to BRAVE_API_KEY |
OPENROUTER_API_KEY |
No | Enables the /v1 LLM gateway tiers (chat, metered, embeddings, rerank, images, speech) and runs the /api/llm*, /api/image-gen*, /api/transcribe* and /api/embed* proxies; the chat, rerank, image and speech routes answer 503 without it |
OPENAI_API_KEY |
No | Enables /api/moderate and text-embedding-ada-002, and is the fallback for the /api/llm*, /api/image-gen*, /api/transcribe* and /api/embed* proxies, /v1/embeddings and /v1/decisions, which also run on OPENROUTER_API_KEY alone |
REDIS_URL |
No | Enables Redis: response caching (see Self-Hosting), and, across replicas, the shared rate limits, breakers and budgets (SHARED_LIMITS=off turns those off), the payment replay guard and idempotency store. A plain redis:// URL to a public host is refused at boot |
STATE_DATABASE_URL |
No | Postgres connection string for the state database; unset keeps state in SQLite and files on /data |
RATE_LIMIT_REPLICAS |
With replicas | How many server replicas share the limits; set it to the replica count (default 1) |
X402_INDEX_CRAWL, MPP_INDEX_CRAWL |
No | The seller crawlers that build the x402 and MPP indexes (/index, /api/index, /api/route). They run on a production boot only: NODE_ENV=production (the Dockerfile sets it) or Railway's production environment, and never under FREE_MODE or CI. on starts a crawler on any other boot; off keeps it off everywhere. A local or test server crawls nothing by default |
INDEX_PULL_MS |
No | How often each replica pulls the seller index rows another wrote (default 30000) |
TEMPO_RELAY |
No | off settles Tempo payments in the server itself (verify, simulate, broadcast over TEMPO_RPC_URL) and screens every party to a per-call payment against OFAC's SDN list; unset uses Tempo's hosted relay |
JEV_MODEL |
No | The Jev version the judgment routes pin to (default jev-1.14.0); TYPESAFE_MODEL overrides it for the internal callers |
DECISION_ONE, GEMINI_DECISION, JEV_OPENROUTER |
No | off turns off one judgment model reached over OpenRouter (Decision-1, Gemini Decision-1, the pinned Jev version); each is on whenever OPENROUTER_API_KEY is set |
DECISION_ONE_SUCCESSOR |
No | on sends the Decision-1 judgment leg to its successor model, only while the cost table has that model's own rate (vendor.decisions.decisionOneSuccessor); unset, the current model serves. The name a buyer sends does not change. |
STOCK_DATA_PROVIDER |
No | The stock data provider behind stock-history and the packs that run it: off (default) or databento, which is active only with DATABENTO_API_KEY set and serves daily venue bars at least 24 hours old (not consolidated). stock-quote is never listed, with or without a provider. With no active provider those routes are not listed and answer 503. A new provider is one adapter file in src/tools/ (see src/tools/stock-provider.js), its key and this setting |
CONTRACTOR_REPORT |
No | on offers the federal contractor report (listed, sold by card on /reports, served); unset (default), it is unlisted and unsold and its route answers a free 503 |
KALSHI_TOOLS |
No | on lists the tools that read the Kalshi API (kalshi-markets, kalshi-event, kalshi-live-data, kalshi-weather-index); unset (default), they are not listed and their routes answer 503 |
GATEWAY_NANOPAYMENTS |
No | on adds the Circle Gateway batched option (Self-Hosting). Off by default |
GATEWAY_NANOPAYMENT_NETWORKS |
No | Which networks carry the batched option: arc, base or both (default arc,base); a network must also be in the plain offer |
GATEWAY_WITHDRAW_ALERT_USD |
No | Gateway balance, in USD, at which gatewayBalance reads withdraw (default 25) |
MPP_SUB_UNCONFIRMED_ALERT_HOURS |
No | How long a wallet-billed monitor renewal may stay unconfirmed on chain before subscriptionRenewals reads unconfirmed (default 3; 0 or off disables) |
GATEWAY_PENDING_UNRESOLVED_HOURS |
No | How long a batched payment Gateway left pending may stay unresolved before gatewayPending raises it (default 24) |
GATEWAY_SETTLE_BREAKER_MAX, GATEWAY_SETTLE_BREAKER_WINDOW_MS, GATEWAY_SETTLE_BREAKER_MIN_FAIL_SHARE, GATEWAY_SETTLE_BREAKER_HARD_MAX, GATEWAY_SETTLE_BREAKER_UNKNOWN_MAX, GATEWAY_SETTLE_BREAKER_GLOBAL_MAX, GATEWAY_SETTLE_BREAKER_MULTI_NETWORK_MIN, GATEWAY_SETTLE_BREAKER_BURST_MAX, GATEWAY_SETTLE_BREAKER_AUTH_MAX, GATEWAY_SETTLE_BREAKER_OVERRUN_ALARM |
No | The settle-failure breaker on wallet-only routes and /v1: for a wallet that has never settled a payment here the count also reads its runs in flight that are not confirmed as covered by its balance, so _HARD_MAX holds for calls that arrive together, and _OVERRUN_ALARM failures (default _MAX) recorded for one wallet after its count already read refusing set settleFailures to burst; an address with no known payer is counted by its IPv6 /64; a wallet is refused after _MAX settle failures that are a verdict on its payment (default 3), or _UNKNOWN_MAX failures of unknown cause (default 9), inside the window (default 15 minutes) only while failures are more than _MIN_FAIL_SHARE of its outcomes there (default 0.5), and after _HARD_MAX failures (default 40) whatever its settled count; a failure on this server's side or the facilitator's is never counted against the wallet; the count is per wallet and per network for a signed EVM payer, so the 429 holds the network its failed payments named and the wallet can pay on another at once. _GLOBAL_MAX distinct failing /v1 buyers (default 12) inside the window set settleFailures to burst on /api/gateway-status for one window and log a line, and so does one wallet whose /v1 failures reach the refusing count on _MULTI_NETWORK_MIN networks (default 3) inside the window; no request is refused for the word. _GLOBAL_MAX distinct /v1 buyers whose payments failed inside the window for a verdict on the payment (never an unknown cause) also hold, for one window, a wallet that has never settled a payment (none in the window and no paid sale on record) after _BURST_MAX such failures (default 1), and its 429 says so; failures of unknown cause keep their _UNKNOWN_MAX count, and a wallet that has ever paid is served as before. One signed EVM authorization whose settlement fails _AUTH_MAX times (default _MAX) for a reason that is the buyer's (a verdict on its payment; never a failure on this server's side, an unknown cause or a payment still settling) is refused on its own; a new authorization from the same wallet is served at once |
INFLIGHT_COVER, INFLIGHT_COVER_UNREAD_MAX, INFLIGHT_COVER_UNREAD_PAID_MAX, INFLIGHT_COVER_LIVE_TTL_MS, INFLIGHT_COVER_SHARED_WINDOW_MS, INFLIGHT_COVER_READ_GAP_MS, INFLIGHT_COVER_READS_DAILY_MAX, INFLIGHT_COVER_PAST_BUDGET_READS_PER_MIN, INFLIGHT_COVER_KEPT_AT_ONCE_MS |
No | The check that a wallet's paid calls in flight are covered by its balance together, on every paid route that is not free through proof-of-work. On routes other than the report and media routes the balance is read inside about a second and decides alone: every call it covers is started, however many, and the check sets no other limit on calls at once (a route's own limit still applies). A call is not held until another call's payment settles: a call whose balance read is slow waits up to that second for it, and a call refused while another call of the wallet is settling answers within about a second (either takes up to about 3.5 seconds when a settlement lands during the read; five seconds on the report and media routes); a call it does not cover answers 429 (Retry-After: 30, or the seconds left until the wallet's balance is read again when the call was judged on an earlier read, or Retry-After: 5 while another call of the wallet is still settling and cover cannot be confirmed yet). When the balance cannot be read right now on those routes, the call is started if the last balance this server read for that wallet within the past 15 minutes, less what the wallet's payments have taken and its calls in progress hold since, covers it; otherwise, and for a wallet with no read that recent, the wallet runs up to _UNREAD_MAX calls at once (default 4), or _UNREAD_PAID_MAX (default 16) with a payment on record, and a call past that answers 429 with Retry-After: 5. The report and media routes are the exception: the balance read is given up to five seconds, a refusal answers Retry-After: 30, and while the balance cannot be read every wallet runs up to _UNREAD_MAX calls at once there. A Tempo pull credential in a multisig envelope is judged on its account's balance once a payment from that account under the same multisig config has settled here (the record is kept in the shared store when one is configured, else in the process); until then calls paid that way run up to _UNREAD_MAX at once per client address, whichever account each names. INFLIGHT_COVER=composite keeps the check on the report and media routes only, and the settle-failure breaker then counts no runs in flight; INFLIGHT_COVER=off switches the check off on every route. Neither value changes these, which are always on: a handler's answer headers are left off a refused payment, a card or Tempo pull challenge must outlive the route's run, the settle-failure breaker keys an address with no known payer by its IPv6 /64, and the breaker is consulted on the page-content routes (extract, meta, dns, render, screenshot, pdf) and the memory routes. With several containers, each run in flight is a reservation in the shared store: it counts only while the container that wrote it keeps its liveness key (_LIVE_TTL_MS, default 30000), and one that nobody removes ages out after _SHARED_WINDOW_MS (default 900000, minimum 60000). A wallet's balance reads are at least a gap apart (_READ_GAP_MS, default 10000, range 1000 to 10000): inside that gap a call its last read does not cover is refused on that read, with Retry-After set to the seconds left in the gap. Reads that reach the capped on-chain data host have a daily budget of their own (_READS_DAILY_MAX, by default a fifth of HARDCAP_ALCHEMY_CALLS, never over half of it), so paid tools keep the rest of that ceiling; past it each wallet is still read once a minute, with at most _PAST_BUDGET_READS_PER_MIN such reads in any minute for all wallets (default 30, per container), a call is otherwise judged as when the balance cannot be read, and a call refused for its balance answers Retry-After with the seconds until its wallet is read again (at most 60). A wallet's last read is judged on at once, with no new read waited for, while it is younger than _KEPT_AT_ONCE_MS (default 60000, range the read gap to 300000); a settled payment refreshes an older one in the background. coverageReads on /api/gateway-status carries two words: status reads degraded when a call was started or refused without a balance read made for it inside the last ten minutes, and alert reads sustained when such calls fell in three or more separate minutes of the last ten for three or more wallets (else ok). |
STELLAR_HORIZON_URL |
No | The Horizon server asked first for a Stellar payer's balance by the check in the row above (an account address, G...; the built-in public Horizon servers are asked after it, and a contract address, C..., has no balance there and is judged as a balance that cannot be read). The same server confirms a Stellar payment on the ledger after a settle that did not answer. Default: https://horizon.stellar.org |
COMPOSITE_GUARD_GLOBAL_MAX_FAILS, COMPOSITE_GUARD_GLOBAL_PAUSE_MS |
No | Report and media runs that spent upstream and then did not settle: at _GLOBAL_MAX_FAILS (default 12, each buyer counted for at most its own per-buyer limit) inside the guard window, unsettledReports reads burst on /api/gateway-status for _GLOBAL_PAUSE_MS (default 15 minutes) and a line is logged; no request is refused for it. The per-buyer block (COMPOSITE_GUARD_MAX_FAILS and its neighbors) is unchanged |
X402_UPTO_NETWORKS |
No | all (never includes Arc) or a CSV of CAIP-2 ids that also offer the upto scheme, in the order the 402 lists them; a facilitator must advertise it for that network. Arc (eip155:5042) offers upto only when the list names it explicitly. Each upto network past the first is charged to a route's 402 budget, so turning Arc upto and sponsoring on shortens about 320 listings to fit; a route that still does not fit keeps every exact accept and one upto accept, on Base (the first listed network that is not Arc) whatever the list order, and declares no gas sponsoring |
X402_UPTO_GAS_SPONSORING |
No | Permit2 gas sponsorship on the metered /v1 routes that offer upto: on declares eip2612GasSponsoring, or a CSV names eip2612GasSponsoring and erc20ApprovalGasSponsoring; a key is declared only when the facilitator settling upto on every offered network advertises it. The facilitators' /supported answers are read at boot and again every ten minutes (X402_UPTO_GAS_REFRESH_MS): a key a settling facilitator stops advertising is withdrawn from the 402s and returns when it is advertised again, while a key first advertised after boot is declared from the next restart. Off by default |
BASE_DENIM_ACTIVATION_TIMESTAMP |
No | When Base's shorter block time takes effect (ISO time); payment windows are counted in seconds either side of it |
ANALYTICS_DATABASE_URL |
No | Postgres connection string for analytics; falls back to DATABASE_URL |
GLAMA_MAINTAINER_EMAIL |
No | Email returned at /.well-known/glama.json |
MPP_SECRET_KEY |
For MPP | HMAC secret binding MPP challenges; presence mounts the MPP dual-stack shim (WWW-Authenticate: Payment on every 402 except to the clients MPP_OFFER_WITHHOLD_USER_AGENTS names, evm method settled through your x402 facilitator). Unset = pure x402 |
MPP_CHALLENGE_NETWORKS |
No | all or a CSV of chain ids that get MPP evm challenges (default Base + Celo) |
MPP_EVM_DOMAIN_FALLBACK |
No | off disarms the wrong-EIP-712-domain detection. On by default: a credential signed under a different known token-domain name than the one your accepts entry advertises is refused locally with an RFC 9457 problem, and MPP challenges are withheld from that client briefly so an MPP-preferring wallet falls through to your x402 offer instead of looping. MPP_EVM_DOMAIN_FALLBACK_TTL_MS (30 min) and MPP_EVM_DOMAIN_FALLBACK_MAX_RESPONSES (5) bound the hold |
MPP_OFFER_WITHHOLD_USER_AGENTS |
No | Comma list of User-Agent prefixes (matched without regard to case) whose 402 carries the x402 offer alone, with no WWW-Authenticate: Payment challenge; the PAYMENT-REQUIRED header and the body are unchanged. Default python-httpx/; off offers MPP to every client. A request with X-Payment-Offers: mpp (or all), or with an Accept-Payment header naming an MPP method (such as tempo/charge), gets the MPP challenges back, and a request carrying an MPP credential is never gated. Counts on the operator view of /api/gateway-status |
TEMPO_API_KEY |
For native Tempo (relay mode) | Tempo MPP relay key (needs the mpp:write scope; not needed with TEMPO_RELAY=off); with a recipient it offers tempo/charge challenges settled natively on Tempo |
TEMPO_RECIPIENT_ADDRESS |
No | Tempo payTo (defaults to WALLET_ADDRESS) |
TEMPO_CURRENCY |
No | CSV of TIP-20 token addresses or names to offer, one challenge each in order (first = preferred; default PathUSD). Names: usdc (USDC.e), pathusd (PathUSD), ousd (OUSD). A stock client pays the first, so list the token most buyers hold first, for example usdc,ousd |
STRIPE_SECRET_KEY |
For card paths | Rollout switch for the human front door: /reports (card checkout), /monitors (subscriptions), /credits (prepaid credits) and the Authorization: Bearer a402_… credits gate. Unset = none of it is mounted; the /v1 report routes still sell over x402 / MPP |
CREDITS_SALES |
No | on opens new prepaid credit sales at /credits. Off by default: the checkout answers 503, and existing keys keep working either way |
CREDITS_DIR, HUMAN_CHECKOUT_DIR |
No | Where the prepaid credits store and the card report store keep their files when STATE_DATABASE_URL is unset (default /data/credits and /data/human-checkout, or under /tmp without a /data directory); the older single-file human-checkout.json is read from beside the report store's directory. With STATE_DATABASE_URL set, the report store's directory still keeps _pending-finals.ndjson, the final records waiting to reach the database. A test server sets both to a directory of its own. The credits file store's key-id and email lookup index lives in each process's memory, so run one server process per CREDITS_DIR |
CREDITS_INDEXES, CREDITS_INDEX_DELAY_MS |
No | With STATE_DATABASE_URL, the prepaid credits balance page finds a balance by key id or email through two expression indexes on the records table, built CONCURRENTLY in the background CREDITS_INDEX_DELAY_MS (default 60000) after the store loads, by one container at a time; CREDITS_INDEXES=off leaves the build to an operator |
STRIPE_WEBHOOK_SECRET |
With Stripe | Signing secret for the Stripe webhook endpoint (subscription status, invoices, credits purchases, refunds and disputes). The webhook is verified only when set |
STRIPE_PROFILE_ID |
No | With STRIPE_SECRET_KEY, mounts cards over the MPP wire (stripe/charge via Shared Payment Tokens) on routes priced $0.50 or more |
STRIPE_AUTOMATIC_TAX |
No | true computes Stripe Tax on report and monitor checkouts, taken out of the tax-included price (enable Stripe Tax in the dashboard first) |
EMAIL_FROM |
For emails | Verified sender address; with a provider key below, report links, monitor reports and credits keys are emailed |
ZEPTOMAIL_TOKEN |
No | Zoho ZeptoMail send-mail token (with or without the Zoho-enczapikey prefix); ZEPTOMAIL_URL overrides the regional API base |
RESEND_API_KEY |
No | Resend API key, the alternative email provider (ZeptoMail wins when both are set) |
MONITOR_SCHEDULER |
No | off disarms the monitor fulfillment timer (manual operator runs still work) |