Back

Snowflake API Essential Guide

Aug 3, 20246 minute read

What type of API does Snowflake provide?

Snowflake primarily offers a REST API for interacting with its services. Here are the key points about Snowflake's API:

REST API

Snowflake provides a SQL REST API that allows you to access and update data in a Snowflake database. This API enables you to:

  • Submit SQL statements for execution
  • Check the status of statement execution
  • Cancel the execution of a statement
  • Perform queries
  • Manage your deployment (e.g., provision users and roles, create tables, etc.)

The SQL REST API supports executing standard queries, as well as most DDL and DML statements.

Key Features

  • Authentication: Uses OAuth or Key Pair authentication methods
  • Request Status: Allows checking request status and retrieving results after a request
  • Stored Procedures: Supports creating stored procedures by specifying them in the request body
  • Transactions: Enables executing SQL in transactions by specifying the start, end, and statements in the transaction

GraphQL Support

While Snowflake's native API is REST-based, there are third-party tools and services that can provide GraphQL functionality on top of Snowflake:

  1. Hasura: Allows you to create GraphQL APIs on top of Snowflake databases. It provides:

    • Instant GraphQL API creation
    • Support for GraphQL read-only queries, relationships, and permissions
    • Nested queries and filtering capabilities
  2. StepZen: Supports connecting to Snowflake databases as a data source for GraphQL APIs.

Best Practices

  1. Use the appropriate authentication method (OAuth or Key Pair) based on your security requirements.
  2. Leverage the SQL REST API for direct interactions with Snowflake when working with SQL queries and database management tasks.
  3. Consider using third-party tools like Hasura or StepZen if you need GraphQL functionality on top of your Snowflake data.
  4. Be aware of any limitations of the SQL API, as some types of statements may not be supported.

In summary, while Snowflake's primary API is REST-based, there are options available to work with Snowflake data using GraphQL if needed. The choice between using the native REST API or a GraphQL layer will depend on your specific use case and requirements.

Does the Snowflake API have webhooks?

Based on the search results provided, it appears that the official Snowflake API does not have native webhook functionality. However, there are ways to integrate webhooks with Snowflake using third-party tools or custom implementations. Here's a summary of the key points:

No Native Webhook Support

The official Snowflake API does not have built-in webhook support. There is no mention of native webhook functionality in the Snowflake documentation.

Integration Methods

While Snowflake doesn't offer native webhook support, there are several methods to integrate webhooks with Snowflake:

  1. Using Third-Party Tools:

    • Platforms like Hevo Data and Estuary Flow offer solutions to integrate webhooks with Snowflake.
    • These tools provide automated data pipelines to sync webhook data to Snowflake in real-time.
  2. Custom Scripts:

    • You can develop custom scripts, for example using Python, to handle webhook data and load it into Snowflake.
  3. Notification Integrations:

    • Snowflake does offer a feature called "Notification Integrations" which allows you to send notifications to external services, including webhooks.
    • This is not the same as receiving webhook data, but rather sending notifications from Snowflake to external webhook endpoints.

Notification Integration Details

For the Notification Integration feature:

  • You can create a webhook integration using the CREATE NOTIFICATION INTEGRATION SQL command.
  • It allows you to specify a webhook URL, headers, and body template.
  • You can include secrets in the webhook configuration using placeholders like SNOWFLAKE_WEBHOOK_SECRET.
  • This feature is primarily for sending notifications from Snowflake to external services, not for receiving webhook data into Snowflake.

Conclusion

While Snowflake doesn't have native webhook support for receiving data, there are workarounds and third-party solutions available. For sending notifications from Snowflake to external webhooks, the Notification Integration feature can be used. If you need to ingest webhook data into Snowflake, you'll likely need to use a third-party tool or develop a custom solution.

Rate Limits and other limitations

Based on the search results provided, here are the key points about API rate limits for the Snowflake API:

Rate Limit Enforcement

  • The Snowflake SQL API does enforce rate limits, but specific numeric limits are not provided in the search results.

  • When rate limits are exceeded, the API returns a 429 "Too Many Requests" error response.

Rate Limit Error Response

When rate limits are hit, the API returns the following:

HTTP/1.1 429 Too many requests
Content-Type: application/json
Content-Length: 69
{
  "code" : "390505",
  "message" : "Too many requests."
}

Handling Rate Limits

  • Applications must reduce the frequency of requests sent to API endpoints when hitting rate limits.

  • Exponentially jittered backoff is recommended for retrying after hitting rate limits.

  • Rate limits can be triggered by too many requests or too many concurrent requests.

Considerations

  • Concurrency limits on the API are determined by the concurrency limits enforced by Snowflake.

  • The specific numeric rate limits are not publicly documented, likely to prevent abuse.

  • Rate limiting is an important security measure to prevent credential compromise and limit potential data exfiltration.

ALTR's Rate Limiting Solution

  • While not native to Snowflake, third-party solutions like ALTR offer more granular rate limiting capabilities:

    • Setting data thresholds for specific user groups/roles
    • Time-based access restrictions
    • Column-level rate limiting
  • This provides an additional layer of security beyond Snowflake's built-in rate limits.

