RaiCentral

Docs / Integrations

Python SDK

Client, session and decision reference for rai-control-plane-sdk 0.2.0.

bash
pip install rai-control-plane-sdk

Client

python
from rai_sdk import RAIClient

with RAIClient(
    base_url,
    api_key=runtime_key,          # sent as X-RAI-Agent-Key
    integration_id=integration_id,
    timeout=30.0,
    fail_closed=True,
) as client:
    client.heartbeat()
Client methodPurpose
health()Contract and version information. No credential needed
heartbeat(capability_matrix=None)Register SDK version and capabilities
start_session(...)Returns a Session
get_decision(decision_id)Fetch an earlier decision
get_approval_status(approval_request_id)Poll an approval
report_execution(decision_id, status=...)Report what happened

Sessions

start_session accepts external_session_id, external_conversation_id, principal, channel, metadata, delegation_id and allow_ended_session_reuse. Use a unique external_session_id per AI turn and the conversation ID for grouping; an ended session is not silently reopened.

Session methodPurpose
observe_input(content)Record what the agent received
authorize_action(tool=..., parameters=...)Ask for a decision. Also tool_id, target, amount, currency, idempotency_key, approval_request_id
authorize_data_access(resource=..., fields=...)Authorize and mask data
record_model_call(...)Report usage
complete_metering_span(span_id, ...)Finish a span whose usage arrives later
observe_output(content)Record what the agent produced
end()Close the session

Decisions

A Decision carries decision, allowed, reason_code, human_message, decision_id, approval_request_id and enforcement_receipt_id. Only allowed (decision ALLOW) permits a side effect.

python
decision = session.authorize_action(
    tool="place_order",
    parameters={"amount": 250, "currency": "USD"},
    idempotency_key=order_id,
)
if decision.allowed:
    try:
        reference = place_order()
    except Exception as exc:
        decision.report_execution(client, status="FAILED", error_metadata={"type": type(exc).__name__})
        raise
    decision.report_execution(client, status="SUCCEEDED", external_execution_id=reference)

Errors

python
from rai_sdk import RAIError

try:
    decision = session.authorize_action(tool="place_order", parameters=params)
except RAIError as exc:
    # exc.code, exc.message, exc.retryable, exc.status_code, exc.details
    log.warning("no decision: %s", exc.code)
    return  # fail closed

With fail_closed=True, network errors and timeouts raise RAIError with code RAI_UNAVAILABLE.

There is no async client yet. In asyncio code, run the client with asyncio.to_thread.