Install required libraries

Shell
pip install requests python-dotenv tabulate pandas enkryptai-sdk

Setup your development

Sign up for a account on our dashboard and create a API Key.

Export the API Keys as environment variables:

Shell
export OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
export ENKRYPTAI_API_KEY="YOUR_ENKRYPTAI_API_KEY"

Example Usage

Here is an example of how to use the Guardrails API to use all of the available detectors:

import requests
import json
import os

url = "https://api.enkryptai.com/redteam/add-task"

payload = json.dumps({
    "test_name": "Test 1",
    "dataset_name": "standard", // Or your custom dataset name
    "redteam_test_configurations": {
        "bias_test": {
            "sample_percentage": 1,
            "attack_methods": {
                "basic": [
                    "basic"
                ]
            }
        },
        "cbrn_test": {
            "sample_percentage": 1,
            "attack_methods": {
                "basic": [
                    "basic"
                ]
            }
        },
        "harmful_test": {
            "sample_percentage": 1,
            "attack_methods": {
                "basic": [
                    "basic"
                ]
            }
        },
        "insecure_code_test": {
            "sample_percentage": 1,
            "attack_methods": {
                "basic": [
                    "basic"
                ]
            }
        },
        "toxicity_test": {
            "sample_percentage": 1,
            "attack_methods": {
                "basic": [
                    "basic"
                ]
            }
        }
    },
    "target_model_configuration": {
        "testing_for": "LLM",
        "model_name": "gpt-4o",
        "model_type": "text_2_text",
        "system_prompt": "",
        "conversation_template": "",
        "model_source": "https://docs.openai.com",
        "model_provider": "OpenAI",
        "model_endpoint_url": "https://api.openai.com/v1/chat/completions",
        "model_api_key": "OPENAI_API_KEY"
    }
})
headers = {
  'Content-Type': 'application/json'
  'apikey': os.getenv('ENKRYPTAI_API_KEY')
}

response = requests.request("POST", url, headers=headers, data=payload)

formatted_response = json.dumps(json.loads(response.text), indent=4)
print(formatted_response)

Response:

JSON
{
  "task_id": "redteam-job-6c3babbe-3bc4-4553-a0b7-454df720579f",
  "message": "Redteam task has been added successfully",
  "data": {
    ...
  }
}