Iron SDK - Python SDK for AI agent protection with LLM proxy and safety controls
Project description
Iron Cage
Python SDK for Iron Cage AI agent protection. Provides LlmRouter and Runtime for protecting AI agents with budget tracking, safety controls, and LLM API proxying.
Installation
uv pip install iron-cage
[!IMPORTANT] Requirements: Python 3.9+ (
python --version)
Quick Start
from iron_cage import LlmRouter
from openai import OpenAI
# Use with Iron Cage server
with LlmRouter(api_key="ic_xxx", server_url="https://api.iron-cage.io") as router:
client = OpenAI(base_url=router.base_url, api_key=router.api_key)
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
# Or with direct provider key (for testing)
with LlmRouter(provider_key="sk-xxx", budget=10.0) as router:
client = OpenAI(base_url=router.base_url, api_key=router.api_key)
# ... use client
Architecture
Iron Cage uses a two-crate architecture:
| Crate | Language | Purpose |
|---|---|---|
iron_runtime |
Pure Rust | Core implementation - LlmRouter, AgentRuntime, policies |
iron_sdk (folder) |
Rust + Python | PyO3 bindings exposing iron_runtime to Python |
Package Hierarchy:
What you install: uv pip install iron-cage
What you import: from iron_cage import LlmRouter, Runtime
Internal: iron_runtime (Rust crate, linked at compile time)
Key Features
- LLM Proxy: Local HTTP proxy that intercepts OpenAI/Anthropic API requests
- Budget Control: Set and track spending limits in USD
- Auto-detection: Automatically detects provider from API key format
- Context Manager: Clean resource management with
withstatement - Type Stubs: Full IDE support with
.pyifiles
API Reference
LlmRouter
LlmRouter(
api_key: str = None, # Iron Cage API token
server_url: str = None, # Iron Cage server URL
cache_ttl_seconds: int = 300, # API key cache TTL
budget: float = None, # Budget limit in USD
provider_key: str = None, # Direct provider API key
)
Properties:
base_url- URL for OpenAI client (e.g., "http://127.0.0.1:52431/v1")api_key- API key to use with clientport- Port the proxy is listening onprovider- Detected provider ("openai" or "anthropic")is_running- Whether proxy is runningbudget- Current budget limit in USDbudget_status- Tuple of (spent, limit) in USD
Methods:
total_spent()- Get total spent in USDset_budget(amount_usd)- Set budget limitstop()- Stop the proxy server
Runtime
Runtime(
budget: float, # Budget limit in USD
verbose: bool = False, # Enable verbose logging
)
Properties:
budget- Budget limitverbose- Verbose setting
Methods:
start_agent(script_path)- Start an agentstop_agent(agent_id)- Stop an agentget_metrics(agent_id)- Get agent metrics as JSON
Optional Dependencies
# LangChain integration
uv pip install iron-cage[langchain]
# CrewAI integration
uv pip install iron-cage[crewai]
# All integrations
uv pip install iron-cage[all]
# Examples dependencies
uv pip install iron-cage[examples]
Examples
See examples/ directory for runnable examples:
examples/langchain/- LangChain integration examplesexamples/crewai/- CrewAI integration examplesexamples/raw_api/- Direct API usage examplesexamples/patterns/- Protection pattern examples
Run examples:
python examples/lead_gen_agent.py
Development
# Build the Python package
cd module/iron_sdk
maturin develop
# Run tests
pytest tests/
Documentation
- Specification: See
spec.mdfor complete technical requirements - Examples: See
examples/directory
License
Apache-2.0 - See license file for details
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file iron_cage-0.2.0.tar.gz.
File metadata
- Download URL: iron_cage-0.2.0.tar.gz
- Upload date:
- Size: 170.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0364ac71a0046e130e1a3003fd4ec12e2679f505dcae0eca99bd1a078ca68a1e
|
|
| MD5 |
b6a62bed61a137d852ab8a2f59b82143
|
|
| BLAKE2b-256 |
f22efb3b2b149cce3e55f9d4db616c43478453df3e9ba4087393d751001a1f11
|
File details
Details for the file iron_cage-0.2.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: iron_cage-0.2.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 3.1 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e9bb6b7ccd646ec4724008b1cbea75c1b2a9ec05ec6c439dbc6741627dded2a
|
|
| MD5 |
705d7ef927821eeff663d6034e7a6242
|
|
| BLAKE2b-256 |
3c95a1d7ac2fd0e59113f4a885b5a29448dc0e6b4d7c436cedb6a14ee84b0577
|
File details
Details for the file iron_cage-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: iron_cage-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 6.8 MB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08d46ce57d2c534734b9de909ecea603a9fff8884d47c0de2bb4d740a1cc8a0f
|
|
| MD5 |
56b8120636cb7e8f71f99e038d3aff4f
|
|
| BLAKE2b-256 |
7bc55fbd0ab19d176bcfdbd9c4814b2b056e24fe32f14915a82650d43974596f
|
File details
Details for the file iron_cage-0.2.0-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: iron_cage-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.2 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e793a789cb35d3075f98cc68a9ba769b2d830650a187e0d2cbbc5e087cb0911f
|
|
| MD5 |
a4a412a096f97961acfc488356536a65
|
|
| BLAKE2b-256 |
2141986e864a0adb697faf6e3988d79ff3b98e208dfba5e1b4e2c516d81f28ed
|