Skip to main content
In this quickstart, you install the SDK, set your credentials, and send one LLM interaction to AI Runtime Security for evaluation. The interaction is a single user prompt: a prompt injection attempt, in which a user tries to make a support chatbot reveal its hidden instructions. Evaluating a prompt before it reaches the model is how you stop such an attempt. The example calls the interaction evaluation endpoint (POST /detection/v2/interaction-evaluations). It needs no model files or other setup, so it is a quick way to confirm that your installation, credentials, and network access work. Select your language in any tab, and every example on the page switches to it.

Before you begin

You need:
  • A supported runtime: Python 3.10 or later, Node.js 22 or later, or Java 8 or later with Gradle.
  • A HiddenLayer client ID and client secret with AI Runtime Security permissions: Interactions (Read, Write). See Create a Client Credential.
  • Access to Agentic Runtime Security for your tenant. See Get started with Agentic Runtime Security.
  • Your region: prod-us (default) or prod-eu.
For details, see Prerequisites.

Make your first request

1

Create a project and install the SDK

A virtual environment keeps the SDK and its dependencies isolated from other Python projects.
For more options, see Installation.
2

Set your credentials

The client reads your client ID and client secret from environment variables, so you never have to put them in code.
Replace the placeholders with your values. If your client credential is in the EU region, change the region in the code in the next step from prod-us to prod-eu (Environment.PROD_US to Environment.PROD_EU in Java). For a self-hosted deployment, pass your base URL in place of the region: a region set in code overrides HIDDENLAYER_BASE_URL. See Choose a region or base URL.
These variables last only for the current terminal session. If you open a new terminal, set them again, or use a .env file as described in Authentication and configuration.
3

Create the quickstart program

Create a file named quickstart.py in your project folder with this content:
quickstart.py
The try block catches the most common errors and prints a hint for each. ApiError is listed after UnauthorizedError and ForbiddenError because it is their parent class, so it catches any other HTTP error status. httpx.TransportError covers timeouts and connection failures.
4

Run the program

Expected result

The program prints the policy outcome, followed by one line per detection. With the default policy, the output looks like this example. The action, threat level, and detections depend on your project’s policy, so your values may differ.
DETECT means the policy reported the detections without changing the interaction. If your project’s policy blocks or redacts prompt injection, the action is BLOCK or REDACT instead. The default detection rules evaluate the most recent message in the interaction. To screen a prompt, send it as the last message, as this example does. If you add the model’s reply after the prompt, rules that check user input do not fire for it. What the fields mean: Python and TypeScript use these field names directly. Java reads them through getters, such as getOutcome().getThreatLevel(). The response also includes outcome.effective_interaction (the interaction to forward, with any redactions applied), evaluated_interaction (the messages with per-message signals and findings), and metadata (such as evaluation_id and the project whose policy applied). For a description of the response, see Evaluation Endpoints.

What just happened

  1. The client read its configuration. The client read HIDDENLAYER_CLIENT_ID and HIDDENLAYER_CLIENT_SECRET from the environment and set the base URL to https://api.us.hiddenlayer.ai for prod-us.
  2. The client obtained an access token. Before sending the request, the SDK exchanged your client ID and client secret for an OAuth2 access token at https://api.us.hiddenlayer.ai/oauth2/token. It caches this token and gets a new one before it expires, so you do not manage tokens yourself.
  3. The client sent the request. It sent the metadata and the interaction to POST /detection/v2/interaction-evaluations, with the token in the Authorization header. If the request had failed with a temporary error, such as HTTP 429 or 5xx, the SDK would have retried up to two times.
  4. The SDK parsed the response. The JSON response was converted into a typed InteractionEvaluationResponse: a Pydantic model in Python, an interface in TypeScript, and a class in Java.
To learn more about clients, resources, and response types, see Core concepts.
If your application uses asyncio, use AsyncHiddenLayer. It takes the same arguments and reads the same environment variables. Await each call.
quickstart_async.py
To close the client’s connections before your program exits, for example to avoid aiohttp’s Unclosed connector warning, use async with AsyncHiddenLayer() as client: or call await client.aclose(). See Async client.

If it fails

The SDK is not installed where your program runs.
  • Python (ModuleNotFoundError: No module named 'hiddenlayer'): the virtual environment is not active, or the SDK is installed in a different environment. Activate .venv and run python -m pip install hiddenlayer-sdk.
  • TypeScript (ERR_MODULE_NOT_FOUND: Cannot find package '@hiddenlayerai/hiddenlayer-sdk'): run npm install @hiddenlayerai/hiddenlayer-sdk in the folder that contains quickstart.mts.
  • Java (package com.hiddenlayer.api does not exist): check that build.gradle.kts lists mavenCentral() and the hiddenlayer-java dependency.
See Common installation errors.
The client found neither a token nor a client ID and client secret. Set both environment variables in the same terminal where you run the program, and check that the values have no extra spaces or quotes. In Python and TypeScript the request fails with this message; in Java, build() throws it as an IllegalStateException. See Authentication and configuration.
The client could not get a valid token. Check that the client ID and client secret are correct, and that the region in your code matches the region where the client credential was created. See Troubleshooting.
Your client credential is valid but lacks permission for AI Runtime Security, or Agentic Runtime Security is not enabled for your tenant. Create a client credential with Interactions (Read, Write) permissions. See Create a Client Credential. If the permissions are correct, contact your HiddenLayer account representative or Support to request access.
The SDK could not connect. Check your network, firewall, and proxy settings, and confirm the base URL. To configure a proxy, see Authentication and configuration.
Your Node.js release cannot run TypeScript files directly. Upgrade to Node.js 22.18 or later, or run npx tsx quickstart.mts.
For more problems and fixes, see Troubleshooting and Error handling.

Next steps

Scan models

Scan model files for malicious code and vulnerabilities.

Runtime security

Protect LLM applications and agents with the evaluation endpoints.

Attack simulation

Run red team sessions against your AI application.

Core concepts

Understand clients, resources, and response types.