Skip to main content

API Reference

The methods you call on the installed clients. Lattica Studio covers account, finance, models, tokens, and workers. The query client covers keys, queries, and encrypted data. Click any method to expand it.

Lattica Studio​

Create the client with your License: studio = LatticaStudio(license_key). Each call is studio.<group>.<method>. A malformed server response raises InvalidResourceResponseError.

Account​

studio.account reads and updates the account that owns the license key.

Retrieve information about the current account. A missing field is None. A malformed server response raises InvalidResourceResponseError.

Signature
studio.account.get() -> dict[str, Any]
Returns
accountIdstr | None · Account id.
createdAtstr | None · When the account was created.
emailstr | None · Account email.
companyNamestr | None · Company name.
contactNamestr | None · Contact name.
phoneNumberstr | None · Phone number.
creditsstr | None · Account credits.
authExpDatestr | None · License authorization expiry.

Update account information. Only the fields you pass are sent. A malformed server response raises InvalidResourceResponseError.

Signature
studio.account.update(
    *,
    company_name: str | None = None,
    contact_name: str | None = None,
    email: str | None = None,
    phone_number: str | None = None,
) -> str
Parameters
company_nameoptionalstr | None · New company name. Keyword only. Defaults to None, which leaves the current value unchanged.
contact_nameoptionalstr | None · New contact name. Keyword only. Defaults to None, which leaves the current value unchanged.
emailoptionalstr | None · New email. Keyword only. Defaults to None, which leaves the current value unchanged.
phone_numberoptionalstr | None · New phone number. Keyword only. Defaults to None, which leaves the current value unchanged.
Returns
strstr · The server's confirmation message.

Finance​

studio.finance reads the credit balance and payment history.

Return the remaining account credit quota. A malformed server response raises InvalidResourceResponseError.

Signature
studio.finance.get_credits() -> str
Returns
strstr · The remaining credit quota.

Return payment transaction history. A malformed server response raises InvalidResourceResponseError.

Signature
studio.finance.list_transactions() -> list[dict[str, Any]]
Returns
list[dict]list[dict[str, Any]] · One dictionary per payment. The dictionary keys are the payment fields returned by the server. The list is empty when there are no payments.

Models​

studio.models creates, looks up, and updates models.

Create a model. A malformed server response raises InvalidResourceResponseError.

Signature
studio.models.create(
    name: str,
    instance_type: InstanceType,
    *,
    num_devices: int = 1,
) -> str
Parameters
namestr · Model name.
instance_typeInstanceType · Compute instance for the model. One of G4DN_XLARGE, G5_2XLARGE, G6E_2XLARGE, G7E_2XLARGE, G7E_12XLARGE, TPU_MEDIUM, CPU_C7G_XLARGE, CPU_C7G_2XLARGE.
num_devicesoptionalint · Number of devices. Keyword only. Defaults to 1.
Returns
strstr · The new model id.

Retrieve information about a model. A malformed server response raises InvalidResourceResponseError.

Signature
studio.models.get_by_id(model_id: str) -> Model
Parameters
model_idstr · Model id.
Returns
idstr | None · Model id.
namestr | None · Model name.
statusstr | None · Model status.
visibilitystr | None · Model visibility.
instance_typestr | None · Instance type id.
num_devicesint | None · Number of devices.
is_compiledbool | None · Whether compilation finished.
compilation_errorstr | None · Compilation error, when one was reported.
descriptionstr | None · Model description.
auto_restartbool | None · Whether the model restarts automatically.
input_typestr | None · Model input type.
output_typestr | None · Model output type.
required_resourcesdict[str, Any] | None · Resources the model requires.

List models. A malformed server response raises InvalidResourceResponseError.

