API authentication and security
# Setup authentication runagent setup # View current API key runagent config show --key api_key
curl -H "Authorization: Bearer YOUR_API_KEY" \ https://api.run-agent.ai/v1/agents
# Python SDK from runagent import RunAgentClient client = RunAgentClient( agent_id="agent-123", api_key="YOUR_API_KEY" )
export RUNAGENT_API_KEY="YOUR_API_KEY"
# Use environment variables api_key = os.environ["RUNAGENT_API_KEY"] # Or configuration files (gitignored) with open(".secrets/api_key") as f: api_key = f.read().strip()
# Never hardcode keys api_key = "sk-abc123..." # WRONG!
# Generate new key runagent keys create --name "production-2024" # Update your application export RUNAGENT_API_KEY="new-key" # Revoke old key runagent keys revoke "old-key-id"
# Read-only key runagent keys create --scope read --name "monitoring" # Agent-specific key runagent keys create --agent-id agent-123 --name "agent-specific"
import hmac import hashlib import time def sign_request(method, path, body, secret): timestamp = str(int(time.time())) message = f"{method}\n{path}\n{timestamp}\n{body}" signature = hmac.new( secret.encode(), message.encode(), hashlib.sha256 ).hexdigest() return { "X-Signature": signature, "X-Timestamp": timestamp }
# Authorization URL auth_url = "https://auth.run-agent.ai/oauth/authorize" params = { "client_id": "your-client-id", "redirect_uri": "https://yourapp.com/callback", "response_type": "code", "scope": "agents:read agents:write" }
X-RateLimit-Limit: 1000 X-RateLimit-Remaining: 999 X-RateLimit-Reset: 1640995200
# Add IP to whitelist runagent keys update <key-id> --add-ip 192.168.1.1 # List whitelisted IPs runagent keys show <key-id>
# View key usage runagent keys usage <key-id> # Set usage alerts runagent keys alert <key-id> --threshold 80
curl -H "Authorization: Bearer YOUR_API_KEY" \ https://api.run-agent.ai/v1/keys/usage
{ "error": { "code": "INVALID_API_KEY", "message": "The provided API key is invalid", "status": 401 } }
{ "error": { "code": "EXPIRED_API_KEY", "message": "The API key has expired", "status": 401 } }
{ "error": { "code": "RATE_LIMITED", "message": "Too many requests", "status": 429, "retry_after": 3600 } }
ra_