Nyraxis AI

Python SDK

Full reference for the nyraxis-sdk Python package.

Python SDK

pip install nyraxis-sdk

Initialization

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
)
ParameterDefaultDescription
api_keyYour API key (starts with nyx_)
base_urlhttps://api.nyraxis.ioAPI endpoint (change for self-hosted)
enforceFalseEnable auto-enforce on OpenAI/Anthropic SDKs
instrumentFalseEnable OpenTelemetry auto-instrumentation
agent_nameNoneName for this agent in the dashboard
agent_versionNoneVersion 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   # float

Violation 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 metadata

Auto-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 block

Enforce options

ParameterDefaultDescription
enforce_fail_openTruePass through if Nyraxis is unreachable
enforce_timeout_s5.0HTTP timeout per evaluation
enforce_cache_ttl_s60.0Cache identical inputs (0 to disable)

Supported SDKs

  • openai (v1+)
  • anthropic
  • langchain / 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 needed

Traces 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.

On this page