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
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.
studio.account.get() -> dict[str, Any]Update account information. Only the fields you pass are sent. A malformed server response raises InvalidResourceResponseError.
studio.account.update(
*,
company_name: str | None = None,
contact_name: str | None = None,
email: str | None = None,
phone_number: str | None = None,
) -> strNone, which leaves the current value unchanged.None, which leaves the current value unchanged.None, which leaves the current value unchanged.None, which leaves the current value unchanged.Finance
studio.finance reads the credit balance and payment history.Return the remaining account credit quota. A malformed server response raises InvalidResourceResponseError.
studio.finance.get_credits() -> strReturn payment transaction history. A malformed server response raises InvalidResourceResponseError.
studio.finance.list_transactions() -> list[dict[str, Any]]Models
studio.models creates, looks up, and updates models.Create a model. A malformed server response raises InvalidResourceResponseError.
studio.models.create(
name: str,
instance_type: InstanceType,
*,
num_devices: int = 1,
) -> str1.Retrieve information about a model. A malformed server response raises InvalidResourceResponseError.
studio.models.get_by_id(model_id: str) -> Model
List models. A malformed server response raises InvalidResourceResponseError.
studio.models.list(*, visibility: str | None = None) -> list[Model]
None, which applies no visibility filter.Return a model with the given name, if one exists. A malformed server response raises InvalidResourceResponseError.
studio.models.find_by_name(name: str) -> Model | None
None.Retrieve a model by its exact name. Raises ResourceNotFoundError when no model has that name. A malformed server response raises InvalidResourceResponseError.
studio.models.get_by_name(name: str) -> Model
Print an easy-to-scan table of models.
studio.models.display(models: Iterable[Model]) -> None
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.
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]None, which leaves the current value unchanged.None, which leaves the current value unchanged.None, which leaves the current value unchanged.None, which leaves the current value unchanged.None, which leaves the current value unchanged.None, which leaves the current value unchanged.None, which leaves the current value unchanged.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.Activate a model. A malformed server response raises InvalidResourceResponseError.
studio.models.activate(model_id: str) -> str
Deactivate a model. A malformed server response raises InvalidResourceResponseError.
studio.models.deactivate(model_id: str) -> str
Update a model's visibility. A malformed server response raises InvalidResourceResponseError.
studio.models.set_visibility(model_id: str, visibility: str) -> dict[str, Any]
Upload a non-homomorphic model file.
studio.models.upload_plain(model_id: str, path: str) -> None
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.
studio.tokens.create(
model_id: str,
*,
name: str | None = None,
save: bool = False,
) -> QueryTokenNone, which generates a random name.False.Load the newest saved query token, optionally restricted by name. A malformed server response raises InvalidResourceResponseError.
studio.tokens.load(name: str | None = None) -> QueryToken
None, which loads the newest saved token of any name.Delete a token. A malformed server response raises InvalidResourceResponseError.
studio.tokens.delete(token_id: str) -> str
Assign a token to a model. A malformed server response raises InvalidResourceResponseError.
studio.tokens.assign(token_id: str, model_id: str) -> dict[str, Any]
None when the server omits it.Unassign a token from a model. A malformed server response raises InvalidResourceResponseError.
studio.tokens.unassign(token_id: str, model_id: str) -> dict[str, Any]
None when the server omits it.Update token information. Only the fields you pass are sent. A malformed server response raises InvalidResourceResponseError.
studio.tokens.update(
token_id: str,
*,
name: str | None = None,
note: str | None = None,
status: str | None = None,
) -> strNone, which leaves the current value unchanged.None, which leaves the current value unchanged.None, which leaves the current value unchanged.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.
studio.tokens.get(token: QueryToken) -> TokenInfo
token.value.List tokens, optionally applying server-side filters. Each filter defaults to None, which omits that filter. A malformed server response raises InvalidResourceResponseError.
studio.tokens.list(
*,
status: str | None = None,
model_id: str | None = None,
issue_date: str | None = None,
) -> list[TokenInfo]None.None.None. The value is sent to the server as issueDate.Print an easy-to-scan table of query tokens.
studio.tokens.display(tokens: Iterable[TokenInfo]) -> None
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.
studio.workers.get(model_id: str, session_id: str) -> Worker
"UP" means the worker is ready.status is "UP".Return active workers for a model. A malformed server response raises InvalidResourceResponseError.
studio.workers.active(model_id: str) -> list[Worker]
"UP" means the worker is ready.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.
studio.workers.stop(
model_id: str | None = None,
session_id: str | None = None,
) -> WorkerNone.None. Pass this together with model_id to stop one session."UP" means the worker is ready.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.
studio.workers.start(
model_id: str,
*,
poll_interval: float = 5,
timeout: float = 600,
) -> Worker5.WorkerStartupTimeoutError. Keyword only. Defaults to 600.is_ready is true. The session id is worker.session_id."UP" means the worker is ready.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.
studio.workers.get_or_start(model_id: str) -> Worker
"UP" means the worker is ready.status is "UP".List worker sessions. Each filter defaults to None, which omits that filter. A malformed server response raises InvalidResourceResponseError.
studio.workers.list_sessions(
*,
model_id: str | None = None,
from_date: str | None = None,
to_date: str | None = None,
) -> list[Worker]None.None. Sent to the server as fromDate.None. Sent to the server as toDate."UP" means the worker is ready.status is "UP".Print an easy-to-scan table of workers.
studio.workers.display(workers: Iterable[Worker]) -> None
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.
studio.workers.running(
model_id: str,
*,
stop_on_exit: bool = False,
) -> WorkerFalse."UP" means the worker is ready.status is "UP".Query client
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.
client.keys.ensure(path: str | Path | None = None) -> QueryKey
None, which uses the default key directory for this token.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.
client.keys.generate(path: str | Path | None = None) -> QueryKey
None, which uses the default key directory for this token. An existing bundle at that path is replaced.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.
client.keys.load(path: str | Path | None = None) -> QueryKey
None, which uses the default key directory for this token.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.
client.query.encrypted(
plaintext: torch.Tensor,
*,
key: QueryKey,
show_timing: bool = False,
) -> torch.Tensorclient.keys. Keyword only. The secret key in this object decrypts the response.False.Run one input on the worker without encryption. A running worker is required.
client.query.clear(plaintext: torch.Tensor) -> torch.Tensor
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.
client.encrypted_data.upload(path: str | Path) -> None
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.
client.close() -> None