How-To: Encrypt, Execute, and Decrypt in One Step

LatticaAI provides a streamlined way to perform end-to-end query execution in a single command using our SDK. Instead of calling separate functions for encryption, query submission, and decryption, this method allows users to provide an input and receive the decrypted output in one step.

This functionality is available in both Python and TypeScript SDKs.


Prerequisites

Before executing a complete query, ensure that:

  1. A valid User Access Token is available, provided by the AI Provider for a specific model.

  2. An Evaluation Key (EVK) is generated and published to the LatticaAI backend.


Executing a Query in One Command

Use the following code snippet to encrypt the input message. The encryption process takes the User Access Token and the message to be encrypted as parameters:

import torch
import matplotlib.pyplot as plt
from lattica_query.lattica_query_client import QueryClient

# Authenticate
client = QueryClient("user_token_from_lattica_console")

# Generate keys and upload the evaluation key to the server.
(
    context,
    secret_key,
    client_blocks,
) = client.generate_key()


# Run multiple encrypted queries
image1 = plt.imread('image1.png')
pt1 = torch.Tensor(image1)
result1 = client.run_query(context, secret_key, pt1, client_blocks)

image2 = plt.imread('image2.png')
pt2 = torch.Tensor(image2)
result2 = client.run_query(context, secret_key, pt2, client_blocks)

Last updated

Was this helpful?