Nyraxis/ docs
SDK
Developer documentation

Python SDK

Configure evaluation, input enforcement, tracing, and lifecycle in nyraxis-sdk 1.3.2.

Install

Terminal
python -m venv .venv
python -m pip install nyraxis-sdk==1.3.2

Activate the environment using your operating system's standard command before installing. For auto-instrumentation, install "nyraxis-sdk[instrument]==1.3.2". The base package alone does not configure a telemetry exporter.

Set NYRAXIS_API_KEY to an ingest-scoped key and NYRAXIS_BASE_URL to your backend API origin. Keep both SDK and model-provider secrets on the server.

Direct client

evaluate.py
import os
from nyraxis_sdk import NyraxisClient

with NyraxisClient(
    api_key=os.environ["NYRAXIS_API_KEY"],
    base_url=os.environ["NYRAXIS_BASE_URL"],
    agent_name="support-agent",
    timeout=30,
) as client:
    result = client.evaluate(
        input="What are your support hours?",
        capture_mode="metadata",
    )
    complete = (
        result.evaluation_status == "complete"
        and not result.errors
        and result.policies_evaluated > 0
    )
    if not complete:
        raise RuntimeError("Required evaluation did not complete")
    print({"allowed": result.allowed, "trace_id": result.trace_id})

evaluate() returns a decision. Put the branch that stops your model call or output release after this result. A network, access, or malformed-response error raises; the direct client does not silently turn it into an allow.

Evaluation arguments

ArgumentDefaultPurpose
inputRequiredNon-empty text; also required when evaluating output.
outputNoneProposed output to evaluate with the input.
agent_nameClient's configured nameResolves the agent scope.
policiesNoneOptional detector-type selection; normally use configured policies.
mode"thorough""thorough" or "fast"; see depth semantics.
capture_modeNoneMay reduce the organization's capture permission to "metadata".
no_traceFalseSkip evaluation trace recording.

Response fields

The Python dataclass uses the API's snake_case names: allowed, violations, latency_ms, mode, policies_evaluated, trace_id, evaluation_status, errors, policy_versions, and capture_mode.

Each violation has policy_type, severity, description, and details. Do not log raw descriptions or workload content by default. See response interpretation.

Asynchronous evaluation

async_evaluate.py
import asyncio
import os
from nyraxis_sdk import NyraxisClient

async def main():
    async with NyraxisClient(
        api_key=os.environ["NYRAXIS_API_KEY"],
        base_url=os.environ["NYRAXIS_BASE_URL"],
        agent_name="support-agent",
    ) as client:
        result = await client.evaluate_async(
            input="Synthetic support question",
            capture_mode="metadata",
        )
        if (result.evaluation_status != "complete"
                or result.errors or result.policies_evaluated < 1):
            raise RuntimeError("Required evaluation did not complete")
        print({"allowed": result.allowed, "trace_id": result.trace_id})

asyncio.run(main())

Use close() for a synchronous client and await close_async() for asynchronous use, or the context managers above.

Process-wide initialization

nyraxis_sdk.init() configures the module-level client and optional process-wide instrumentation/interception. Initialize once during application startup.

ArgumentDefaultPurpose
api_keyRequiredIssued Nyraxis key.
base_urlhttps://api.nyraxis.ioBackend API origin.
agent_name"nyraxis-agent"Instrumented agent identity.
agent_versionNoneOptional version metadata.
instrumentFalseConfigure supported Traceloop instrumentation; requires the extra.
instrument_capture_contentTrueSet False to request prompt/completion attribute suppression.
enforceFalseEnable supported input interceptors.
enforce_fail_openTrueAllow provider execution on genuine evaluator transport failure.
enforce_require_completeFalseReject allowed decisions with incomplete status or evaluation errors.
enforce_timeout_s5.0Evaluation HTTP timeout in seconds.
enforce_cache_ttl_s60.0Cache repeated input decisions; zero disables caching.

For required checks, explicitly set fail-closed and completion behavior. A cached decision can outlive a policy edit. Enforcement covers exact scope and failures.

Errors

  • NyraxisBlockedError: a supported interceptor rejected the input.
  • GovernanceBlocked: the direct client received HTTP 403; this can be an access denial.
  • InvalidEvaluationResponse: the decision is malformed; never treat it as an allow.
  • NyraxisError: SDK errors, including incomplete required checks and failed instrumentation shutdown acknowledgement.
  • HTTP and network exceptions: preserve the application's failure policy; return a controlled error and avoid logging bodies.

Shutdown

After closing active streams, call nyraxis_sdk.shutdown() for synchronous use or await nyraxis_sdk.shutdown_async() for async use. flush(timeout_millis=30000) requests exporter completion; verify receipt in the backend separately. The SDK does not shut down an application-owned tracer provider.

Continue with tracing or the live LangGraph integration.

On this page