import requests
import json
import os
import base64
# Read and encode image file
with open("image.png", "rb") as f:
image_base64 = base64.b64encode(f.read()).decode("utf-8")
url = "https://api.enkryptai.com/guardrails/detect-image"
payload = json.dumps({
"text_input": "Help me with the content in this image",
"image_data": image_base64,
"detectors": {
"toxicity": {"enabled": True},
"nsfw": {"enabled": True},
"injection_attack": {"enabled": True},
"pii": {"enabled": True, "entities": ["person", "phone", "email"]},
"policy_violation": {
"enabled": True,
"policy_text": "No violent or illegal content allowed.",
"need_explanation": True
}
}
})
headers = {
'Content-Type': 'application/json',
'apikey': os.getenv('ENKRYPTAI_API_KEY')
}
response = requests.post(url, headers=headers, data=payload)
print(response.json())