Complete API documentation for WhiteBoxAI SDK.
Main client for interacting with the WhiteBoxAI API.
WhiteBoxAI(
api_key: str = None,
base_url: str = "https://api.whiteboxai.io",
timeout: int = 30,
max_retries: int = 3,
enable_offline: bool = False,
offline_dir: str = "./whiteboxai_offline",
offline_max_queue_size: int = 10000,
offline_auto_sync: bool = False,
offline_sync_interval: int = 60,
enable_caching: bool = False,
cache_ttl: int = 3600,
cache_max_size: int = 1000,
enable_privacy_filters: bool = False,
enable_sampling: bool = False,
sampling_rate: float = 1.0
)Parameters:
api_key(str): API key for authentication. Can be set via EXPLAINAI_API_KEY env varbase_url(str): Base URL for API endpointtimeout(int): Request timeout in secondsmax_retries(int): Maximum number of retry attemptsenable_offline(bool): Enable offline mode with persistent queueoffline_dir(str): Directory for offline queue storageoffline_max_queue_size(int): Maximum queued operations (0 = unlimited)offline_auto_sync(bool): Enable automatic background syncoffline_sync_interval(int): Sync interval in secondsenable_caching(bool): Enable local cachingcache_ttl(int): Cache time-to-live in secondscache_max_size(int): Maximum cache entriesenable_privacy_filters(bool): Enable PII detection and maskingenable_sampling(bool): Enable prediction samplingsampling_rate(float): Sampling rate (0.0-1.0)
client.models # Models resource
client.predictions # Predictions resource
client.explanations # Explanations resource
client.drift # Drift detection resource
client.alerts # Alerts resourceget_offline_status() -> dictGet offline queue status.
Returns: Dictionary with queue_size, last_sync_time, failed_count
sync_offline_queue() -> dictManually sync offline queue.
Returns: Dictionary with synced and failed counts
cleanup_offline_queue(older_than_days: int = 7)Remove old operations from queue.
Simplified monitoring interface.
ModelMonitor(
client: WhiteBoxAI,
model_id: int = None,
sampling_rate: float = 1.0,
enable_explanations: bool = False
)register_model(
name: str,
model_type: str,
framework: str = None,
version: str = None,
**metadata
) -> intRegister a new model.
Parameters:
name(str): Model namemodel_type(str): Type (classification, regression, etc.)framework(str): Framework name (sklearn, pytorch, etc.)version(str): Model version**metadata: Additional metadata
Returns: Model ID
log_prediction(
inputs: dict,
output: dict,
ground_truth: Any = None,
explanation: dict = None,
metadata: dict = None,
priority: str = "NORMAL"
)Log a single prediction.
Parameters:
inputs(dict): Input featuresoutput(dict): Model outputground_truth(Any): Actual value (optional)explanation(dict): Model explanation (optional)metadata(dict): Additional metadata (optional)priority(str): Queue priority (CRITICAL, HIGH, NORMAL, LOW)
log_batch(predictions: List[dict])Log multiple predictions.
set_baseline(data: np.ndarray, **kwargs)Set baseline data for drift detection.
detect_drift(data: np.ndarray) -> dictDetect drift in current data.
Returns: Drift detection report
@monitor_model(
monitor: ModelMonitor,
input_keys: List[str] = None,
output_key: str = None,
explain: bool = False
)
def predict(...):
...Monitor all predictions from a function.
@monitor_prediction(
monitor: ModelMonitor,
input_extractor: Callable = None,
output_extractor: Callable = None
)
def predict(...):
...Monitor predictions with custom extractors.
from whiteboxai.integrations.sklearn import SklearnMonitor
monitor = SklearnMonitor(
client: WhiteBoxAI,
model=None,
model_name: str = None
)
monitor.register_from_model(model_type: str, **kwargs) -> int
monitor.wrap_model(model)
monitor.predict(model, X, y=None, log=True)from whiteboxai.integrations.pytorch import TorchMonitor
monitor = TorchMonitor(
client: WhiteBoxAI,
model=None,
model_name: str = None
)
monitor.register_from_model(model_type: str, **kwargs) -> int
monitor.wrap_model(model)from whiteboxai.integrations.tensorflow import KerasMonitor, WhiteBoxAICallback
monitor = KerasMonitor(
client: WhiteBoxAI,
model=None,
model_name: str = None
)
monitor.register_from_model(model_type: str, **kwargs) -> int
callback = WhiteBoxAICallback(monitor, log_frequency=1)
monitor.predict(X, log=True)from whiteboxai.integrations.transformers import TransformersMonitor
monitor = TransformersMonitor(
client: WhiteBoxAI,
pipeline=None,
model_name: str = None
)
monitor.register_from_model(name: str, version: str = "1.0.0") -> int
monitor.predict(text, log=True)from whiteboxai.integrations.langchain import LangChainMonitor
monitor = LangChainMonitor(
client: WhiteBoxAI,
application_name: str,
track_tokens: bool = True,
track_cost: bool = True
)
monitor.register_application(name: str, version: str = "1.0.0") -> int
callback = monitor.create_callback_handler()from whiteboxai.integrations.boosting import XGBoostMonitor, LightGBMMonitor
monitor = XGBoostMonitor(
client: WhiteBoxAI,
model_name: str,
track_feature_importance: bool = True,
importance_type: str = "gain"
)
monitor.register_from_model(model, X_train, y_train) -> int
monitor.predict(model, X, y=None, log=True)from whiteboxai.exceptions import (
WhiteBoxAIError, # Base exception
AuthenticationError, # Authentication failed
APIError, # API request error
ValidationError, # Validation error
RateLimitError, # Rate limit exceeded
)from whiteboxai.privacy import mask_data
masked = mask_data(
data: dict,
patterns: List[str] = None # Custom PII patterns
) -> dictMask sensitive data before sending to API.