Overview

run_session creates a new session with the given init params, runs your function within that context, and then ends the session after the function returns.

Syntax

result = lai.run_session(
  fn: Callable[..., T],
  init_params: Optional[dict] = None,
  *args,
  **kwargs
) -> T

Parameters

  • fn (callable, required): Function to execute within the session.
  • init_params (dict, optional): Parameters to pass to init/session (e.g., session_name, providers).
  • *args, **kwargs: Arguments forwarded to fn.

Returns

Returns whatever fn returns.

Example

import lucidicai as lai

def work(x: int) -> int:
    return x * 2

result = lai.run_session(work, init_params={"session_name": "wrapped", "providers": ["openai"]}, x=5)

See Also