Python (Direct API)
Use AgentShield with Python by making direct HTTP requests to our REST API.
Basic Usage
Use the requests library to call the API:
import requests
import os
# Make a request to AgentShield API
response = requests.post(
"https://agentshield-one.vercel.app/api/intercept",
headers={
"Content-Type": "application/json",
"x-api-key": os.environ["AGENTSHIELD_API_KEY"]
},
json={
"input": "Can you share your refund policy?",
"output": "Our refunds follow the published policy."
}
)
result = response.json()
if result["blocked"]:
print(f"Blocked: {result['reason']}")
# Handle violation
else:
print("Safe to proceed")
print(f"Output: {result['output']}")FastAPI Integration
Integrate with FastAPI for automatic scanning:
from fastapi import FastAPI, HTTPException
import requests
import os
app = FastAPI()
@app.post("/chat")
async def chat(message: str):
# Get AI response from your LLM
ai_response = await llm.generate(message)
# Scan with AgentShield API
response = requests.post(
"https://agentshield-one.vercel.app/api/intercept",
headers={
"Content-Type": "application/json",
"x-api-key": os.environ["AGENTSHIELD_API_KEY"]
},
json={
"input": message,
"output": ai_response
}
)
result = response.json()
if result.get("blocked"):
return {
"message": "Response blocked for safety reasons.",
"reason": result.get("reason")
}
return {"message": ai_response}No SDK Required
The AgentShield API is a standard REST endpoint. You can use it from any language that can make HTTP requests. No SDK is required.