Signature
studio.models.list(*, visibility: str | None = None) -> list[Model]
Parameters
visibilityoptionalstr | None · When set, only models with this visibility are returned. Keyword only. Defaults to None, which applies no visibility filter.
Returns
list[Model]list[Model] · Each item is a Model. The list is empty when no models match.
idstr | None · Model id.
namestr | None · Model name.
statusstr | None · Model status.
visibilitystr | None · Model visibility.
instance_typestr | None · Instance type id.
num_devicesint | None · Number of devices.
is_compiledbool | None · Whether compilation finished.
compilation_errorstr | None · Compilation error, when one was reported.
descriptionstr | None · Model description.
auto_restartbool | None · Whether the model restarts automatically.
input_typestr | None · Model input type.
output_typestr | None · Model output type.
required_resourcesdict[str, Any] | None · Resources the model requires.

Return a model with the given name, if one exists. A malformed server response raises InvalidResourceResponseError.

Signature
studio.models.find_by_name(name: str) -> Model | None
Parameters
namestr · Exact model name.
Returns
Model | NoneModel | None · A Model when a model with that name exists, otherwise None.
idstr | None · Model id.
namestr | None · Model name.
statusstr | None · Model status.
visibilitystr | None · Model visibility.
instance_typestr | None · Instance type id.
num_devicesint | None · Number of devices.
is_compiledbool | None · Whether compilation finished.
compilation_errorstr | None · Compilation error, when one was reported.
descriptionstr | None · Model description.
auto_restartbool | None · Whether the model restarts automatically.
input_typestr | None · Model input type.
output_typestr | None · Model output type.
required_resourcesdict[str, Any] | None · Resources the model requires.

Retrieve a model by its exact name. Raises ResourceNotFoundError when no model has that name. A malformed server response raises InvalidResourceResponseError.

Signature
studio.models.get_by_name(name: str) -> Model
Parameters
namestr · Exact model name.
Returns
idstr | None · Model id.
namestr | None · Model name.
statusstr | None · Model status.
visibilitystr | None · Model visibility.
instance_typestr | None · Instance type id.
num_devicesint | None · Number of devices.
is_compiledbool | None · Whether compilation finished.
compilation_errorstr | None · Compilation error, when one was reported.
descriptionstr | None · Model description.
auto_restartbool | None · Whether the model restarts automatically.
input_typestr | None · Model input type.
output_typestr | None · Model output type.
required_resourcesdict[str, Any] | None · Resources the model requires.

Print an easy-to-scan table of models.

Signature
studio.models.display(models: Iterable[Model]) -> None
Parameters
modelsIterable[Model] · Models to print. Columns are name, model id, status, compiled, and instance type.
Returns
NoneNone · The table is printed. An empty iterable prints No models found.

Update model configuration. Only the fields you pass are sent. A missing return field is None. A malformed server response raises InvalidResourceResponseError.

Signature
studio.models.update(
    model_id: str,
    *,
    name: str | None = None,
    description: str | None = None,
    visibility: str | None = None,
    auto_restart: bool | None = None,
    input_type: str | None = None,
    output_type: str | None = None,
    status: str | None = None,
    instance_type: InstanceType | None = None,
) -> dict[str, Any]
Parameters
model_idstr · Model to update.
nameoptionalstr | None · New model name. Keyword only. Defaults to None, which leaves the current value unchanged.
descriptionoptionalstr | None · New description. Keyword only. Defaults to None, which leaves the current value unchanged.
visibilityoptionalstr | None · New visibility. Keyword only. Defaults to None, which leaves the current value unchanged.
auto_restartoptionalbool | None · Whether the model restarts automatically. Keyword only. Defaults to None, which leaves the current value unchanged.
input_typeoptionalstr | None · New input type. Keyword only. Defaults to None, which leaves the current value unchanged.
output_typeoptionalstr | None · New output type. Keyword only. Defaults to None, which leaves the current value unchanged.
statusoptionalstr | None · New status. Keyword only. Defaults to None, which leaves the current value unchanged.
instance_typeoptionalInstanceType | None · New instance type. Keyword only. Defaults to None, which leaves the current value unchanged. One of G4DN_XLARGE, G5_2XLARGE, G6E_2XLARGE, G7E_2XLARGE, G7E_12XLARGE, TPU_MEDIUM, CPU_C7G_XLARGE, CPU_C7G_2XLARGE.
Returns
messagestr | None · Server message.
modelIdstr | None · Updated model id.
warningstr | None · Server warning, when one was returned.

