Python SDK
Full reference for the nyraxis-sdk Python package.
Python SDK
pip install nyraxis-sdkInitialization
import nyraxis_sdk
nyraxis_sdk.init(
api_key="nyx_...", # Required
base_url="https://api.nyraxis.io", # Default
enforce=True, # Auto-enforce mode
instrument=False, # OpenTelemetry tracing
agent_name="my-agent", # Agent identifier
)| Parameter | Default | Description |
|---|---|---|
api_key | — | Your API key (starts with nyx_) |
base_url | https://api.nyraxis.io | API endpoint (change for self-hosted) |
enforce | False | Enable auto-enforce on OpenAI/Anthropic SDKs |
instrument | False | Enable OpenTelemetry auto-instrumentation |
agent_name | None | Name for this agent in the dashboard |
agent_version | None | Version string for tracking |
Evaluate
result = nyraxis_sdk.evaluate(
input="User message to check",
output=None, # Optional: model output
policies=["pii_detection"], # Optional: specific policies
mode="thorough", # "thorough" or "fast"
)
result.allowed # bool
result.violations # list[Violation]
result.latency_ms # floatViolation object
@dataclass
class Violation:
policy_type: str # e.g. "pii_detection"
severity: str # "low" | "medium" | "high" | "critical"
description: str # Human-readable explanation
details: dict # Provider-specific metadataAuto-Enforce
When enforce=True, the SDK patches supported LLM SDKs so every call is evaluated before reaching the model.
import nyraxis_sdk
import openai
nyraxis_sdk.init(api_key="nyx_...", enforce=True)
client = openai.OpenAI()
try:
client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "malicious input"}],
)
except nyraxis_sdk.NyraxisBlockedError as e:
print(e.violations) # list of violations that triggered the blockEnforce options
| Parameter | Default | Description |
|---|---|---|
enforce_fail_open | True | Pass through if Nyraxis is unreachable |
enforce_timeout_s | 5.0 | HTTP timeout per evaluation |
enforce_cache_ttl_s | 60.0 | Cache identical inputs (0 to disable) |
Supported SDKs
openai(v1+)anthropiclangchain/langchain-openai- Any HTTP-based LLM client (via manual evaluate)
OpenTelemetry Instrumentation
nyraxis_sdk.init(
api_key="nyx_...",
instrument=True,
agent_name="research-agent",
)
# All LLM calls auto-traced — no code changes neededTraces are sent to {base_url}/api/v1/ingest/otel.
Low-level Client
from nyraxis_sdk import NyraxisClient
client = NyraxisClient(api_key="nyx_...", base_url="https://api.nyraxis.io")
result = client.evaluate(input="some text")
client.close()Shutdown
nyraxis_sdk.shutdown()Closes the HTTP client and releases resources. Call this when your application exits.