Connector
Register Python functions as testable endpoints in Rhesis using the SDK connector. This code-first approach automatically creates and manages endpoints, providing an alternative to manual endpoint configuration.
@endpoint vs @observe: Tracing-only helpers use @observe; functions Rhesis should invoke from the platform (test runs, connector) use @endpoint. See Observe vs endpoint.
The SDK connects over a WebSocket and keeps registered endpoints in sync with your code as functions are added, changed, or removed.
Quick Start
Initialize the Client
Decorate Functions
Automatic Registration
When your app starts, functions are automatically registered as endpoints. View them in Projects → Your Project → Endpoints.
Running the connector
For a script that only defines endpoints and does not run a web server, call client.connect() at the end of the script. It blocks until the process is interrupted (e.g. Ctrl+C). While the script is running, you can run tests from the Rhesis platform against your registered endpoint(s).
If you already have a running event loop (e.g. in an async REPL or Jupyter), do not call connect(). Run the connector as a task in that loop instead.
Platform context with EndpointContext
Most SDK endpoint functions only need business inputs such as input, files, or
conversation_id. Backend-integrated endpoint functions can also declare an
EndpointContext parameter when they need tenant-scoped platform access during
execution.
EndpointContext is injected by type annotation. It is never accepted from
remote inputs, so callers cannot forge organization_id, user_id, or
project_id through the request payload. The context exposes:
| Attribute or method | Description |
|---|---|
organization_id | Organization associated with the connector execution |
user_id | User associated with the connector execution |
project_id | Active project for this execution, if available |
get_db() | Returns a context-managed database session scoped to the tenant |
When the endpoint runs inside the Rhesis backend, get_db() uses the backend
tenant-aware session factory. If you construct EndpointContext outside the
backend process, pass _db_factory so get_db() can create a scoped session.
SDK-side metrics with @metric
Register custom metric functions through the same connector runtime used by @endpoint.
Metric functions are executed from the backend during evaluation.
Allowed metric function parameters
@metric validates function signatures at registration time.
| Parameter | Required | Description |
|---|---|---|
input | Yes | Input prompt or user message |
output | Yes | Model output to evaluate |
expected_output | No | Ground truth reference output |
context | No | Retrieved context documents used for generation |
The metric function must return a dict containing at least a score key (or a MetricResult instance).
Any unsupported parameter names cause registration-time errors.
Metrics-only connector mode (optional project_id)
If your script only registers SDK metrics with @metric, project_id is optional.
In this mode, the connector still establishes a WebSocket session and registers metrics for backend-side evaluation.
@endpoint registrations still require a project_id. It can come from the constructor, RHESIS_PROJECT_ID
env var, or a project-scoped API token. The optional project_id behavior applies to metrics-only connector usage.
See it in action
This video connects an LLM application with a single @endpoint decorator and runs single- and multi-turn tests against it:
Environment
The environment parameter is required and must be one of:
development: Local iteration and testingstaging: Pre-production validationproduction: Live systems
Production: Changes take effect immediately. Test in development/staging first.
Disabling the Connector
To disable all connector and tracing functionality (useful for CI/CD or testing), set:
Accepted values: true, 1, yes, on (case-insensitive)
When disabled, @endpoint and @observe return functions unmodified, no WebSocket connection is established, and all SDK method calls become no-ops.
Viewing endpoints
Registered endpoints appear under Projects → Your Project → Endpoints with connection type SDK, named {Project Name} ({function_name}), and status Active (connected) or Inactive (disconnected). The SDK reconnects and re-registers functions automatically after a dropped connection; removing a function marks its endpoint Inactive.
When to use the connector
Use the connector when the functions under test live in your codebase and you want a code-first definition. Use manual endpoint configuration for external APIs or services outside your codebase. Always add type hints so parameters and return values serialize correctly (see Advanced Mapping).
Troubleshooting
Functions not appearing as Active:
- Confirm
RhesisClientis initialized withapi_keyandenvironment, and that aproject_idis available (constructor,RHESIS_PROJECT_IDenv var, or a project-scoped token). Metrics-only scripts do not needproject_id. - Confirm functions use the
@endpoint()decorator, then restart the app to re-register. "RhesisClient not initialized"means theRhesisClientinstance must be created before the decorator runs.
Next steps
- Map inputs and outputs to your function’s parameters and return values.
- Inject dependencies like database sessions with
bind. - Attach files to test executions.