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

# How to create an app in Snowpark Container Services

export const maia = "Maia";

<Badge color="green" shape="pill" stroke size="lg">Public preview</Badge>

This page outlines the steps that are required to build a Docker image that can be deployed into Snowpark Container Services and used with {maia} [Snowpark Container Prompt](/docs/components/snowpark-container-prompt) component.

***

## Prerequisites

Review the [Snowflake prerequisites](https://docs.snowflake.com/en/developer-guide/snowpark-container-services/tutorials/common-setup#configure-prerequisites) to confirm you meet the requirements for creating an app.

***

## Instructions

1. You may wish to set up a security integration and make sure that the role you use to set up the Snowpark Container Services app has the `BIND SERVICE ENDPOINT` PERMISSION. For example:

   ```sql theme={null}
   CREATE SECURITY INTEGRATION IF NOT EXISTS snowservices_ingress_oauth
     TYPE=oauth
     OAUTH_CLIENT=snowservices_ingress
     ENABLED=true;
   GRANT BIND SERVICE ENDPOINT ON ACCOUNT TO ROLE test_role;
   ```

2. Create a Snowflake compute pool (if not created). This is the pool of virtual machine nodes on which your service will run.

   ```sql theme={null}
   CREATE COMPUTE POOL tutorial_compute_pool
     MIN_NODES = 1
     MAX_NODES = 1
     INSTANCE_FAMILY = CPU_X64_XS;
   ```

3. Check your compute pool is running:

   ```sql theme={null}
   DESCRIBE COMPUTE POOL tutorial_compute_pool;
   ```

4. Create a Snowflake stage to store your service specification files:

   ```sql theme={null}
   CREATE STAGE IF NOT EXISTS tutorial_stage
     DIRECTORY = ( ENABLE = true );
   ```

5. Create an image repository on your Snowflake account. This is where you push images to, and where Snowflake will pull images from:

   ```sql theme={null}
   CREATE IMAGE REPOSITORY IF NOT EXISTS tutorial_repository
   ```

The Snowpark Container Prompt component generates a [user-defined function (UDF)](https://docs.snowflake.com/en/developer-guide/udf/udf-overview) at runtime with the signature.

`udf(systemPrompt VARCHAR, userPrompt VARCHAR, inputValues VARIANT, metadata VARIANT)`

`inputValues` is a JSON object containing the `{ columnName: columnValue }` of all of your inputs selected in the component. Metadata is also a JSON object, containing any key:value pairs specified in the metadata parameters.

The UDF is invoked by the Snowpark Container Prompt component and translated into JSON, which is what your app will receive. This looks as below:

```json theme={null}
{
    "data": [
                [0, "System Prompt", "User Prompt", {"Input Column Name": "Input Column Value"}, {"metadata key": "metadata value"}]
    ]
}
```

Your service response must look like this:

```json theme={null}
{
    "data": [
      [0, "completion result"]
    ]
}
```

<Note>
  If the Output Format parameter in the Snowpark Container Prompt component is set to JSON, your service must respond with valid JSON, otherwise your output rows will all error.
</Note>

***

## Build and deploy your Docker image

<Note>
  In the code blocks below, `my_service` is an example service name. Replace it with your own service name.
</Note>

1. [Build and push a Docker image](https://docs.snowflake.com/en/developer-guide/snowpark-container-services/tutorials/tutorial-1#build-an-image-and-upload) to the repo:

   ```dockerfile theme={null}
   docker build --rm --platform linux/amd64 -t <repository_url>/my_service_image:latest
   docker login <registry_hostname> -u <username>
   docker push <repository_url>/<image_name>

   e.g docker push myorg-myacct.registry.snowflakecomputing.com/tutorial_db/data_schema/tutorial_repository/my_service_image:latest
   ```

   <Note>
     Your service will be selectable in the [Snowpark Container Prompt](/docs/components/snowpark-container-prompt) component within the `Service` property.
   </Note>

2. Create your Snowpark Container Services service:

   ```dockerfile theme={null}
    CREATE SERVICE my_service
     IN COMPUTE POOL tutorial_compute_pool
     FROM SPECIFICATION $$
       spec:
         containers:
         - name: echo
           image: /tutorial_db/data_schema/tutorial_repository/my_service:latest
           env:
             SERVER_PORT: 8000
           readinessProbe:
             port: 8000
             path: /healthcheck
         endpoints:
         - name: echoendpoint
           port: 8000
           public: true
         $$
      MIN_INSTANCES=1
      MAX_INSTANCES=1;
   ```

   <Note>
     Your endpoint will be selectable in the [Snowpark Container Prompt](/docs/components/snowpark-container-prompt) component within the `Endpoint` property.
   </Note>

3. Check service details:

   ```sql theme={null}
   SELECT SYSTEM$GET_SERVICE_STATUS('my_service');
   ```

   ```
   DESCRIBE SERVICE my_service;
   ```