Activate a model. A malformed server response raises InvalidResourceResponseError.

Signature
studio.models.activate(model_id: str) -> str
Parameters
model_idstr · Model to activate.
Returns
strstr · The server's confirmation message.

Deactivate a model. A malformed server response raises InvalidResourceResponseError.

Signature
studio.models.deactivate(model_id: str) -> str
Parameters
model_idstr · Model to deactivate.
Returns
strstr · The server's confirmation message.

Update a model's visibility. A malformed server response raises InvalidResourceResponseError.

Signature
studio.models.set_visibility(model_id: str, visibility: str) -> dict[str, Any]
Parameters
model_idstr · Model to update.
visibilitystr · New visibility value.
Returns
messagestr | None · Server message.
modelIdstr | None · Updated model id.
newVisibilitystr | None · Visibility after the update.

Upload a non-homomorphic model file.

Signature
studio.models.upload_plain(model_id: str, path: str) -> None
Parameters
model_idstr · Model that receives the file.
pathstr · Local filesystem path of the file to upload.
Returns
NoneNone · Nothing is returned.

Tokens​

studio.tokens creates and manages query tokens. A QueryToken is the secret credential used by the query client. Most management calls take the token id string (token.identity.id). studio.tokens.get takes a QueryToken.

Create a query token for a model. When name is omitted, a random 10-character name is generated. When save is true, the token is written to local storage so studio.tokens.load can read it later. A malformed server response raises InvalidResourceResponseError.

Signature
studio.tokens.create(
    model_id: str,
    *,
    name: str | None = None,
    save: bool = False,
) -> QueryToken
Parameters
model_idstr · Model the token is created for.
nameoptionalstr | None · Token name. Keyword only. Defaults to None, which generates a random name.
saveoptionalbool · Store the token locally. Keyword only. Defaults to False.
Returns
valuestr · Secret token credential.
identity.idstr · Token id.
identity.namestr | None · Token name.

Load the newest saved query token, optionally restricted by name. A malformed server response raises InvalidResourceResponseError.

Signature
studio.tokens.load(name: str | None = None) -> QueryToken
Parameters
nameoptionalstr | None · When set, load the newest saved token with this name. Defaults to None, which loads the newest saved token of any name.
Returns
valuestr · Secret token credential.
identity.idstr · Token id.
identity.namestr | None · Token name.

Delete a token. A malformed server response raises InvalidResourceResponseError.

Signature
studio.tokens.delete(token_id: str) -> str
Parameters
token_idstr · Id of the token to delete.
Returns
strstr · The server's confirmation message.

Assign a token to a model. A malformed server response raises InvalidResourceResponseError.

Signature
studio.tokens.assign(token_id: str, model_id: str) -> dict[str, Any]
Parameters
token_idstr · Id of the token to assign.
model_idstr · Model that receives the token.
Returns
messagestr | None · Server message.
warningstr | None · Server warning. None when the server omits it.

Unassign a token from a model. A malformed server response raises InvalidResourceResponseError.

Signature
studio.tokens.unassign(token_id: str, model_id: str) -> dict[str, Any]
Parameters
token_idstr · Id of the token to unassign.
model_idstr · Model the token is removed from.
Returns
messagestr | None · Server message.
warningstr | None · Server warning. None when the server omits it.

Update token information. Only the fields you pass are sent. A malformed server response raises InvalidResourceResponseError.

Signature
studio.tokens.update(
    token_id: str,
    *,
    name: str | None = None,
    note: str | None = None,
    status: str | None = None,
) -> str
Parameters
token_idstr · Id of the token to update.
nameoptionalstr | None · New token name. Keyword only. Defaults to None, which leaves the current value unchanged.
noteoptionalstr | None · New note. Keyword only. Defaults to None, which leaves the current value unchanged.
statusoptionalstr | None · New status. Keyword only. Defaults to None, which leaves the current value unchanged.
Returns
strstr · The server's confirmation message.

Return information associated with a token. The call sends token.value. Fields such as model_name and worker_status are filled from the token, model, worker, and evaluation-key records returned for this credential. A malformed server response raises InvalidResourceResponseError.

