SteerPlane SDK
The safety layer for the AGI era. Runtime guardrails for autonomous AI agents.
steerplane.com · Guides · Docs
Cost limits · Loop detection · Action rules · Approval callbacks · Gateway · CLI · Docker · 4 framework integrations
Install
pip install steerplane # Core SDK
pip install "steerplane[cli]" # + CLI tool
pip install "steerplane[all]" # + CLI + YAML config + LangChain
Quick Start
Option 1: Gateway Mode
Point your OpenAI client at the SteerPlane gateway. Model calls sent through it are checked against the key's model rules, cost limits, request rate and repeated prompts, and a streamed reply is cut when the estimated cost reaches the limit. It does not apply action rules to tool calls. See what the gateway covers.
import openai
client = openai.OpenAI(
base_url="http://localhost:8000/gateway/v1",
api_key="sk_sp_...", # SteerPlane API key
default_headers={"X-LLM-API-Key": "sk-..."}
)
# Calls sent through the gateway are checked, including stream=True.
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Hello"}],
stream=True # SSE streaming with real-time cost tracking
)
Option 2: Decorator Mode
Wrap your agent; its code stays as it is.
from openai import OpenAI
from steerplane import guard
client = OpenAI()
@guard(
agent_name="support_bot",
max_cost_usd=10.00,
max_steps=50,
denied_actions=["delete_*"],
rate_limits=[{"pattern": "send_email", "max_count": 5, "window_seconds": 60}],
)
def run_agent():
reply = client.chat.completions.create(model="gpt-4o-mini", messages=msgs, tools=tools)
...
Inside @guard, every openai or anthropic client call (Chat Completions, Responses, Messages; sync, async and streaming) is checked against the step and cost limits before it is sent, counted with its tokens and cost, and checked for the tool calls the model asks for. A denied tool raises before your code can run it; a require_approval rule calls your approval_callback with the tool's arguments.
Not covered: tools that run without a model asking for them, other HTTP clients or providers, threads started inside the run, the .stream() helpers and with_streaming_response, and the cost of OpenAI streams without stream_options={"include_usage": True}. Report those steps yourself:
from steerplane import get_active_run
def call_tool(name, fn):
run = get_active_run()
run.check_before_step(name) # raises before the tool runs
result = fn()
run.log_step(name, check_policy=False)
return result
Set @guard(auto_instrument=False) if you already log model calls yourself or use a framework integration, so calls aren't counted twice. Rules match the action (tool) name, not its arguments.
Option 3: Context Manager
from steerplane import SteerPlane
sp = SteerPlane(agent_id="my_bot")
with sp.run(max_cost_usd=10.0, max_steps=50) as run:
run.log_step("query_db", tokens=380, cost=0.002, latency_ms=45)
run.log_step("generate_response", tokens=1240, cost=0.008, latency_ms=320)
What's New in v1.2.0
@guardnow tracks model calls on its own.openaiandanthropicclient calls inside it are checked against the step and cost limits before they are sent, counted with tokens and cost, and the tool calls the model asks for are checked against your policy before your code can run them. Passauto_instrument=Falseif you log model calls yourself.- Policies saved in the dashboard now apply to runs. When a run starts, the SDK loads every active saved policy from the API (
GET /sdk/policy) and checks each reported step against it, next to the rules in your code. A refused step names the policy. Before, saved policies were never sent to SDK runs. rate_limitsin.steerplane.ymlnow work with@guard. They were read but not applied.approval_callbackon its own is kept, so it can answer a saved policy'srequire_approvalrule.- Claude Code through the gateway. The API has an Anthropic-format route (
/gateway/v1/messages), and Claude prompt-cache tokens are priced, so spend limits count them. - Claude on the OpenAI route now handles tools and tool calls, and streams come back as OpenAI chunks.
- Faster gateway. It adds about 5 ms per call instead of about 950 ms (measured locally).
What's New in v1.1.5
- Small cost limits are shown properly. A $0.001 ceiling used to print as "Limit: $0.00". It now prints "$0.0010". Limits of $1 or more print as before.
What's New in v1.1.4
steerplane runs killnow stops a live run. The run stops at its next logged step and raisesRunTerminatedError. Before, the kill only changed the status on the server, the agent kept running, and the run's cost and step totals were reset to 0. Those totals are now kept.
What's New in v1.1.3
- Framework integrations now stop runs. LangChain, OpenAI Agents SDK, CrewAI and AutoGen check limits and policy rules before each model call and tool call. Before this release, with the setup the docs showed, they recorded calls but did not stop a run.
- Real token usage. Cost comes from what the model reports, not a character estimate.
- Routed names priced correctly:
openai/gpt-4o-miniuses thegpt-4o-miniprice. - Changes you may notice: loop detection is off by default in the integrations, CrewAI needs 1.15.35 or newer, and the
autogenextra now installsag2before 1.0.
What's New in v1.1.2
- Built-in pricing now covers 106 models. Adds Mistral's current models by their API ids
(for example
mistral-large-4,mistral-medium-3-5,codestral-2508), GPT-5.6 Cyber and GPT-5.5 Cyber, GPT-Rosalind, Gemini Robotics-ER 2, and the Gemini and Mistral-latestaliases. - Fixes ids that were priced as an older model with a similar name:
gemini-pro-latestwas priced as the oldgemini-prorow,gpt-5.6-cyberasgpt-5, and current Mistral ids as the older Mistral rows. - Audio, image, video, speech, realtime, transcription and embedding models are not in the table, and nor
are ids with a cloud or router prefix (such as Bedrock's
anthropic.ids). For those, pass your own cost per step:run.log_step(..., cost=0.0042).
What's New in v1.1.1
- Built-in pricing now covers 83 models, checked against the OpenAI, Anthropic and Google pricing pages on 21 Oct 2026 (current GPT, Claude and Gemini models, by their API ids).
- Dated model names such as
gpt-4o-2024-08-06are priced as their model instead of the default rate, andgpt-4.1is no longer priced asgpt-4. - For a model that is not in the table, pass your own cost per step:
run.log_step(..., cost=0.0042).
What's New in v1.1.0
detect_loopsnow works. The docs have shown@guard(detect_loops=True)for a long time, but the parameter did not exist. It is accepted by@guard,SteerPlane.run(),RunManagerand all four framework integrations, and in.steerplane.yml. Set it toFalseto stop loop detection from ending a run; cost, step, runtime and policy limits still apply.- Self-hosting for several teams: see
docs/hosted-deployment.mdin the repository.
What's New in v0.4.0
🌊 SSE Streaming Gateway
The AI Gateway now supports Server-Sent Events (SSE) streaming. It accumulates token costs per chunk in real time and can terminate a stream mid-response by injecting a steerplane_enforcement event when the cost ceiling is breached — without corrupting the SSE protocol.
🖥️ CLI Tool
steerplane status # Check API health
steerplane runs list # List recent runs
steerplane runs inspect <id> # Inspect a run
steerplane runs kill <id> # Mark a run as terminated
steerplane keys list # List API keys
steerplane keys create # Create new gateway key
steerplane logs --tail # Live log stream
🐳 Docker Compose
Full 3-service stack in one command (for one server shared by several teams, use docker-compose.hosted.yml):
docker compose up -d
# API (8000) + Dashboard (3000) + PostgreSQL (5432)
📄 Config File (.steerplane.yml)
Project-level defaults auto-discovered from your working directory:
api_url: http://localhost:8000
agent_name: my_bot
defaults:
max_cost_usd: 10.0
max_steps: 100
detect_loops: true
🔌 Framework Integrations
Native support for 4 frameworks — all use lazy imports, so framework dependencies are only required when used:
LangChain:
from steerplane.integrations import SteerPlaneCallbackHandler
handler = SteerPlaneCallbackHandler(agent_name="lc_bot", max_cost_usd=5.0)
result = agent.invoke(inputs, config={"callbacks": [handler]})
handler.finish()
OpenAI Agents SDK:
from steerplane.integrations import SteerPlaneAgentHooks
hooks = SteerPlaneAgentHooks(agent_name="openai_agent", max_cost_usd=10.0)
result = await hooks.run(agent, "Hello!")
CrewAI:
from steerplane.integrations import SteerPlaneCrewMonitor
monitor = SteerPlaneCrewMonitor(agent_name="crew_bot", max_cost_usd=15.0)
result = monitor.kickoff(crew)
AutoGen:
from steerplane.integrations import SteerPlaneAutoGenMonitor
monitor = SteerPlaneAutoGenMonitor(agent_name="autogen_bot", max_cost_usd=10.0)
result = monitor.initiate_chat(user_proxy, assistant, message="Hello!")
Each counts every model call and tool call as one step, and refuses a call that would go past a limit before it starts. They only see calls they are passed to, and loop detection is off by default in them. See the SDK usage guide for what they don't cover. To limit every call whatever the agent structure, use the gateway.
All Features
| Feature | Description |
|---|---|
| 🌉 AI Gateway Proxy | OpenAI-style chat/completions proxy: model rules, cost, request rate and repeated-prompt checks. |
| 🌊 SSE Streaming | Real-time chunk forwarding with mid-stream cost enforcement. |
| 🛡️ Policy Engine | Allow/deny rules, sliding-window rate limits, human-approval callbacks. |
| 🔄 Loop Detection | Sliding-window pattern detector catches infinite agent loops. |
| 💰 Hard Cost Ceiling | Per-run USD limits in the SDK, per-key monthly limits in the gateway. Built-in pricing for 106 models; for any other model, pass your own cost= to log_step. |
| 🚫 Step Limits | Cap maximum execution steps. |
| 📊 Deep Telemetry | Tokens, cost, latency per step — synced to the dashboard. |
| 🛡️ Graceful Degradation | API down? SDK still enforces guards locally. |
| 🖥️ CLI Tool | steerplane status, runs, keys, logs from terminal. |
| 🐳 Docker Compose | 3-service stack in one command. |
| 📄 Config File | .steerplane.yml for project-level defaults. |
| 🔌 4 Integrations | LangChain, OpenAI Agents SDK, CrewAI, AutoGen. |
Architecture
┌─────────────┐ ┌──────────────┐ ┌────────────┐ ┌───────────────┐
│ AI Agent │────▶│ SteerPlane │────▶│ FastAPI │────▶│ PostgreSQL │
│ (Your App) │ │ SDK / GW │ │ Server │ │ Database │
└─────────────┘ └──────────────┘ └────────────┘ └───────────────┘
│
▼
┌───────────────┐
│ Next.js │
│ Dashboard │
└───────────────┘
Tech Stack
| Component | Technology |
|---|---|
| Python SDK | Python 3.10+, Decorator/Context Manager API, CLI, Config files |
| TypeScript SDK | TypeScript, guard() wrapper, npm-ready |
| Gateway | FastAPI + httpx, SSE streaming, built-in pricing for 106 models |
| API | FastAPI, Alembic migrations, OpenAPI docs |
| Database | PostgreSQL 16 + SQLAlchemy ORM |
| Infrastructure | Docker Compose (API + Dashboard + PostgreSQL) |
| CI/CD | GitHub Actions (lint, test, Docker build) |
| Dashboard | Next.js 16, React 19, Framer Motion |
Guides
- Stop an AI agent stuck in an infinite loop
- Cap what an AI agent can spend per run
- Stop an AI agent sending the same email twice
- Put a time limit on an AI agent that ran all night
- Stop an AI agent from deleting data
- Set a cost limit on a LangChain or LangGraph agent
- Limit what a CrewAI crew can spend
- Put a budget on an OpenAI Agents SDK agent
Links
- Website: steerplane.com
- GitHub: github.com/vijaym2k6/SteerPlane
- npm: npmjs.com/package/steerplane
- Dashboard:
http://localhost:3000 - API Docs:
http://localhost:8000/docs
License
Metadata
Release files for steerplane 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| steerplane-1.2.0.tar.gz | 79.7 kB | Without provenance | Details for steerplane-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| steerplane-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for steerplane-1.2.0-py3-none-any.whl |
Total release size: 143.0 kB
Release files / steerplane-1.2.0.tar.gz
| Download URL | steerplane-1.2.0.tar.gz |
|---|---|
| Size | 79.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2f6361664ef9120d9cba5435b2339812c6d500c1f1aa5340198da0017f5b493c
|
|
BLAKE2b-256 checksum How to use checksums |
d008f315b315f467fa7b0b63a3ea5a11248672f7e4185263304c2816297681b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / steerplane-1.2.0-py3-none-any.whl
| Download URL | steerplane-1.2.0-py3-none-any.whl |
|---|---|
| Size | 63.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3f95d6d2273eb6912191ce87524bf0f3c7253de4ad6a75bb97fae259b99b085b
|
|
BLAKE2b-256 checksum How to use checksums |
e8c0ad21d2d3406296ecfe9c718a67fbc8b42c66e8aac31d1af95aa6abd5d9cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for steerplane 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.