The official Python library for the HiddenLayer API
Actively maintained. Last release 5 days ago, commits in 5 of the last 26 weeks. A safe choice.
pip install hiddenlayer-sdkHiddenLayer Python API Library
This library provides access to the HiddenLayer REST API from Python 3.10 or later, with synchronous and asynchronous clients built on httpx. The REST API documentation is on dev.hiddenlayer.ai; every method of this library is in reference.md.
Upgrading from 3.x? docs/BREAKING_CHANGES_v4.0.0.md lists every change.
Installation
pip install hiddenlayer-sdk
Usage
from hiddenlayer import HiddenLayer, InteractionsInput, InteractionsMetadata, InteractionsTextContent
client = HiddenLayer(
environment="prod-eu", # defaults to "prod-us"
)
response = client.interactions.analyze(
metadata=InteractionsMetadata(model="gpt-5", requester_id="user-1234", provider="openai"),
input=InteractionsInput(messages=[InteractionsTextContent(role="user", content="Hello")]),
)
print(response.analysis)
AsyncHiddenLayer has the same methods, as coroutines:
import asyncio
from hiddenlayer import AsyncHiddenLayer, InteractionsMetadata
async def main() -> None:
client = AsyncHiddenLayer()
response = await client.interactions.analyze(
metadata=InteractionsMetadata(model="gpt-5", requester_id="user-1234"),
)
print(response.analysis)
asyncio.run(main())
With the aiohttp extra installed, pip install hiddenlayer-sdk[aiohttp], the async client sends its requests with aiohttp instead of httpx's own transport.
Credentials
Give the client a client ID and secret, created under Client Credentials in the HiddenLayer Console. It exchanges them for an access token on its first call, reuses that token, and gets a new one two minutes before it expires:
import os
from hiddenlayer import HiddenLayer
client = HiddenLayer(
client_id=os.environ["HIDDENLAYER_CLIENT_ID"],
client_secret=os.environ["HIDDENLAYER_CLIENT_SECRET"],
)
The client authenticates with the first of these it finds, arguments before the environment: