Skip to Content
SDKEntitiesEndpoints

Endpoints

Endpoints represent AI services or APIs that tests execute against. They define how Rhesis connects to your application, sends test inputs, and receives responses for evaluation.

For code-first endpoint registration using decorators, see the Connector documentation.

Properties

PropertyTypeDescription
idstrUnique identifier
namestrDisplay name
descriptionstrEndpoint description
connection_typeConnectionTypeHow Rhesis connects: REST, WebSocket, GRPC, or SDK
urlstrEndpoint URL (for REST/WebSocket/GRPC)
project_idstrAssociated project ID

Connection Types

TypeDescription
RESTHTTP API endpoints
WebSocketReal-time WebSocket connections
GRPCgRPC service endpoints
SDKFunctions registered via the Connector decorator

Fetching Endpoints

fetch_endpoints.py
from rhesis.sdk.entities import Endpoints

# List all endpoints
for endpoint in Endpoints.all():
    print(f"{endpoint.name} ({endpoint.connection_type})")

# Get by ID
endpoint = Endpoints.pull(id="endpoint-123")

# Get by name
endpoint = Endpoints.pull(name="Production Chatbot")

Invoking Endpoints

Send test inputs to an endpoint and receive responses:

invoke_endpoint.py
from rhesis.sdk.entities import Endpoints

endpoint = Endpoints.pull(name="Customer Support Bot")

# Single-turn invocation
response = endpoint.invoke(input="What are your business hours?")
print(f"Response: {response['output']}")

# Multi-turn with session
response1 = endpoint.invoke(
    input="I need help with my order",
    session_id="session-abc"
)
response2 = endpoint.invoke(
    input="It was order #12345",
    session_id="session-abc"  # Same session for context
)

Response Structure

The invoke() method returns a standardized response:

response_structure.py
{
    "output": "Response text from the endpoint",
    "session_id": "session-abc",
    "metadata": {...},   # Optional endpoint metadata
    "context": [...]     # Optional context items
}

Testing Endpoint Connectivity

Verify an endpoint is responding correctly:

test_endpoint.py
from rhesis.sdk.entities import Endpoints

endpoint = Endpoints.pull(name="Production Chatbot")

# Quick connectivity test
try:
    endpoint.test()
    print("Endpoint is working correctly")
except ValueError as e:
    print(f"Endpoint not responding: {e}")

Creating Endpoints

Create endpoints programmatically:

create_endpoint.py
from rhesis.sdk.entities import Endpoint
from rhesis.sdk.entities.endpoint import ConnectionType

endpoint = Endpoint(
    name="Staging API",
    description="Staging environment for testing",
    connection_type=ConnectionType.REST,
    url="https://staging-api.example.com/chat",
    project_id="project-123",
)

endpoint.push()
print(f"Created endpoint: {endpoint.id}")

Running Tests Against Endpoints

Execute test sets or individual tests:

run_tests.py
from rhesis.sdk.entities import TestSets, Tests, Endpoints

endpoint = Endpoints.pull(name="Production Chatbot")

# Execute entire test set
test_set = TestSets.pull(name="Safety Evaluation")
result = test_set.execute(endpoint)

# Execute single test
test = Tests.pull(id="test-123")
result = test.execute(endpoint)

SDK-Registered Endpoints

When using the Connector, functions decorated with @endpoint appear as SDK connection type endpoints:

sdk_endpoint.py
from rhesis.sdk import RhesisClient, endpoint

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

@endpoint()
def my_chatbot(input: str, session_id: str = None) -> dict:
    return {"output": process(input), "session_id": session_id}

These endpoints can be fetched and used like any other:

fetch_sdk_endpoint.py
from rhesis.sdk.entities import Endpoints

# SDK endpoints appear with connection_type="SDK"
sdk_endpoints = Endpoints.all(filter="connection_type eq 'SDK'")

for ep in sdk_endpoints:
    print(f"{ep.name}: {ep.connection_type}")

Next Steps - Use the Connector for code-first endpoint registration