Signature
studio.tokens.get(token: QueryToken) -> TokenInfo
Parameters
tokenQueryToken · Query token whose server-side record to read. The call sends token.value.
Returns
idstr | None · Token id.
namestr | None · Token name.
statusstr | None · Token status.
expirationstr | None · Expiration time.
model_idstr | None · Id of the assigned model.
model_namestr | None · Name of the assigned model.
model_statusstr | None · Status of the assigned model.
worker_statusstr | None · Status of the model's worker.
evaluation_key_created_atstr | None · When the evaluation key was created.

List tokens, optionally applying server-side filters. Each filter defaults to None, which omits that filter. A malformed server response raises InvalidResourceResponseError.

Signature
studio.tokens.list(
    *,
    status: str | None = None,
    model_id: str | None = None,
    issue_date: str | None = None,
) -> list[TokenInfo]
Parameters
statusoptionalstr | None · When set, only tokens with this status are returned. Keyword only. Defaults to None.
model_idoptionalstr | None · When set, only tokens for this model are returned. Keyword only. Defaults to None.
issue_dateoptionalstr | None · When set, only tokens issued on this date are returned. Keyword only. Defaults to None. The value is sent to the server as issueDate.
Returns
list[TokenInfo]list[TokenInfo] · Each item is a TokenInfo.
idstr | None · Token id.
namestr | None · Token name.
statusstr | None · Token status.
expirationstr | None · Expiration time.
model_idstr | None · Id of the assigned model.
model_namestr | None · Name of the assigned model.
model_statusstr | None · Status of the assigned model.
worker_statusstr | None · Status of the model's worker.
evaluation_key_created_atstr | None · When the evaluation key was created.

Print an easy-to-scan table of query tokens.

Signature
studio.tokens.display(tokens: Iterable[TokenInfo]) -> None
Parameters
tokensIterable[TokenInfo] · Tokens to print. Columns are name, token id, status, model, and expiration.
Returns
NoneNone · The table is printed. An empty iterable prints No tokens found.

Workers​

studio.workers starts, inspects, and stops worker sessions. A running worker serves encrypted queries. The worker keeps running, and runtime is billed, until you stop it.

Return the current status of a worker. A malformed server response raises InvalidResourceResponseError.

Signature
studio.workers.get(model_id: str, session_id: str) -> Worker
Parameters
model_idstr · Model that owns the session.
session_idstr · Worker session to read.
Returns
session_idstr | None · Worker session id.
model_idstr | None · Model this session belongs to.
statusstr | None · Current worker status. "UP" means the worker is ready.
started_atstr | None · When the session started.
stopped_atstr | None · When the session stopped.
is_readybool · True when status is "UP".

Return active workers for a model. A malformed server response raises InvalidResourceResponseError.

Signature
studio.workers.active(model_id: str) -> list[Worker]
Parameters
model_idstr · Model whose active workers to list.
Returns
list[Worker]list[Worker] · Each item is a Worker.
session_idstr | None · Worker session id.
model_idstr | None · Model this session belongs to.
statusstr | None · Current worker status. "UP" means the worker is ready.
started_atstr | None · When the session started.
stopped_atstr | None · When the session stopped.
is_readybool · True when status is "UP".

Stop a worker session. If only model_id is provided, the backend may stop all workers associated with that model. Pass session_id together with model_id to stop one session. A malformed server response raises InvalidResourceResponseError.

Signature
studio.workers.stop(
    model_id: str | None = None,
    session_id: str | None = None,
) -> Worker
Parameters
model_idoptionalstr | None · Model whose worker or workers to stop. Defaults to None.
session_idoptionalstr | None · Session to stop. Defaults to None. Pass this together with model_id to stop one session.
Returns
session_idstr | None · Worker session id.
model_idstr | None · Model this session belongs to.
statusstr | None · Current worker status. "UP" means the worker is ready.
started_atstr | None · When the session started.
stopped_atstr | None · When the session stopped.
is_readybool · True when status is "UP".

Start a worker and wait until it becomes ready (status is "UP"). The call polls every poll_interval seconds. If the worker is still not ready after timeout seconds, it raises WorkerStartupTimeoutError. A malformed server response raises InvalidResourceResponseError.

