API Reference Overview¶
The Snowflake Cortex Agents SDK provides Python clients for interacting with Snowflake's Cortex Agents and Cortex Analyst APIs.
Main Components¶
Client Classes¶
The SDK provides both synchronous and asynchronous clients:
- CortexAgent - Synchronous client for Cortex Agents API
- AsyncCortexAgent - Asynchronous client for Cortex Agents API
- CortexAnalyst - Synchronous client for Cortex Analyst API
- AsyncCortexAnalyst - Asynchronous client for Cortex Analyst API
Response Classes¶
Response wrappers provide convenient access to API results:
- AgentResponse - Wrapper for agent run responses with streaming support
- AnalystResponse - Wrapper for analyst message responses
- EventType - Enumeration of SSE event types
Core Modules¶
Advanced users can access lower-level components:
- Entity Management - Create, read, update, and delete agents
- Run Management - Execute agent runs
- Thread Management - Manage conversation threads
- Feedback Management - Submit user feedback
Utilities¶
Helper functions and base classes:
- Base Classes - Base agent class and exceptions
- Chart Utilities - Chart plotting helpers
- Utils - Credential loading and validation
Quick Start¶
Cortex Agent¶
from cortex_agents import CortexAgent
# Initialize client
with CortexAgent() as agent:
# Create an agent
agent.create_agent(
name="MY_AGENT",
config={
"instructions": {"system": "You are helpful"},
"models": {"orchestration": "claude-sonnet-4-6"}
},
database="MY_DB",
schema="MY_SCHEMA"
)
# Run the agent
response = agent.run(
"What's the revenue?",
agent_name="MY_AGENT",
database="MY_DB",
schema="MY_SCHEMA"
)
# Access results
print(response.text)
print(response.sql)
Cortex Analyst¶
from cortex_agents import CortexAnalyst
# Initialize client
analyst = CortexAnalyst()
# Generate SQL from natural language
response = analyst.message(
"Which company had the most revenue?",
semantic_model_file="@my_stage/model.yaml"
)
# Access results
print(response.text) # Natural language interpretation
print(response.sql) # Generated SQL query
Key Features¶
- Streaming Support: All run/message methods support SSE streaming for real-time responses
- Context Management: Automatic resource cleanup with context managers
- Thread Management: Multi-turn conversations with thread support
- Feedback Collection: Submit user feedback on agent responses
- Type Hints: Full type annotations for better IDE support
- Async Support: Complete async/await API with AsyncCortexAgent and AsyncCortexAnalyst
Error Handling¶
All API errors raise SnowflakeAPIError:
from cortex_agents import CortexAgent, SnowflakeAPIError
try:
with CortexAgent() as agent:
response = agent.run("test", agent_name="MY_AGENT", database="DB", schema="SCHEMA")
except SnowflakeAPIError as e:
print(f"API Error: {e}")
Authentication¶
The SDK supports two authentication methods:
-
Environment Variables (recommended):
-
Direct Parameters:
Next Steps¶
- See Examples for detailed usage examples
- Read Quick Start for getting started guide
- Explore the Main Classes documentation