Schema:

ORGANIZATION_USAGE

USER_AI_USAGE_HISTORY view

Important

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

This Organization Usage view can be used to query the credits that users consume for AI services across all the accounts in your organization, aggregated by hour.

Each row represents the credits consumed by one user, for one service type and one object, during one hour. The view attributes usage to the user that ran the work, including service users.

The view covers a subset of AI service types. It doesn’t include every service type that is billed as AI usage in the METERING_DAILY_HISTORY view. For the service types that the view covers, see Service types.

See also:

USER_AI_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
USAGE_HOURTIMESTAMP_LTZStart of the hour in which the usage occurred. The value is aligned to the hour.
USER_IDNUMBERInternal identifier of the user that the usage is attributed to. 0 indicates usage that couldn’t be attributed to a user. See Usage notes.
USER_NAMEVARCHARName of the user. Empty when USER_ID is 0.
SERVICE_TYPEVARCHARService type that the usage is billed as. Values correspond to the SERVICE_TYPE column in the METERING_DAILY_HISTORY view.
ENTITY_TYPEVARCHARProduct category of the object that consumed the credits. See Service types.
ENTITY_IDNUMBERInternal identifier of the object that consumed the credits. NULL for service types that aren’t tied to a specific object.
ENTITY_NAMEVARCHARName of the object that consumed the credits. See Service types.
CREDITSNUMBERCredits consumed by the user for the service type and object during the hour. Can be 0. Doesn’t include warehouse credits.

Service types

The view returns the following combinations of SERVICE_TYPE, ENTITY_TYPE, and ENTITY_NAME:

SERVICE_TYPEENTITY_TYPEENTITY_NAME
AI_FUNCTIONSAI FUNCTIONName of the AI Function, such as AI_COMPLETE or AI_EMBED. ENTITY_ID is NULL.
CORTEX_AGENTSCORTEX AGENTName of the Cortex Agent. Use ENTITY_ID to distinguish agents that share a name.
SNOWFLAKE_COWORKSNOWFLAKE INTELLIGENCESNOWFLAKE_INTELLIGENCE_OBJECT_DEFAULT.
SNOWFLAKE_COCO_CLICORTEX CODECORTEX_CODE_CLI. ENTITY_ID is NULL.
SNOWFLAKE_COCO_SNOWSIGHTCORTEX CODECORTEX_CODE_SNOWSIGHT. ENTITY_ID is NULL.
SNOWFLAKE_COCO_DESKTOPCORTEX CODECORTEX_CODE_DESKTOP. ENTITY_ID is NULL.
SNOWFLAKE_COCOCORTEX CODECORTEX_CODE. ENTITY_ID is NULL.
AI_INFERENCEAI GATEWAYSNOWFLAKE. Usage for the AI Gateway only. Usage for the Cortex REST API isn’t included.
CORTEX_TOOLSAI GATEWAYSNOWFLAKE.

Usage notes

  • Latency for the view may be up to 24 hours.
  • The view provides credit usage within the last 365 days (1 year).
  • Usage that Snowflake can’t attribute to a user is returned with USER_ID set to 0 and USER_NAME empty. A task or a dynamic table runs as the system user unless you set EXECUTE AS USER. To attribute that usage to a user, run the task or dynamic table with EXECUTE AS USER.
  • Rows can report 0 credits.
  • The credits in this view reconcile with the CREDITS_BILLED column of the METERING_DAILY_HISTORY view for the service types that the view covers, except AI_INFERENCE. The AI_INFERENCE service type includes AI Gateway usage only, so its credits are lower than the AI_INFERENCE total in METERING_DAILY_HISTORY.
  • Credit rates are listed in the Snowflake Service Consumption Table.

Examples

Retrieve credits consumed by each user in the last 30 days, across all accounts:

SELECT account_name,
       user_name,
       SUM(credits) AS total_credits
  FROM SNOWFLAKE.ORGANIZATION_USAGE.USER_AI_USAGE_HISTORY
  WHERE usage_hour >= DATEADD('day', -30, CURRENT_TIMESTAMP())
    AND user_id > 0
  GROUP BY account_name, user_name
  ORDER BY total_credits DESC;

Retrieve credits consumed by each service type in the last 30 days:

SELECT service_type,
       SUM(credits) AS total_credits
  FROM SNOWFLAKE.ORGANIZATION_USAGE.USER_AI_USAGE_HISTORY
  WHERE usage_hour >= DATEADD('day', -30, CURRENT_TIMESTAMP())
  GROUP BY service_type
  ORDER BY total_credits DESC;