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.

feat(blocks): charge Ayrshare per-post + align Bannerbear/Jina floors (#12893)

Zamil Majdy80bfde1ca624
diff --git a/autogpt_platform/backend/backend/blocks/ayrshare/_cost.py b/autogpt_platform/backend/backend/blocks/ayrshare/_cost.py
new file mode 100644
index 0000000000..709d642b73
--- /dev/null
+++ b/autogpt_platform/backend/backend/blocks/ayrshare/_cost.py
@@ -0,0 +1,18 @@
+from backend.sdk import BlockCost, BlockCostType
+
+# Ayrshare is a subscription proxy ($149/mo Business). Per-post credit charges
+# prevent a single heavy user from absorbing the fixed cost and align with the
+# upload cost of each post variant.
+# cost_filter matches on input_data.is_video BEFORE run() executes, so the flag
+# has to be correct at input-eval time. Video-only platforms (YouTube, Snapchat)
+# override the base default to True; platforms that accept both (TikTok, etc.)
+# rely on the caller setting is_video explicitly for accurate billing.
+# First match wins in block_usage_cost, so list the video tier first.
+AYRSHARE_POST_COSTS = (
+ BlockCost(
+ cost_amount=5, cost_type=BlockCostType.RUN, cost_filter={"is_video": True}
+ ),
+ BlockCost(
+ cost_amount=2, cost_type=BlockCostType.RUN, cost_filter={"is_video": False}
+ ),
+)
diff --git a/autogpt_platform/backend/backend/blocks/ayrshare/_util.py b/autogpt_platform/backend/backend/blocks/ayrshare/_util.py
index 231239310f..49089c4853 100644
--- a/autogpt_platform/backend/backend/blocks/ayrshare/_util.py
+++ b/autogpt_platform/backend/backend/blocks/ayrshare/_util.py
@@ -29,7 +29,9 @@ class BaseAyrshareInput(BlockSchemaInput):
advanced=False,
)
is_video: bool = SchemaField(
- description="Whether the media is a video", default=False, advanced=True
+ description="Whether the media is a video. Set to True when uploading a video so billing applies the video tier.",
+ default=False,
+ advanced=True,
)
schedule_date: Optional[datetime] = SchemaField(
description="UTC datetime for scheduling (YYYY-MM-DDThh:mm:ssZ)",
diff --git a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_bluesky.py b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_bluesky.py
index df0d5ad269..1b7b556887 100644
--- a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_bluesky.py
+++ b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_bluesky.py
@@ -6,11 +6,14 @@ from backend.sdk import (
BlockSchemaOutput,
BlockType,
SchemaField,
+ cost,
)
+from ._cost import AYRSHARE_POST_COSTS
from ._util import BaseAyrshareInput, create_ayrshare_client, get_profile_key
+@cost(*AYRSHARE_POST_COSTS)
class PostToBlueskyBlock(Block):
"""Block for posting to Bluesky with Bluesky-specific options."""
diff --git a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_facebook.py b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_facebook.py
index a9087915e6..211cf23f6f 100644
--- a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_facebook.py
+++ b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_facebook.py
@@ -6,8 +6,10 @@ from backend.sdk import (
BlockSchemaOutput,
BlockType,
SchemaField,
+ cost,
)
+from ._cost import AYRSHARE_POST_COSTS
from ._util import (
BaseAyrshareInput,
CarouselItem,
@@ -16,6 +18,7 @@ from ._util import (
)
+@cost(*AYRSHARE_POST_COSTS)
class PostToFacebookBlock(Block):
"""Block for posting to Facebook with Facebook-specific options."""
diff --git a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_gmb.py b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_gmb.py
index 1f223f1f80..6d65bcdba5 100644
--- a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_gmb.py
+++ b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_gmb.py
@@ -6,11 +6,14 @@ from backend.sdk import (
BlockSchemaOutput,
BlockType,
SchemaField,
+ cost,
)
+from ._cost import AYRSHARE_POST_COSTS
from ._util import BaseAyrshareInput, create_ayrshare_client, get_profile_key
+@cost(*AYRSHARE_POST_COSTS)
class PostToGMBBlock(Block):
"""Block for posting to Google My Business with GMB-specific options."""
diff --git a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_instagram.py b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_instagram.py
index 06d80db528..c5100702a9 100644
--- a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_instagram.py
+++ b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_instagram.py
@@ -8,8 +8,10 @@ from backend.sdk import (
BlockSchemaOutput,
BlockType,
SchemaField,
+ cost,
)
+from ._cost import AYRSHARE_POST_COSTS
from ._util import (
BaseAyrshareInput,
InstagramUserTag,
@@ -18,6 +20,7 @@ from ._util import (
)
+@cost(*AYRSHARE_POST_COSTS)
class PostToInstagramBlock(Block):
"""Block for posting to Instagram with Instagram-specific options."""
@@ -191,7 +194,7 @@ class PostToInstagramBlock(Block):
# Validate alt text length
for i, alt in enumerate(input_data.alt_text):
if len(alt) > 1000:
- yield "error", f"Alt text {i+1} exceeds 1,000 character limit ({len(alt)} characters)"
+ yield "error", f"Alt text {i + 1} exceeds 1,000 character limit ({len(alt)} characters)"
return
instagram_options["altText"] = input_data.alt_text
diff --git a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_linkedin.py b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_linkedin.py
index 961587d201..560d4bed2b 100644
--- a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_linkedin.py
+++ b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_linkedin.py
@@ -6,11 +6,14 @@ from backend.sdk import (
BlockSchemaOutput,
BlockType,
SchemaField,
+ cost,
)
+from ._cost import AYRSHARE_POST_COSTS
from ._util import BaseAyrshareInput, create_ayrshare_client, get_profile_key
+@cost(*AYRSHARE_POST_COSTS)
class PostToLinkedInBlock(Block):
"""Block for posting to LinkedIn with LinkedIn-specific options."""
diff --git a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_pinterest.py b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_pinterest.py
index 834cd4e301..504640aad8 100644
--- a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_pinterest.py
+++ b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_pinterest.py
@@ -6,8 +6,10 @@ from backend.sdk import (
BlockSchemaOutput,
BlockType,
SchemaField,
+ cost,
)
+from ._cost import AYRSHARE_POST_COSTS
from ._util import (
BaseAyrshareInput,
PinterestCarouselOption,
@@ -16,6 +18,7 @@ from ._util import (
)
+@cost(*AYRSHARE_POST_COSTS)
class PostToPinterestBlock(Block):
"""Block for posting to Pinterest with Pinterest-specific options."""
@@ -141,7 +144,7 @@ class PostToPinterestBlock(Block):
# Validate alt text length
for i, alt in enumerate(input_data.alt_text):
if len(alt) > 500:
- yield "error", f"Pinterest alt text {i+1} exceeds 500 character limit ({len(alt)} characters)"
+ yield "error", f"Pinterest alt text {i + 1} exceeds 500 character limit ({len(alt)} characters)"
return
# Convert datetime to ISO format if provided
diff --git a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_reddit.py b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_reddit.py
index 1df721f424..a1723cc0e5 100644
--- a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_reddit.py
+++ b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_reddit.py
@@ -6,11 +6,14 @@ from backend.sdk import (
BlockSchemaOutput,
BlockType,
SchemaField,
+ cost,
)
+from ._cost import AYRSHARE_POST_COSTS
from ._util import BaseAyrshareInput, create_ayrshare_client, get_profile_key
+@cost(*AYRSHARE_POST_COSTS)
class PostToRedditBlock(Block):
"""Block for posting to Reddit."""
diff --git a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_snapchat.py b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_snapchat.py
index 3645f7cc9b..da9f0c9b02 100644
--- a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_snapchat.py
+++ b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_snapchat.py
@@ -6,11 +6,14 @@ from backend.sdk import (
BlockSchemaOutput,
BlockType,
SchemaField,
+ cost,
)
+from ._cost import AYRSHARE_POST_COSTS
from ._util import BaseAyrshareInput, create_ayrshare_client, get_profile_key
+@cost(*AYRSHARE_POST_COSTS)
class PostToSnapchatBlock(Block):
"""Block for posting to Snapchat with Snapchat-specific options."""
@@ -31,6 +34,14 @@ class PostToSnapchatBlock(Block):
advanced=False,
)
+ # Snapchat is video-only; override the base default so the @cost filter
+ # selects the 5-credit video tier instead of the 2-credit image tier.
+ is_video: bool = SchemaField(
+ description="Whether the media is a video (always True for Snapchat)",
+ default=True,
+ advanced=True,
+ )
+
# Snapchat-specific options
story_type: str = SchemaField(
description="Type of Snapchat content: 'story' (24-hour Stories), 'saved_story' (Saved Stories), or 'spotlight' (Spotlight posts)",
diff --git a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_telegram.py b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_telegram.py
index a220cbe9e8..8ccfb3be39 100644
--- a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_telegram.py
+++ b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_telegram.py
@@ -6,11 +6,14 @@ from backend.sdk import (
BlockSchemaOutput,
BlockType,
SchemaField,
+ cost,
)
+from ._cost import AYRSHARE_POST_COSTS
from ._util import BaseAyrshareInput, create_ayrshare_client, get_profile_key
+@cost(*AYRSHARE_POST_COSTS)
class PostToTelegramBlock(Block):
"""Block for posting to Telegram with Telegram-specific options."""
diff --git a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_threads.py b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_threads.py
index 75983b2d13..eb0d8e6366 100644
--- a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_threads.py
+++ b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_threads.py
@@ -6,11 +6,14 @@ from backend.sdk import (
BlockSchemaOutput,
BlockType,
SchemaField,
+ cost,
)
+from ._cost import AYRSHARE_POST_COSTS
from ._util import BaseAyrshareInput, create_ayrshare_client, get_profile_key
+@cost(*AYRSHARE_POST_COSTS)
class PostToThreadsBlock(Block):
"""Block for posting to Threads with Threads-specific options."""
diff --git a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_tiktok.py b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_tiktok.py
index 2d68f10ff0..36ae2d4911 100644
--- a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_tiktok.py
+++ b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_tiktok.py
@@ -8,8 +8,10 @@ from backend.sdk import (
BlockSchemaOutput,
BlockType,
SchemaField,
+ cost,
)
+from ._cost import AYRSHARE_POST_COSTS
from ._util import BaseAyrshareInput, create_ayrshare_client, get_profile_key
@@ -19,6 +21,7 @@ class TikTokVisibility(str, Enum):
FOLLOWERS = "followers"
+@cost(*AYRSHARE_POST_COSTS)
class PostToTikTokBlock(Block):
"""Block for posting to TikTok with TikTok-specific options."""
diff --git a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_x.py b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_x.py
index bbecd31ed4..764b38aa2b 100644
--- a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_x.py
+++ b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_x.py
@@ -6,11 +6,14 @@ from backend.sdk import (
BlockSchemaOutput,
BlockType,
SchemaField,
+ cost,
)
+from ._cost import AYRSHARE_POST_COSTS
from ._util import BaseAyrshareInput, create_ayrshare_client, get_profile_key
+@cost(*AYRSHARE_POST_COSTS)
class PostToXBlock(Block):
"""Block for posting to X / Twitter with Twitter-specific options."""
@@ -156,7 +159,7 @@ class PostToXBlock(Block):
if input_data.alt_text:
for i, alt in enumerate(input_data.alt_text):
if len(alt) > 1000:
- yield "error", f"X alt text {i+1} exceeds 1,000 character limit ({len(alt)} characters)"
+ yield "error", f"X alt text {i + 1} exceeds 1,000 character limit ({len(alt)} characters)"
return
# Validate subtitle settings
diff --git a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_youtube.py b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_youtube.py
index 8a366ba5c5..a24fbcbb76 100644
--- a/autogpt_platform/backend/backend/blocks/ayrshare/post_to_youtube.py
+++ b/autogpt_platform/backend/backend/blocks/ayrshare/post_to_youtube.py
@@ -9,8 +9,10 @@ from backend.sdk import (
BlockSchemaOutput,
BlockType,
SchemaField,
+ cost,
)
+from ._cost import AYRSHARE_POST_COSTS
from ._util import BaseAyrshareInput, create_ayrshare_client, get_profile_key
@@ -20,6 +22,7 @@ class YouTubeVisibility(str, Enum):
UNLISTED = "unlisted"
+@cost(*AYRSHARE_POST_COSTS)
class PostToYouTubeBlock(Block):
"""Block for posting to YouTube with YouTube-specific options."""
@@ -39,6 +42,14 @@ class PostToYouTubeBlock(Block):
advanced=False,
)
+ # YouTube is video-only; override the base default so the @cost filter
+ # selects the 5-credit video tier instead of the 2-credit image tier.
+ is_video: bool = SchemaField(
+ description="Whether the media is a video (always True for YouTube)",
+ default=True,
+ advanced=True,
+ )
+
# YouTube-specific required options
title: str = SchemaField(
description="Video title (max 100 chars, required). Cannot contain < or > characters.",
diff --git a/autogpt_platform/backend/backend/blocks/bannerbear/_config.py b/autogpt_platform/backend/backend/blocks/bannerbear/_config.py
index 0303f49ca2..32fe7fff21 100644
--- a/autogpt_platform/backend/backend/blocks/bannerbear/_config.py
+++ b/autogpt_platform/backend/backend/blocks/bannerbear/_config.py
@@ -3,6 +3,6 @@ from backend.sdk import BlockCostType, ProviderBuilder
bannerbear = (
ProviderBuilder("bannerbear")
.with_api_key("BANNERBEAR_API_KEY", "Bannerbear API Key")
- .with_base_cost(1, BlockCostType.RUN)
+ .with_base_cost(3, BlockCostType.RUN)
.build()
)
diff --git a/autogpt_platform/backend/backend/data/block_cost_config.py b/autogpt_platform/backend/backend/data/block_cost_config.py
index a9f2215239..9659662004 100644
--- a/autogpt_platform/backend/backend/data/block_cost_config.py
+++ b/autogpt_platform/backend/backend/data/block_cost_config.py
@@ -13,6 +13,11 @@ from backend.blocks.apollo.organization import SearchOrganizationsBlock
from backend.blocks.apollo.people import SearchPeopleBlock
from backend.blocks.apollo.person import GetPersonDetailBlock
from backend.blocks.claude_code import ClaudeCodeBlock
+from backend.blocks.code_executor import (
+ ExecuteCodeBlock,
+ ExecuteCodeStepBlock,
+ InstantiateCodeSandboxBlock,
+)
from backend.blocks.codex import CodeGenerationBlock, CodexModel
from backend.blocks.enrichlayer.linkedin import (
GetLinkedinProfileBlock,
@@ -20,8 +25,10 @@ from backend.blocks.enrichlayer.linkedin import (
LinkedinPersonLookupBlock,
LinkedinRoleLookupBlock,
)
+from backend.blocks.fal.ai_video_generator import AIVideoGeneratorBlock
from backend.blocks.flux_kontext import AIImageEditorBlock, FluxKontextModelName
from backend.blocks.ideogram import IdeogramModelBlock
+from backend.blocks.jina.chunking import JinaChunkingBlock
from backend.blocks.jina.embeddings import JinaEmbeddingBlock
from backend.blocks.jina.fact_checker import FactCheckerBlock
from backend.blocks.jina.search import ExtractWebsiteContentBlock, SearchTheWebBlock
@@ -54,6 +61,7 @@ from backend.blocks.smartlead.campaign import (
from backend.blocks.talking_head import CreateTalkingAvatarVideoBlock
from backend.blocks.text_to_speech_block import UnrealTextToSpeechBlock
from backend.blocks.video.narration import VideoNarrationBlock
+from backend.blocks.youtube import TranscribeYoutubeVideoBlock
from backend.blocks.zerobounce.validate_emails import ValidateEmailsBlock
from backend.integrations.credentials_store import (
aiml_api_credentials,
@@ -63,6 +71,7 @@ from backend.integrations.credentials_store import (
e2b_credentials,
elevenlabs_credentials,
enrichlayer_credentials,
+ fal_credentials,
groq_credentials,
ideogram_credentials,
jina_credentials,
@@ -77,6 +86,7 @@ from backend.integrations.credentials_store import (
smartlead_credentials,
unreal_credentials,
v0_credentials,
+ webshare_proxy_credentials,
zerobounce_credentials,
)
@@ -956,12 +966,9 @@ BLOCK_COSTS: dict[Type[Block], list[BlockCost]] = {
},
)
],
- # ClaudeCodeBlock runs an E2B sandbox (~$0.00003/sec compute) AND
- # executes Claude Sonnet inside it. Real session cost is dominated by
- # the LLM and varies $0.50–$2 per typical run. Flat 100 credits ($1.00)
- # is a conservative-but-fair estimate; revisit once we expose the
- # x-total-cost header from the in-sandbox Claude calls back to
- # NodeExecutionStats.provider_cost.
+ # ClaudeCodeBlock runs an E2B sandbox AND executes Claude Sonnet inside it.
+ # Real cost $0.50-$2/run; flat 100 credits is conservative until we pipe
+ # x-total-cost from the in-sandbox Claude calls into provider_cost.
ClaudeCodeBlock: [
BlockCost(
cost_amount=100,
@@ -974,4 +981,92 @@ BLOCK_COSTS: dict[Type[Block], list[BlockCost]] = {
},
)
],
+ # Ayrshare post blocks use the @cost(...) decorator directly on each block
+ # class (see backend/blocks/ayrshare/_cost.py). They can't be listed here
+ # because post_to_*.py imports from backend.sdk, which imports from this
+ # module — registering via decorator avoids the circular import.
+ # E2B code-execution blocks: Hobby tier ~$0.000014/vCPU-s. A typical 30s
+ # sandbox with 2 vCPU is ~$0.00084. Flat 2 credits covers the floor with
+ # margin; accurate per-second billing happens via walltime-based resolver
+ # in the dynamic-pricing follow-up.
+ ExecuteCodeBlock: [
+ BlockCost(
+ cost_amount=2,
+ cost_filter={
+ "credentials": {
+ "id": e2b_credentials.id,
+ "provider": e2b_credentials.provider,
+ "type": e2b_credentials.type,
+ }
+ },
+ )
+ ],
+ InstantiateCodeSandboxBlock: [
+ BlockCost(
+ cost_amount=2,
+ cost_filter={
+ "credentials": {
+ "id": e2b_credentials.id,
+ "provider": e2b_credentials.provider,
+ "type": e2b_credentials.type,
+ }
+ },
+ )
+ ],
+ ExecuteCodeStepBlock: [
+ BlockCost(
+ cost_amount=2,
+ cost_filter={
+ "credentials": {
+ "id": e2b_credentials.id,
+ "provider": e2b_credentials.provider,
+ "type": e2b_credentials.type,
+ }
+ },
+ )
+ ],
+ # FAL video generation: $0.001-$0.02 per output second. A 5s clip costs
+ # us ~$0.05-$0.10 in practice. 10 credits is a safe floor until walltime
+ # billing lands.
+ AIVideoGeneratorBlock: [
+ BlockCost(
+ cost_amount=10,
+ cost_filter={
+ "credentials": {
+ "id": fal_credentials.id,
+ "provider": fal_credentials.provider,
+ "type": fal_credentials.type,
+ }
+ },
+ )
+ ],
+ # Webshare is a flat monthly proxy subscription — the per-call cost to us
+ # is effectively zero, but the transcription step itself consumes compute
+ # time we haven't otherwise charged for. 1 credit is a tooling-tax floor.
+ TranscribeYoutubeVideoBlock: [
+ BlockCost(
+ cost_amount=1,
+ cost_filter={
+ "credentials": {
+ "id": webshare_proxy_credentials.id,
+ "provider": webshare_proxy_credentials.provider,
+ "type": webshare_proxy_credentials.type,
+ }
+ },
+ )
+ ],
+ # Jina chunking: $0.02/1M tokens. Flat 1 credit floor so the block is not
+ # wallet-free; embedding/search already have their own entries.
+ JinaChunkingBlock: [
+ BlockCost(
+ cost_amount=1,
+ cost_filter={
+ "credentials": {
+ "id": jina_credentials.id,
+ "provider": jina_credentials.provider,
+ "type": jina_credentials.type,
+ }
+ },
+ )
+ ],
}
diff --git a/autogpt_platform/backend/backend/data/block_cost_config_test.py b/autogpt_platform/backend/backend/data/block_cost_config_test.py
new file mode 100644
index 0000000000..7b69517c16
--- /dev/null
+++ b/autogpt_platform/backend/backend/data/block_cost_config_test.py
@@ -0,0 +1,156 @@
+import pytest
+
+from backend.blocks.ayrshare.post_to_bluesky import PostToBlueskyBlock
+from backend.blocks.ayrshare.post_to_facebook import PostToFacebookBlock
+from backend.blocks.ayrshare.post_to_gmb import PostToGMBBlock
+from backend.blocks.ayrshare.post_to_instagram import PostToInstagramBlock
+from backend.blocks.ayrshare.post_to_linkedin import PostToLinkedInBlock
+from backend.blocks.ayrshare.post_to_pinterest import PostToPinterestBlock
+from backend.blocks.ayrshare.post_to_reddit import PostToRedditBlock
+from backend.blocks.ayrshare.post_to_snapchat import PostToSnapchatBlock
+from backend.blocks.ayrshare.post_to_telegram import PostToTelegramBlock
+from backend.blocks.ayrshare.post_to_threads import PostToThreadsBlock
+from backend.blocks.ayrshare.post_to_tiktok import PostToTikTokBlock
+from backend.blocks.ayrshare.post_to_x import PostToXBlock
+from backend.blocks.ayrshare.post_to_youtube import PostToYouTubeBlock
+from backend.blocks.bannerbear.text_overlay import BannerbearTextOverlayBlock
+from backend.blocks.code_executor import (
+ ExecuteCodeBlock,
+ ExecuteCodeStepBlock,
+ InstantiateCodeSandboxBlock,
+)
+from backend.blocks.fal.ai_video_generator import AIVideoGeneratorBlock
+from backend.blocks.jina.chunking import JinaChunkingBlock
+from backend.blocks.youtube import TranscribeYoutubeVideoBlock
+from backend.data.block_cost_config import BLOCK_COSTS
+from backend.executor.utils import block_usage_cost
+from backend.integrations.credentials_store import (
+ e2b_credentials,
+ fal_credentials,
+ jina_credentials,
+ webshare_proxy_credentials,
+)
+
+ALL_AYRSHARE_BLOCKS = [
+ PostToBlueskyBlock,
+ PostToFacebookBlock,
+ PostToGMBBlock,
+ PostToInstagramBlock,
+ PostToLinkedInBlock,
+ PostToPinterestBlock,
+ PostToRedditBlock,
+ PostToSnapchatBlock,
+ PostToTelegramBlock,
+ PostToThreadsBlock,
+ PostToTikTokBlock,
+ PostToXBlock,
+ PostToYouTubeBlock,
+]
+
+# YouTube and Snapchat are video-only platforms, so their Input overrides
+# is_video default to True; the @cost filter should pick the 5-credit tier.
+AYRSHARE_VIDEO_ONLY_BLOCKS = [PostToYouTubeBlock, PostToSnapchatBlock]
+
+
[email protected]("block_class", ALL_AYRSHARE_BLOCKS)
+def test_ayrshare_block_has_video_and_default_tier(block_class):
+ costs = BLOCK_COSTS.get(block_class)
+ assert costs is not None and len(costs) == 2
+ amounts = {c.cost_amount for c in costs}
+ assert amounts == {2, 5}
+
+
+def test_ayrshare_video_post_charges_video_tier():
+ block = PostToXBlock()
+ cost, _ = block_usage_cost(block, {"is_video": True})
+ assert cost == 5
+
+
+def test_ayrshare_non_video_post_charges_default_tier():
+ block = PostToXBlock()
+ cost, _ = block_usage_cost(block, {"is_video": False})
+ assert cost == 2
+
+
+def test_ayrshare_default_is_video_false_still_matches_default_tier():
+ block = PostToXBlock()
+ cost, _ = block_usage_cost(block, {})
+ assert cost == 2
+
+
[email protected]("block_class", AYRSHARE_VIDEO_ONLY_BLOCKS)
+def test_ayrshare_video_only_block_defaults_to_video_tier(block_class):
+ # Video-only platforms override is_video default to True so billing matches
+ # the is_video=True passed into client.create_post.
+ block = block_class()
+ default_is_video = block.input_schema.model_fields["is_video"].default
+ assert default_is_video is True
+ cost, _ = block_usage_cost(block, {"is_video": default_is_video})
+ assert cost == 5
+
+
+def test_jina_chunking_has_flat_cost_floor():
+ block = JinaChunkingBlock()
+ cost, _ = block_usage_cost(
+ block,
+ {
+ "credentials": {
+ "id": jina_credentials.id,
+ "provider": jina_credentials.provider,
+ "type": jina_credentials.type,
+ }
+ },
+ )
+ assert cost == 1
+
+
+def test_bannerbear_base_cost_is_three_credits():
+ # Bannerbear is registered via the SDK ProviderBuilder with base_cost=3.
+ block = BannerbearTextOverlayBlock()
+ cost, _ = block_usage_cost(block, {})
+ assert cost == 3
+
+
+def test_e2b_sandbox_blocks_have_two_credit_floor():
+ creds = {
+ "credentials": {
+ "id": e2b_credentials.id,
+ "provider": e2b_credentials.provider,
+ "type": e2b_credentials.type,
+ }
+ }
+ for block_cls in (
+ ExecuteCodeBlock,
+ InstantiateCodeSandboxBlock,
+ ExecuteCodeStepBlock,
+ ):
+ cost, _ = block_usage_cost(block_cls(), creds)
+ assert cost == 2, f"{block_cls.__name__} floor must be 2 credits, got {cost}"
+
+
+def test_fal_video_generator_has_ten_credit_floor():
+ cost, _ = block_usage_cost(
+ AIVideoGeneratorBlock(),
+ {
+ "credentials": {
+ "id": fal_credentials.id,
+ "provider": fal_credentials.provider,
+ "type": fal_credentials.type,
+ }
+ },
+ )
+ assert cost == 10
+
+
+def test_transcribe_youtube_has_one_credit_tooling_floor():
+ cost, _ = block_usage_cost(
+ TranscribeYoutubeVideoBlock(),
+ {
+ "credentials": {
+ "id": webshare_proxy_credentials.id,
+ "provider": webshare_proxy_credentials.provider,
+ "type": webshare_proxy_credentials.type,
+ }
+ },
+ )
+ assert cost == 1
diff --git a/autogpt_platform/backend/backend/sdk/cost_integration.py b/autogpt_platform/backend/backend/sdk/cost_integration.py
index 2eec1aece0..f3be41cc52 100644
--- a/autogpt_platform/backend/backend/sdk/cost_integration.py
+++ b/autogpt_platform/backend/backend/sdk/cost_integration.py
@@ -1,17 +1,19 @@
"""
Integration between SDK provider costs and the execution cost system.
-This module provides the glue between provider-defined base costs and the
+This module provides the glue between provider-defined base costs and the
BLOCK_COSTS configuration used by the execution system.
"""
import logging
-from typing import List, Type
+from typing import List, Type, TypeVar
from backend.blocks._base import Block, BlockCost
from backend.data.block_cost_config import BLOCK_COSTS
from backend.sdk.registry import AutoRegistry
+BlockT = TypeVar("BlockT", bound=Type[Block])
+
logger = logging.getLogger(__name__)
@@ -150,7 +152,7 @@ def cost(*costs: BlockCost):
*costs: Variable number of BlockCost objects
"""
- def decorator(block_class: Type[Block]) -> Type[Block]:
+ def decorator(block_class: BlockT) -> BlockT:
# Register the costs for this block
if costs:
BLOCK_COSTS[block_class] = list(costs)
diff --git a/docs/integrations/block-integrations/ayrshare/post_to_bluesky.md b/docs/integrations/block-integrations/ayrshare/post_to_bluesky.md
index 9931a2edb0..3dbda5638e 100644
--- a/docs/integrations/block-integrations/ayrshare/post_to_bluesky.md
+++ b/docs/integrations/block-integrations/ayrshare/post_to_bluesky.md
@@ -21,7 +21,7 @@ The block authenticates through your Ayrshare credentials and sends the post dat
|-------|-------------|------|----------|
| post | The post text to be published (max 300 characters for Bluesky) | str | No |
| media_urls | Optional list of media URLs to include. Bluesky supports up to 4 images or 1 video. | List[str] | No |
-| is_video | Whether the media is a video | bool | No |
+| is_video | Whether the media is a video. Set to True when uploading a video so billing applies the video tier. | bool | No |
| schedule_date | UTC datetime for scheduling (YYYY-MM-DDThh:mm:ssZ) | str (date-time) | No |
| disable_comments | Whether to disable comments | bool | No |
| shorten_links | Whether to shorten links | bool | No |
diff --git a/docs/integrations/block-integrations/ayrshare/post_to_facebook.md b/docs/integrations/block-integrations/ayrshare/post_to_facebook.md
index ee41ded42c..a5dbf292ee 100644
--- a/docs/integrations/block-integrations/ayrshare/post_to_facebook.md
+++ b/docs/integrations/block-integrations/ayrshare/post_to_facebook.md
@@ -21,7 +21,7 @@ The block authenticates through Ayrshare and leverages the Meta Graph API to han
|-------|-------------|------|----------|
| post | The post text to be published | str | No |
| media_urls | Optional list of media URLs to include. Set is_video in advanced settings to true if you want to upload videos. | List[str] | No |
-| is_video | Whether the media is a video | bool | No |
+| is_video | Whether the media is a video. Set to True when uploading a video so billing applies the video tier. | bool | No |
| schedule_date | UTC datetime for scheduling (YYYY-MM-DDThh:mm:ssZ) | str (date-time) | No |
| disable_comments | Whether to disable comments | bool | No |
| shorten_links | Whether to shorten links | bool | No |
diff --git a/docs/integrations/block-integrations/ayrshare/post_to_gmb.md b/docs/integrations/block-integrations/ayrshare/post_to_gmb.md
index 4ada1bd966..e930be535d 100644
--- a/docs/integrations/block-integrations/ayrshare/post_to_gmb.md
+++ b/docs/integrations/block-integrations/ayrshare/post_to_gmb.md
@@ -21,7 +21,7 @@ The block integrates with Google's Business Profile API through Ayrshare, enabli
|-------|-------------|------|----------|
| post | The post text to be published | str | No |
| media_urls | Optional list of media URLs. GMB supports only one image or video per post. | List[str] | No |
-| is_video | Whether the media is a video | bool | No |
+| is_video | Whether the media is a video. Set to True when uploading a video so billing applies the video tier. | bool | No |
| schedule_date | UTC datetime for scheduling (YYYY-MM-DDThh:mm:ssZ) | str (date-time) | No |
| disable_comments | Whether to disable comments | bool | No |
| shorten_links | Whether to shorten links | bool | No |
diff --git a/docs/integrations/block-integrations/ayrshare/post_to_instagram.md b/docs/integrations/block-integrations/ayrshare/post_to_instagram.md
index 63ea5a3208..5f5e17dbca 100644
--- a/docs/integrations/block-integrations/ayrshare/post_to_instagram.md
+++ b/docs/integrations/block-integrations/ayrshare/post_to_instagram.md
@@ -21,7 +21,7 @@ The block requires an Instagram account connected to a Facebook Page and authent
|-------|-------------|------|----------|
| post | The post text (max 2,200 chars, up to 30 hashtags, 3 @mentions) | str | No |
| media_urls | Optional list of media URLs. Instagram supports up to 10 images/videos in a carousel. | List[str] | No |
-| is_video | Whether the media is a video | bool | No |
+| is_video | Whether the media is a video. Set to True when uploading a video so billing applies the video tier. | bool | No |
| schedule_date | UTC datetime for scheduling (YYYY-MM-DDThh:mm:ssZ) | str (date-time) | No |
| disable_comments | Whether to disable comments | bool | No |
| shorten_links | Whether to shorten links | bool | No |
diff --git a/docs/integrations/block-integrations/ayrshare/post_to_linkedin.md b/docs/integrations/block-integrations/ayrshare/post_to_linkedin.md
index 08e82ef0b1..88a4bf0aec 100644
--- a/docs/integrations/block-integrations/ayrshare/post_to_linkedin.md
+++ b/docs/integrations/block-integrations/ayrshare/post_to_linkedin.md
@@ -19,7 +19,7 @@ _Add technical explanation here._
|-------|-------------|------|----------|
| post | The post text (max 3,000 chars, hashtags supported with #) | str | No |
| media_urls | Optional list of media URLs. LinkedIn supports up to 9 images, videos, or documents (PPT, PPTX, DOC, DOCX, PDF <100MB, <300 pages). | List[str] | No |
-| is_video | Whether the media is a video | bool | No |
+| is_video | Whether the media is a video. Set to True when uploading a video so billing applies the video tier. | bool | No |
| schedule_date | UTC datetime for scheduling (YYYY-MM-DDThh:mm:ssZ) | str (date-time) | No |
| disable_comments | Whether to disable comments | bool | No |
| shorten_links | Whether to shorten links | bool | No |
diff --git a/docs/integrations/block-integrations/ayrshare/post_to_pinterest.md b/docs/integrations/block-integrations/ayrshare/post_to_pinterest.md
index f548e69749..70a8375fbe 100644
--- a/docs/integrations/block-integrations/ayrshare/post_to_pinterest.md
+++ b/docs/integrations/block-integrations/ayrshare/post_to_pinterest.md
@@ -21,7 +21,7 @@ The block connects to Pinterest's API through Ayrshare, allowing you to specify
|-------|-------------|------|----------|
| post | Pin description (max 500 chars, links not clickable - use link field instead) | str | No |
| media_urls | Required image/video URLs. Pinterest requires at least one image. Videos need thumbnail. Up to 5 images for carousel. | List[str] | No |
-| is_video | Whether the media is a video | bool | No |
+| is_video | Whether the media is a video. Set to True when uploading a video so billing applies the video tier. | bool | No |
| schedule_date | UTC datetime for scheduling (YYYY-MM-DDThh:mm:ssZ) | str (date-time) | No |
| disable_comments | Whether to disable comments | bool | No |
| shorten_links | Whether to shorten links | bool | No |
diff --git a/docs/integrations/block-integrations/ayrshare/post_to_reddit.md b/docs/integrations/block-integrations/ayrshare/post_to_reddit.md
index 1fab74fd8a..4a4cd8026d 100644
--- a/docs/integrations/block-integrations/ayrshare/post_to_reddit.md
+++ b/docs/integrations/block-integrations/ayrshare/post_to_reddit.md
@@ -21,7 +21,7 @@ The block authenticates through Ayrshare and submits content to your connected R
|-------|-------------|------|----------|
| post | The post text to be published | str | No |
| media_urls | Optional list of media URLs to include. Set is_video in advanced settings to true if you want to upload videos. | List[str] | No |
-| is_video | Whether the media is a video | bool | No |
+| is_video | Whether the media is a video. Set to True when uploading a video so billing applies the video tier. | bool | No |
| schedule_date | UTC datetime for scheduling (YYYY-MM-DDThh:mm:ssZ) | str (date-time) | No |
| disable_comments | Whether to disable comments | bool | No |
| shorten_links | Whether to shorten links | bool | No |
diff --git a/docs/integrations/block-integrations/ayrshare/post_to_snapchat.md b/docs/integrations/block-integrations/ayrshare/post_to_snapchat.md
index 247f49f8c5..947ccd7732 100644
--- a/docs/integrations/block-integrations/ayrshare/post_to_snapchat.md
+++ b/docs/integrations/block-integrations/ayrshare/post_to_snapchat.md
@@ -21,7 +21,7 @@ The block authenticates through Ayrshare and uploads video content with optional
|-------|-------------|------|----------|
| post | The post text (optional for video-only content) | str | No |
| media_urls | Required video URL for Snapchat posts. Snapchat only supports video content. | List[str] | No |
-| is_video | Whether the media is a video | bool | No |
+| is_video | Whether the media is a video (always True for Snapchat) | bool | No |
| schedule_date | UTC datetime for scheduling (YYYY-MM-DDThh:mm:ssZ) | str (date-time) | No |
| disable_comments | Whether to disable comments | bool | No |
| shorten_links | Whether to shorten links | bool | No |
diff --git a/docs/integrations/block-integrations/ayrshare/post_to_threads.md b/docs/integrations/block-integrations/ayrshare/post_to_threads.md
index 65c5fdbe99..59cd5db33b 100644
--- a/docs/integrations/block-integrations/ayrshare/post_to_threads.md
+++ b/docs/integrations/block-integrations/ayrshare/post_to_threads.md
@@ -21,7 +21,7 @@ The block authenticates through Meta's API via Ayrshare. Content can mention use
|-------|-------------|------|----------|
| post | The post text (max 500 chars, empty string allowed). Only 1 hashtag allowed. Use @handle to mention users. | str | No |
| media_urls | Optional list of media URLs. Supports up to 20 images/videos in a carousel. Auto-preview links unless media is included. | List[str] | No |
-| is_video | Whether the media is a video | bool | No |
+| is_video | Whether the media is a video. Set to True when uploading a video so billing applies the video tier. | bool | No |
| schedule_date | UTC datetime for scheduling (YYYY-MM-DDThh:mm:ssZ) | str (date-time) | No |
| disable_comments | Whether to disable comments | bool | No |
| shorten_links | Whether to shorten links | bool | No |
diff --git a/docs/integrations/block-integrations/ayrshare/post_to_tiktok.md b/docs/integrations/block-integrations/ayrshare/post_to_tiktok.md
index f6bff7b940..d7b09046eb 100644
--- a/docs/integrations/block-integrations/ayrshare/post_to_tiktok.md
+++ b/docs/integrations/block-integrations/ayrshare/post_to_tiktok.md
@@ -21,7 +21,7 @@ The block connects to TikTok's API through Ayrshare with controls for visibility
|-------|-------------|------|----------|
| post | The post text (max 2,200 chars, empty string allowed). Use @handle to mention users. Line breaks will be ignored. | str | Yes |
| media_urls | Required media URLs. Either 1 video OR up to 35 images (JPG/JPEG/WEBP only). Cannot mix video and images. | List[str] | No |
-| is_video | Whether the media is a video | bool | No |
+| is_video | Whether the media is a video. Set to True when uploading a video so billing applies the video tier. | bool | No |
| schedule_date | UTC datetime for scheduling (YYYY-MM-DDThh:mm:ssZ) | str (date-time) | No |
| disable_comments | Disable comments on the published post | bool | No |
| shorten_links | Whether to shorten links | bool | No |
diff --git a/docs/integrations/block-integrations/ayrshare/post_to_x.md b/docs/integrations/block-integrations/ayrshare/post_to_x.md
index 9881107505..02df7e7e57 100644
--- a/docs/integrations/block-integrations/ayrshare/post_to_x.md
+++ b/docs/integrations/block-integrations/ayrshare/post_to_x.md
@@ -21,7 +21,7 @@ The block authenticates through Ayrshare and handles X-specific features like au
|-------|-------------|------|----------|
| post | The post text (max 280 chars, up to 25,000 for Premium users). Use @handle to mention users. Use \n\n for thread breaks. | str | Yes |
| media_urls | Optional list of media URLs. X supports up to 4 images or videos per tweet. Auto-preview links unless media is included. | List[str] | No |
-| is_video | Whether the media is a video | bool | No |
+| is_video | Whether the media is a video. Set to True when uploading a video so billing applies the video tier. | bool | No |
| schedule_date | UTC datetime for scheduling (YYYY-MM-DDThh:mm:ssZ) | str (date-time) | No |
| disable_comments | Whether to disable comments | bool | No |
| shorten_links | Whether to shorten links | bool | No |
diff --git a/docs/integrations/block-integrations/ayrshare/post_to_youtube.md b/docs/integrations/block-integrations/ayrshare/post_to_youtube.md
index df21c43ef3..6bbceb6faa 100644
--- a/docs/integrations/block-integrations/ayrshare/post_to_youtube.md
+++ b/docs/integrations/block-integrations/ayrshare/post_to_youtube.md
@@ -19,7 +19,7 @@ _Add technical explanation here._
|-------|-------------|------|----------|
| post | Video description (max 5,000 chars, empty string allowed). Cannot contain < or > characters. | str | Yes |
| media_urls | Required video URL. YouTube only supports 1 video per post. | List[str] | No |
-| is_video | Whether the media is a video | bool | No |
+| is_video | Whether the media is a video (always True for YouTube) | bool | No |
| schedule_date | UTC datetime for scheduling (YYYY-MM-DDThh:mm:ssZ) | str (date-time) | No |
| disable_comments | Whether to disable comments | bool | No |
| shorten_links | Whether to shorten links | bool | No |