Skip to main content
This page explains the ideas you use in every program built on a HiddenLayer SDK. The Python, TypeScript, and Java SDKs share one design: a client, resources grouped by product area, typed requests and responses, and the same authentication, retry, and pagination behavior. Where the languages differ, the examples show each one in its own tab. Read this page once before you start the workflow guides. Each section links to a page with more detail.

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.

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.
How you release a client’s resources depends on the language:
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:
  1. The base URL option: base_url (Python), baseUrl (TypeScript), or url(...) on the builder (Java).
  2. The environment option.
  3. The HIDDENLAYER_BASE_URL environment variable, read only when neither option is given.
  4. The US region.
Use the base URL option for a self-hosted endpoint, such as a local AI Runtime Security container. Credentials are region specific, because the token request goes to the same base URL. Use credentials created in the same region you connect to.

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_ID and HIDDENLAYER_CLIENT_SECRET. The client fetches, caches, and refreshes the token for you.
  • A token. Set HIDDENLAYER_TOKEN to an API key or an access token you obtained elsewhere. The client sends it as a bearer token and does not refresh it.
Options passed to the client win over environment variables, and a token wins over client credentials. See Authentication and configuration for the full resolution order and setup steps.

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.
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 as ScanReportSummaryResponseV3 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.
Responses are Pydantic models. You read fields as attributes, and optional fields are 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.
Every response type is importable from 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.
A few endpoints return untyped JSON instead of a typed object: a dictionary (Python), an object (TypeScript), or a 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:
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.
With Python’s 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.
Call the next-page method only while the has-next check is true. In Python, page.next_page() after the last page sends another request instead of returning None, and a list paged by cursor starts again from its first 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:
The Java raw response has no status code, because a raw method returns only for a 2xx status and throws for any other. Its header names keep the case the server sent them in. Paginated methods differ. In TypeScript, a paginated method such as 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:
At the 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 logging module. Its default console format prints only the message, such as DEBUG - Making HTTP request; the method, URL, and headers are passed to the log record as extra fields.
  • TypeScript uses console and prints each message with its fields.
  • Java uses java.util.logging and prints request lines at the FINE level, such as FINE - HTTP Request: GET https://api.us.hiddenlayer.ai/scan/v3/results/....
Each SDK also accepts your own logger object with 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.
Debug logging records each request’s method, URL, and headers. The SDKs replace the Authorization header and other credential headers with [REDACTED], but URLs and other headers can still identify your users or projects. Do not enable debug logging in production or anywhere logs are shared.

Next steps