Production-ready examples for The Passport for AI Agents
Add runtime authorization to your AI agents in minutes, not days.
curl "https://api.aport.io/api/verify/ap_a2d10232c6534523812423eec8a1425c"curl -X POST "https://api.aport.io/api/verify/policy/finance.payment.refund.v1" \
-H "Content-Type: application/json" \
-d '{
"context": {
"agent_id": "ap_a2d10232c6534523812423eec8a1425c",
"policy_id": "finance.payment.refund.v1",
"context": {
"amount": 5000,
"currency": "USD",
"customer_id": "cust_123",
"order_id": "order_456",
"reason_code": "customer_request",
"region": "US",
"idempotency_key": "refund_001"
}
}
}'That's it! Policy verification automatically verifies the passport - no separate call needed.
| Example | Language | Description | File |
|---|---|---|---|
| Basic Usage | JavaScript | Complete Node.js client with all API methods | javascript/basic-usage.js |
| Basic Usage | Python | Full-featured Python client class | python/basic_usage.py |
| cURL Examples | Bash | Copy-paste ready API calls | curl/basic-usage.sh |
| MCP Enforcement | JavaScript | Express.js middleware for MCP validation | javascript/mcp-enforcement.js |
| MCP Enforcement | Python | FastAPI middleware for MCP validation | python/mcp_enforcement.py |
| Framework | Pattern | Status | Directory |
|---|---|---|---|
| OpenAI Agents SDK | Decorator | β Production Ready | openai-agents/ |
| Microsoft Agent Framework | Middleware | β Production Ready | microsoft-agent-framework/ |
| Anthropic Claude | Decorator | π Coming Soon | anthropic/ |
| LangChain / LangGraph | Decorator | π Coming Soon | langchain/ |
| Tool | Description | File |
|---|---|---|
| GitHub Actions | Policy verification in CI/CD pipelines | github-actions/aport-verify.yml |
| Tutorial | Description |
|---|---|
| Getting Started | Your first API call and policy verification |
graph LR
A[π€ AI Agent] -->|Decides Action| B[π‘οΈ APort Check]
B -->|β
Allowed| C[β‘ Execute Tool]
B -->|β Denied| D[π« Block Action]
C --> E[β
Success]
D --> F[β Error]
style A fill:#8b5cf6,color:#ffffff
style B fill:#10b981,color:#ffffff
style C fill:#f59e0b,color:#ffffff
style D fill:#ef4444,color:#ffffff
style E fill:#10b981,color:#ffffff
style F fill:#ef4444,color:#ffffff
APort enforces authorization after the agent decides an action but before executing it.
# Install dependencies (if using SDK)
npm install @aporthq/sdk-node
# Run basic examples
node examples/javascript/basic-usage.js
# Run MCP enforcement example
node examples/javascript/mcp-enforcement.js# Install dependencies (if using SDK)
pip install aporthq-sdk-python
# Run basic examples
python examples/python/basic_usage.py
# Run MCP enforcement example
python examples/python/mcp_enforcement.py# Make executable and run
chmod +x examples/curl/basic-usage.sh
./examples/curl/basic-usage.shLocation: examples/openai-agents/
What it does: Pre-action authorization using decorator pattern
Quick example:
from openai_agents import Agent
from aport_examples.openai_agents import with_pre_action_authorization
@with_pre_action_authorization(
policy_id="finance.payment.refund.v1",
extract_context=lambda args, kwargs: {
"amount": kwargs.get("amount"),
"currency": kwargs.get("currency"),
"customer_id": kwargs.get("customer_id"),
}
)
def process_refund(amount, currency, customer_id):
# Your refund logic here
return {"refund_id": "ref_123"}See full examples:
pre_action_authorization.py- Core decoratorcomplete-example.py- Full integrationwith-guardrails-openai.py- Combined with GuardrailsOpenAI
Location: examples/microsoft-agent-framework/
What it does: Pre-action authorization using middleware pattern
Quick example:
from agent_framework import Agent
from aport_examples.microsoft_agent_framework import aport_agent_middleware
agent = Agent(
middleware=[
aport_agent_middleware(
policy_id="finance.payment.refund.v1",
extract_context=lambda context: {
"amount": context.get("amount"),
"currency": context.get("currency"),
}
)
]
)See full examples:
aport_middleware.py- Core middlewaresimple-example.py- Minimal setupcomplete-example.py- Full integration
APort validates MCP servers and tools against passport allowlists.
const decision = await client.verifyPolicy(agentId, "finance.payment.refund.v1", {
amount: 5000,
currency: "USD",
mcp_server: "https://mcp.stripe.com",
mcp_tool: "stripe.refunds.create"
});const decision = await client.verifyPolicy(agentId, "finance.payment.refund.v1", {
amount: 5000,
currency: "USD",
mcp_servers: ["https://mcp.stripe.com", "https://mcp.notion.com"],
mcp_tools: ["stripe.refunds.create", "notion.pages.export"]
});Full examples:
javascript/mcp-enforcement.js- Express.js middlewarepython/mcp_enforcement.py- FastAPI middleware
examples/
βββ README.md β You are here
βββ javascript/
β βββ basic-usage.js β Complete Node.js client
β βββ mcp-enforcement.js β MCP middleware for Express
βββ python/
β βββ basic_usage.py β Complete Python client
β βββ mcp_enforcement.py β MCP middleware for FastAPI
βββ curl/
β βββ basic-usage.sh β Copy-paste API calls
βββ openai-agents/
β βββ README.md β Full documentation
β βββ pre_action_authorization.py β Core decorator
β βββ complete-example.py β Full integration
β βββ with-guardrails-openai.py β Combined with GuardrailsOpenAI
βββ microsoft-agent-framework/
β βββ README.md β Full documentation
β βββ aport_middleware.py β Core middleware
β βββ simple-example.py β Minimal setup
β βββ complete-example.py β Full integration
βββ github-actions/
β βββ aport-verify.yml β CI/CD integration
βββ tutorials/
βββ getting-started.md β Step-by-step guide
- Read
tutorials/getting-started.md - Run a cURL example:
curl/basic-usage.sh
- JavaScript:
javascript/basic-usage.js - Python:
python/basic_usage.py
- OpenAI Agents SDK:
openai-agents/ - Microsoft Agent Framework:
microsoft-agent-framework/
- JavaScript:
javascript/mcp-enforcement.js - Python:
python/mcp_enforcement.py
- GitHub Actions:
github-actions/aport-verify.yml
APort enforces authorization after an agent decides an action but before executing it:
sequenceDiagram
participant User
participant Agent
participant APort
participant Tool
User->>Agent: Request action
Agent->>Agent: Decide to execute tool
Agent->>APort: Verify policy
APort->>APort: Check passport + policy
alt Authorized
APort->>Agent: β
Allow
Agent->>Tool: Execute
Tool->>Agent: Result
Agent->>User: Success
else Denied
APort->>Agent: β Deny
Agent->>User: Error
end
graph TB
A[Agent Request] --> B[Extract Context]
B --> C[Call /api/verify/policy/{pack_id}]
C --> D[APort Verifies Passport]
D --> E[APort Evaluates Policy]
E --> F{Decision}
F -->|β
Allow| G[Execute Action]
F -->|β Deny| H[Return Error]
style A fill:#8b5cf6,color:#ffffff
style C fill:#10b981,color:#ffffff
style D fill:#3b82f6,color:#ffffff
style E fill:#3b82f6,color:#ffffff
style G fill:#10b981,color:#ffffff
style H fill:#ef4444,color:#ffffff
# API Configuration
export APORT_API_BASE_URL="https://api.aport.io"
export APORT_API_KEY="your-api-key"
# For admin operations
export ADMIN_TOKEN="your-admin-token"| Endpoint | Method | Purpose |
|---|---|---|
/api/verify/{agent_id} |
GET | Verify agent passport |
/api/verify/policy/{pack_id} |
POST | Verify policy (auto-verifies passport) |
/api/admin/create |
POST | Create new passport |
/api/admin/update |
POST | Update passport |
decision = await client.verify_policy(
agent_id="ap_my_agent",
policy_id="finance.payment.refund.v1",
context={
"amount": 5000,
"currency": "USD",
"customer_id": "cust_123",
"order_id": "order_456",
"reason_code": "customer_request",
"region": "US",
"idempotency_key": "refund_001"
}
)
if decision.allow:
# Process refund
process_refund(amount, currency, customer_id)
else:
# Handle denial
raise AuthorizationError(decision.reasons)decision = await client.verify_policy(
agent_id="ap_my_agent",
policy_id="data.export.create.v1",
context={
"table_name": "users",
"row_limit": 1000,
"include_pii": False,
"mcp_servers": ["https://mcp.notion.com"],
"mcp_tools": ["notion.pages.export"]
}
)decision = await client.verify_policy(
agent_id="ap_my_agent",
policy_id="code.repository.merge.v1",
context={
"repo": "company/my-repo",
"base_branch": "main",
"files_changed": 5,
"lines_added": 100
}
)All examples include robust error handling:
try:
decision = await client.verify_policy(agent_id, policy_id, context)
if not decision.allow:
# Policy denied
for reason in decision.reasons:
print(f"Denied: {reason.code} - {reason.message}")
except AportError as e:
# API error
print(f"API Error: {e.message}")
except Exception as e:
# Unexpected error
print(f"Error: {e}")Found a bug or want to add an example? We'd love your help!
- Fork the repo
- Create your example in the appropriate directory
- Add documentation (README or inline comments)
- Submit a PR
See CONTRIBUTING.md for guidelines.
- π Full Documentation:
../docs/ - π Report Issues: GitHub Issues
- π¬ Ask Questions: GitHub Discussions
- π Website: aport.io
All examples are provided under the same license as the main project. See ../LICENSE for details.
Made with β€οΈ by the APort team