Install the SDK
Requirements
Section titled “Requirements”- Python 3.9 or higher
- pip (or any PEP 517 installer)
Install
Section titled “Install”pip install systemrThe package installs one dependency: httpx for HTTP requests.
Import
Section titled “Import”from systemr import SystemRClientFor error handling:
from systemr import ( SystemRClient, SystemRError, InsufficientBalanceError, AuthenticationError,)Initialize the client
Section titled “Initialize the client”client = SystemRClient(api_key="sr_agent_...")Constructor parameters
Section titled “Constructor parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | Required | Your agent API key (starts with sr_agent_). |
base_url | str | https://agents.systemr.ai | API base URL. Override for local development. |
timeout | float | 30.0 | Request timeout in seconds. |
Custom base URL
Section titled “Custom base URL”For local development or self-hosted deployments:
client = SystemRClient( api_key="sr_agent_...", base_url="http://localhost:8000",)Context manager
Section titled “Context manager”The client supports Python’s context manager protocol for automatic cleanup:
with SystemRClient(api_key="sr_agent_...") as client: result = client.pre_trade_gate( symbol="AAPL", direction="long", entry_price="185.50", stop_price="180.00", equity="100000", ) print(result)# HTTP connection is closed automaticallyOr close manually:
client = SystemRClient(api_key="sr_agent_...")# ... use client ...client.close()Error handling
Section titled “Error handling”from systemr import SystemRClient, InsufficientBalanceError, AuthenticationError, SystemRError
client = SystemRClient(api_key="sr_agent_...")
try: result = client.pre_trade_gate( symbol="AAPL", direction="long", entry_price="185.50", stop_price="180.00", equity="100000", )except AuthenticationError: print("Invalid API key or agent is not active")except InsufficientBalanceError: print("Deposit compute credits to continue")except SystemRError as e: print(f"API error ({e.status_code}): {e.detail}")Error types
Section titled “Error types”| Exception | HTTP Status | Meaning |
|---|---|---|
AuthenticationError | 401 | Invalid or missing API key. |
AuthenticationError | 403 | Agent is suspended or terminated. |
InsufficientBalanceError | 402 | Compute credit balance too low. |
SystemRError | 4xx/5xx | All other API errors. |
Using raw REST calls
Section titled “Using raw REST calls”You do not need the SDK. Any HTTP client works:
import httpx
resp = httpx.post( "https://agents.systemr.ai/v1/tools/call", headers={"X-API-Key": "sr_agent_..."}, json={ "tool_name": "calculate_position_size", "arguments": { "equity": "100000", "entry_price": "185.50", "stop_price": "180.00", "direction": "long", }, },)
print(resp.json())curl -X POST https://agents.systemr.ai/v1/tools/call \ -H "X-API-Key: sr_agent_..." \ -H "Content-Type: application/json" \ -d '{ "tool_name": "calculate_position_size", "arguments": { "equity": "100000", "entry_price": "185.50", "stop_price": "180.00", "direction": "long" } }'Authentication
Section titled “Authentication”Every authenticated request requires the X-API-Key header:
X-API-Key: sr_agent_abc123def456...The SDK handles this automatically. If you use raw HTTP, include the header in every request.
Public endpoints (no auth required):
GET /v1/billing/pricingGET /v1/tools/listGET /v1/guardian/statusGET /v1/broker/supported