Schema:

ACCOUNT_USAGE

CORTEX_CODE_CLI_USAGE_HISTORY view

The CORTEX_CODE_CLI_USAGE_HISTORY view can be used to query the usage history of Cortex Code CLI.

The information in the view includes the number of credits consumed each time a user interacts with Cortex Code CLI. 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 in Snowsight. Requests originating from Cortex Code in Snowsight are recorded in the CORTEX_CODE_SNOWSIGHT_USAGE_HISTORY view.

Columns

Column Name

Data Type

Description

USER_ID

NUMBER

The unique identifier of the user who made the request.

USER_TAGS

ARRAY

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_ID

VARCHAR

The unique identifier for the request.

PARENT_REQUEST_ID

VARCHAR

The identifier of the parent request, if applicable.

USAGE_TIME

TIMESTAMP_TZ

The timestamp when the usage was recorded.

TOKEN_CREDITS

NUMBER

The number of token credits used for the request.

TOKENS

NUMBER

The total number of tokens used for the request.

TOKENS_GRANULAR

OBJECT

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_GRANULAR

OBJECT

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

  • 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.

Examples

Retrieve Cortex Code CLI usage history:

SELECT *
  FROM SNOWFLAKE.ACCOUNT_USAGE.CORTEX_CODE_CLI_USAGE_HISTORY;

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

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