# Valstorm Cloud SaaS Pay-As-You-Go Billing Plugin (`valstorm-plugin-billing`) Opt-in Pay-As-You-Go (PAYG) SaaS billing engine for **Valstorm Cloud** (`platform.billing`). Self-hosted and enterprise-licensed Open Valstorm deployments can disable this plugin (`VALSTORM_PLUGINS` without `billing`) to run with zero metering or billing checks. --- ## 🤖 Agent-Assisted Quick Setup (Let the Valstorm Agent Set It Up) ### 1. Minimal Human Prerequisite Provide your Valstorm Cloud SaaS Stripe credentials (`STRIPE_API_KEY`, `STRIPE_ENDPOINT_SECRET_KEY`, and your credit/subscription `price_*` IDs). ### 2. Copy-Paste Prompt for Your Valstorm Agent ```text Set up the Valstorm Cloud SaaS Billing plugin (`valstorm-plugin-billing`) using `plugins/valstorm-plugin-billing/README.md`: 1. Save the SaaS Stripe configuration via `billing_configure_saas_settings`. 2. Initialize the PostgreSQL `billing_usage_event` and `billing_daily_rollup` tables and verify the Valkey Hot Ledger via `billing_get_overview`. 3. Verify route tier pricing, AI token pricing, Deepgram +25% markup, Telnyx Option B rate card, and storage rates ($0.05/GB/mo S3 VFS + $1.00/GB/mo structured DB). ``` --- ## 🛠️ End-to-End DIY Setup Guide ### Step 1: Configure Environment Variables Add to `apps/open-api/.env`: ```env BILLING_SYSTEM_ENABLED=true BILLING_METERING_ENABLED=true BILLING_BLOCKING_ENABLED=true BILLING_AUTO_CHARGE_ENABLED=true STRIPE_API_KEY=sk_live_... STRIPE_ENDPOINT_SECRET_KEY=whsec_... STRIPE_CREDIT_PRODUCT_ID=prod_V3qMljJiNcZgRq STRIPE_CREDIT_PRICE_ID=price_1U3igEAE0XXF93AeibV3Dbwc VALSTORM_SUBSCRIPTION_PRICE_ID=price_1UBMBMAE0XXF93AeL5SdeJGb BILLING_S3_RATE_PER_GB=0.05 BILLING_DB_RATE_PER_GB=1.00 ``` ### Step 2: Published Pricing Tiers - **Data Queries & VFS Internal Reads (`TIER_LOW`):** `$0.0002 / call` - **Standard API Mutations (`TIER_STANDARD`):** `$0.0010 / call` - **Telephony Relay (`TIER_TELEPHONY`):** `$0.0030 / call` - **Heavy Compute / Automations / VFS Hybrid Search (`TIER_HEAVY_COMPUTE`):** `$0.0100 / call` - **Cloud Object / VFS Storage (S3 documents, call recordings, voicemails, MMS media):** `$0.05 / GB / month` - **Structured Database Storage:** `$1.00 / GB / month` ### Step 3: Run Tests ```bash uv run --project apps/open-api pytest apps/open-api/tests/test_plugin_billing.py -v ```