Signature
studio.workers.start(
    model_id: str,
    *,
    poll_interval: float = 5,
    timeout: float = 600,
) -> Worker
Parameters
model_idstr · Model to start a worker for.
poll_intervaloptionalfloat · Seconds between status checks. Keyword only. Defaults to 5.
timeoutoptionalfloat · Seconds to wait before raising WorkerStartupTimeoutError. Keyword only. Defaults to 600.
Returns
WorkerWorker · A ready worker. is_ready is true. The session id is worker.session_id.
session_idstr | None · Worker session id.
model_idstr | None · Model this session belongs to.
statusstr | None · Current worker status. "UP" means the worker is ready.
started_atstr | None · When the session started.
stopped_atstr | None · When the session stopped.
is_readybool · True when status is "UP".

Return an existing ready worker. Non-ready active workers are stopped before a new worker is started. A malformed server response raises InvalidResourceResponseError.

Signature
studio.workers.get_or_start(model_id: str) -> Worker
Parameters
model_idstr · Model that needs a ready worker.
Returns
WorkerWorker · Either an already ready worker, or a newly started ready worker.
session_idstr | None · Worker session id.
model_idstr | None · Model this session belongs to.
statusstr | None · Current worker status. "UP" means the worker is ready.
started_atstr | None · When the session started.
stopped_atstr | None · When the session stopped.
is_readybool · True when status is "UP".

List worker sessions. Each filter defaults to None, which omits that filter. A malformed server response raises InvalidResourceResponseError.

Signature
studio.workers.list_sessions(
    *,
    model_id: str | None = None,
    from_date: str | None = None,
    to_date: str | None = None,
) -> list[Worker]
Parameters
model_idoptionalstr | None · When set, only sessions for this model are returned. Keyword only. Defaults to None.
from_dateoptionalstr | None · Lower bound of the session time range. Keyword only. Defaults to None. Sent to the server as fromDate.
to_dateoptionalstr | None · Upper bound of the session time range. Keyword only. Defaults to None. Sent to the server as toDate.
Returns
list[Worker]list[Worker] · Each item is a Worker.
session_idstr | None · Worker session id.
model_idstr | None · Model this session belongs to.
statusstr | None · Current worker status. "UP" means the worker is ready.
started_atstr | None · When the session started.
stopped_atstr | None · When the session stopped.
is_readybool · True when status is "UP".

Print an easy-to-scan table of workers.

Signature
studio.workers.display(workers: Iterable[Worker]) -> None
Parameters
workersIterable[Worker] · Workers to print. Columns are worker session, model id, status, and started time.
Returns
NoneNone · The table is printed. An empty iterable prints No workers found.

Context manager that ensures a ready worker for the duration of a with block. It reuses a ready worker when one exists, and starts one otherwise. When stop_on_exit is true and the worker has a session id, that session is stopped when the block exits, including when the block raises. When stop_on_exit is false, the worker is left running. The object bound by with is a Worker.

Signature
studio.workers.running(
    model_id: str,
    *,
    stop_on_exit: bool = False,
) -> Worker
Parameters
model_idstr · Model that needs a ready worker inside the block.
stop_on_exitoptionalbool · Stop the worker session when the block exits. Keyword only. Defaults to False.
Returns
session_idstr | None · Worker session id.
model_idstr | None · Model this session belongs to.
statusstr | None · Current worker status. "UP" means the worker is ready.
started_atstr | None · When the session started.
stopped_atstr | None · When the session stopped.
is_readybool · True when status is "UP".

Query client​

Create the client with a QueryToken and use it as a context manager: with QueryClient(token) as client. The token comes from studio.tokens.create or studio.tokens.load. Each call is client.<group>.<method>. A running worker is required to generate keys, run queries, and upload encrypted data. client.keys.load, and client.keys.ensure when a key is already registered, read the local key bundle and do not contact the worker.

Keys​

