# How Block Cost Configuration Controls Credit Usage in AutoGPT

> Master AutoGPT block cost configuration to precisely control credit usage. Learn how execution units map to monetary costs and optimize your AI spending effectively.

- Repository: [AutoGPT/AutoGPT](https://github.com/Significant-Gravitas/AutoGPT)
- Tags: deep-dive
- Published: 2026-02-24

---

**AutoGPT's block cost configuration defines exactly how many credits each Block consumes by mapping execution units to monetary costs in `BLOCK_COSTS`, enabling per-request, per-second, or per-byte billing based on runtime context.**

The Significant-Gravitas/AutoGPT platform implements a granular credit system where every atomic unit of work—whether an LLM call, image generation, or web search—consumes credits according to a configurable pricing model. The **block cost configuration** stored in `BLOCK_COSTS` serves as the single source of truth for these calculations, allowing dynamic pricing based on execution parameters like model selection or runtime duration.

## Understanding the Block Cost Configuration Structure

The central registry for pricing lives in [`autogpt_platform/backend/backend/data/block_cost_config.py`](https://github.com/Significant-Gravitas/AutoGPT/blob/main/autogpt_platform/backend/backend/data/block_cost_config.py). This file maintains the `BLOCK_COSTS` dictionary, which maps each Block class to a list of `BlockCost` objects that define when and how to charge users.

### The BLOCK_COSTS Registry

Each entry in `BLOCK_COSTS` associates a Block class with one or more `BlockCost` instances. When the platform initializes, the SDK registers model-specific costs through [`autogpt_platform/backend/backend/sdk/cost_integration.py`](https://github.com/Significant-Gravitas/AutoGPT/blob/main/autogpt_platform/backend/backend/sdk/cost_integration.py), populating this registry with provider-specific pricing tiers.

### BlockCost Parameters

Every `BlockCost` object contains three critical fields that determine credit consumption:

- **`cost_type`** – Defines the billing metric using the `BlockCostType` enum: `RUN` (per execution), `SECOND` (per runtime second), or `BYTE` (per data size).
- **`cost_amount`** – The numeric credit value to deduct.
- **`cost_filter`** – Optional criteria dictionary specifying model names, credential IDs, or feature flags that must match the execution context for the cost to apply.

For example, an OpenAI LLM call configuration specifies the model and credentials in the filter while charging per request:

```python
BlockCost(
    cost_type=BlockCostType.RUN,
    cost_filter={
        "model": model,
        "credentials": {
            "id": openai_credentials.id,
            "provider": openai_credentials.provider,
            "type": openai_credentials.type,
        },
    },
    cost_amount=cost,  # Value from MODEL_COST dict

)

```

## Runtime Credit Calculation and Deduction

When a Block executes, the system consults the configuration to determine the exact credit charge. This process involves three stages: cost retrieval, context filtering, and balance adjustment.

### Cost Lookup with get_block_cost

The executor calls `get_block_cost(block)` from [`autogpt_platform/backend/backend/data/credit.py`](https://github.com/Significant-Gravitas/AutoGPT/blob/main/autogpt_platform/backend/backend/data/credit.py) to retrieve applicable pricing. This function performs a simple dictionary lookup using `BLOCK_COSTS.get(type(block))`. If the Block class lacks an entry, the function returns an empty list and no credits are charged.

### Filter Matching and Context-Aware Pricing

Before applying any charges, the system validates each `BlockCost` against the current execution context through `_is_cost_filter_match`. This filtering enables dynamic pricing where the same Block can incur different costs depending on input parameters. A user might pay one rate for GPT-4 and another for GPT-3.5 based on the `"model"` key in `cost_filter`.

### Credit Deduction by Cost Type

The actual deduction logic resides in [`autogpt_platform/backend/backend/executor/utils.py`](https://github.com/Significant-Gravitas/AutoGPT/blob/main/autogpt_platform/backend/backend/executor/utils.py). The executor iterates through matched `BlockCost` objects and calculates the credit delta based on the `cost_type`:

- **`RUN`** – Deducts `cost_amount` once per execution.
- **`SECOND`** – Multiplies `cost_amount` by the Block's runtime in seconds.
- **`BYTE`** – Multiplies `cost_amount` by the size of processed data in bytes.

The calculated delta passes to `credit.adjust_user_balance(user_id, delta)`, which updates the user's stored balance, enforces credit ceilings, and records the transaction ledger.

## Configuring Custom Block Costs

Developers can extend the pricing model by registering new Blocks in [`block_cost_config.py`](https://github.com/Significant-Gravitas/AutoGPT/blob/main/block_cost_config.py). The following example configures a custom Block with dual billing: a flat fee per execution plus time-based charges:

```python

# In autogpt_platform/backend/backend/data/block_cost_config.py

from backend.blocks.my_new_block import MyNewBlock
from backend.data.block import BlockCost, BlockCostType

BLOCK_COSTS[MyNewBlock] = [
    BlockCost(
        cost_type=BlockCostType.RUN,    # Charge per execution

        cost_amount=4,                   # 4 credits per run

        cost_filter={},                  # Applies universally

    ),
    BlockCost(
        cost_type=BlockCostType.SECOND,  # Charge per runtime second

        cost_amount=1,                   # 1 credit per second

        cost_filter={},                  # No filtering restrictions

    ),
]

```

Within the Block implementation, you can inspect these costs during execution:

```python
from backend.data.credit import get_block_cost

class MyNewBlock(Block):
    async def run(self, input_data):
        # Resolve applicable costs for logging or custom handling

        costs = get_block_cost(self)  # Returns list of BlockCost objects

        # Execution logic continues...

```

## Summary

- The **block cost configuration** in `BLOCK_COSTS` dictates exactly how many credits each Block consumes during execution.
- **Three billing models** exist: per-run (`RUN`), per-second (`SECOND`), and per-byte (`BYTE`), configurable via `BlockCostType`.
- **Context-aware filtering** through `cost_filter` allows dynamic pricing based on model selection, credentials, or execution flags.
- **Runtime deduction** occurs in [`executor/utils.py`](https://github.com/Significant-Gravitas/AutoGPT/blob/main/executor/utils.py) via `adjust_user_balance()`, which updates user credit balances immediately after cost calculation.
- Modifying `BLOCK_COSTS` instantly changes credit consumption across the platform without requiring code changes to individual Blocks.

## Frequently Asked Questions

### What happens if a Block isn't registered in BLOCK_COSTS?

If `get_block_cost()` cannot find the Block class in `BLOCK_COSTS`, it returns an empty list. The executor charges zero credits for that execution, making the Block effectively free. This behavior allows development and testing without immediate pricing configuration.

### How does AutoGPT handle different pricing for different LLM models?

The `cost_filter` dictionary in `BlockCost` objects includes a `"model"` key that must match the current execution's selected model. When running an LLM Block, the executor filters the available costs and only applies those matching the specific model and credentials, enabling per-model pricing tiers within the same Block class.

### Can I set time-based charges for custom blocks?

Yes. Set `cost_type=BlockCostType.SECOND` in your `BlockCost` configuration with a `cost_amount` representing credits per second. During execution, the system measures the Block's runtime and multiplies the duration by this rate before deducting from the user's balance.

### Where is the user credit balance stored and updated?

The `adjust_user_balance()` function in [`autogpt_platform/backend/backend/data/credit.py`](https://github.com/Significant-Gravitas/AutoGPT/blob/main/autogpt_platform/backend/backend/data/credit.py) handles all credit mutations. This function updates the persistent user balance, enforces maximum credit limits, and records transaction history for auditing purposes.