In summary, while Snowflake does enforce API rate limits, the specific limits are not publicly documented. Applications should be prepared to handle 429 errors and implement backoff strategies. For more granular control, third-party solutions can be considered to implement custom rate limiting policies.

Latest API Version

Based on the search results provided, the most recent version of the Snowflake API appears to be:

Version 0.7.0 of the Snowflake Python API, released on March 20, 2024 [2].

Key points to consider:

  1. This is specifically for the Snowflake Python API, which is one implementation of Snowflake's APIs.

  2. The release notes mention updates across the snowflake and snowflake.core packages [2].

  3. There are also ongoing releases for other Snowflake clients and drivers, with the most recent ones listed in the December 2023 release notes [3]. However, these are not necessarily the "API" itself.

  4. The Snowflake SQL API V2 is mentioned [4], but no specific version number is provided.

  5. There is a note about deprecated functionality in the SQL API from version 5.40 [5], but this refers to older versions.

It's important to note that Snowflake has multiple APIs and clients, each potentially on different version schedules. The Python API version 0.7.0 is the most specific and recent version mentioned in the provided search results.

For the most up-to-date information on Snowflake API versions, it's always best to check the official Snowflake documentation or contact Snowflake support directly, as versions can change rapidly.

How to get a Snowflake developer account and API Keys?

To get a developer account for Snowflake and create an API integration, you need to follow these steps:

Sign up for a Snowflake account

  1. Visit the Snowflake website and sign up for a free trial or a paid account.
  2. Complete the registration process, providing necessary details like your name, email, and company information.

Create an API integration

To create an API integration in Snowflake, follow these steps:

  1. Open a Snowflake session, typically using the Snowflake web interface.

  2. Use a role with ACCOUNTADMIN privileges or the CREATE INTEGRATION privilege:

USE ROLE accountadmin;
  1. Create the API integration using the CREATE API INTEGRATION command. The exact syntax will depend on the cloud provider you're using (AWS, Azure, or Google Cloud). Here's a general example:
CREATE OR REPLACE API INTEGRATION my_api_integration API_PROVIDER = <provider> <provider-specific parameters> API_ALLOWED_PREFIXES = ('<allowed_url_prefix>') ENABLED = true;

Key points to consider:

  • The API_PROVIDER parameter depends on your cloud platform (e.g., aws_api_gateway, azure_api_management, or google_api_gateway).
  • You'll need to specify additional parameters based on your chosen cloud provider.
  • The API_ALLOWED_PREFIXES should contain the URL of your API gateway or proxy service.
  • Ensure you have the necessary permissions and roles to create the integration.

Best practices:

  1. Use a descriptive name for your API integration.
  2. Limit the API_ALLOWED_PREFIXES to only the necessary URLs for security.
  3. Keep your API integration credentials and sensitive information secure.
  4. Regularly review and update your API integrations as needed.

Remember that the exact steps and parameters may vary depending on your specific use case and cloud provider. Always refer to the official Snowflake documentation for the most up-to-date and accurate information regarding API integrations for your specific setup.

What can you do with the Snowflake API?

Based on the information provided in the search results, here are the key data models you can interact with using the Snowflake API, along with what is possible for each:

Snowflake Model Registry

  • Provides a centralized repository to manage ML models and related artifacts/metadata
  • Allows securely managing and running predictions over models deployed on Snowflake warehouses
  • Supports models trained on Snowflake or external platforms
  • Enables defining custom versioning schemes, lifecycle stages, and model types
  • Accessible through Python and SQL APIs for inference with CPUs or GPUs
  • Can be used from the Snowsight UI, SQL, or Snowpark ML Python library

Snowflake Feature Store

  • Used to define, manage, store and discover ML features
  • Unifies feature pipelines across Snowflake and external tools
  • Provides a single source of truth for model training and inference
  • Supports automated incremental refresh from batch and streaming data sources
  • Enables backfill and point-in-time correct feature lookup
  • Accessible through a UI in Snowsight or Python APIs

ML Lineage

  • Helps trace end-to-end lineage of features, datasets and models
  • Provides visibility into usage of objects and artifacts across ML lifecycle
  • Enables reproducibility, compliance and observability for ML workflows
  • Will have a graphical UI available in Snowsight

SQL Data Models

  • Can execute standard queries and most DDL/DML statements via the SQL API
  • Allows submitting SQL statements, checking execution status, and canceling execution
  • Supports creating and executing stored procedures
  • Enables executing SQL in transactions

LLM Models

  • Provides access to various LLM models like Snowflake Arctic, Reka Flash, Mixtral, etc.
  • Offers functions for text completion, embedding, question answering, sentiment analysis, summarization, translation
  • Models can be accessed via SQL functions or Python APIs
  • Different models optimized for various enterprise use cases

In summary, the Snowflake API allows interacting with ML model registries, feature stores, lineage tracking, SQL data models, and LLM models - providing comprehensive capabilities for managing and operationalizing machine learning and data workflows.