client.keys generates a secret key and an evaluation key on this machine, saves both locally, and uploads only the evaluation key. The default key directory is $LATTICA_HOME/keys/<encoded-token-id>, or ~/.lattica/keys/<encoded-token-id> when LATTICA_HOME is unset.

Load an existing key, or generate one when none is stored. If a previous upload of the evaluation key was interrupted, this call finishes that upload. When a complete local bundle is already marked as uploaded, the call returns that key and does not contact the server. Raises KeyTokenMismatchError when the bundle at path belongs to a different token.

Signature
client.keys.ensure(path: str | Path | None = None) -> QueryKey
Parameters
pathoptionalstr | Path | None · Directory of the local key bundle. Defaults to None, which uses the default key directory for this token.
Returns
contextbytes · Encryption context used to encrypt and decrypt.
secret_keybytes · Secret key. It stays on this machine.
client_modelbytes · Client-side preprocess and postprocess model.

Generate a new secret key and evaluation key, replacing any local bundle at the destination. The evaluation key is uploaded. The secret key remains in the local bundle and in the returned QueryKey. Generating a key fetches initialization data from the worker, so a worker must be reachable.

Signature
client.keys.generate(path: str | Path | None = None) -> QueryKey
Parameters
pathoptionalstr | Path | None · Directory where the new bundle is written. Defaults to None, which uses the default key directory for this token. An existing bundle at that path is replaced.
Returns
contextbytes · Encryption context used to encrypt and decrypt.
secret_keybytes · Secret key. It stays on this machine.
client_modelbytes · Client-side preprocess and postprocess model.

Load a local key. This call does not contact the server and does not upload the evaluation key. Raises FileNotFoundError when no bundle is stored at path. Raises KeyTokenMismatchError when the bundle belongs to a different token.

Signature
client.keys.load(path: str | Path | None = None) -> QueryKey
Parameters
pathoptionalstr | Path | None · Directory of the local key bundle. Defaults to None, which uses the default key directory for this token.
Returns
contextbytes · Encryption context used to encrypt and decrypt.
secret_keybytes · Secret key. It stays on this machine.
client_modelbytes · Client-side preprocess and postprocess model.

Queries​

client.query runs a model on a worker. encrypted keeps the input and the result encrypted while they are on the server. clear sends the tensor without encryption. A running worker is required.

Encrypt one input, run it on the worker, and decrypt the response. A running worker is required. On this client the call preprocesses the tensor with the client model, encrypts it with the secret key, sends the ciphertext to the worker, decrypts the worker response with the secret key, and postprocesses the plaintext. The secret key is not sent to the worker.

Signature
client.query.encrypted(
    plaintext: torch.Tensor,
    *,
    key: QueryKey,
    show_timing: bool = False,
) -> torch.Tensor
Parameters
plaintexttorch.Tensor · Clear input tensor. Its shape must match the deployed model.
keyQueryKey · Local key from client.keys. Keyword only. The secret key in this object decrypts the response.
show_timingoptionalbool · Print client and server timing after the query. Keyword only. Defaults to False.
Returns
torch.Tensortorch.Tensor · The decrypted model output.

Run one input on the worker without encryption. A running worker is required.

Signature
client.query.clear(plaintext: torch.Tensor) -> torch.Tensor
Parameters
plaintexttorch.Tensor · Clear input tensor. Its shape must match the deployed model.
Returns
torch.Tensortorch.Tensor · The model output.

Encrypted data​

client.encrypted_data uploads a prepared encrypted-data file for the pipeline. This is separate from encrypting the query input inside client.query.encrypted.

Upload an encrypted-data file and ask the worker to load it. A running worker is required. This call is separate from encrypting the query input inside client.query.encrypted.

Signature
client.encrypted_data.upload(path: str | Path) -> None
Parameters
pathstr | Path · Local filesystem path of the encrypted-data file.
Returns
NoneNone · The file is uploaded, then the worker loads it.

Client​

client.close releases the HTTP connection owned by this client. A with QueryClient(...) block calls it when the block exits.

Release the HTTP connection pool owned by this client. A second call does nothing. Leaving a with QueryClient(...) block calls close.

Signature
client.close() -> None
Returns
NoneNone · The HTTP connection pool is released.