caelum0x d56639a594
Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

71 lines
2.3 KiB
Python

"""Pure spend policy: BYOK routing-fee math + config (no DB, no IO).
When a customer routes a stage through their OWN provider key (BYOK), ReelForge
does not pay the provider — so instead of the pass-through provider price it
charges a disclosed **routing fee** (PROVIDER_MARKETPLACE_PLAN.md §1.3). The fee
rate is versioned configuration; it is never applied silently (a stage's usage
record shows the fee as its cost).
"""
from __future__ import annotations
import os
from typing import Any
_DEFAULT_BYOK_FEE_BPS = 1000 # 10.00% of the equivalent provider price
_DEFAULT_BYOK_MIN_FEE_MICROS = 1_000 # $0.001 floor per BYOK stage
def _config_value(env_name: str, config_key: str, default: Any) -> Any:
raw = os.getenv(env_name)
if raw is not None:
return raw
try:
from app.config import config
return config.app.get(config_key, default)
except Exception:
return default
def _bounded_int(value: Any, default: int, minimum: int, maximum: int) -> int:
try:
return max(minimum, min(int(value), maximum))
except (TypeError, ValueError):
return default
def byok_fee_bps() -> int:
"""Platform BYOK routing-fee rate in basis points; bounded [0, 5000]."""
return _bounded_int(
_config_value("REELFORGE_BYOK_FEE_BPS", "reelforge_byok_fee_bps", _DEFAULT_BYOK_FEE_BPS),
_DEFAULT_BYOK_FEE_BPS,
0,
5000,
)
def byok_min_fee_micros() -> int:
return _bounded_int(
_config_value("REELFORGE_BYOK_MIN_FEE_MICROS", "reelforge_byok_min_fee_micros", _DEFAULT_BYOK_MIN_FEE_MICROS),
_DEFAULT_BYOK_MIN_FEE_MICROS,
0,
10_000_000,
)
def byok_fee_micros(provider_cost_micros: int) -> int:
"""The routing fee charged for a BYOK stage, from the equivalent provider cost.
``max(min_fee, provider_cost * rate)`` in integer microdollars, HALF_UP on the
/10_000 division. When the fee rate is 0 the fee is 0 (BYOK is free — the
customer only pays their own provider).
"""
base = max(0, int(provider_cost_micros))
rate = byok_fee_bps()
# No fee when disabled or when there is no billable work (zero-cost stage).
if rate <= 0 or base <= 0:
return 0
metered = (base * rate + 5_000) // 10_000
return int(max(byok_min_fee_micros(), metered))