> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# Run AI functions from SQL

> Configure an AI Provider, grant access, and test a text or embedding function.

Choose an OpenAI-compatible endpoint and a model that supports your task. Use a `chat` Provider for text generation and other text functions, or an `embedding` Provider for text embeddings.

## 1. Configure and check a Provider

Use [CREATE AI PROVIDER](/documents/4.2/sql-reference/sql-statements/cluster-management/ai_provider/CREATE_AI_PROVIDER.md) to register the endpoint and model. Check the resulting configuration with [DESC AI PROVIDER](/documents/4.2/sql-reference/sql-statements/cluster-management/ai_provider/DESC_AI_PROVIDER.md).

## 2. Grant access to the function and Provider

Give the calling role or user `USAGE` on both the function and the Provider. See [GRANT](/documents/4.2/sql-reference/sql-statements/account-management/GRANT.md) for the two statements. If you want callers to omit the Provider name, set a default for its type with [SET DEFAULT AI PROVIDER](/documents/4.2/sql-reference/sql-statements/cluster-management/ai_provider/SET_DEFAULT_AI_PROVIDER.md).

## 3. Test with one input

As the calling user, pass a short prompt and the name of the chat Provider to [`ai_complete`](/documents/4.2/sql-reference/sql-functions/ai-functions/ai_text_functions#ai_complete). For embeddings, pass a short string and the name of the embedding Provider to [`ai_embed`](/documents/4.2/sql-reference/sql-functions/ai-functions/ai_text_functions#ai_embed). Check the returned text or vector before running the function over table rows.

See [Provider setup and SQL examples](/documents/4.2/sql-reference/sql-functions/ai-functions/ai_functions.md#getting-started) for both Provider types. To index and query the resulting embeddings, follow the [vector search guide](/documents/4.2/vector-search/overview.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.