Automate customer onboarding and key management like the prosBuilding a SaaS platform with AI features? Stop manually creating API keys for every customer. AnyAPI’s Provisioning API turns key management into a competitive advantage with automated customer onboarding, usage tracking, and bulletproof security controls.
From manual grunt work to automated excellenceBefore: Manually create keys, copy-paste limits, pray you don’t mess up customer billing.After: Fully automated customer lifecycle management:
🎯 Instant customer onboarding → Keys created in seconds, not hours
key_manager = AnyAPIKeyManager(PROVISIONING_KEY)def complete_customer_onboarding(customer_data): """Handle new customer signup""" try: # Create their API key key_info = key_manager.onboard_customer( customer_data["id"], customer_data["plan"] ) # Store in your database save_customer_key_to_db(customer_data["id"], key_info) # Send welcome email with their key send_welcome_email(customer_data["email"], key_info["api_key"]) # Set up usage monitoring schedule_usage_monitoring(customer_data["id"], key_info["hash"]) return {"success": True, "key_hash": key_info["hash"]} except Exception as e: # Rollback any partial creation print(f"Onboarding failed for {customer_data['id']}: {e}") return {"success": False, "error": str(e)}# Usagenew_signup = { "id": "cust_67890", "email": "founder@startup.com", "plan": "pro"}result = complete_customer_onboarding(new_signup)# Customer is now live with working AI features
def monitor_customer_usage(): """Run this as a scheduled job (hourly/daily)""" customers = get_all_customer_keys_from_db() for customer in customers: usage = key_manager.check_customer_usage(customer["key_hash"]) if usage: # Update your billing system update_customer_usage_in_db(customer["id"], usage) # Handle usage warnings if usage["status"] == "warning": send_usage_warning_email(customer["email"], usage) # Handle overages (if you allow them) if usage["usage_percentage"] > 100: handle_customer_overage(customer["id"], usage) # Upgrade suggestions for high usage if usage["usage_percentage"] > 85 and customer["plan"] != "enterprise": suggest_plan_upgrade(customer["email"], customer["plan"])# Run as cron job# 0 * * * * /usr/bin/python /path/to/monitor_usage.py
def security_audit(): """Run security checks on all keys""" all_keys = key_manager.list_all_keys() security_issues = [] for key in all_keys: # Check for dormant keys if not key.get("last_used"): security_issues.append({ "type": "dormant_key", "key_hash": key["hash"], "created": key["created_at"] }) # Check for keys without limits if not key.get("limit") or key["limit"] == 0: security_issues.append({ "type": "unlimited_key", "key_hash": key["hash"] }) # Check for old keys created = datetime.datetime.fromisoformat(key["created_at"].replace('Z', '+00:00')) if created < datetime.datetime.now() - relativedelta(days=180): security_issues.append({ "type": "stale_key", "key_hash": key["hash"], "age_days": (datetime.datetime.now() - created).days }) if security_issues: send_security_report(security_issues) return security_issues