Schema:

ORGANIZATION_USAGE

CORTEX_CODE_SNOWSIGHT_USAGE_HISTORY view

Important

This view is only available in the organization account. For more information, see Premium views in the organization account.

The CORTEX_CODE_SNOWSIGHT_USAGE_HISTORY view in the ORGANIZATION_USAGE schema can be used to query the usage history of Cortex Code in Snowsight across all the accounts in your organization.

The information in the view includes the number of credits consumed each time a user interacts with Cortex Code in Snowsight. 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 and request ID.

Note

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

See also:

CORTEX_CODE_SNOWSIGHT_USAGE_HISTORY view (Account Usage)

Columns

Organization-level columns

Column NameData TypeDescription
ORGANIZATION_NAMEVARCHARName of the organization.
ACCOUNT_LOCATORVARCHARSystem-generated identifier for the account.
ACCOUNT_NAMEVARCHARUser-defined identifier for the account.

Additional columns

Column NameData TypeDescription
USER_IDNUMBERThe unique identifier of the user who made the request.
USER_TAGSARRAY

Tags associated with the user. Each object in the array contains the following value pairs:

  • level: The level at which the tag is applied (for example, “ACCOUNT” or “USER”).
  • tag_database: The database where the tag is defined.
  • tag_schema: The schema where the tag is defined.
  • tag_name: The name of the tag.
  • tag_value: The value of the tag.
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 number of token credits used for the request.
TOKENSNUMBERThe total number of tokens used for the request.
TOKENS_GRANULAROBJECT

Granular breakdown of token usage by model. Each key is a model name, and each value is an object containing the following fields:

  • input: Number of input tokens.
  • cache_read_input: Number of cache read input tokens.
  • cache_write_input: Number of cache write input tokens.
  • output: Number of output tokens.
CREDITS_GRANULAROBJECT

Granular breakdown of credit usage by model. Each key is a model name, and each value is an object containing the following fields:

  • input: Credit value for input tokens.
  • cache_read_input: Credit value for cache read input tokens.
  • cache_write_input: Credit value for cache write input tokens.
  • output: Credit value for output tokens.

Usage notes

Examples

Retrieve Cortex Code in Snowsight usage history across all accounts in the organization:

SELECT *
  FROM SNOWFLAKE.ORGANIZATION_USAGE.CORTEX_CODE_SNOWSIGHT_USAGE_HISTORY;

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

SELECT ACCOUNT_NAME,
       SUM(TOKEN_CREDITS) AS TOTAL_CREDITS
  FROM SNOWFLAKE.ORGANIZATION_USAGE.CORTEX_CODE_SNOWSIGHT_USAGE_HISTORY
  WHERE USAGE_TIME >= DATEADD('day', -30, CURRENT_TIMESTAMP())
  GROUP BY ACCOUNT_NAME
  ORDER BY TOTAL_CREDITS DESC;