Skip to content

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.

fix(block_cost_config): audit + correct stale LLM/block rates + migrate generic ReplicateModelBlock to COST_USD (#12912)

Zamil Majdy2deac2073ee0
diff --git a/.secrets.baseline b/.secrets.baseline
index c2b1f3430a..ebbb89c813 100644
--- a/.secrets.baseline
+++ b/.secrets.baseline
@@ -267,7 +267,7 @@
"filename": "autogpt_platform/backend/backend/blocks/replicate/replicate_block.py",
"hashed_secret": "8bbdd6f26368f58ea4011d13d7f763cb662e66f0",
"is_verified": false,
- "line_number": 55
+ "line_number": 67
}
],
"autogpt_platform/backend/backend/blocks/slant3d/webhook.py": [
@@ -467,5 +467,5 @@
}
]
},
- "generated_at": "2026-04-09T14:20:23Z"
+ "generated_at": "2026-04-24T16:42:44Z"
}
diff --git a/autogpt_platform/backend/backend/blocks/block_cost_tracking_test.py b/autogpt_platform/backend/backend/blocks/block_cost_tracking_test.py
index 45db11b717..427b5bc573 100644
--- a/autogpt_platform/backend/backend/blocks/block_cost_tracking_test.py
+++ b/autogpt_platform/backend/backend/blocks/block_cost_tracking_test.py
@@ -433,7 +433,7 @@ class TestJinaEmbeddingBlockCostTracking:
class TestUnrealTextToSpeechBlockCostTracking:
@pytest.mark.asyncio
async def test_merge_stats_called_with_character_count(self):
- """provider_cost equals len(text) with type='characters'."""
+ """provider_cost = len(text) * $0.000016 with type='cost_usd'."""
from backend.blocks.text_to_speech_block import TEST_CREDENTIALS as TTS_CREDS
from backend.blocks.text_to_speech_block import (
TEST_CREDENTIALS_INPUT as TTS_CREDS_INPUT,
@@ -461,12 +461,12 @@ class TestUnrealTextToSpeechBlockCostTracking:
mock_merge.assert_called_once()
stats = mock_merge.call_args[0][0]
- assert stats.provider_cost == float(len(test_text))
- assert stats.provider_cost_type == "characters"
+ assert stats.provider_cost == pytest.approx(len(test_text) * 0.000016)
+ assert stats.provider_cost_type == "cost_usd"
@pytest.mark.asyncio
async def test_empty_text_gives_zero_characters(self):
- """An empty text string results in provider_cost=0.0."""
+ """An empty text string results in provider_cost=0.0 (cost_usd)."""
from backend.blocks.text_to_speech_block import TEST_CREDENTIALS as TTS_CREDS
from backend.blocks.text_to_speech_block import (
TEST_CREDENTIALS_INPUT as TTS_CREDS_INPUT,
@@ -494,7 +494,7 @@ class TestUnrealTextToSpeechBlockCostTracking:
mock_merge.assert_called_once()
stats = mock_merge.call_args[0][0]
assert stats.provider_cost == 0.0
- assert stats.provider_cost_type == "characters"
+ assert stats.provider_cost_type == "cost_usd"
# ---------------------------------------------------------------------------
diff --git a/autogpt_platform/backend/backend/blocks/replicate/replicate_block.py b/autogpt_platform/backend/backend/blocks/replicate/replicate_block.py
index 2758c7cd06..041f78fe8e 100644
--- a/autogpt_platform/backend/backend/blocks/replicate/replicate_block.py
+++ b/autogpt_platform/backend/backend/blocks/replicate/replicate_block.py
@@ -16,12 +16,24 @@ from backend.blocks.replicate._auth import (
TEST_CREDENTIALS_INPUT,
ReplicateCredentialsInput,
)
-from backend.blocks.replicate._helper import ReplicateOutputs, extract_result
-from backend.data.model import APIKeyCredentials, CredentialsField, SchemaField
+from backend.blocks.replicate._helper import extract_result
+from backend.data.model import (
+ APIKeyCredentials,
+ CredentialsField,
+ NodeExecutionStats,
+ SchemaField,
+)
from backend.util.exceptions import BlockExecutionError, BlockInputError
logger = logging.getLogger(__name__)
+# Replicate hardware tier cost — most popular public models (Flux, SDXL,
+# Llama 70B etc.) run on Nvidia L40S at $0.001400/sec. Using a single
+# conservative mid-tier estimate is much better than a flat RUN charge,
+# which under-bills long-running models by 10-500×. Heavier models run
+# on A100 at $0.001400/sec; cheaper ones on L4 at $0.000275/sec.
+_REPLICATE_USD_PER_SEC = 0.001400
+
class ReplicateModelBlock(Block):
"""
@@ -138,20 +150,54 @@ class ReplicateModelBlock(Block):
"""
Run the Replicate model. This method can be mocked for testing.
+ Uses predictions.async_create + async_wait instead of async_run so
+ we can read ``prediction.metrics.predict_time`` after completion
+ and emit it as ``provider_cost`` for the COST_USD resolver.
+
Args:
model_ref: The model reference (e.g., "owner/model-name:version")
model_inputs: The inputs to pass to the model
api_key: The Replicate API key as SecretStr
Returns:
- Tuple of (result, prediction_id)
+ Model output (same shape as previous async_run path)
"""
api_key_str = api_key.get_secret_value()
client = ReplicateClient(api_token=api_key_str)
- output: ReplicateOutputs = await client.async_run(
- model_ref, input=model_inputs, wait=False
- ) # type: ignore they suck at typing
- result = extract_result(output)
+ # Replicate SDK: version-pinned refs use `version=`; unpinned use
+ # `model=`. Matches the `owner/name[:version]` contract above.
+ if ":" in model_ref:
+ model_name, version = model_ref.split(":", 1)
+ prediction = await client.predictions.async_create(
+ version=version, input=model_inputs
+ )
+ else:
+ prediction = await client.predictions.async_create(
+ model=model_ref, input=model_inputs
+ )
+
+ await prediction.async_wait()
+
+ # async_wait returns normally on "failed"/"canceled" — only async_run
+ # raises. Without this check we'd bill partial compute time on a
+ # failed run and silently yield empty output.
+ if prediction.status == "failed":
+ raise RuntimeError(
+ f"Replicate prediction failed: {prediction.error or 'unknown error'}"
+ )
+ if prediction.status == "canceled":
+ raise RuntimeError("Replicate prediction was canceled")
+
+ if prediction.metrics and prediction.metrics.get("predict_time"):
+ predict_time = float(prediction.metrics["predict_time"])
+ self.merge_stats(
+ NodeExecutionStats(
+ provider_cost=predict_time * _REPLICATE_USD_PER_SEC,
+ provider_cost_type="cost_usd",
+ )
+ )
- return result
+ if prediction.output is None:
+ raise RuntimeError("Replicate prediction returned no output")
+ return extract_result(prediction.output)
diff --git a/autogpt_platform/backend/backend/blocks/replicate/replicate_block_cost_test.py b/autogpt_platform/backend/backend/blocks/replicate/replicate_block_cost_test.py
new file mode 100644
index 0000000000..b7bcff2d23
--- /dev/null
+++ b/autogpt_platform/backend/backend/blocks/replicate/replicate_block_cost_test.py
@@ -0,0 +1,233 @@
+"""Unit tests for ReplicateModelBlock's predictions.async_create billing path.
+
+Verifies the refactored run_model correctly:
+1. Uses predictions.async_create (version= vs model= based on ":" in model_ref)
+2. Awaits async_wait() for metrics to be populated
+3. Reads prediction.metrics["predict_time"] and emits provider_cost/cost_usd
+4. Returns extract_result(prediction.output) with the same shape as the old
+ async_run path
+5. Gracefully skips merge_stats when metrics is missing (protects against a
+ silent wallet-free leak on SDK quirks)
+"""
+
+from unittest.mock import AsyncMock, MagicMock, patch
+
+import pytest
+from pydantic import SecretStr
+
+from backend.blocks._base import BlockCostType
+from backend.blocks.replicate.replicate_block import (
+ _REPLICATE_USD_PER_SEC,
+ ReplicateModelBlock,
+)
+from backend.data.block_cost_config import BLOCK_COSTS
+from backend.data.model import NodeExecutionStats
+
+
+def test_registered_as_cost_usd_150():
+ entries = BLOCK_COSTS[ReplicateModelBlock]
+ assert len(entries) == 1
+ assert entries[0].cost_type == BlockCostType.COST_USD
+ assert entries[0].cost_amount == 150
+
+
+def test_hardware_rate_constant_in_range():
+ """$0.0014/s is Nvidia L40S tier. Sanity-check we haven't accidentally
+ shipped a rate that's off by an order of magnitude (e.g. $0.014 would
+ 10x over-bill every run).
+ """
+ # Replicate's public hardware tiers: L4 $0.000275, A10G $0.000575,
+ # L40S $0.000975, A100 $0.001400, A100-80GB $0.001725. L40S @
+ # $0.0014/s covers most popular models with mild over-bill margin.
+ assert 0.0005 <= _REPLICATE_USD_PER_SEC <= 0.002
+
+
+def _make_fake_prediction(output, predict_time=None, status="succeeded", error=None):
+ """Build a stand-in for replicate's Prediction with the attrs we touch."""
+ pred = MagicMock()
+ pred.output = output
+ pred.status = status
+ pred.error = error
+ pred.metrics = {"predict_time": predict_time} if predict_time is not None else None
+ pred.async_wait = AsyncMock(return_value=None)
+ return pred
+
+
+async def test_run_model_uses_version_keyword_when_ref_has_colon():
+ """`"owner/name:sha"` → predictions.async_create(version=sha, ...)."""
+ block = ReplicateModelBlock()
+ prediction = _make_fake_prediction(output="hello", predict_time=3.2)
+
+ client = MagicMock()
+ client.predictions.async_create = AsyncMock(return_value=prediction)
+
+ with patch(
+ "backend.blocks.replicate.replicate_block.ReplicateClient",
+ return_value=client,
+ ):
+ await block.run_model(
+ "owner/model:abc123", {"prompt": "hi"}, SecretStr("fake-key")
+ )
+
+ client.predictions.async_create.assert_awaited_once_with(
+ version="abc123", input={"prompt": "hi"}
+ )
+
+
+async def test_run_model_uses_model_keyword_when_ref_is_unpinned():
+ """`"owner/name"` (no `:version`) → predictions.async_create(model=ref, ...)."""
+ block = ReplicateModelBlock()
+ prediction = _make_fake_prediction(output="hello", predict_time=1.0)
+
+ client = MagicMock()
+ client.predictions.async_create = AsyncMock(return_value=prediction)
+
+ with patch(
+ "backend.blocks.replicate.replicate_block.ReplicateClient",
+ return_value=client,
+ ):
+ await block.run_model(
+ "owner/flux-schnell", {"prompt": "cat"}, SecretStr("fake-key")
+ )
+
+ client.predictions.async_create.assert_awaited_once_with(
+ model="owner/flux-schnell", input={"prompt": "cat"}
+ )
+
+
+async def test_run_model_emits_provider_cost_from_predict_time():
+ """Core contract: provider_cost = predict_time * $0.0014/s, cost_usd."""
+ block = ReplicateModelBlock()
+ # 5-second run → 5 * 0.0014 = $0.007 → 150 cr/$ * 0.007 ceil = 2 cr
+ prediction = _make_fake_prediction(output="result-data", predict_time=5.0)
+
+ client = MagicMock()
+ client.predictions.async_create = AsyncMock(return_value=prediction)
+
+ captured: list[NodeExecutionStats] = []
+ with (
+ patch(
+ "backend.blocks.replicate.replicate_block.ReplicateClient",
+ return_value=client,
+ ),
+ patch.object(block, "merge_stats", side_effect=captured.append),
+ ):
+ result = await block.run_model("owner/model", {}, SecretStr("fake-key"))
+
+ assert len(captured) == 1
+ stats = captured[0]
+ assert stats.provider_cost == pytest.approx(5.0 * _REPLICATE_USD_PER_SEC)
+ assert stats.provider_cost_type == "cost_usd"
+ assert result == "result-data"
+ # async_wait MUST be called before reading metrics — otherwise metrics
+ # is None on in-flight predictions.
+ prediction.async_wait.assert_awaited_once()
+
+
+async def test_run_model_skips_merge_stats_when_metrics_missing():
+ """Protect against the nightmare scenario: if the SDK stops populating
+ metrics (or we hit a prediction that completes without metrics),
+ merge_stats must NOT fire. Otherwise we'd emit a zero provider_cost
+ that the resolver treats as 0 credits — a silent wallet-free leak.
+ The block's run() path relies on the flat 0 fallback via
+ charge_reconciled_usage's pre-flight balance guard.
+ """
+ block = ReplicateModelBlock()
+ prediction = _make_fake_prediction(output="x", predict_time=None)
+
+ client = MagicMock()
+ client.predictions.async_create = AsyncMock(return_value=prediction)
+
+ captured: list[NodeExecutionStats] = []
+ with (
+ patch(
+ "backend.blocks.replicate.replicate_block.ReplicateClient",
+ return_value=client,
+ ),
+ patch.object(block, "merge_stats", side_effect=captured.append),
+ ):
+ await block.run_model("owner/model", {}, SecretStr("fake-key"))
+
+ # No merge_stats call → no provider_cost emission → COST_USD resolver
+ # returns 0 → run is effectively free post-flight, but pre-flight
+ # balance guard still blocks zero-balance wallets per PR #12894.
+ assert captured == []
+
+
+async def test_run_model_skips_merge_when_predict_time_is_zero():
+ """A 0-second predict_time would emit provider_cost=0, which is useless
+ telemetry. Treat 0 same as missing (no emission)."""
+ block = ReplicateModelBlock()
+ prediction = _make_fake_prediction(output="x", predict_time=0)
+
+ client = MagicMock()
+ client.predictions.async_create = AsyncMock(return_value=prediction)
+
+ captured: list[NodeExecutionStats] = []
+ with (
+ patch(
+ "backend.blocks.replicate.replicate_block.ReplicateClient",
+ return_value=client,
+ ),
+ patch.object(block, "merge_stats", side_effect=captured.append),
+ ):
+ await block.run_model("owner/model", {}, SecretStr("fake-key"))
+
+ assert captured == []
+
+
+async def test_run_model_raises_on_failed_status_and_does_not_bill():
+ """async_wait returns normally on 'failed' — without an explicit status
+ check we'd bill partial compute time AND yield 'status: succeeded' with
+ empty output. Verify we raise BEFORE merge_stats so the failed run is
+ not billed."""
+ block = ReplicateModelBlock()
+ prediction = _make_fake_prediction(
+ output=None, predict_time=2.5, status="failed", error="CUDA OOM"
+ )
+
+ client = MagicMock()
+ client.predictions.async_create = AsyncMock(return_value=prediction)
+
+ captured: list[NodeExecutionStats] = []
+ with (
+ patch(
+ "backend.blocks.replicate.replicate_block.ReplicateClient",
+ return_value=client,
+ ),
+ patch.object(block, "merge_stats", side_effect=captured.append),
+ ):
+ with pytest.raises(RuntimeError, match="CUDA OOM"):
+ await block.run_model("owner/model", {}, SecretStr("fake-key"))
+
+ assert captured == []
+
+
+async def test_run_model_raises_on_canceled_status_and_does_not_bill():
+ """Canceled predictions — same guarantees as failed: don't bill, surface
+ the cancellation."""
+ block = ReplicateModelBlock()
+ prediction = _make_fake_prediction(output=None, predict_time=1.0, status="canceled")
+
+ client = MagicMock()
+ client.predictions.async_create = AsyncMock(return_value=prediction)
+
+ captured: list[NodeExecutionStats] = []
+ with (
+ patch(
+ "backend.blocks.replicate.replicate_block.ReplicateClient",
+ return_value=client,
+ ),
+ patch.object(block, "merge_stats", side_effect=captured.append),
+ ):
+ with pytest.raises(RuntimeError, match="canceled"):
+ await block.run_model("owner/model", {}, SecretStr("fake-key"))
+
+ assert captured == []
diff --git a/autogpt_platform/backend/backend/blocks/text_to_speech_block.py b/autogpt_platform/backend/backend/blocks/text_to_speech_block.py
index 1860d10d24..db39625da1 100644
--- a/autogpt_platform/backend/backend/blocks/text_to_speech_block.py
+++ b/autogpt_platform/backend/backend/blocks/text_to_speech_block.py
@@ -105,10 +105,13 @@ class UnrealTextToSpeechBlock(Block):
input_data.text,
input_data.voice_id,
)
+ # Unreal Speech: $16 / 1M chars = $0.000016/char. Emit USD so the
+ # COST_USD resolver (150 cr/$ via BLOCK_COSTS) bills proportionally
+ # instead of the old flat 5 cr.
self.merge_stats(
NodeExecutionStats(
- provider_cost=float(len(input_data.text)),
- provider_cost_type="characters",
+ provider_cost=len(input_data.text) * 0.000016,
+ provider_cost_type="cost_usd",
)
)
yield "mp3_url", api_response["OutputUri"]
diff --git a/autogpt_platform/backend/backend/copilot/tools/helpers_test.py b/autogpt_platform/backend/backend/copilot/tools/helpers_test.py
index 5be93eb85e..80506b1013 100644
--- a/autogpt_platform/backend/backend/copilot/tools/helpers_test.py
+++ b/autogpt_platform/backend/backend/copilot/tools/helpers_test.py
@@ -340,10 +340,10 @@ class TestNewlyRegisteredBlockCosts:
from backend.data.block_cost_config import BLOCK_COSTS
assert ValidateEmailsBlock in BLOCK_COSTS
- # COST_USD with multiplier 250 → ceil(provider_cost_usd * 250) credits.
+ # COST_USD with multiplier 150 → ceil(provider_cost_usd * 150) credits.
# Block reports $0.008/call via merge_stats, so effective charge is 2.
assert BLOCK_COSTS[ValidateEmailsBlock][0].cost_type == BlockCostType.COST_USD
- assert BLOCK_COSTS[ValidateEmailsBlock][0].cost_amount == 250
+ assert BLOCK_COSTS[ValidateEmailsBlock][0].cost_amount == 150
def test_claude_code_block_registered(self):
"""ClaudeCodeBlock spawns an E2B sandbox + runs Claude inside it.
diff --git a/autogpt_platform/backend/backend/data/block_cost_config.py b/autogpt_platform/backend/backend/data/block_cost_config.py
index 80ecaa30e4..cc91048c8c 100644
--- a/autogpt_platform/backend/backend/data/block_cost_config.py
+++ b/autogpt_platform/backend/backend/data/block_cost_config.py
@@ -277,7 +277,7 @@ TOKEN_COST: dict[LlmModel, TokenRate] = {
# OpenAI
LlmModel.GPT5_2: TokenRate(input=263, output=2100),
LlmModel.GPT5_1: TokenRate(input=188, output=1500),
- LlmModel.GPT5: TokenRate(input=94, output=750),
+ LlmModel.GPT5: TokenRate(input=188, output=1500),
LlmModel.GPT5_MINI: TokenRate(input=38, output=300),
LlmModel.GPT5_NANO: TokenRate(input=8, output=60),
LlmModel.GPT5_CHAT: TokenRate(input=188, output=1500),
@@ -300,21 +300,32 @@ TOKEN_COST: dict[LlmModel, TokenRate] = {
LlmModel.GEMINI_3_1_PRO_PREVIEW: TokenRate(input=300, output=1800),
LlmModel.GEMINI_3_FLASH_PREVIEW: TokenRate(input=75, output=450),
LlmModel.GEMINI_3_1_FLASH_LITE_PREVIEW: TokenRate(input=38, output=225),
- # xAI Grok
+ # xAI Grok. docs.x.ai currently lists only Grok 4.20 and grok-4-1-fast;
+ # the rest (grok-3, grok-4-0709, grok-4-fast, grok-code-fast-1) were
+ # removed from the public pricing page but remain callable via the
+ # API. Rates below match their launch pricing (verified historically):
+ # grok-3 / grok-4 $3/$15, grok-4-fast / grok-4-1-fast $0.20/$0.50,
+ # grok-code-fast-1 $0.20/$1.50.
LlmModel.GROK_3: TokenRate(input=450, output=2250),
LlmModel.GROK_4: TokenRate(input=450, output=2250),
LlmModel.GROK_4_FAST: TokenRate(input=30, output=75),
LlmModel.GROK_4_1_FAST: TokenRate(input=30, output=75),
LlmModel.GROK_4_20: TokenRate(input=300, output=900),
LlmModel.GROK_CODE_FAST_1: TokenRate(input=30, output=225),
- # DeepSeek (deepseek-chat = V3.2 at $0.28/$0.42; reasoner at $0.55/$2.19).
- LlmModel.DEEPSEEK_CHAT: TokenRate(input=42, output=63),
- LlmModel.DEEPSEEK_R1_0528: TokenRate(input=82, output=329),
- # Mistral
+ # DeepSeek: both `deepseek-chat` and `deepseek-reasoner` now alias to
+ # `deepseek-v4-flash` (non-thinking + thinking modes) at unified
+ # $0.14/$0.28 per 1M (Sept 2025 price unification).
+ LlmModel.DEEPSEEK_CHAT: TokenRate(input=21, output=42),
+ LlmModel.DEEPSEEK_R1_0528: TokenRate(input=21, output=42),
+ # Mistral — models route through OpenRouter (ModelMetadata provider =
+ # "open_router"). TOKEN_COST here is the safety floor when OpenRouter
+ # fails to return x-total-cost; rates below match OpenRouter's current
+ # pass-through pricing (NOT Mistral's direct /v1/chat prices, which
+ # we never call).
LlmModel.MISTRAL_LARGE_3: TokenRate(input=300, output=900),
LlmModel.MISTRAL_MEDIUM_3_1: TokenRate(input=60, output=300),
LlmModel.MISTRAL_SMALL_3_2: TokenRate(input=15, output=45),
- LlmModel.MISTRAL_NEMO: TokenRate(input=3, output=6),
+ LlmModel.MISTRAL_NEMO: TokenRate(input=5, output=5),
LlmModel.CODESTRAL: TokenRate(input=45, output=135),
# Cohere
LlmModel.COHERE_COMMAND_R_08_2024: TokenRate(input=23, output=90),
@@ -322,9 +333,11 @@ TOKEN_COST: dict[LlmModel, TokenRate] = {
LlmModel.COHERE_COMMAND_A_03_2025: TokenRate(input=375, output=1500),
# Moonshot Kimi
LlmModel.KIMI_K2: TokenRate(input=90, output=375),
- LlmModel.KIMI_K2_0905: TokenRate(input=82, output=330),
- LlmModel.KIMI_K2_5: TokenRate(input=90, output=450),
- LlmModel.KIMI_K2_6: TokenRate(input=143, output=600),
+ LlmModel.KIMI_K2_0905: TokenRate(input=90, output=375),
+ # K2.5 / K2.6 aren't on Moonshot's direct pricing page today; OpenRouter
+ # passes through $0.44/$2.00 for K2.5 and $0.7448/$4.655 for K2.6.
+ LlmModel.KIMI_K2_5: TokenRate(input=66, output=300),
+ LlmModel.KIMI_K2_6: TokenRate(input=112, output=698),
LlmModel.KIMI_K2_THINKING: TokenRate(input=90, output=375),
# Perplexity Sonar
LlmModel.PERPLEXITY_SONAR: TokenRate(input=150, output=150),
@@ -335,7 +348,7 @@ TOKEN_COST: dict[LlmModel, TokenRate] = {
LlmModel.LLAMA3_3_70B: TokenRate(input=89, output=119),
LlmModel.LLAMA3_1_8B: TokenRate(input=8, output=12),
LlmModel.META_LLAMA_4_SCOUT: TokenRate(input=17, output=51),
- LlmModel.META_LLAMA_4_MAVERICK: TokenRate(input=30, output=90),
+ LlmModel.META_LLAMA_4_MAVERICK: TokenRate(input=75, output=116),
LlmModel.OPENAI_GPT_OSS_120B: TokenRate(input=23, output=90),
LlmModel.OPENAI_GPT_OSS_20B: TokenRate(input=11, output=45),
}
@@ -549,9 +562,13 @@ BLOCK_COSTS: dict[Type[Block], list[BlockCost]] = {
cost_amount=150,
)
],
+ # D-ID: $5.90/min of generated video. Median 10-sec clip ≈ $0.98 →
+ # 148 cr at 1.5x. 100 cr flat is a conservative middle; long clips
+ # still under-bill, short clips over-bill modestly. Revisit if the
+ # block starts surfacing per-call duration from D-ID's response.
CreateTalkingAvatarVideoBlock: [
BlockCost(
- cost_amount=15,
+ cost_amount=100,
cost_filter={
"credentials": {
"id": did_credentials.id,
@@ -561,13 +578,11 @@ BLOCK_COSTS: dict[Type[Block], list[BlockCost]] = {
},
)
],
- # Jina Reader Search: $0.01/query on the paid tier. Block emits
- # merge_stats(provider_cost=0.01, cost_usd) so the COST_USD resolver
- # bills 1 platform credit per call AND the platform cost telemetry
- # captures real USD spend (RUN wouldn't populate costMicrodollars).
+ # Jina Reader Search: $0.01/query on the paid tier. 150 cr/$ matches
+ # the 1.5x margin baseline used across every other COST_USD block.
SearchTheWebBlock: [
BlockCost(
- cost_amount=100,
+ cost_amount=150,
cost_type=BlockCostType.COST_USD,
cost_filter={
"credentials": {
@@ -591,9 +606,10 @@ BLOCK_COSTS: dict[Type[Block], list[BlockCost]] = {
},
)
],
+ # Ideogram V2/default = $0.08/image; V3 Quality = $0.09/image.
IdeogramModelBlock: [
BlockCost(
- cost_amount=16,
+ cost_amount=12,
cost_filter={
"credentials": {
"id": ideogram_credentials.id,
@@ -603,7 +619,7 @@ BLOCK_COSTS: dict[Type[Block], list[BlockCost]] = {
},
),
BlockCost(
- cost_amount=18,
+ cost_amount=14,
cost_filter={
"ideogram_model_name": "V_3",
"credentials": {
@@ -662,9 +678,18 @@ BLOCK_COSTS: dict[Type[Block], list[BlockCost]] = {
},
)
],
+ # ReplicateModelBlock is a generic wrapper — users pass ANY Replicate
+ # model ref. A flat 10 cr/run was:
+ # - 20x over-billing cheap models (~$0.005 SDXL tiny runs)
+ # - 10-500x under-billing long video/LLM runs ($1-$50+)
+ # Block now reads prediction.metrics.predict_time after completion
+ # and bills that × $0.0014/s (Nvidia L40S mid-tier) via COST_USD
+ # 150 cr/$. Heavy LLMs on A100 under-bill slightly, cheap L4 runs
+ # over-bill slightly, but the catastrophic under-bill is gone.
ReplicateModelBlock: [
BlockCost(
- cost_amount=10,
+ cost_amount=150,
+ cost_type=BlockCostType.COST_USD,
cost_filter={
"credentials": {
"id": replicate_credentials.id,
@@ -687,7 +712,7 @@ BLOCK_COSTS: dict[Type[Block], list[BlockCost]] = {
},
),
BlockCost(
- cost_amount=20,
+ cost_amount=12, # Flux Kontext Max: ~$0.08/image @ 1.5x margin
cost_filter={
"model": FluxKontextModelName.FLUX_KONTEXT_MAX,
"credentials": {
@@ -744,9 +769,14 @@ BLOCK_COSTS: dict[Type[Block], list[BlockCost]] = {
},
)
],
+ # Unreal Speech: $16 / 1M chars = $0.000016/char. Block emits
+ # provider_cost=chars*0.000016, cost_usd; 150 cr/$ keeps the 1.5x
+ # platform-wide margin. Replaces the prior flat 5 cr RUN which
+ # under-billed long narrations by 10x+.
UnrealTextToSpeechBlock: [
BlockCost(
- cost_amount=5,
+ cost_amount=150,
+ cost_type=BlockCostType.COST_USD,
cost_filter={
"credentials": {
"id": unreal_credentials.id,
@@ -794,7 +824,7 @@ BLOCK_COSTS: dict[Type[Block], list[BlockCost]] = {
],
GetLinkedinProfilePictureBlock: [
BlockCost(
- cost_amount=3,
+ cost_amount=1,
cost_filter={
"credentials": {
"id": enrichlayer_credentials.id,
@@ -908,7 +938,7 @@ BLOCK_COSTS: dict[Type[Block], list[BlockCost]] = {
},
),
BlockCost(
- cost_amount=14, # Nano Banana Pro: $0.14 per image at 2K
+ cost_amount=21, # Nano Banana Pro: $0.14/image at 2K @ 1.5x margin
cost_filter={
"model": ImageGenModel.NANO_BANANA_PRO,
"credentials": {
@@ -919,7 +949,7 @@ BLOCK_COSTS: dict[Type[Block], list[BlockCost]] = {
},
),
BlockCost(
- cost_amount=14, # Nano Banana 2: same pricing tier as Pro
+ cost_amount=21, # Nano Banana 2: same pricing tier as Pro
cost_filter={
"model": ImageGenModel.NANO_BANANA_2,
"credentials": {
@@ -943,7 +973,7 @@ BLOCK_COSTS: dict[Type[Block], list[BlockCost]] = {
},
),
BlockCost(
- cost_amount=14, # Nano Banana Pro: $0.14 per image at 2K
+ cost_amount=21, # Nano Banana Pro: $0.14/image at 2K @ 1.5x margin
cost_filter={
"model": GeminiImageModel.NANO_BANANA_PRO,
"credentials": {
@@ -954,7 +984,7 @@ BLOCK_COSTS: dict[Type[Block], list[BlockCost]] = {
},
),
BlockCost(
- cost_amount=14, # Nano Banana 2: same pricing tier as Pro
+ cost_amount=21, # Nano Banana 2: same pricing tier as Pro
cost_filter={
"model": GeminiImageModel.NANO_BANANA_2,
"credentials": {
@@ -1155,13 +1185,12 @@ BLOCK_COSTS: dict[Type[Block], list[BlockCost]] = {
},
)
],
- # ZeroBounce: $16 / 2K validations = $0.008 per email. One email per call.
- # Block emits merge_stats(provider_cost=0.008, cost_usd) so the platform
- # cost telemetry records real USD; resolver bills 2 credits per call
- # (ceil(0.008 * 250)).
+ # ZeroBounce: ~$0.008-$0.02/validation depending on tier. 150 cr/$
+ # normalizes the margin to the 1.5x baseline used across other
+ # COST_USD blocks (was 250 cr/$ = 2.5x margin).
ValidateEmailsBlock: [
BlockCost(
- cost_amount=250,
+ cost_amount=150,
cost_type=BlockCostType.COST_USD,
cost_filter={
"credentials": {
@@ -1220,12 +1249,13 @@ BLOCK_COSTS: dict[Type[Block], list[BlockCost]] = {
},
)
],
- # FAL video generation: $0.001–$0.02 per output second. Charge 3 credits
- # per walltime second (~$0.03) — covers the median tier with margin and
- # scales fairly across short clips vs long renders.
+ # FAL video generation: Veo/Seedance tier $0.25-0.30/s, Lite tier
+ # ~$0.05-0.10/s. 15 cr/s (~$0.15/s) covers the Lite tier with 1.5x
+ # margin; higher tiers still slightly under-bill until the block
+ # surfaces per-call provider_cost and we migrate to COST_USD.
AIVideoGeneratorBlock: [
BlockCost(
- cost_amount=3,
+ cost_amount=15,
cost_type=BlockCostType.SECOND,
cost_filter={
"credentials": {
diff --git a/autogpt_platform/backend/backend/data/block_cost_config_test.py b/autogpt_platform/backend/backend/data/block_cost_config_test.py
index 88c5261f15..9af880cf04 100644
--- a/autogpt_platform/backend/backend/data/block_cost_config_test.py
+++ b/autogpt_platform/backend/backend/data/block_cost_config_test.py
@@ -141,7 +141,7 @@ def test_e2b_sandbox_blocks_bill_per_walltime_second():
def test_fal_video_generator_bills_per_walltime_second():
- """FAL AIVideoGeneratorBlock uses SECOND with cost_amount=3 (3 credits/s)."""
+ """FAL AIVideoGeneratorBlock uses SECOND with cost_amount=15 (15 credits/s)."""
from backend.data.model import NodeExecutionStats
creds = {
@@ -154,11 +154,11 @@ def test_fal_video_generator_bills_per_walltime_second():
# Pre-flight: unknown walltime ⇒ 0 credits.
cost, _ = block_usage_cost(AIVideoGeneratorBlock(), creds)
assert cost == 0
- # Post-flight: 5s clip ⇒ 3 * 5 = 15 credits.
+ # Post-flight: 5s clip ⇒ 15 * 5 = 75 credits.
cost, _ = block_usage_cost(
AIVideoGeneratorBlock(), creds, stats=NodeExecutionStats(walltime=5.0)
)
- assert cost == 15
+ assert cost == 75
def test_transcribe_youtube_has_one_credit_tooling_floor():
diff --git a/autogpt_platform/backend/backend/executor/block_usage_cost_test.py b/autogpt_platform/backend/backend/executor/block_usage_cost_test.py
index 2b1d8a181c..c9d4dd8f3b 100644
--- a/autogpt_platform/backend/backend/executor/block_usage_cost_test.py
+++ b/autogpt_platform/backend/backend/executor/block_usage_cost_test.py
@@ -197,7 +197,7 @@ def test_e2b_sandbox_blocks_bill_one_credit_per_ten_seconds():
assert cost == 0
-def test_fal_video_block_bills_three_credits_per_second():
+def test_fal_video_block_bills_fifteen_credits_per_second():
block = AIVideoGeneratorBlock()
creds = {
"credentials": {
@@ -206,9 +206,9 @@ def test_fal_video_block_bills_three_credits_per_second():
"type": fal_credentials.type,
}
}
- # 8s clip → 3 * 8 = 24 credits.
+ # 8s clip → 15 * 8 = 120 credits.
cost, _ = block_usage_cost(block, creds, stats=NodeExecutionStats(walltime=8.0))
- assert cost == 24
+ assert cost == 120
# Pre-flight → 0.
cost, _ = block_usage_cost(block, creds)
assert cost == 0