AI_COMPLETE
Overview
Generates a completion for a given text string or image using a selected Large Language Model (LLM). This is the primary function for most generative AI tasks in Snowflake.
Syntax
Parameters
model_name (VARCHAR): Name of the LLM model to use (e.g., 'claude-4-sonnet', 'llama3.1-70b', 'mistral-large2')
prompt (VARCHAR or OBJECT): The input text or conversation history
options (OBJECT): Optional parameters like max_tokens, temperature, etc.
Use Cases
Text generation and creative writing
Question answering
Code generation
Data analysis and insights
Conversational AI
Content summarization
Multi-turn conversations
Code Examples
Example 1: Simple Text Completion
Output:
Example 2: Using Claude for SQL Generation
Output:
Example 3: Batch Processing with Table Data
Example 4: Multi-turn Conversation
Data Output Examples
Simple Query Response
Structured Data Generation
Available Models
Model | Context Window | Max Output | Best For |
|---|---|---|---|
claude-4-sonnet | 200,000 | 32,000 | Complex reasoning, long documents |
llama3.1-70b | 128,000 | 8,192 | General purpose, cost-effective |
mistral-large2 | 128,000 | 8,192 | Code generation, multilingual |
llama3.1-8b | 128,000 | 8,192 | Simple tasks, high speed |
deepseek-r1 | 32,768 | 8,192 | Math, code, reasoning |
Limitations & Considerations
Token Limits
Input + Output cannot exceed the model's context window
Example: claude-4-sonnet allows 200K tokens total; if input is 150K, output is limited to 32K (max output) or 50K (remaining context)
Cost
Billing based on input AND output tokens
Costs vary by model (see Snowflake pricing)
Use AI_COUNT_TOKENS to estimate costs before processing
Performance
Use MEDIUM warehouse or smaller
Larger warehouses don't improve performance
Best for batch processing, not real-time
Regional Availability
Available via cross-region inference in most regions. Check availability:
AWS US West/East: ✓
Azure East US: ✓
EU regions: ✓ (most models)
Related Functions
AI_COUNT_TOKENS - Count tokens before processing
PROMPT - Build dynamic prompts
TRY_COMPLETE - Returns NULL on error instead of failing





