AI function call permissions
This topic describes the ACCESS AI MODEL permission for calling AI functions. The ACCESS AI MODEL permission allows you to call the AI_COMPLETE, AI_EMBED, AI_RERANK, and AI_PROMPT functions.
Prerequisites
To call an AI function, you must have the AI MODEL permission. This is because registering an AI model and endpoint requires the AI MODEL permission. After you register an AI model and endpoint, you can call an AI function. For more information about the AI MODEL permission, see Manage model permissions. For information about how to register and manage an AI model, see Register and manage an AI model.
Syntax
The syntax for granting the ACCESS AI MODEL permission is as follows:
GRANT ACCESS AI MODEL ON *.* TO 'username'@'host';
The syntax for revoking the ACCESS AI MODEL permission is as follows:
REVOKE ACCESS AI MODEL ON *.* FROM 'username'@'host';
Examples
-
Call the
AI_COMPLETEfunction.SELECT AI_COMPLETE("ob_complete","You are a translation master. Please translate the following text into English: {{Hello world.}}, and output only the translation result.") as ans;The following error is returned because the
ACCESS AI MODELpermission is not granted to the current user:ERROR 42501: Access denied; you need (at least one of) the access ai model endpoint privilege(s) for this operation -
Grant the
ACCESS AI MODELpermission to thetest_ai_useruser.GRANT ACCESS AI MODEL ON *.* TO test_ai_user@'%'; -
Verify the permission.
SELECT AI_COMPLETE("ob_complete","You are a translation master. Please translate the following text into English: {{Hello world.}}, and output only the translation result.") as ans;The execution succeeds.
```shell
+----------------+
| ans |
+----------------+
| "Hello world." |
+----------------+
1 row in set