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, then to the project bound to the API token.
environmentNoEnvironment name. Falls back to RHESIS_ENVIRONMENT env var. Default: development

Project ID Resolution

The client resolves project_id in the following order:

  1. Explicit parameter passed to the constructor
  2. RHESIS_PROJECT_ID environment variable
  3. Token introspection - if the API token is scoped to a project, the client automatically resolves the project ID from the token

If a project-scoped token is used and an explicit project_id is also provided, the values must match. A project-scoped token cannot be used to access a different project.

Organization-scoped tokens (without a project boundary) require an explicit project_id via the constructor or environment variable.

What It Does

When you create a RhesisClient, it:

  1. Resolves project scope - Determines the project from explicit config or token introspection
  2. Initializes telemetry - Sets up OpenTelemetry for tracing
  3. Registers as default - Becomes the default client for @endpoint and @observe decorators
  4. 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_DISABLED=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, conversation_id: str = None) -> dict:
    # Automatically traced and registered as endpoint
    return {"output": process(input), "conversation_id": conversation_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