Built a Cortex Code Credit Manager on Snowflake to control Cortex Code usage at a per-user level. Most Snowflake Cortex Code setups stop at enabling access. That leaves a real gap — there’s no native control on how much each user spends. This system adds guardrails on Cortex Code usage. ✅ Core capabilities Per-user daily credit limits Automated enforcement Separate limits for: Cortex Code CLI, Cortex Code Snowsight Access is revoked once a user exceeds their daily limit Enforced by removing the CORTEX_ACCESS_ROLE Daily reset Revoked users are automatically restored at midnight Continuous monitoring Tasks run every 15 minutes to: Track usage Enforce limits Sync users Centralized access control Removed default Cortex Code access from PUBLIC, SYSADMIN and similar Introduced a dedicated CORTEX_ACCESS_ROLE Auto-onboarding: New users are automatically added with default limits No manual tracking required 📊 Cost tracking (Snowflake native) Usage is derived directly from: SNOWFLAKE.ACCOUNT_USAGE.CORTEX_CODE_SNOWSIGHT_USAGE_HISTORY SNOWFLAKE.ACCOUNT_USAGE.CORTEX_CODE_CLI_USAGE_HISTORY SNOWFLAKE.ACCOUNT_USAGE.USERS Used for: User-level usage tracking Credit consumption monitoring Interface-level enforcement (CLI vs Snowsight) 📊 Streamlit dashboard (inside Snowflake) Per-user visibility: Spend ($ + credits) Status (Active / Revoked) Admin controls (ACCOUNTADMIN only): Update limits Revoke / restore access Bulk updates Usage analytics: 30-day trends (CLI vs Snowsight) Per-user breakdown ⚠️ Important caveat ACCOUNT_USAGE views have ~2–3 hour latency. So users can temporarily exceed limits before enforcement kicks in. 🧠 Built fully inside Snowflake Tasks Procedures (SQL + JavaScript) ACCOUNT_USAGE views Streamlit No external services. No extra infrastructure. 🔗 GitHub Repo: https://lnkd.in/gPM43DX6 📩 Contact me if you want implementation details or to set this up in your environment. #Snowflake #SnowflakeCortex #CortexCode #DataEngineering #GenAI #SquadronData
Nice work, Marmik. That is valuable for visibility and ROI.
Very useful
Marmik Patel Per-user daily credit limits is now supported out-of-the-box in Snowflake through a couple separate parameters: CORTEX_CODE_CLI_DAILY_EST_CREDIT_LIMIT_PER_USER and CORTEX_CODE_SNOWSIGHT_DAILY_EST_CREDIT_LIMIT_PER_USER Please see https://docs.snowflake.com/en/user-guide/cortex-code/credit-usage-limit