> ## Documentation Index
> Fetch the complete documentation index at: https://splinter.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Step Limits

> Cap total LLM calls

Stop agents after N LLM calls.

## Simple API

```python theme={null}
from splinter import Splinter

s = Splinter(
    openai_key="sk-...",
    max_steps=20,  # Stop at 20 LLM calls
)

result = await s.run("helper", "Do something")
print(f"Steps used: {s.steps}")
```

## Advanced API

```python theme={null}
from splinter import Gateway, ExecutionLimits

gateway = Gateway(limits=ExecutionLimits(
    max_steps=100,  # 100 calls max
))

# Check current steps
metrics = gateway.get_metrics()
print(f"Total steps: {metrics['total_steps']}")
```

## Per-Agent Limits

```python theme={null}
from splinter import ExecutionLimits

limits = ExecutionLimits(
    max_steps=100,           # Workflow max
    per_agent_max_steps=20,  # Each agent max
)
```

## Error Handling

```python theme={null}
from splinter.exceptions import StepLimitExceededError

try:
    result = await workflow.run()
except StepLimitExceededError as e:
    print(f"Step limit exceeded: {e.current} >= {e.limit}")
```

## Use Cases

* **Prevent runaway agents**: Stop agents that keep calling LLM
* **Cost control**: Limit calls to control costs
* **Testing**: Limit steps during development
