Skip to Content
SDKRhesis Client

RhesisClient

The RhesisClient is the central entry point for the Rhesis SDK. It initializes telemetry, manages the connector for remote testing, and provides access to the Rhesis API.

Initialization

app.py
from rhesis.sdk import RhesisClient

client = RhesisClient(
    api_key="your-api-key",
    project_id="your-project-id",
    environment="development",
)

Parameters

ParameterRequiredDescription
api_keyNoAPI key for authentication. Falls back to RHESIS_API_KEY env var.
base_urlNoAPI base URL. Falls back to RHESIS_BASE_URL env var. Default: https://api.rhesis.ai
project_idNoProject ID for endpoint registration and tracing. Falls back to RHESIS_PROJECT_ID env var.
environmentNoEnvironment name. Falls back to RHESIS_ENVIRONMENT env var. Default: development

What It Does

When you create a RhesisClient, it:

  1. Initializes telemetry - Sets up OpenTelemetry for tracing
  2. Registers as default - Becomes the default client for @endpoint and @observe decorators
  3. Lazy-loads connector - WebSocket connector is initialized only when @endpoint is used

The RhesisClient must be initialized before using @observe or @endpoint decorators. Without it, a RuntimeError is raised.

Environment Variables

Configure the client entirely through environment variables:

terminal
export RHESIS_API_KEY="your-api-key"
export RHESIS_PROJECT_ID="your-project-id"
export RHESIS_ENVIRONMENT="development"
export RHESIS_BASE_URL="https://api.rhesis.ai"  # optional
app.py
from rhesis.sdk import RhesisClient

# All configuration from environment variables
client = RhesisClient()

Environment Values

The environment parameter determines where your endpoints and traces are registered:

ValueUse Case
developmentLocal development and testing
stagingPre-production validation
productionLive systems

Changes in production take effect immediately. Always test in development or staging first.

Disabling the Client

To disable all SDK functionality (useful for CI/CD or testing):

terminal
export RHESIS_CONNECTOR_DISABLE=true

Accepted values: true, 1, yes, on (case-insensitive)

When disabled:

  • @endpoint and @observe decorators return functions unmodified
  • No telemetry initialization occurs
  • No WebSocket connection is established
  • All SDK method calls become no-ops

Usage Patterns

Tracing Only

For observability without remote testing:

app.py
from rhesis.sdk import RhesisClient, observe

client = RhesisClient(
    api_key="your-api-key",
    project_id="your-project-id",
    environment="production",
)

@observe.llm(provider="openai", model="gpt-4")
def generate(prompt: str) -> str:
    return openai.chat.completions.create(...)

Remote Testing

For registering functions as testable endpoints:

app.py
from rhesis.sdk import RhesisClient, endpoint

client = RhesisClient(
    api_key="your-api-key",
    project_id="your-project-id",
    environment="development",
)

@endpoint()
def chat(input: str, session_id: str = None) -> dict:
    # Automatically traced and registered as endpoint
    return {"output": process(input), "session_id": session_id}

Next Steps

  • Connector - Register functions as remote endpoints
  • Tracing - Learn about observability and the @observe decorator
  • Entities - Work with tests, test sets, and projects