CORTEX_CODE_DESKTOP_USAGE_HISTORY view

The CORTEX_CODE_DESKTOP_USAGE_HISTORY view can be used to query the usage history of Cortex Code Desktop.

The information in the view includes the number of credits consumed each time a user interacts with Cortex Code Desktop. Each row in the view represents a single request and provides detail about the aggregated tokens and credits as well as a granular breakdown by model. The view also includes relevant metadata, such as the user ID, user name, user tags, and request ID.

Note

This view does not include requests originating from Cortex Code CLI or Cortex Code in Snowsight. Requests originating from Cortex Code CLI are recorded in the CORTEX_CODE_CLI_USAGE_HISTORY view. Requests originating from Cortex Code in Snowsight are recorded in the CORTEX_CODE_SNOWSIGHT_USAGE_HISTORY view.

Columns

Column NameData TypeDescription
USER_IDNUMBERThe unique identifier of the user who made the request.
USER_NAMEVARCHARThe login name of the user who made the request.
USER_TAGSARRAYTags associated with the user. Each object in the array contains: level (the level at which the tag is applied), tag_database, tag_schema, tag_name, and tag_value.
REQUEST_IDVARCHARThe unique identifier for the request.
PARENT_REQUEST_IDVARCHARThe identifier of the parent request, if applicable.
USAGE_TIMETIMESTAMP_TZThe timestamp when the usage was recorded.
TOKEN_CREDITSNUMBERThe total number of credits consumed for the request.
TOKENSNUMBERThe total number of tokens used for the request.
TOKENS_GRANULAROBJECTGranular breakdown of token usage by model. Each key is a model name, and each value is an object containing: input, cache_read_input, cache_write_input, and output.
CREDITS_GRANULAROBJECTGranular breakdown of credit usage by model. Each key is a model name, and each value is an object containing: input, cache_read_input, cache_write_input, and output.

Usage notes

  • The view provides up-to-date credit usage for an account within the last 365 days (1 year).
  • Credit rate usage is based on the number of tokens processed, as outlined in the Snowflake Service Consumption Table.
  • The USER_TAGS column returns an empty array for usage records that predate the introduction of user tag support.

Examples

Retrieve Cortex Code Desktop usage history:

SELECT *
  FROM SNOWFLAKE.ACCOUNT_USAGE.CORTEX_CODE_DESKTOP_USAGE_HISTORY;

Retrieve total credits consumed per user in the last 30 days:

SELECT USER_ID,
       USER_NAME,
       SUM(TOKEN_CREDITS) AS TOTAL_CREDITS
  FROM SNOWFLAKE.ACCOUNT_USAGE.CORTEX_CODE_DESKTOP_USAGE_HISTORY
  WHERE USAGE_TIME >= DATEADD('day', -30, CURRENT_TIMESTAMP())
  GROUP BY USER_ID, USER_NAME
  ORDER BY TOTAL_CREDITS DESC;

Retrieve usage by model for a specific user in the last 7 days:

SELECT REQUEST_ID,
       USAGE_TIME,
       TOKENS_GRANULAR,
       CREDITS_GRANULAR
  FROM SNOWFLAKE.ACCOUNT_USAGE.CORTEX_CODE_DESKTOP_USAGE_HISTORY
  WHERE USER_NAME = 'my_user'
    AND USAGE_TIME >= DATEADD('day', -7, CURRENT_TIMESTAMP())
  ORDER BY USAGE_TIME DESC;

Filter usage by a specific user tag:

SELECT USER_ID,
       USER_NAME,
       SUM(TOKEN_CREDITS) AS TOTAL_CREDITS
  FROM SNOWFLAKE.ACCOUNT_USAGE.CORTEX_CODE_DESKTOP_USAGE_HISTORY,
       LATERAL FLATTEN(input => USER_TAGS) t
  WHERE t.value:tag_name::STRING = 'department'
    AND t.value:tag_value::STRING = 'engineering'
  GROUP BY USER_ID, USER_NAME
  ORDER BY TOTAL_CREDITS DESC;