HiddenLayer's SDK documentation
The HiddenLayer platform enhances the developer experience for protecting artificial intelligence (AI) and machine learning (ML) models without needing to write complex code or manage the underlying infrastructure.
The HiddenLayer SDK uses Python to provide a simple and efficient way to interact with the HiddenLayer API. This guide will walk you through how to install and use the HiddenLayer Python SDK to retrieve AI Runtime Security and AI Supply Chain Security information.
This SDK can be used to interact with the following HiddenLayer services:
- AI Supply Chain Security (model scanning)
- AI Runtime Security — Interactions (LLM input/output analysis)
- AI Runtime Security for Predictive Models
- AI Attack Simulation (red team evaluations)
This project is under active development. The full API surface is documented in the SDK’s api.md.
Before You Begin
The following are required for using the HiddenLayer Python SDK:
- Python 3.9+ (this should include pip)
- HiddenLayer API key and secret; see Create API Key
Install SDK
Install the hiddenlayer-sdk package with pip.
The HiddenLayer Python SDK offers functionality to interact with other services, such as HuggingFace, AWS, etc.
-
To scan models from HuggingFace, install the necessary HuggingFace dependencies via:
-
To scan models from AWS, install the necessary AWS dependencies via:
Usage Overview
The main client exposed by the SDK is hiddenlayer.HiddenLayer, which provides access to all HiddenLayer services exposed via API. An async equivalent (AsyncHiddenLayer) is also available with the same interface.
API methods are grouped by resource on the client, for example:
For the full list of resources and methods, see the SDK’s api.md and the Developer Portal.
Authentication
To authenticate to HiddenLayer, generate a client ID and secret from the platform UI. See Create API Key.
The SDK supports two authentication methods:
- OAuth2 client credentials — set
HIDDENLAYER_CLIENT_IDandHIDDENLAYER_CLIENT_SECRET, or passclient_id/client_secretdirectly. - Bearer token — set
HIDDENLAYER_TOKEN, or passbearer_tokendirectly.
Data Models
The HiddenLayer Python SDK uses Pydantic to represent data for APIs, which makes the code more readable and type-safe and easier to work with.
Specific data models are organized under hiddenlayer.types. Each resource exposes its own request and response types — see the SDK’s api.md for the full inventory.
Example Usage
The HiddenLayer Python SDK comes with a number of examples demonstrating how to use the library for various common use-cases.
These examples and more are located in the examples directory of the GitHub repository.
Initiate Client
Scanning Models
Scanning a model on disk
Scanning a Hugging Face model
Runtime Security
Analyzing LLM Interactions
Use client.interactions.analyze to send LLM input and output to the Interactions endpoint. For a full walkthrough and an example response, see Getting Started with Interactions.
To target a locally-running Runtime Security container instead of the SaaS endpoint, set base_url="http://localhost:8000" (or your container’s URL) when constructing the client.
Submitting vectors to Runtime Security (Predictive Models)
For Predictive Model runtime use cases, see the examples/mldr.py script in the SDK repository.