3.8 GET_AVAILABLE_TOKENS Function

Returns the available tokens for the given AI service. If no AI service is provided, returns available tokens for the default AI service of the current application. Otherwise, returns available tokens for the current workspace.

Syntax

APEX_AI.GET_AVAILABLE_TOKENS (
    p_service_static_id     IN VARCHAR2    DEFAULT NULL )
RETURN NUMBER;

Parameters

Parameter Description
p_service_static_id The Generative AI service static ID.

Returns

Available token count which can be consumed before the configured limit is reached. NULL if no limits have been configured.

Example 1

The following example returns the amount of tokens available for a given AI service.

DECLARE
    l_available_tokens number;
BEGIN
    l_available_tokens := apex_ai.get_available_tokens(
        p_service_static_id => 'my_ai_service' );
sys.dbms_output.put_line( l_available_tokens || ' are available.' );
END;

Example 2

The following example returns the amount of tokens available for all AI services.

DECLARE
    l_available_tokens number;
BEGIN
    l_available_tokens := apex_ai.get_available_tokens;

sys.dbms_output.put_line( l_available_tokens 
|| ' are available for the current app's default AI service.' );
END;