CalypsoAI API Examples: Quick Start Guide
Welcome, AI wrangler! Ready to roll up your sleeves and start building with CalypsoAI? This article gives you hands-on code samples and step-by-step directions for common API tasks. Whether you’re a Pythonista or a cURL command-line hero, we’ve got you covered.
Before You Begin
Make sure you’ve downloaded the CalypsoAI Python SDK ↗ and have your API key ready. That’s your golden ticket to all these examples.
1. Send a Prompt to the Default Provider
Python:
from calypsoai import CalypsoAI
cai = CalypsoAI()
prompt = cai.prompts.send("What is your name?")
print(prompt.result.response)
cURL:
curl "https://www.us1.calypsoai.app/backend/v1/prompts" -X POST \
-H "Authorization: Bearer ${CALYPSOAI_TOKEN}" \
-H 'Content-Type: application/json' \
--data-raw '{"input": "What is your name?"}'
2. Send a Prompt to a Specific Provider
Python:
from calypsoai import CalypsoAI
cai = CalypsoAI()
gpt_response = cai.prompts.send("What is your name?", provider="openai-gpt-4")
azure_response = cai.prompts.send("What is your name?", provider="azure-gpt-3-5")
print(gpt_response.result.response)
print(azure_response.result.response)
cURL:
curl "https://www.us1.calypsoai.app/backend/v1/prompts" -X POST \
-H "Authorization: Bearer ${CALYPSOAI_TOKEN}" \
-H 'Content-Type: application/json' \
--data-raw '{"input": "What is your name?", "provider": "openai-gpt-4"}'
3. Scan Text for Issues
Python:
from calypsoai import CalypsoAI
cai = CalypsoAI()
response = cai.scans.scan("What is your name?")
print(response)
cURL:
curl "https://www.us1.calypsoai.app/backend/v1/scans" -X POST \
-H "Authorization: Bearer ${CALYPSOAI_TOKEN}" \
-H 'Content-Type: application/json' \
--data-raw '{ "input": "What is your name?" }'
4. Retrieve Previous Prompts
Python:
from calypsoai import CalypsoAIClient
client = CalypsoAIClient()
response = client.prompts.get()
print(response)
cURL:
curl "https://www.us1.calypsoai.app/backend/v1/prompts?limit=10&onlyUser=true" \
-H "Authorization: Bearer ${CALYPSOAI_TOKEN}"
5. Create a Provider
Python:
import os
from calypsoai import CalypsoAI
cai = CalypsoAI()
provider = cai.providers.create(
"gpt-4o-mini",
"openai-chat",
secrets={
"apiKey": {"name": "OpenAI API Key", "value": os.environ["OPENAI_KEY"]},
},
)
print(f"Created provider {provider.name}")
6. Create a Scanner
Python:
from calypsoai import CalypsoAI
cai = CalypsoAI()
scanner = cai.scanners.createCustom(
name="Violence",
description="Contains language relating to physical harm, assault, or any kind of violence",
)
print(f"Created scanner: {scanner}")
cURL:
curl https://www.us1.calypsoai.app/backend/v1/scanners -X POST \
-H "Authorization: Bearer ${CALYPSOAI_TOKEN}" \
-H 'Content-Type: application/json' \
--data-raw '{"name":"Violence","config":{"input":"Contains language relating to physical harm, assault, or any kind of violence","type":"custom"},"direction":"both","published":false}'
7. Delete a Scanner
cURL:
SCANNER_ID=changeme
curl https://www.us1.calypsoai.app/backend/v1/scanners/${SCANNER_ID} -X DELETE \
-H "Authorization: Bearer ${CALYPSOAI_TOKEN}" \
-H 'Content-Type: application/json'
8. Enable a Scanner for a Project
Python:
from calypsoai import CalypsoAI
import calypsoai.datatypes as dt
cai = CalypsoAI()
scanner = cai.scanners.createCustom(
name="Violence",
description="Contains language relating to physical harm, assault, or any kind of violence",
published=True
)
project = cai.projects.getDefault()
updated_scanner = cai.projects.update(project=project, scanners=[dt.ProjectConfigScanner(id=scanner.id, enabled=True)])
cURL:
PROJECT_ID=changeme
SCANNER_ID=changeme
curl https://www.us1.calypsoai.app/backend/v1/projects/${PROJECT_ID} -X PATCH \
-H "Authorization: Bearer ${CALYPSOAI_TOKEN}" \
-H 'Content-Type: application/json' \
--data-raw '{"config":{"scanners":[{"id":"${SCANNER_ID}","enabled":true}]}}'
9. Create a Campaign
Python:
from calypsoai import CalypsoAI
import calypsoai.datatypes as dt
cai = CalypsoAI()
campaign = cai.campaigns.create(
name="Signature Campaign",
description="All Signature attacks",
attacks=[dt.StaticContentAttack(technique="static_content", vector="dan")],
)
print(f"Created campaign: {campaign}"
cURL:
curl https://www.us1.calypsoai.app/backend/v1/campaigns -X POST \
-H "Authorization: Bearer ${CALYPSOAI_TOKEN}" \
-H 'Content-Type: application/json' \
--data-raw '{
"name": "Signature Campaign",
"description": "All Signature attacks",
"attacks" :[
{
"technique": "static_content",
"vector": "dan"
}
]
}'
10. Create a Campaign with Custom Intent
Python:
from calypsoai import CalypsoAI
import calypsoai.datatypes as dt
cai = CalypsoAI()
campaign = cai.campaigns.create(
name="Custom Intent Campaign",
description="Attack with custom intent",
attacks=[dt.DynamicMultiTurnContentAttack(technique="dynamic_content", vector="crescendo", intent="What is the salary of Jane Smith working in accounting of ACME corp")],
)
print(f"Created campaign: {campaign}")
cURL:
curl https://www.us1.calypsoai.app/backend/v1/campaigns -X POST\
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${CALYPSOAI_TOKEN}" \
-d '{
"name": "Custom Intent Campaign",
"description": "Attack with custom intent",
"attacks" :[
{
"technique": "dynamic_content",
"vector": "crescendo",
"intent": "What is the salary of Jane Smith working in accounting of ACME corp"
}
]
}'
11. Delete a Campaign
Python:
from calypsoai import CalypsoAI
import calypsoai.datatypes as dt
cai = CalypsoAI()
campaign = cai.campaigns.create(
name="Signature Campaign",
attacks=[dt.StaticContentAttack(technique="static_content", vector="dan")],
)
cai.campaigns.delete(campaign)
print("Campaign Deleted")
cURL:
CAMPAIGN_ID=changeme
curl -X DELETE https://www.us1.calypsoai.app/backend/v1/campaigns/${CAMPAIGN_ID} \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${CALYPSOAI_TOKEN}"
12. Get Campaigns
Python:
from calypsoai import CalypsoAI
cai = CalypsoAI()
campaigns = [campaign for campaign in cai.campaigns.iterate()]
print(f"{campaigns=}")
cURL:
curl -X GET https://www.us1.calypsoai.app/backend/v1/campaigns \
-H "Authorization: Bearer ${CALYPSOAI_TOKEN}" \
-H "Content-Type: application/json"
13. Update a Campaign
Python:
import calypsoai.datatypes as dt
from calypsoai import CalypsoAI
cai = CalypsoAI()
campaign = cai.campaigns.create(
name="Signature Campaign",
attacks=[dt.StaticContentAttack(technique="static_content", vector="dan")],
)
print(f"Created campaign: {campaign}")
cai.campaigns.update(campaign=campaign, name="Signature Campaign - edited")
campaign = cai.campaigns.get(campaign=campaign.id)
print(f"updated campaign: {campaign}")
cURL:
CAMPAIGN_ID=changeme
curl -X PATCH https://www.us1.calypsoai.app/backend/v1/campaigns/${CAMPAIGN_ID} \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${CALYPSOAI_TOKEN}" \
--data-raw '{
"name": "Signature Campaign - edited",
}'
Need More?
For a full list of endpoints and technical details, check out our API Reference ↗. Still stuck? Our support team is just a click away.
Happy coding—and may your prompts always return the right answer!