Metadata-Version: 2.4
Name: steerplane
Version: 1.1.3
Summary: The safety layer for the AGI era. Runtime guardrails for autonomous AI agents. Loop detection, cost limits, and telemetry.
Author-email: SteerPlane <hello@steerplane.com>
License-Expression: MIT
Project-URL: Homepage, https://steerplane.com
Project-URL: Documentation, https://docs.steerplane.com
Project-URL: Repository, https://github.com/vijaym2k6/SteerPlane
Project-URL: Issues, https://github.com/vijaym2k6/SteerPlane/issues
Keywords: ai,agents,guard,safety,monitoring,telemetry,llm,steerplane
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: requests>=2.28.0
Provides-Extra: cli
Requires-Dist: click>=8.1.0; extra == "cli"
Provides-Extra: yaml
Requires-Dist: pyyaml>=6.0; extra == "yaml"
Provides-Extra: langchain
Requires-Dist: langchain-core>=0.1.0; extra == "langchain"
Provides-Extra: openai-agents
Requires-Dist: openai-agents>=0.24.0; extra == "openai-agents"
Provides-Extra: crewai
Requires-Dist: crewai>=1.15.35; extra == "crewai"
Provides-Extra: autogen
Requires-Dist: ag2[openai]<1,>=0.14.0; extra == "autogen"
Provides-Extra: all
Requires-Dist: click>=8.1.0; extra == "all"
Requires-Dist: pyyaml>=6.0; extra == "all"
Requires-Dist: langchain-core>=0.1.0; extra == "all"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: ruff; extra == "dev"

# SteerPlane SDK

**The safety layer for the AGI era.** Runtime guardrails for autonomous AI agents.

> Cost limits · Loop detection · Policy engine · Human approval callbacks · SSE streaming gateway · CLI · Docker · 4 framework integrations

[![PyPI](https://img.shields.io/pypi/v/steerplane?style=flat-square&color=3B82F6&label=PyPI)](https://pypi.org/project/steerplane/)
[![License](https://img.shields.io/badge/License-MIT-green?style=flat-square)](https://github.com/vijaym2k6/SteerPlane/blob/main/LICENSE)
[![Python](https://img.shields.io/badge/Python-3.10+-blue?style=flat-square&logo=python&logoColor=white)](https://python.org)

## Install

```bash
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 (Zero Code Changes)

Point your existing OpenAI client to SteerPlane. Every LLM call is automatically monitored, rate-limited, and cost-tracked — including SSE streaming with mid-stream cost enforcement.

```python
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-..."}
)

# All calls — including stream=True — are now guarded.
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

```python
from steerplane import guard

@guard(
    agent_name="support_bot",
    max_cost_usd=10.00,
    max_steps=50,
    denied_actions=["DROP TABLE*", "rm -rf *"],
    rate_limits=[{"pattern": "send_email", "max_count": 5, "window_seconds": 60}],
    require_approval=["execute_trade*"]
)
def run_agent():
    agent.run()
```

### Option 3: Context Manager

```python
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.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-mini` uses the `gpt-4o-mini` price.
- **Changes you may notice**: loop detection is off by default in the integrations, CrewAI needs 1.15.35 or newer, and the `autogen` extra now installs `ag2` before 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 `-latest` aliases.
- Fixes ids that were priced as an older model with a similar name: `gemini-pro-latest` was priced
  as the old `gemini-pro` row, `gpt-5.6-cyber` as `gpt-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-06` are priced as their model instead of the
  default rate, and `gpt-4.1` is no longer priced as `gpt-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_loops` now 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()`, `RunManager` and all
  four framework integrations, and in `.steerplane.yml`. Set it to `False` to stop loop detection
  from ending a run; cost, step, runtime and policy limits still apply.
- Self-hosting for several teams: see `docs/hosted-deployment.md` in 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
```bash
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`):
```bash
docker compose up -d
# API (8000) + Dashboard (3000) + PostgreSQL (5432)
```

### 📄 Config File (.steerplane.yml)
Project-level defaults auto-discovered from your working directory:
```yaml
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:**
```python
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:**
```python
from steerplane.integrations import SteerPlaneAgentHooks
hooks = SteerPlaneAgentHooks(agent_name="openai_agent", max_cost_usd=10.0)
result = await hooks.run(agent, "Hello!")
```

**CrewAI:**
```python
from steerplane.integrations import SteerPlaneCrewMonitor
monitor = SteerPlaneCrewMonitor(agent_name="crew_bot", max_cost_usd=15.0)
result = monitor.kickoff(crew)
```

**AutoGen:**
```python
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](https://github.com/vijaym2k6/SteerPlane/blob/main/docs/sdk-usage.md#framework-integrations) 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-compatible proxy. Point your client, get instant monitoring. |
| 🌊 **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 |

## Links

- **GitHub**: [github.com/vijaym2k6/SteerPlane](https://github.com/vijaym2k6/SteerPlane)
- **npm**: [npmjs.com/package/steerplane](https://www.npmjs.com/package/steerplane)
- **Dashboard**: `http://localhost:3000`
- **API Docs**: `http://localhost:8000/docs`

## License

MIT — [Patent Pending](https://github.com/vijaym2k6/SteerPlane)
