- Categories:
String & binary functions (AI Functions)
AI_ COMPLETE (Prompt object)¶
Generates a response (completion) for a prompt object. The prompt combines text with one or more FILE objects, which can contain images, documents, audio, or video. The input types you can use depend on the model. For limits by model and input type, see Model limitations and document limits.
Syntax¶
The function can be used with either positional or named argument syntax.
Arguments¶
modelA string specifying the model to be used. For text only inputs, you can use one of the following models:
claude-haiku-4-5claude-haiku-5-5claude-opus-4-5claude-opus-4-6claude-opus-4-7claude-opus-4-8claude-opus-5claude-opus-5-5claude-sonnet-4-5claude-sonnet-4-6claude-sonnet-5claude-sonnet-5-5gemini-3.1-flash-litegemini-3.1-progemini-3.5-flashgemini-3.7-flashgemini-3.8-flashgemini-4-argongemini-4-carbongemini-4-hydrogenglm-5.3grok-4.7llama3.1-8bllama3.3-70bmistral-large3openai-gpt-5openai-gpt-5-miniopenai-gpt-5-nanoopenai-gpt-5.1openai-gpt-5.2openai-gpt-5.4openai-gpt-5.4-miniopenai-gpt-5.4-nanoqwen3-32bqwen3-next-80b-a3bqwen3-vl-235b-a22b
Model availability changes over time. A model in the legacy state can only be used by accounts that used it before its legacy date, and a model past its end-of-life date can’t be used by any account. Run SHOW CORTEX BASE MODELS to see which models are currently available to your account and their lifecycle status.
For image inputs, you can use one of the following models:
claude-haiku-4-5claude-haiku-5-5claude-opus-4-5claude-opus-4-6claude-opus-4-7claude-opus-4-8claude-opus-5claude-opus-5-5claude-sonnet-4-5claude-sonnet-4-6claude-sonnet-5claude-sonnet-5-5gemini-3.1-flash-litegemini-3.1-progemini-3.5-flashgemini-3.7-flashgemini-3.8-flashgemini-4-argongemini-4-carbongemini-4-hydrogenopenai-gpt-5openai-gpt-5-miniopenai-gpt-5-nanoopenai-gpt-5.1openai-gpt-5.2openai-gpt-5.4
For document inputs, you can use one of the following models:
claude-haiku-4-5claude-haiku-5-5claude-opus-4-5claude-opus-4-6claude-opus-4-7claude-opus-4-8claude-opus-5claude-opus-5-5claude-sonnet-4-5claude-sonnet-4-6claude-sonnet-5claude-sonnet-5-5gemini-3.1-flash-litegemini-3.1-progemini-3.5-flashgemini-3.7-flashgemini-3.8-flashgemini-4-argongemini-4-carbongemini-4-hydrogen
For audio inputs, you can use one of the following models:
gemini-3.1-flash-litegemini-3.1-progemini-3.5-flashgemini-3.7-flashgemini-3.8-flashgemini-4-argongemini-4-carbongemini-4-hydrogen
For video inputs, you can use one of the following models:
gemini-3.1-flash-litegemini-3.1-progemini-3.5-flashgemini-3.7-flashgemini-3.8-flashgemini-4-argongemini-4-carbongemini-4-hydrogen
Supported models might have different costs.
promptA prompt object containing text and, optionally, one or more files. Depending on the model, the files can be images, documents, audio, or video. You can combine input types in a single prompt if the model supports each of them.
model_parametersAn object containing zero or more of the following options that affect the model’s hyperparameters. See LLM Settings.
-
temperature: A value from 0 to 1 (inclusive) that controls the randomness of the output of the language model. A higher temperature (for example, 0.7) results in more diverse and random output, while a lower temperature (such as 0.2) makes the output more deterministic and focused.Default: 0
-
top_p: A value from 0 to 1 (inclusive) that controls the randomness and diversity of the language model, generally used as an alternative totemperature. The difference is thattop_prestricts the set of possible tokens that the model outputs, whiletemperatureinfluences which tokens are chosen at each step.Default: 0
-
max_tokens: Sets the maximum number of output tokens in the response. Small values can result in truncated responses.Default: 4096
-
guardrails: Filters potentially unsafe and harmful responses from a language model using Cortex Guard. EitherTRUEorFALSE. The default value isFALSE.
-
Important
If you’re using AI_COMPLETE with a prompt object and a Snowflake-hosted Cortex model, you can’t provide a JSON schema to get a structured output as a response. For the arguments supported by models deployed on Snowpark Container Services, see Syntax.
To get a structured output as the response, use the response_format parameter with AI_COMPLETE (Single string). For more information using structured outputs, see AI_COMPLETE (Structured outputs).
Example¶
Passing multiple images as the input¶
The following example compares two images by passing both as input to the AI_COMPLETE function and asking whether both are pictures of cats:
Batch processing images from a directory or table¶
For batch processing of multiple images, performing the same operation on each, store the image files in the same stage. Apply the AI_COMPLETE function to each row of the table.
Note
The stage must have a directory table to retrieve the paths to its files.
First, create the table by retrieving the image locations from the directory, convert these to FILE objects, and storing the resulting FILE objects in a column in a table. Use SQL like the following:
Then, apply the AI_COMPLETE function to the column containing the FILE objects. The following example classifies each image in the table:
Response:
If you already have a table with paths to the images, you can use the TO_FILE function to construct the FILE objects within the query:
You can also retrieve the images to be processed directly from a stage’s directory, as shown here:
Providing images and prompts in a table¶
To perform a different operation on each image in a table, provide the images and their corresponding prompts in a
table. In the following example, the table contains the stage path of each image in the img_path column and the
prompt in the prompt column.
Usage notes for processing images¶
The following notes apply to Snowflake-hosted Cortex models. For models deployed on Snowpark Container Services, see Usage notes for processing images.
-
To process multiple images, specify a prompt object in the function call that defines a prompt template and the associated image files. You can use the PROMPT function to create this object. The prompt template can contain numbered placeholders ({0}, {1}, etc.) that correspond to the images in the prompt object. Use the TO_FILE function to specify the document files in the prompt object.
-
Image support depends on the model. See the image model list under Arguments. Gemini models listed for audio or video inputs also accept audio or video files in the same prompt; see Usage notes for processing audio and video. Other models accept only text and images.
-
Supported image formats:
.jpg.jpeg.png.gif.webp
The
pixtralandllama4models also support.bmp. -
The maximum image size is 10 MB for most models, and 3.75 MB for
claudemodels.claudemodels do not support images with resolutions above 8000x8000. -
The stage containing the images must have server-side encryption enabled. Client-side encrypted stages are not supported.
-
The function does not support custom network policies.
-
Stage names are case-insensitive; paths are case-sensitive.
Usage notes for processing documents¶
The following notes apply to Snowflake-hosted Cortex models. For models deployed on Snowpark Container Services, see Usage notes for processing documents.
- To process multiple documents, specify a prompt object in the function call that defines a prompt template and the associated document files. You can use the PROMPT function to create this object. The prompt template can contain numbered placeholders ({0}, {1}, etc.) that correspond to the documents in the prompt object. Use the TO_FILE function to specify the document files in the prompt object.
- Document support depends on the model. See the document model list under Arguments. Gemini models listed for audio or video inputs also accept audio or video files in the same prompt; see Usage notes for processing audio and video. Claude models accept only text, images, and documents.
- All models support these formats:
.txt,.md, and.pdf. Claude models also support.txt,.md,.pdf,.doc,.docx,.xls,.xlsx,.csv, and.xhtml. - Claude models have a maximum document size of 22 MB. Gemini models have a maximum document size of 37.5 MB.
- Claude models accept up to 5 documents per prompt. Gemini models accept up to 20 documents per prompt. For context windows and page limits, see Supported models and limitations in AI_COMPLETE with documents.
- The function does not support custom network policies.
- Stage names are case-insensitive; paths are case-sensitive.
Usage notes for processing audio and video¶
The following notes apply to Snowflake-hosted Cortex models.
- Only the Gemini models listed for audio inputs under Arguments accept audio files. Only the Gemini models listed for video inputs accept video files.
- Supported audio formats:
.wav,.mp3,.aiff,.aac,.ogg,.flac,.m4a,.mp4,.pcm, and.webm. - Supported video formats:
.mp4,.mpeg,.mov,.avi,.flv,.mpg,.webm,.wmv, and.3gpp. - A single prompt can include up to 20 image files, 10 audio files, and 10 video files, with a combined size of up to 100 MB. For context windows and other limits, see Model limitations.
- The stage containing the files must have server-side encryption enabled. Client-side encrypted stages are not supported.
- The function does not support custom network policies.
- Stage names are case-insensitive; paths are case-sensitive.
Note
AI_COMPLETE is the updated version of COMPLETE. For the latest functionality, use AI_COMPLETE.
Legal notices¶
Refer to Snowflake AI and ML for legal notices.