> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hiddenlayer.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication and configuration

> Provide HiddenLayer credentials to the Python, TypeScript, or Java SDK, choose a region or base URL, and configure timeouts, retries, proxies, and headers.

Every request to the HiddenLayer API must be authenticated, and it must go to the correct regional API host. This page explains how the SDKs get your credentials, how they decide where to send requests, and which client options you can change. The three SDKs follow the same rules. The examples show each language in its own tab.

## Authentication methods

The SDKs support two ways to authenticate. Configure one of them.

| Method | Credentials | When to use it |
| - | - | - |
| OAuth2 client credentials (recommended) | Client ID and client secret | Services, scripts, CI/CD pipelines, and most other cases. The SDK obtains and renews access tokens for you. |
| Bearer token | An API key, or an access token you obtain yourself | You use a HiddenLayer API key, or you already obtain tokens through another system and want to pass one in directly. |

### OAuth2 client credentials

OAuth2 client credentials is a standard flow in which an application authenticates as itself by exchanging a client ID and client secret for a short-lived access token. You get a client ID and client secret when you create a client credential in the HiddenLayer Console. See [Create a Client Credential](https://docs.hiddenlayer.ai/docs/products/console/apikey_aisec_platform.md#create-a-client-credential).

When you provide a client ID and client secret, the SDK handles the token for you:

1. Before the first API request, the client sends a `POST` request to `{base_url}/oauth2/token` with `grant_type=client_credentials`, your client ID, and your client secret.
2. The client caches the returned access token and adds it to each request as an `Authorization: Bearer <token>` header.
3. The client gets a new token two minutes before the cached one expires, based on the `expires_in` value in the token response.

Because the token URL is built from the base URL, your credentials must belong to the same region as the base URL. A `prod-eu` client credential does not work against the `prod-us` host. If the token request fails, the call you made fails with the token endpoint's error, such as an `UnauthorizedError` (HTTP 401) for a wrong client ID or client secret.

### Bearer token

The SDK sends a bearer token as `Authorization: Bearer <token>` and never refreshes it. Use a bearer token for:

* **A HiddenLayer API key.** The SDKs send an API key the same way as an access token. See [Use an API Key](https://docs.hiddenlayer.ai/docs/products/console/apikey_aisec_platform.md#use-an-api-key).
* **An access token you obtain yourself.** When the token expires, requests fail with HTTP 401 until you supply a new one. In Python and TypeScript, you can pass a function that returns the current token instead of a fixed value. The client calls it before every request. See [Pass credentials explicitly](#pass-credentials-explicitly).

Client credentials are still recommended, because a leaked access token stops working on its own within a short time.

### Which credentials the client uses

If more than one credential is available, the client uses the first of these it finds. Credentials you pass to the client win over the environment, and a token wins over client credentials:

1. A token passed to the client.
2. A client ID and client secret passed to the client. If you pass only one of them, the client takes the other from the environment.
3. The `HIDDENLAYER_TOKEN` environment variable.
4. The `HIDDENLAYER_CLIENT_ID` and `HIDDENLAYER_CLIENT_SECRET` environment variables.

A blank value counts as not set. If the client finds no credentials at all:

> [tab] Python
>
> The client is still created, but each request raises an `ApiError` (from `hiddenlayer.core`) whose message names the arguments and environment variables to set.

> [tab] TypeScript
>
> The client is still created, but each request fails with a `HiddenLayerError` whose message names the options and environment variables to set. For a deployment that accepts unauthenticated requests, such as a local container, pass `auth: false`.

> [tab] Java
>
> `build()` throws an `IllegalStateException` whose message names the builder methods and environment variables to set.

## Environment variables

The client reads these environment variables when you create it. Values that you pass to the client take precedence over environment variables. All three SDKs read the same variables.

| Variable | Purpose | Example value |
| - | - | - |
| `HIDDENLAYER_CLIENT_ID` | Client ID for OAuth2 client credentials. | Your client ID |
| `HIDDENLAYER_CLIENT_SECRET` | Client secret for OAuth2 client credentials. | Your client secret |
| `HIDDENLAYER_TOKEN` | Bearer token, such as an API key. | Your API key |
| `HIDDENLAYER_BASE_URL` | Base URL for all requests, used when you do not choose a region or URL in code. Use it for self-hosted deployments or a local container. | `http://localhost:8000` |

> [!NOTE]
>
> The SDKs no longer read `HIDDENLAYER_LOG` or `HIDDENLAYER_CUSTOM_HEADERS`. Configure logging and extra headers with client options instead. See [Client options](#client-options).

### Set environment variables

Set your credentials in the terminal session that runs your code:

> [tab] macOS/Linux
>
> ```bash theme={null}
> export HIDDENLAYER_CLIENT_ID="your-client-id"
> export HIDDENLAYER_CLIENT_SECRET="your-client-secret"
> ```

> [tab] Windows
>
> ```powershell theme={null}
> $env:HIDDENLAYER_CLIENT_ID = "your-client-id"
> $env:HIDDENLAYER_CLIENT_SECRET = "your-client-secret"
> ```

Replace the placeholder values with your own. These commands set the variables only for the current terminal session. In production, use your platform's secret management, such as CI/CD secrets, a container orchestrator's secrets, or a cloud secret manager, to inject the variables at runtime.

> [!TIP]
>
> Typing a secret on the command line can save it in your shell history. For local development, a `.env` file (described next) avoids this.

### Optional: use a .env file

A `.env` file is a plain text file of `NAME=value` lines that you keep in your project folder. The SDKs do not read `.env` files on their own.

**1. Create a .env file**

```text .env theme={null}
HIDDENLAYER_CLIENT_ID=your-client-id
HIDDENLAYER_CLIENT_SECRET=your-client-secret
```

**2. Keep the file out of version control**

Add `.env` to your `.gitignore` file so that you never commit your secret:

```text .gitignore theme={null}
.env
```

**3. Load the file before you create the client**

> [tab] Python
>
> Install `python-dotenv` with `python -m pip install python-dotenv`, then load the file:
>
> ```python theme={null}
> from dotenv import load_dotenv
> from hiddenlayer import HiddenLayer
>
> load_dotenv()  # Copies values from .env into os.environ.
>
> client = HiddenLayer()
> ```
>
> Call `load_dotenv()` before you create the client, because the client reads environment variables only when it is constructed.

> [tab] TypeScript
>
> Start Node.js with the `--env-file` option. No package is needed:
>
> ```bash theme={null}
> node --env-file=.env app.mts
> ```
>
> Node.js runs TypeScript files directly from version 22.18. On an earlier Node.js 22 release, run `npx tsx --env-file=.env app.mts` instead.

> [tab] Java
>
> Java has no built-in `.env` loader, and the client reads only real environment variables. Set the variables in your shell or in your IDE's run configuration. If you read the file with a library, pass the values to the builder as shown in [Pass credentials explicitly](#pass-credentials-explicitly).

## Choose a region or base URL

The base URL is the root address that the client sends every request to, for example `https://api.us.hiddenlayer.ai`. HiddenLayer provides two SaaS environments (regions):

| Environment | Base URL | Python | TypeScript | Java |
| - | - | - | - | - |
| `prod-us` (default) | `https://api.us.hiddenlayer.ai` | `"prod-us"` or `HiddenLayerEnvironment.PROD_US` | `"prod-us"` or `HiddenLayerEnvironment.ProdUs` | `Environment.PROD_US` |
| `prod-eu` | `https://api.eu.hiddenlayer.ai` | `"prod-eu"` or `HiddenLayerEnvironment.PROD_EU` | `"prod-eu"` or `HiddenLayerEnvironment.ProdEu` | `Environment.PROD_EU` |

Select the EU region:

```python Python theme={null}
from hiddenlayer import HiddenLayer, HiddenLayerEnvironment

client = HiddenLayer(environment="prod-eu")

# The same region, as an enum value.
client = HiddenLayer(environment=HiddenLayerEnvironment.PROD_EU)
```

```typescript TypeScript theme={null}
import { HiddenLayer, HiddenLayerEnvironment } from "@hiddenlayerai/hiddenlayer-sdk";

const client = new HiddenLayer({ environment: "prod-eu" });

// The same region, as a constant.
const sameClient = new HiddenLayer({ environment: HiddenLayerEnvironment.ProdEu });
```

```java Java theme={null}
import com.hiddenlayer.api.HiddenLayerClient;
import com.hiddenlayer.api.HiddenLayerClientBuilder;
import com.hiddenlayer.api.core.Environment;

HiddenLayerClient client = new HiddenLayerClientBuilder()
    .environment(Environment.PROD_EU)
    .build();
```

In Python, an unknown region name, such as `environment="eu"`, raises `ValueError: Unknown environment: eu`.

To send requests to another host, such as a self-hosted deployment or a local AI Runtime Security container, set the base URL:

```python Python theme={null}
from hiddenlayer import HiddenLayer

client = HiddenLayer(base_url="http://localhost:8000")
```

```typescript TypeScript theme={null}
import { HiddenLayer } from "@hiddenlayerai/hiddenlayer-sdk";

const client = new HiddenLayer({ baseUrl: "http://localhost:8000" });
```

```java Java theme={null}
import com.hiddenlayer.api.HiddenLayerClient;
import com.hiddenlayer.api.HiddenLayerClientBuilder;

HiddenLayerClient client = new HiddenLayerClientBuilder()
    .url("http://localhost:8000")
    .build();
```

### How the client resolves the base URL

The client picks the base URL in this order and uses the first match:

1. The base URL you pass: `base_url` in Python, `baseUrl` in TypeScript, or `url(...)` in Java.
2. The region you pass with `environment`.
3. The `HIDDENLAYER_BASE_URL` environment variable, if it is set.
4. The `prod-us` environment.

`HIDDENLAYER_BASE_URL` applies only when your code chooses neither a region nor a base URL, so passing `environment` overrides the variable. In Java, `environment(...)` and `url(...)` set the same value, so call only one of them.

## Pass credentials explicitly

By default, the client reads credentials from environment variables. You can also pass them to the client, for example when your application loads secrets from a secret manager under different names. Read the values from your secret store or the environment. Never write them as literals in code.

```python Python theme={null}
import os

from hiddenlayer import HiddenLayer

client = HiddenLayer(
    client_id=os.environ["HIDDENLAYER_CLIENT_ID"],
    client_secret=os.environ["HIDDENLAYER_CLIENT_SECRET"],
    environment="prod-us",
)
```

```typescript TypeScript theme={null}
import { HiddenLayer } from "@hiddenlayerai/hiddenlayer-sdk";

const client = new HiddenLayer({
    clientId: process.env.HIDDENLAYER_CLIENT_ID,
    clientSecret: process.env.HIDDENLAYER_CLIENT_SECRET,
    environment: "prod-us",
});
```

```java Java theme={null}
import com.hiddenlayer.api.HiddenLayerClient;
import com.hiddenlayer.api.HiddenLayerClientBuilder;
import com.hiddenlayer.api.core.Environment;

HiddenLayerClient client = new HiddenLayerClientBuilder()
    .clientId(System.getenv("HIDDENLAYER_CLIENT_ID"))
    .clientSecret(System.getenv("HIDDENLAYER_CLIENT_SECRET"))
    .environment(Environment.PROD_US)
    .build();
```

To use a bearer token, such as an API key, instead, pass it as the token. In this example your application reads the key from its own `HIDDENLAYER_API_KEY` variable; the SDK reads a token from the environment only from `HIDDENLAYER_TOKEN`.

```python Python theme={null}
import os

from hiddenlayer import HiddenLayer

client = HiddenLayer(token=os.environ["HIDDENLAYER_API_KEY"])
```

```typescript TypeScript theme={null}
import { HiddenLayer } from "@hiddenlayerai/hiddenlayer-sdk";

const client = new HiddenLayer({ token: process.env.HIDDENLAYER_API_KEY });
```

```java Java theme={null}
import com.hiddenlayer.api.HiddenLayerClient;
import com.hiddenlayer.api.HiddenLayerClientBuilder;

HiddenLayerClient client = new HiddenLayerClientBuilder()
    .token(System.getenv("HIDDENLAYER_API_KEY"))
    .build();
```

If your tokens rotate, pass a function that returns the current token. The client calls it before every request:

> [tab] Python
>
> ```python theme={null}
> from hiddenlayer import HiddenLayer
>
>
> def current_token() -> str:
>     # Return the current token from your secret store or identity provider.
>     with open("/var/run/secrets/hiddenlayer/token") as f:
>         return f.read().strip()
>
>
> client = HiddenLayer(token=current_token)
> ```
>
> `AsyncHiddenLayer` also takes `async_token`, an async function. See [Async client](#async-client).

> [tab] TypeScript
>
> ```typescript theme={null}
> import { readFile } from "node:fs/promises";
>
> import { HiddenLayer } from "@hiddenlayerai/hiddenlayer-sdk";
>
> const client = new HiddenLayer({
>     // Called before every request; return the current token from your secret store or identity provider.
>     token: async () => (await readFile("/var/run/secrets/hiddenlayer/token", "utf8")).trim(),
> });
> ```

> [tab] Java
>
> The Java builder takes a token as a fixed `String`. To rotate it, build a new client with the new token, or use client credentials, which the client renews for you.

> [!WARNING]
>
> Do not hard-code client secrets or tokens in source files, notebooks, or container images. Anyone with access to the code can use them, and secrets committed to version control remain in the history. If a secret is exposed, [regenerate the client secret](https://docs.hiddenlayer.ai/docs/products/console/apikey_aisec_platform.md#regenerate-a-client-secret) in the Console.

## Client options

Each SDK exposes the same settings under names that follow its language's conventions. Python takes keyword arguments, TypeScript takes an options object, and Java uses builder methods.

| Setting | Python | TypeScript | Java builder | Default |
| - | - | - | - | - |
| Client ID | `client_id` | `clientId` | `clientId(String)` | `HIDDENLAYER_CLIENT_ID` |
| Client secret | `client_secret` | `clientSecret` | `clientSecret(String)` | `HIDDENLAYER_CLIENT_SECRET` |
| Bearer token | `token` (a string or a function) | `token` (a string or a function) | `token(String)` | `HIDDENLAYER_TOKEN` |
| Region | `environment` | `environment` | `environment(Environment)` | `prod-us` |
| Base URL | `base_url` | `baseUrl` | `url(String)` | Resolved as described in [How the client resolves the base URL](#how-the-client-resolves-the-base-url) |
| Timeout per request | `timeout` (seconds, `float`) | `timeoutInSeconds` | `timeout(int)` (seconds) | 60 seconds |
| Retries | `max_retries` | `maxRetries` | `maxRetries(int)` | `2` |
| Headers sent with every request | `headers` (a `dict`) | `headers` (an object) | `addHeader(name, value)` | None |
| Logging | `logging` | `logging` | `logging(LogConfig)` | Silent |
| HTTP client | `httpx_client` (an `httpx.Client`) | `fetch` (a `fetch` function) | `httpClient(OkHttpClient)` | Managed by the SDK |

Failed requests are retried with exponential backoff when the response is HTTP 408, 429, or 5xx. Python also retries HTTP 409 and failed connections. Set retries to `0` to disable them.

Java also has `maxConcurrentRequests(int)`, `addInterceptor(Interceptor)`, and settings that fine-tune retries, such as `retryOnStatusCodes` and `initialRetryDelayMillis`. For every option, see the SDK's method reference, listed in [Method reference and migration guides](#method-reference-and-migration-guides).

Example with a custom timeout, retries, and a header:

```python Python theme={null}
from hiddenlayer import HiddenLayer

client = HiddenLayer(
    timeout=20.0,
    max_retries=3,
    headers={"X-Team": "ml-platform"},
)
```

```typescript TypeScript theme={null}
import { HiddenLayer } from "@hiddenlayerai/hiddenlayer-sdk";

const client = new HiddenLayer({
    timeoutInSeconds: 20,
    maxRetries: 3,
    headers: { "X-Team": "ml-platform" },
});
```

```java Java theme={null}
import com.hiddenlayer.api.HiddenLayerClient;
import com.hiddenlayer.api.HiddenLayerClientBuilder;

HiddenLayerClient client = new HiddenLayerClientBuilder()
    .timeout(20)
    .maxRetries(3)
    .addHeader("X-Team", "ml-platform")
    .build();
```

For details on retry behavior and timeout errors, see [Error handling](https://docs.hiddenlayer.ai/docs/integrations/sdk/error_handling.md).

### Use a proxy

If your network requires an HTTP proxy, give the client an HTTP client that uses it.

> [tab] Python
>
> Pass an `httpx.Client` configured with your proxy:
>
> ```python theme={null}
> import os
>
> import httpx
> from hiddenlayer import HiddenLayer
>
> client = HiddenLayer(
>     httpx_client=httpx.Client(
>         proxy=os.environ["HTTPS_PROXY"],  # For example, http://proxy.example.com:8080
>         timeout=60.0,
>         follow_redirects=True,
>     ),
> )
> ```
>
> When you pass your own `httpx.Client`, the SDK uses that client's timeout and redirect settings, so set them as shown. The `proxy` argument requires `httpx` 0.26 or later. The client also sends its token requests through the `httpx.Client` you pass.
>
> `httpx` reads the `HTTPS_PROXY` environment variable by default, so if it is set where your code runs, a client created without `httpx_client` already sends its requests through that proxy.

> [tab] TypeScript
>
> Install `undici` with `npm install undici`, then pass a `fetch` function that sends requests through an undici `ProxyAgent`:
>
> ```typescript theme={null}
> import { HiddenLayer } from "@hiddenlayerai/hiddenlayer-sdk";
> import { ProxyAgent, fetch as undiciFetch } from "undici";
>
> const dispatcher = new ProxyAgent(process.env.HTTPS_PROXY ?? "http://proxy.example.com:8080");
>
> // undici's fetch types differ from the global fetch types, hence the cast.
> const proxiedFetch = ((url: string, init?: Parameters<typeof undiciFetch>[1]) =>
>     undiciFetch(url, { ...init, dispatcher })) as unknown as typeof fetch;
>
> const client = new HiddenLayer({ fetch: proxiedFetch });
> ```
>
> The client sends API calls and token requests through this function. The model scanner uploads files to presigned storage URLs with the global `fetch`, so those uploads do not use it.

> [tab] Java
>
> Pass an `OkHttpClient` configured with your proxy:
>
> ```java theme={null}
> import com.hiddenlayer.api.HiddenLayerClient;
> import com.hiddenlayer.api.HiddenLayerClientBuilder;
> import java.net.InetSocketAddress;
> import java.net.Proxy;
> import okhttp3.OkHttpClient;
>
> OkHttpClient httpClient = new OkHttpClient.Builder()
>     .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.example.com", 8080)))
>     .build();
>
> HiddenLayerClient client = new HiddenLayerClientBuilder()
>     .httpClient(httpClient)
>     .build();
> ```
>
> The SDK keeps its retries on the client you pass, and uses that client's timeouts unless you also call `timeout(...)`. Two kinds of request don't go through it: the exchange of a client ID and client secret for an access token, and the model scanner's uploads of file parts to presigned URLs. To send those through the proxy as well, set the standard JVM proxy properties, for example `-Dhttps.proxyHost=proxy.example.com -Dhttps.proxyPort=8080`. The JVM properties alone also route the client's API calls, so you can use them instead of passing an `OkHttpClient`.

### Override options for a single request

Every method takes request options as its last argument. Use them when one call needs different settings, such as a longer timeout for a large request. The client's own settings are not changed.

```python Python theme={null}
from hiddenlayer import (
    CanonicalInteraction,
    CanonicalInteractionMessage,
    ContentPart_Text,
    HiddenLayer,
    InteractionEvaluationRequestMetadata,
)

client = HiddenLayer()

result = client.runtime.evaluate_interaction(
    metadata=InteractionEvaluationRequestMetadata(model="gpt-4o", provider="openai", requester_id="user-1234"),
    interaction=CanonicalInteraction(
        messages=[
            CanonicalInteractionMessage(
                role="user", content=[ContentPart_Text(text="Summarize the attached contract.")]
            )
        ]
    ),
    request_options={"timeout": 120.0, "max_retries": 5},
)
```

```typescript TypeScript theme={null}
import { HiddenLayer } from "@hiddenlayerai/hiddenlayer-sdk";

const client = new HiddenLayer();

const result = await client.runtime.evaluateInteraction(
    {
        metadata: { model: "gpt-4o", provider: "openai", requester_id: "user-1234" },
        interaction: {
            messages: [{ role: "user", content: [{ type: "text", text: "Summarize the attached contract." }] }],
        },
    },
    { timeoutInSeconds: 120, maxRetries: 5 },
);
```

```java Java theme={null}
import com.hiddenlayer.api.core.RequestOptions;
import com.hiddenlayer.api.resources.runtime.requests.InteractionEvaluationRequest;
import com.hiddenlayer.api.resources.runtime.types.InteractionEvaluationRequestInteraction;
import com.hiddenlayer.api.types.CanonicalInteraction;
import com.hiddenlayer.api.types.CanonicalInteractionMessage;
import com.hiddenlayer.api.types.ContentPart;
import com.hiddenlayer.api.types.InteractionEvaluationRequestMetadata;
import com.hiddenlayer.api.types.InteractionEvaluationResponse;
import com.hiddenlayer.api.types.TextPart;

InteractionEvaluationResponse result = client.runtime().evaluateInteraction(
    InteractionEvaluationRequest.builder()
        .metadata(InteractionEvaluationRequestMetadata.builder()
            .model("gpt-4o")
            .requesterId("user-1234")
            .provider("openai")
            .build())
        .interaction(InteractionEvaluationRequestInteraction.of(CanonicalInteraction.builder()
            .addMessages(CanonicalInteractionMessage.builder()
                .role("user")
                .addContent(ContentPart.text(TextPart.builder().text("Summarize the attached contract.").build()))
                .build())
            .build()))
        .build(),
    RequestOptions.builder().timeout(120).maxRetries(5).build());
```

Request options can also add headers and query parameters to one call: `additional_headers` and `additional_query_parameters` in Python, `headers` and `queryParams` in TypeScript, and `addHeader` and `addQueryParameter` in Java.

## Close the client

Create one client when your application starts and reuse it for all requests. A client keeps HTTP connections open so that it can reuse them, and it caches its access token.

> [tab] Python
>
> `HiddenLayer` is a context manager. Use a `with` block, or call `close()` when you are finished, to close the client's connections:
>
> ```python theme={null}
> from hiddenlayer import HiddenLayer
>
> with HiddenLayer() as client:
>     page = client.scans.jobs.list(limit=10)
>     for scan in page.items or []:
>         print(scan.scan_id, scan.status)
> ```
>
> A closed client can't send requests. If you pass your own `httpx.Client` as `httpx_client`, the SDK never closes it, so close it yourself.
>
> For `AsyncHiddenLayer`, see [Async client](#async-client).

> [tab] TypeScript
>
> The client has no `close()` method and needs no cleanup. Node.js manages the connections that `fetch` opens.

> [tab] Java
>
> `HiddenLayerClient` and `AsyncHiddenLayerClient` implement `AutoCloseable`. Call `close()` when you are finished, or use try-with-resources, to release the client's connection pool:
>
> ```java theme={null}
> import com.hiddenlayer.api.HiddenLayerClient;
> import com.hiddenlayer.api.HiddenLayerClientBuilder;
>
> try (HiddenLayerClient client = new HiddenLayerClientBuilder().build()) {
>     // Use the client.
> }
> ```
>
> Always close an `AsyncHiddenLayerClient`. Its model scanner runs on threads of its own, which keep the JVM running until `close()` stops them.

## Async client

> [tab] Python
>
> `AsyncHiddenLayer` accepts the same arguments and reads the same environment variables as `HiddenLayer`. Await each method call.
>
> ```python theme={null}
> import asyncio
>
> from hiddenlayer import (
>     AsyncHiddenLayer,
>     CanonicalInteraction,
>     CanonicalInteractionMessage,
>     ContentPart_Text,
>     InteractionEvaluationRequestMetadata,
> )
>
>
> async def main() -> None:
>     client = AsyncHiddenLayer(environment="prod-us")
>     result = await client.runtime.evaluate_interaction(
>         metadata=InteractionEvaluationRequestMetadata(model="gpt-4o", provider="openai", requester_id="user-1234"),
>         interaction=CanonicalInteraction(
>             messages=[
>                 CanonicalInteractionMessage(role="user", content=[ContentPart_Text(text="Hello")])
>             ]
>         ),
>     )
>     print(result.outcome.action)
>
>
> asyncio.run(main())
> ```
>
> If the `aiohttp` extra is installed (`python -m pip install "hiddenlayer-sdk[aiohttp]"`), `AsyncHiddenLayer` sends its requests with `aiohttp` automatically.
>
> To close the client's connections when you are done, use `async with`, or call `await client.aclose()`. With the `aiohttp` extra installed, this also avoids aiohttp's `Unclosed connector` warning when your program exits.
>
> ```python theme={null}
> import asyncio
>
> from hiddenlayer import (
>     AsyncHiddenLayer,
>     CanonicalInteraction,
>     CanonicalInteractionMessage,
>     ContentPart_Text,
>     InteractionEvaluationRequestMetadata,
> )
>
>
> async def main() -> None:
>     async with AsyncHiddenLayer() as client:
>         result = await client.runtime.evaluate_interaction(
>             metadata=InteractionEvaluationRequestMetadata(model="gpt-4o", provider="openai", requester_id="user-1234"),
>             interaction=CanonicalInteraction(
>                 messages=[
>                     CanonicalInteractionMessage(role="user", content=[ContentPart_Text(text="Hello")])
>                 ]
>             ),
>         )
>         print(result.outcome.action)
>
>
> asyncio.run(main())
> ```
>
> If you pass your own `httpx.AsyncClient` as `httpx_client`, the SDK never closes it, so close it yourself. To send requests with `aiohttp` through a client of your own, pass an `HttpxAiohttpClient` from the `httpx_aiohttp` package, which the extra installs.
>
> To supply a rotating token without blocking the event loop, pass `async_token`, an async function that returns the current token:
>
> ```python theme={null}
> import asyncio
>
> from hiddenlayer import AsyncHiddenLayer
>
>
> async def fetch_token() -> str:
>     # Fetch the current token from your secret store without blocking the event loop.
>     await asyncio.sleep(0)
>     return "token-from-your-secret-store"
>
>
> client = AsyncHiddenLayer(async_token=fetch_token)
> ```

> [tab] TypeScript
>
> The TypeScript client is asynchronous. Every method returns a promise, so `await` each call or chain it with `.then()`. There is no separate async client.

> [tab] Java
>
> `AsyncHiddenLayerClient` has the same methods as `HiddenLayerClient`, and each returns a `CompletableFuture`. Build it with `AsyncHiddenLayerClientBuilder`, which takes the same options and reads the same environment variables. Close it when you are done.
>
> ```java theme={null}
> import com.hiddenlayer.api.AsyncHiddenLayerClient;
> import com.hiddenlayer.api.AsyncHiddenLayerClientBuilder;
> import com.hiddenlayer.api.resources.runtime.requests.InteractionEvaluationRequest;
> import com.hiddenlayer.api.resources.runtime.types.InteractionEvaluationRequestInteraction;
> import com.hiddenlayer.api.types.CanonicalInteraction;
> import com.hiddenlayer.api.types.CanonicalInteractionMessage;
> import com.hiddenlayer.api.types.ContentPart;
> import com.hiddenlayer.api.types.InteractionEvaluationRequestMetadata;
> import com.hiddenlayer.api.types.TextPart;
>
> try (AsyncHiddenLayerClient client = new AsyncHiddenLayerClientBuilder().build()) {
>     client.runtime()
>         .evaluateInteraction(InteractionEvaluationRequest.builder()
>             .metadata(InteractionEvaluationRequestMetadata.builder()
>                 .model("gpt-4o")
>                 .requesterId("user-1234")
>                 .provider("openai")
>                 .build())
>             .interaction(InteractionEvaluationRequestInteraction.of(CanonicalInteraction.builder()
>                 .addMessages(CanonicalInteractionMessage.builder()
>                     .role("user")
>                     .addContent(ContentPart.text(TextPart.builder().text("Hello").build()))
>                     .build())
>                 .build()))
>             .build())
>         .thenAccept(result -> System.out.println(result.getOutcome().getAction()))
>         .join();
> }
> ```
>
> When a call fails, the future completes exceptionally. `join()` throws a `CompletionException` whose cause is the SDK's error, such as a `HiddenLayerApiException`.

## Method reference and migration guides

Each SDK's repository has a `reference.md` that lists every resource, method, and parameter, and a breaking-changes guide for the move from Python 3.x, TypeScript 3.x, or Java 2.x. If you are upgrading from one of those versions, read the guide first: client options, error types, and type names changed. For the changes in later releases, see [Version compatibility and upgrades](https://docs.hiddenlayer.ai/docs/integrations/sdk/versioning.md#upgrade-notes).

| SDK | Method reference | Breaking changes |
| - | - | - |
| Python | [reference.md](https://github.com/hiddenlayerai/hiddenlayer-sdk-python/blob/main/reference.md) | [3.x to 4.0.0](https://github.com/hiddenlayerai/hiddenlayer-sdk-python/blob/main/docs/BREAKING_CHANGES_v4.0.0.md) |
| TypeScript | [reference.md](https://github.com/hiddenlayerai/hiddenlayer-sdk-typescript/blob/main/reference.md) | [3.x to 4.0.0](https://github.com/hiddenlayerai/hiddenlayer-sdk-typescript/blob/main/docs/BREAKING_CHANGES_v4.0.0.md) |
| Java | [reference.md](https://github.com/hiddenlayerai/hiddenlayer-sdk-java/blob/main/reference.md) | [2.x to 3.0.0](https://github.com/hiddenlayerai/hiddenlayer-sdk-java/blob/main/docs/BREAKING_CHANGES_v3.0.0.md) |

## Next step

> [card] [Quickstart](https://docs.hiddenlayer.ai/docs/integrations/sdk/quickstart.md)
>
> Make your first authenticated API call.
