# Zooming Into Each Step of Demo Run with LatticaAI flow

## Installation & Setup

Before you begin, ensure you have the following:

* **Python 3.10+** installed on your client machine.
* **Install Lattica query package.**

{% tabs %}
{% tab title="🧊 Python SDK" %}

```python
pip install lattica_query
```

{% endtab %}

{% tab title="📦 TypeScript SDK" %}

```typescript
npm install "@Lattica-ai/lattica-query-client"
```

{% endtab %}
{% endtabs %}

***

## Authentication & Model ID

You need an authentication JWT token to interact with our cloud infrastructure. This token validates your requests and ensures secure communication.

Each public model we run on the cloud has its own unique **modelID**. The specific modelID for each demo is provided in its corresponding tutorial.

1. **Request an authentication Token**: Run the code below.&#x20;
2. **Store the Token** securely for subsequent operations.

{% tabs %}
{% tab title="🧊 Python SDK" %}

```python
from lattica_query.auth import get_demo_token

# Use the model ID provided in the specific demo tutorial (e.g., 'imageEnhancement', 'sentimentAnalysis')
model_id = "demoModelId"
my_token = get_demo_token(model_id)
```

{% endtab %}

{% tab title="📦 TypeScript SDK" %}

```typescript
import { getDemoToken } from '@Lattica-ai/lattica-query-client';

// Use the model ID provided in the specific demo tutorial (e.g., 'imageEnhancement', 'sentimentAnalysis')
const modelId = "demoModelId"
const token = await getDemoToken(modelId);
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
In our web demo version, the client logic is initialized automatically in your browser—no separate install or setup is required. The web page manages your authentication and sets the appropriate Model ID behind the scenes.
{% endhint %}

***

## Generating & Registering Keys

We supply a class that handles all the local calculations and communications to the LatticaAI server. Initialize this class using the token you obtained.

{% tabs %}
{% tab title="🧊 Python SDK" %}

```python
from lattica_query.lattica_query_client import QueryClient


client = QueryClient(my_token)
```

{% endtab %}

{% tab title="📦 TypeScript SDK" %}

```typescript
import { LatticaQueryClient } from '@Lattica-ai/lattica-query-client';

const client = new LatticaQueryClient(myToken);
```

{% endtab %}
{% endtabs %}

Our encryption scheme relies on a **secret key** (which stays on your machine) and an **evaluation key (EVK)** (sent to LatticaAI cloud server).

{% hint style="info" %}
One key pair can be reused for multiple demo sessions.
{% endhint %}

{% tabs %}
{% tab title="🧊 Python SDK" %}

```python
context, secret_key, client_blocks, = client.generate_key()
```

{% endtab %}

{% tab title="📦 TypeScript SDK" %}

```typescript
await client.init();
```

{% endtab %}
{% endtabs %}

***

## Process the requested query

You can now encrypt it and send it securely to the cloud for processing.

{% tabs %}
{% tab title="🧊 Python SDK" %}
{% code overflow="wrap" %}

```python
result = client.run_query(context, secret_key, pt, client_blocks)
```

{% endcode %}
{% endtab %}

{% tab title="📦 TypeScript SDK" %}

```typescript
const result = await client.runQuery(pt);
```

{% endtab %}
{% endtabs %}

The **run\_query** method works in 4 steps:

1. Prepares your input using the model's preprocessing rules
2. Takes your secret key to encrypt the data into a secure format
3. Sends your encrypted data to LatticaAI server and waits for the response
4. Decrypts what comes back and turns it into a ready-to-use PyTorch tensor

Here are snippets of the inner implementation of **run\_query** method:

{% tabs %}
{% tab title="🧊 Python SDK" %}
{% code overflow="wrap" %}

```python
import lattica_query.query_toolkit as toolkit_interface


# apply preprocessing on plain text
pt = toolkit_interface.apply_client_block(client_block, context, pt)

# enctypt and get ct (cipher text)
ct = toolkit_interface.enc(context, secret_key, pt, pack_for_transmission=True)

# send to server and recieve enrypted cipher text
ct_res = self.worker_api.apply_hom_pipeline(ct, block_index=client_block.block_index+1)

# decrypt and get result plain text
pt_dec = toolkit_interface.dec(context, secret_key, ct_res)
```

{% endcode %}
{% endtab %}
{% endtabs %}

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://platformdocs.lattica.ai/demo-tutorials/zooming-into-each-step-of-demo-run-with-latticaai-flow.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
