AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
feat(backend/copilot): recalibrate AutoPilot's per-plan daily and weekly spend limits (#14442)
Reinier van der Leer4ac36463613c
diff --git a/autogpt_platform/backend/backend/api/features/subscription_routes_test.py b/autogpt_platform/backend/backend/api/features/subscription_routes_test.pyindex c3a67ba516..0ec85f588e 100644--- a/autogpt_platform/backend/backend/api/features/subscription_routes_test.py+++ b/autogpt_platform/backend/backend/api/features/subscription_routes_test.py@@ -261,8 +261,8 @@ def test_get_subscription_status_pro(# so the frontend never renders a multiplier badge for a hidden row.assert set(data["tier_multipliers"].keys()) == set(data["tier_costs"].keys())assert data["tier_multipliers"]["BASIC"] == 1.0- assert data["tier_multipliers"]["PRO"] == 5.0- assert data["tier_multipliers"]["MAX"] == 20.0+ assert data["tier_multipliers"]["PRO"] == 1.25+ assert data["tier_multipliers"]["MAX"] == 10.6667assert data["tier_multipliers"]["BUSINESS"] == 60.0diff --git a/autogpt_platform/backend/backend/copilot/config.py b/autogpt_platform/backend/backend/copilot/config.pyindex bc1a3841af..d5c03b2cbf 100644--- a/autogpt_platform/backend/backend/copilot/config.py+++ b/autogpt_platform/backend/backend/copilot/config.py@@ -359,7 +359,7 @@ class ChatConfig(BaseSettings):# These defaults act as the ceiling when LaunchDarkly is unreachable;# the live per-tier values come from the COPILOT_*_COST_LIMIT flags.daily_cost_limit_microdollars: int = Field(- default=1_000_000,+ default=2_500_000,description="Max cost per day in microdollars, resets at midnight UTC. ""0 means no spend allowed (will block); there is no unlimited tier.",)diff --git a/autogpt_platform/backend/backend/copilot/rate_limit.py b/autogpt_platform/backend/backend/copilot/rate_limit.pyindex 9ee1fc786e..39f2e6f920 100644--- a/autogpt_platform/backend/backend/copilot/rate_limit.py+++ b/autogpt_platform/backend/backend/copilot/rate_limit.py@@ -100,8 +100,8 @@ class SubscriptionTier(str, Enum):# Default multiplier applied to the base cost limits (from LD / config) for each# tier. Used as the fallback when the LD flag ``copilot-tier-multipliers`` is-# unset or unparseable — see ``get_tier_multipliers``. BUSINESS matches-# ENTERPRISE (60x); MAX sits at 20x as the self-service $320 tier. Float-typed+# unset or unparseable — see ``get_tier_multipliers``. PRO and MAX are the two+# self-serve plans; their multipliers set what those plans allow. Float-typed# so LD-provided fractional multipliers (e.g. 8.5×) compose naturally; the# eventual ``int(base * multiplier)`` in ``get_global_rate_limits`` keeps the# downstream microdollar math integer.@@ -111,12 +111,12 @@ _DEFAULT_TIER_MULTIPLIERS: dict[SubscriptionTier, float] = {# all rate-limited routes (CoPilot chat, AutoPilot) refuse with 429# before any business logic runs. This is the backend half of the# paywall (the frontend modal nudges UI users; this gate enforces- # server-side regardless of client). BASIC stays as a future paid-tier- # option; for now it falls back to the same baseline as paid tiers.+ # server-side regardless of client). BASIC is not sold today and stays on+ # the base limits.SubscriptionTier.NO_TIER: 0.0,SubscriptionTier.BASIC: 1.0,- SubscriptionTier.PRO: 5.0,- SubscriptionTier.MAX: 20.0,+ SubscriptionTier.PRO: 1.25,+ SubscriptionTier.MAX: 10.6667,SubscriptionTier.BUSINESS: 60.0,SubscriptionTier.ENTERPRISE: 60.0,}diff --git a/autogpt_platform/backend/backend/copilot/rate_limit_test.py b/autogpt_platform/backend/backend/copilot/rate_limit_test.pyindex 4024f4b51f..b182e86119 100644--- a/autogpt_platform/backend/backend/copilot/rate_limit_test.py+++ b/autogpt_platform/backend/backend/copilot/rate_limit_test.py@@ -882,8 +882,8 @@ class TestSubscriptionTier:# rate-limited routes refuse with 429 (backend half of the paywall).assert TIER_MULTIPLIERS[SubscriptionTier.NO_TIER] == 0.0assert TIER_MULTIPLIERS[SubscriptionTier.BASIC] == 1.0- assert TIER_MULTIPLIERS[SubscriptionTier.PRO] == 5.0- assert TIER_MULTIPLIERS[SubscriptionTier.MAX] == 20.0+ assert TIER_MULTIPLIERS[SubscriptionTier.PRO] == 1.25+ assert TIER_MULTIPLIERS[SubscriptionTier.MAX] == 10.6667assert TIER_MULTIPLIERS[SubscriptionTier.BUSINESS] == 60.0assert TIER_MULTIPLIERS[SubscriptionTier.ENTERPRISE] == 60.0assert TIER_MULTIPLIERS is _DEFAULT_TIER_MULTIPLIERS@@ -1721,8 +1721,8 @@ class TestGetGlobalRateLimitsWithTiers:assert tier == SubscriptionTier.BASIC@pytest.mark.asyncio- async def test_pro_tier_5x_multiplier(self):- """Pro tier should multiply limits by 5."""+ async def test_pro_tier_multiplier(self):+ """Pro tier should multiply limits by 1.25."""with (patch("backend.copilot.rate_limit.get_user_tier",@@ -1738,13 +1738,13 @@ class TestGetGlobalRateLimitsWithTiers:_USER, 2_500_000, 12_500_000)- assert daily == 12_500_000- assert weekly == 62_500_000+ assert daily == 3_125_000+ assert weekly == 15_625_000assert tier == SubscriptionTier.PRO@pytest.mark.asyncio- async def test_max_tier_20x_multiplier(self):- """Max tier should multiply limits by 20 (self-service $320 tier)."""+ async def test_max_tier_multiplier(self):+ """Max tier should multiply limits by 10.6667."""with (patch("backend.copilot.rate_limit.get_user_tier",@@ -1760,8 +1760,8 @@ class TestGetGlobalRateLimitsWithTiers:_USER, 2_500_000, 12_500_000)- assert daily == 50_000_000- assert weekly == 250_000_000+ assert daily == 26_666_750+ assert weekly == 133_333_750assert tier == SubscriptionTier.MAX@pytest.mark.asyncio@@ -1878,7 +1878,7 @@ class TestTierLimitsRespected:@pytest.mark.asyncioasync def test_pro_user_allowed_above_basic_limit(self):"""A PRO user with usage above the BASIC limit should be allowed."""- # Usage: 3M tokens (above BASIC limit of 2.5M, below PRO limit of 12.5M)+ # Usage: 3M tokens (above BASIC limit of 2.5M, below PRO limit of 3.125M)mock_redis = AsyncMock()mock_redis.get = AsyncMock(side_effect=["3000000", "3000000"])@@ -1900,10 +1900,10 @@ class TestTierLimitsRespected:daily, weekly, tier = await get_global_rate_limits(_USER, self._BASE_DAILY, self._BASE_WEEKLY)- # PRO: 5x multiplier- assert daily == 12_500_000+ # PRO: 1.25x multiplier+ assert daily == 3_125_000assert tier == SubscriptionTier.PRO- # Should NOT raise — 3M < 12.5M+ # Should NOT raise — 3M < 3.125Mawait check_rate_limit(_USER, daily_cost_limit=daily, weekly_cost_limit=weekly)@@ -2253,7 +2253,7 @@ class TestTierLimitsEnforced:basic_daily = int(self._BASE_DAILY * TIER_MULTIPLIERS[SubscriptionTier.BASIC])pro_daily = int(self._BASE_DAILY * TIER_MULTIPLIERS[SubscriptionTier.PRO])# Usage above BASIC limit but below PRO limit- usage = basic_daily + 500_000+ usage = basic_daily + (pro_daily - basic_daily) // 2assert usage < pro_daily, "test sanity: usage must be under PRO limit"mock_redis = AsyncMock()