The client
The client is the object that holds your configuration (credentials, region, timeouts, retries) and sends requests to the HiddenLayer API.
In Python and Java, the synchronous and asynchronous clients take the same options and have the same methods. Every method of the TypeScript client is asynchronous.
The following example creates a client from environment credentials and prints the five most recent scans.
- Python
- TypeScript
- Java
Create one client and reuse it
Create the client once (for example at application startup) and share it. Reusing a client matters for two reasons:- Connection reuse. The client keeps HTTP connections open, so later requests are faster.
- Token caching. With client ID and client secret authentication, the client requests an access token on its first call, caches it, and requests a new one shortly before it expires. A new client per request would fetch a new token every time.
- Python
- TypeScript
- Java
HiddenLayer and AsyncHiddenLayer are context managers. Use with HiddenLayer() as client: or async with AsyncHiddenLayer() as client:, or call client.close() or await client.aclose() when your application shuts down. Closing releases the client’s connections, and a closed client can’t send requests. An httpx.Client (or httpx.AsyncClient) that you pass as httpx_client stays open, so close that yourself. See Authentication and configuration.Resources and methods
The client groups API operations into resources. You call an operation on a resource, and some resources are nested. The naming follows each language’s conventions:
The following table lists the resources the workflow guides use. Resource names are shown in Python form. The SDKs cover every public operation in the HiddenLayer API, so the client also has resources such as
access, asset_inventory, audit, compliance, governance, and metrics. See the API reference for every language’s names.
High-level helpers and API resources
Most resources map one-to-one to a REST endpoint: one method call sends one HTTP request. A few attributes are high-level helpers built on top of those resources. Which helpers exist depends on the language:
Start with the helpers for common tasks. Use the API resources when you need control the helpers do not offer, such as listing past scans or exporting SARIF. The API usage examples page shows recipes that use them.
Environments and base URL
An environment is the HiddenLayer region your account lives in. The client turns the environment into a base URL, the address every request starts with.
The client chooses the base URL in this order:
- The base URL option:
base_url(Python),baseUrl(TypeScript), orurl(...)on the builder (Java). - The
environmentoption. - The
HIDDENLAYER_BASE_URLenvironment variable, read only when neither option is given. - The US region.
Authentication
The client supports two kinds of credentials:- OAuth2 client credentials (recommended). Your program exchanges a client ID and client secret for a short-lived access token. Set
HIDDENLAYER_CLIENT_IDandHIDDENLAYER_CLIENT_SECRET. The client fetches, caches, and refreshes the token for you. - A token. Set
HIDDENLAYER_TOKENto an API key or an access token you obtained elsewhere. The client sends it as a bearer token and does not refresh it.
Request types
Every SDK types its requests, so editors can autocomplete fields and the compiler or type checker can flag mistakes. The shape of a request depends on the language. The following example evaluates a user prompt with the Runtime Security interaction-evaluations endpoint.- Python
- TypeScript
- Java
Arguments are keyword arguments. Nested objects, such as
metadata and interaction, are Pydantic models you import from hiddenlayer. A plain dict with the same keys is still sent correctly, but a type checker such as Pyright or mypy reports it.Response types
Methods return typed objects named after the API specification’s schemas, such asScanReportSummaryResponseV3 or InteractionEvaluationResponse. A field the API adds after your SDK version was released is still readable, and enumerated fields accept values the SDK does not know yet.
- Python
- TypeScript
- Java
Responses are Pydantic models. You read fields as attributes, and optional fields are Every response type is importable from
None when the response leaves them out. Models are immutable: assigning to a field raises an error. Use model.dict() or model.json() to get a plain dictionary or a JSON string with the API’s field names.hiddenlayer for type hints, for example from hiddenlayer import ScanReportSummaryResponseV3. A response that does not match its model raises hiddenlayer.core.ParsingError. See Error handling.Map<String, Object> (Java). The SARIF export returns the SARIF log this way, and the request-evaluations and response-evaluations endpoints return the provider payload this way.
Projects and the HL-Project-Id header
In AI Runtime Security, a project groups your application’s traffic and selects the policy used to evaluate it. The Runtime Security methods and Prompt Analyzer accept an optional project ID or alias, which the SDK sends as the HL-Project-Id HTTP header. If you omit it, your tenant’s default project and its policy apply.
The Request types example sets the project in each language. The red team
create method takes the project in the request body instead: hl_project_id in Python and TypeScript, and hlProjectId in Java. The Python red team session helper names the argument hiddenlayer_project_id. See Runtime security and the policy documentation.
Beta APIs and beta warnings
Some endpoints are Beta: they are not generally available and can change without notice, including breaking changes. Beta endpoints are excluded from the SDKs’ semantic versioning guarantees. See the Beta API guidelines. In the current releases, the Beta endpoints include the AI Attack Simulation red team endpoints (evaluations.red_team, and the Python session helper that calls them) and the v2 asset inventory endpoints. The Runtime Security v2 evaluation endpoints are not Beta.
The first time a client calls a Beta endpoint, the SDK warns you. The warning names the endpoint by HTTP method and path:
- Python
- TypeScript
- Java
The SDK emits a
hiddenlayer.BetaWarning, a subclass of UserWarning, through Python’s warnings module, once per endpoint for each client. After you have reviewed the Beta terms, you can silence it:Pagination
Methods that list many items return a page object. Iterating it walks every item across every page: the SDK requests the next page whenever it needs more items.
The following example prints every file result of a scan, 50 results per request.
AsyncHiddenLayer, await the method first, then iterate: async for file_result in await client.scans.results.list_files(...). The Java AsyncHiddenLayerClient completes its future with the first page; iterating past it blocks the calling thread for each further page.
See API usage examples for page-by-page loops.
Raw responses
By default, methods return the parsed body only. To read the HTTP status or a response header, request the raw response:scans.jobs.list has no withRawResponse(); the page it returns has rawResponse, the current page’s status and headers. In Python, with_raw_response on a paginated method returns the same page object as the method, without headers or a status code. In Java, withRawResponse() works for paginated methods too.
Use raw responses to read the hl-runtime-action header that the Runtime Security request-evaluations and response-evaluations endpoints return. See Runtime security.
Retries and timeouts
The client retries failed requests automatically so that short outages do not break your program.Retries and timeouts apply to each HTTP request. They do not limit how long the model scanner or community scanner wait for a scan to finish. Those helpers poll until the scan reaches a final status, with no overall time limit. See Model scanning.
Logging
Each SDK can log the requests it sends and the responses it receives. Logging is off by default. To turn it on, pass a logging configuration with a level (debug, info, warn, or error) and turn off silent:
debug level, the SDK logs each request and response with its method, URL, status, and headers. The default loggers write to the console:
- Python uses the standard
loggingmodule. Its default console format prints only the message, such asDEBUG - Making HTTP request; the method, URL, and headers are passed to the log record as extra fields. - TypeScript uses
consoleand prints each message with its fields. - Java uses
java.util.loggingand prints request lines at theFINElevel, such asFINE - HTTP Request: GET https://api.us.hiddenlayer.ai/scan/v3/results/....
debug, info, warn, and error methods, passed as logger in the configuration, which receives the same fields. The SDKs no longer read the HIDDENLAYER_LOG environment variable.

