Skip to main content

API Gateway Agent

The API Gateway Agent provides unified API access with authentication, rate limiting, and routing.

πŸ“‹ Overview​

PropertyValue
Modulesrc.agents.integration.api_gateway_agent
ClassAPIGatewayAgent
AuthorUIP Team
Version1.0.0

🎯 Purpose​

  • Unified API endpoint for all platform services
  • Authentication and authorization management
  • Rate limiting per client/endpoint
  • Request routing to appropriate services

πŸš€ Usage​

Initialize Gateway​

from src.agents.integration.api_gateway_agent import APIGatewayAgent

gateway = APIGatewayAgent()

# Start gateway
await gateway.start(port=8080)

Register Routes​

# Register service routes
gateway.register_route(
path="/api/v1/cameras",
service="camera-service",
methods=["GET", "POST"]
)

gateway.register_route(
path="/api/v1/analytics",
service="analytics-service",
methods=["GET"],
rate_limit="100/minute"
)

Authentication​

# Validate request
result = await gateway.authenticate(request)
# {
# "valid": True,
# "user_id": "USER_001",
# "roles": ["viewer", "reporter"],
# "rate_limit_remaining": 95
# }

βš™οΈ Configuration​

# config/api_gateway_config.yaml
api_gateway:
enabled: true
port: 8080

# Authentication
auth:
type: "jwt"
secret: "${JWT_SECRET}"
expiry_hours: 24

# Rate limiting
rate_limiting:
enabled: true
default: "1000/hour"
by_endpoint:
"/api/v1/analytics": "100/minute"
"/api/v1/reports": "50/minute"

# CORS
cors:
allowed_origins: ["*"]
allowed_methods: ["GET", "POST", "PUT", "DELETE"]
allowed_headers: ["Authorization", "Content-Type"]

# Routing
routes:
- path: "/api/v1/cameras"
upstream: "http://camera-service:8001"
- path: "/api/v1/analytics"
upstream: "http://analytics-service:8002"

πŸ“Š Endpoints​

EndpointMethodDescription
/api/v1/camerasGETList cameras
/api/v1/cameras/{id}GETGet camera details
/api/v1/analytics/trafficGETTraffic analytics
/api/v1/reportsPOSTSubmit report
/healthGETHealth check

See the complete agents reference for all available agents.