diff --git a/compose.testing.yml b/compose.testing.yml index 36532d91..d734c447 100644 --- a/compose.testing.yml +++ b/compose.testing.yml @@ -19,10 +19,10 @@ services: - "ONION_URL=http://test.onion" - "CORS_ORIGINS=*" - "RECEIVE_LN_ADDRESS=test@routstr.com" - - "COST_PER_REQUEST=10" - - "COST_PER_1K_INPUT_TOKENS=0" - - "COST_PER_1K_OUTPUT_TOKENS=0" - - "MODEL_BASED_PRICING=true" + - "FIXED_COST_PER_REQUEST=10" + - "FIXED_PER_1K_INPUT_TOKENS=0" + - "FIXED_PER_1K_OUTPUT_TOKENS=0" + - "FIXED_PRICING=false" - "NSEC=nsec1testkey1234567890abcdef" - "REFUND_PROCESSING_INTERVAL=3600" - "MINIMUM_PAYOUT=1000" diff --git a/docs/advanced/custom-pricing.md b/docs/advanced/custom-pricing.md index 1ab429c7..27d1f153 100644 --- a/docs/advanced/custom-pricing.md +++ b/docs/advanced/custom-pricing.md @@ -14,11 +14,11 @@ Routstr supports three pricing models: ### Configuration -Enable model-based pricing: +Enable model-based pricing (default behavior): ```bash # .env -MODEL_BASED_PRICING=true +FIXED_PRICING=false MODELS_PATH=/app/config/models.json EXCHANGE_FEE=1.005 # 0.5% exchange fee UPSTREAM_PROVIDER_FEE=1.05 # 5% provider margin @@ -118,14 +118,14 @@ if __name__ == "__main__": ### Configuration -Set up token-based pricing: +Set up token-based pricing overrides: ```bash # .env -MODEL_BASED_PRICING=false -COST_PER_REQUEST=1 # 1 sat base fee -COST_PER_1K_INPUT_TOKENS=5 # 5 sats per 1K input -COST_PER_1K_OUTPUT_TOKENS=15 # 15 sats per 1K output +FIXED_PRICING=false # use model pricing +FIXED_COST_PER_REQUEST=1 # optional base fee +FIXED_PER_1K_INPUT_TOKENS=5 # optional override +FIXED_PER_1K_OUTPUT_TOKENS=15 # optional override ``` ### Custom Token Counting diff --git a/docs/api/endpoints.md b/docs/api/endpoints.md index 345eed00..abff6d64 100644 --- a/docs/api/endpoints.md +++ b/docs/api/endpoints.md @@ -436,6 +436,27 @@ Authorization: Bearer sk-... ## Provider Discovery +## Admin Settings + +These endpoints are protected by the Admin cookie (`admin_password` set to your configured admin password). + +### Get Settings + +```http +GET /admin/api/settings +``` + +Returns the current application settings (sensitive values may be redacted). + +### Update Settings + +```http +PATCH /admin/api/settings +Content-Type: application/json +``` + +Body is a partial JSON of settings fields to update. Validated and persisted to the database. + ### List Providers Get available upstream providers. diff --git a/docs/getting-started/configuration.md b/docs/getting-started/configuration.md index 904553b7..360437cc 100644 --- a/docs/getting-started/configuration.md +++ b/docs/getting-started/configuration.md @@ -1,6 +1,6 @@ # Configuration -Routstr Core is configured through environment variables. This guide covers all available options. +Routstr Core is configured via a single settings row in the database. Environment variables are only used on first run to seed that row (with a few computed defaults like `ONION_URL`). After that, the database is the source of truth. You can update settings at runtime via the admin API. `DATABASE_URL` is always env-only. ## Environment Variables @@ -33,10 +33,10 @@ Routstr Core is configured through environment variables. This guide covers all | Variable | Description | Default | Required | |----------|-------------|---------|----------| -| `MODEL_BASED_PRICING` | Enable model-specific pricing from models.json | `false` | ❌ | -| `COST_PER_REQUEST` | Fixed cost per API request in sats | `1` | ❌ | -| `COST_PER_1K_INPUT_TOKENS` | Cost per 1000 input tokens in sats | `0` | ❌ | -| `COST_PER_1K_OUTPUT_TOKENS` | Cost per 1000 output tokens in sats | `0` | ❌ | +| `FIXED_PRICING` | Force fixed per-request pricing (ignore model token pricing) | `false` | ❌ | +| `FIXED_COST_PER_REQUEST` | Fixed cost per API request in sats | `1` | ❌ | +| `FIXED_PER_1K_INPUT_TOKENS` | Optional override: sats per 1000 input tokens | `0` | ❌ | +| `FIXED_PER_1K_OUTPUT_TOKENS` | Optional override: sats per 1000 output tokens | `0` | ❌ | | `EXCHANGE_FEE` | Exchange rate markup (1.005 = 0.5% fee) | `1.005` | ❌ | | `UPSTREAM_PROVIDER_FEE` | Provider fee markup (1.05 = 5% fee) | `1.05` | ❌ | @@ -46,6 +46,8 @@ Routstr Core is configured through environment variables. This guide covers all |----------|-------------|---------|----------| | `CORS_ORIGINS` | Comma-separated list of allowed CORS origins | `*` | ❌ | | `TOR_PROXY_URL` | SOCKS5 proxy URL for Tor connections | `socks5://127.0.0.1:9050` | ❌ | +| `RELAYS` | Comma-separated nostr relays for NIP-91 | defaults applied | ❌ | +| `PROVIDERS_REFRESH_INTERVAL_SECONDS` | Provider cache refresh interval | `300` | ❌ | ### Logging Configuration @@ -60,6 +62,7 @@ Routstr Core is configured through environment variables. This guide covers all |----------|-------------|---------|----------| | `CHAT_COMPLETIONS_API_VERSION` | Append `api-version` to `/chat/completions` (Azure OpenAI) | - | ❌ | | `DATABASE_URL` | SQLite database connection string | `sqlite+aiosqlite:///keys.db` | ❌ | +| `REFUND_CACHE_TTL_SECONDS` | Cache TTL for refund responses (seconds) | `3600` | ❌ | ## Configuration Examples @@ -78,7 +81,6 @@ ADMIN_PASSWORD=my-secure-password # .env UPSTREAM_BASE_URL=https://api.anthropic.com/v1 UPSTREAM_API_KEY=your-anthropic-key -MODEL_BASED_PRICING=true MODELS_PATH=/app/config/anthropic-models.json ``` @@ -115,36 +117,21 @@ ONION_URL=http://lightningai.onion CASHU_MINTS=https://mint1.com,https://mint2.com ``` -## Pricing Models +## Pricing -### Fixed Pricing +- Default: pricing comes from your `models.json`. +- Force fixed per-request pricing: set `FIXED_PRICING=true` and `FIXED_COST_PER_REQUEST`. +- Optional token overrides when using model pricing: set + `FIXED_PER_1K_INPUT_TOKENS` and/or `FIXED_PER_1K_OUTPUT_TOKENS`. +- Legacy envs are still accepted and mapped automatically: + `MODEL_BASED_PRICING` → `!FIXED_PRICING`, `COST_PER_REQUEST` → `FIXED_COST_PER_REQUEST`, + `COST_PER_1K_*` → `FIXED_PER_1K_*`. -Simple per-request pricing: +Example fixed pricing: ```bash -MODEL_BASED_PRICING=false -COST_PER_REQUEST=10 # 10 sats per request -``` - -### Token-Based Pricing - -Charge based on token usage: - -```bash -MODEL_BASED_PRICING=false -COST_PER_REQUEST=1 # 1 sat base fee -COST_PER_1K_INPUT_TOKENS=5 # 5 sats per 1k input -COST_PER_1K_OUTPUT_TOKENS=15 # 15 sats per 1k output -``` - -### Model-Based Pricing - -Use dynamic pricing from models.json: - -```bash -MODEL_BASED_PRICING=true -EXCHANGE_FEE=1.01 # 1% exchange fee -UPSTREAM_PROVIDER_FEE=1.00 # No additional markup +FIXED_PRICING=true +FIXED_COST_PER_REQUEST=10 ``` ## Custom Models Configuration diff --git a/docs/getting-started/docker.md b/docs/getting-started/docker.md index 0620937f..9357a44f 100644 --- a/docs/getting-started/docker.md +++ b/docs/getting-started/docker.md @@ -115,8 +115,8 @@ NPUB=npub1... HTTP_URL=https://api.mynode.com ONION_URL=http://mynode.onion -# Pricing -MODEL_BASED_PRICING=true +# Pricing (optional) +FIXED_PRICING=false EXCHANGE_FEE=1.005 UPSTREAM_PROVIDER_FEE=1.05 ``` diff --git a/docs/user-guide/models-pricing.md b/docs/user-guide/models-pricing.md index 24ce7d6c..c5f08850 100644 --- a/docs/user-guide/models-pricing.md +++ b/docs/user-guide/models-pricing.md @@ -11,8 +11,8 @@ Routstr supports three pricing models: Simple per-request charging: ```bash -MODEL_BASED_PRICING=false -COST_PER_REQUEST=10 # 10 sats per request +FIXED_PRICING=true +FIXED_COST_PER_REQUEST=10 # 10 sats per request ``` **Best for:** @@ -26,10 +26,10 @@ COST_PER_REQUEST=10 # 10 sats per request Charge based on actual token usage: ```bash -MODEL_BASED_PRICING=false -COST_PER_REQUEST=1 # 1 sat base fee -COST_PER_1K_INPUT_TOKENS=5 # 5 sats per 1K input -COST_PER_1K_OUTPUT_TOKENS=15 # 15 sats per 1K output +FIXED_PRICING=false # use model pricing +FIXED_COST_PER_REQUEST=1 # optional base fee +FIXED_PER_1K_INPUT_TOKENS=5 # optional override +FIXED_PER_1K_OUTPUT_TOKENS=15 # optional override ``` **Best for:** @@ -43,7 +43,7 @@ COST_PER_1K_OUTPUT_TOKENS=15 # 15 sats per 1K output Dynamic pricing based on model costs: ```bash -MODEL_BASED_PRICING=true +FIXED_PRICING=false EXCHANGE_FEE=1.005 # 0.5% exchange fee UPSTREAM_PROVIDER_FEE=1.05 # 5% provider fee ```