Skip to Content
SDKReference & Integration

SDK Reference & Integration Patterns

Comprehensive guide to advanced SDK features, integration patterns, and production-ready workflows for building robust AI testing pipelines.

New to the SDK? Start with Installation & Setup to install the SDK, configure your API key, and learn the fundamentals.

API Client

The API client provides direct interaction with Rhesis platform APIs for programmatic control of projects, endpoints, and test execution:

api_client.py
from rhesis.sdk import RhesisClient

client = RhesisClient(api_key="your-api-key")

# Create a project
project = client.create_project(
  name="My AI Application",
  description="Testing my chatbot"
)

# Create an endpoint
endpoint = client.create_endpoint(
  project_id=project.id,
  name="Production API",
  url="https://api.myapp.com/chat",
  method="POST"
)

# Generate tests
tests = client.generate_tests(
  project_id=project.id,
  description="Customer support scenarios",
  count=100
)

Custom Metrics

Create custom evaluation metrics for your specific use cases:

custom_metric.py
from rhesis.sdk.metrics import CustomMetric

class ToneMetric(CustomMetric):
  def evaluate(self, prompt: str, response: str) -> dict:
      # Your custom evaluation logic
      score = self.analyze_tone(response)
      return {
          "score": score,
          "passed": score >= 0.7,
          "reason": f"Tone analysis score: {score}"
      }

# Use in test execution
metric = ToneMetric(name="professional_tone")
result = client.run_test_with_metrics(
  test_id=class="code-string">"test-123",
  endpoint_id=class="code-string">"endpoint-456",
  metrics=[metric]
)

Batch Operations

Efficiently handle large-scale testing operations:

batch_operations.py
# Batch create tests
tests = client.batch_create_tests([
  {"prompt": "Hello", "behavior": "Greeting"},
  {"prompt": "Goodbye", "behavior": "Farewell"},
  # ... more tests
])

# Batch run tests
results = client.batch_run_tests(
  test_ids=[test.id for test in tests],
  endpoint_id=class="code-string">"endpoint-123"
)

Webhooks and Callbacks

Set up webhooks to receive notifications about test completions:

webhooks.py
# Register a webhook
webhook = client.create_webhook(
  url="https://myapp.com/webhooks/rhesis",
  events=["test_run.completed", "test_run.failed"]
)

# Handle webhook in your application
@app.route('/webhooks/rhesis', methods=['POST'])
def handle_webhook():
  event = request.json
  if event['type'] == 'test_run.completed':
      # Process completed test run
      process_test_results(event['data'])
  return '', 200

Integration Patterns

CI/CD Integration

Integrate Rhesis testing into your continuous integration pipeline:

ci_test.py
# ci_test.py
import os
from rhesis.sdk import RhesisClient

def run_regression_tests():
  client = RhesisClient(api_key=os.getenv('RHESIS_API_KEY'))

  # Run regression test set
  result = client.run_test_set(
      test_set_id="regression-suite",
      endpoint_id="staging-endpoint"
  )

  # Check if tests passed
  if result.pass_rate < 0.95:  class="code-comment"># 95% pass rate threshold
      raise Exception(fclass="code-string">"Tests failed with {result.pass_rate:.1%} pass rate")

  print(fclass="code-string">"✅ All tests passed ({result.pass_rate:.1%})")

if __name__ == "__main__":
  run_regression_tests()

Monitoring Integration

Set up continuous monitoring of your AI application:

monitor.py
import schedule
import time
from rhesis.sdk import RhesisClient

def monitor_production():
  client = RhesisClient()

  # Run health check tests
  result = client.run_test_set(
      test_set_id="health-check",
      endpoint_id="production-endpoint"
  )

  # Alert if quality degrades
  if result.pass_rate < 0.90:
      send_alert(fclass="code-string">"Production quality degraded: {result.pass_rate:.1%}")

# Run every hour
schedule.every().hour.do(monitor_production)

while True:
  schedule.run_pending()
  time.sleep(60)

Next Steps - Learn about Contributing to the SDK - Explore Platform Features that complement SDK usage - Check out the Backend Documentation for API architecture details