Cut Snowflake Cortex Code Costs with Prompts and Limits

Precise prompts reduce token usage; monitor via ACCOUNT_USAGE tables, set alerts, and enforce per-user daily credit limits like 5 for Snowsight to prevent surprise bills.

Craft Precise Prompts to Slash Token Consumption

Cortex Code (CoCo) bills by tokens from both input prompts and outputs, so vague prompts trigger extra tool calls and higher costs. Bad example: "Help me with my data." Good: "Create staging model for RAW.SALES.ORDERS with not_null on ORDER_ID."

Follow these practices to minimize tokens:

  • Use full table names (e.g., RAW.SALES.ORDERS).
  • Specify exact output format.
  • Keep prompts concise.
  • Include business logic upfront.
  • Reference AGENTS.md for consistent agent behavior.

This approach directly cuts credits since CoCo is serverless and doesn't use warehouses.

Query Usage History and Set Proactive Alerts

Track daily credits, per-user usage, and request counts with these ACCOUNT_USAGE tables (data lags 45 mins to 2 hours):

  • SNOWFLAKE.ACCOUNT_USAGE.CORTEX_CODE_SNOWSIGHT_USAGE_HISTORY
  • SNOWFLAKE.ACCOUNT_USAGE.CORTEX_CODE_CLI_USAGE_HISTORY

Example query for last 30 days:

SELECT
  DATE(u.USAGE_TIME) AS usage_date,
  us.NAME AS user_name,
  ROUND(SUM(u.TOKEN_CREDITS), 4) AS daily_credits,
  SUM(u.TOKENS) AS total_tokens,
  COUNT(*) AS request_count
FROM SNOWFLAKE.ACCOUNT_USAGE.CORTEX_CODE_SNOWSIGHT_USAGE_HISTORY u
LEFT JOIN SNOWFLAKE.ACCOUNT_USAGE.USERS us ON u.USER_ID = us.USER_ID
WHERE u.USAGE_TIME >= DATEADD('day', -30, CURRENT_TIMESTAMP())
GROUP BY DATE(u.USAGE_TIME), us.NAME
ORDER BY usage_date DESC, daily_credits DESC;

For notifications:

  • Activate account budgets: CALL SNOWFLAKE.LOCAL.ACCOUNT_ROOT_BUDGET!ACTIVATE(); then set limits (e.g., 7 credits monthly) and emails.
  • Build custom alerts, like firing if Snowsight exceeds 2 credits in 24 hours via CRON '* * * * * UTC', using SYSTEM$SEND_EMAIL.

Budgets alert but don't hard-stop usage.

Enforce Rolling 24-Hour Credit Limits Per User

Set daily estimated credit limits on a rolling 24-hour window—access blocks when hit until usage drops below:

Account-wide:

ALTER ACCOUNT SET CORTEX_CODE_SNOWSIGHT_DAILY_EST_CREDIT_LIMIT_PER_USER = 5;
ALTER ACCOUNT SET CORTEX_CODE_CLI_DAILY_EST_CREDIT_LIMIT_PER_USER = 10;

Per-user overrides:

ALTER USER power_user SET CORTEX_CODE_SNOWSIGHT_DAILY_EST_CREDIT_LIMIT_PER_USER = 20;
ALTER USER intern_user SET CORTEX_CODE_SNOWSIGHT_DAILY_EST_CREDIT_LIMIT_PER_USER = 0;

Unset with ALTER ACCOUNT UNSET ... or per user. This prevents runaway costs from heavy users.

Work Around Key Limitations

CoCo lacks file uploads (use stages), external API calls (use external functions), background jobs, multi-session memory (use AGENTS.md), full large-context handling, and free tier support. These constraints avoid misuse but require planning to stay efficient without extra credits.

Summarized by x-ai/grok-4.1-fast via openrouter

4776 input / 1640 output tokens in 9737ms

© 2026 Edge