Overview
Theinit function initializes a new or existing Lucidic session for tracking and monitoring AI agent workflows. It sets up the SDK with your credentials, configures providers, and starts or continues a session.
Syntax
Parameters
The display name for this session. Used for easy identification in the Lucidic dashboard. If not provided, the session will be created without a name.
ID for the session. If not provided, a random ID will be generated and returned by init().
Your Lucidic API key for authentication. If not provided, the SDK will use the
LUCIDIC_API_KEY environment variable.Your agent identifier. If not provided, the SDK will use the
LUCIDIC_AGENT_ID environment variable.A high-level description of the task or workflow being performed in this session.
List of LLM providers to automatically instrument. Supported values:
"openai", "anthropic", "langchain", "pydantic_ai", "openai_agents".Flag to enable production monitoring mode for tracking sessions in production environments. When enabled, sessions appear in the Production Monitoring dashboard with comprehensive metrics on cost, performance, and errors. Can also be set via
LUCIDIC_PRODUCTION_MONITORING environment variable. See Production Monitoring for details.ID of a mass simulation to include this session in. Use with
create_mass_sim().ID of an experiment to include this session in. Experiments must be created in the dashboard first. The experiment ID can be found in the experiment URL.
ID of a dataset item being tested in this session. Links the session to a specific test case from a dataset. Use when running dataset tests to track which test case each session corresponds to. See Working with Datasets for details.
List of evaluation criteria for this session. Used for automated evaluation workflows.
List of tags to categorize and filter sessions in the dashboard.
Custom function to mask sensitive data before sending to Lucidic. Function should accept text and return masked text.
Automatically end the session when the process exits. Ensures data is not lost on unexpected termination.
Returns
Returns the session ID as a string.Authentication
Setting up Credentials
You need to provide your Lucidic API key and Agent ID to use the SDK. There are several ways to do this:Option 1: Environment Variables (Recommended)
Set these environment variables in your shell or.env file:
Option 2: Direct Parameters
Pass credentials directly to the init function:Option 3: Using python-dotenv
For local development, you can use a.env file:
Getting Your Credentials
- Log in to the Lucidic Dashboard
- Navigate to your agent settings
- Copy your API Key and Agent ID
- Store them securely - never commit them to version control
Security Best Practices
- Never hardcode credentials in your source code
- Use environment variables for production deployments
- Add
.envto.gitignoreif using dotenv - Rotate API keys regularly for enhanced security
- Use different keys for development and production
Examples
Basic Usage
With Provider Integration
Production Configuration
Dataset Testing
Mass Simulation Usage
Experiment Usage
Notes
- Either
api_keyorLUCIDIC_API_KEYenvironment variable must be set - Either
agent_idorLUCIDIC_AGENT_IDenvironment variable must be set - The SDK can only have one active session at a time
- If a session is already active, calling
initwill switch to the new session. init(...)binds the created session to the current async/thread context for correct attribution in concurrent environments- Prefer
with lai.session(...)for self-contained workflows; see Session Context - The
auto_endfeature ensures your session data is preserved even on unexpected exits - Provider instrumentation happens automatically once configured