Lakera Guard API

You can interact with the Lakera Guard API through HTTP requests to the available endpoints in any programming language. It is versioned via a URL path parameter, and the current version is v2.

$https://api.lakera.ai/v2

Available Endpoints

Working with the Lakera Guard API is as simple as making an HTTP request to any of the endpoints below:

  • /guard - Request screening for text contents and receive a flagged response if any threats are detected
  • /guard/results - Request detailed results of detectors in order to understand Guard decisions and analyze policy suitability

Additionally SaaS customers can use the following endpoints to manage their security configuration:

Additionally self-hosting customers can use the following endpoints to check their Guard deployment:

More details about each endpoint and any additional request or response parameters are available in the documentation for each endpoint linked above.

Authentication

Self-hosted deployments of the Lakera Guard API do not use authorization so do not need API keys.

The public Lakera Guard SaaS API uses API keys to authenticate requests. You can view and manage your API keys in the API access section of the Lakera platform.

Every API request must include your API key in the Authorization HTTP header:

$Authorization: Bearer $LAKERA_GUARD_API_KEY

API keys are considered secrets. Do not share them with other users or expose them in client-side code.

Making Requests

You can make requests to the Lakera Guard API using any HTTP client.

1import os
2# requests library must be available in current Python environment
3import requests
4
5prompt = "Hello, world!"
6session = requests.Session() # Allows persistent connection
7
8response = session.post(
9 "https://api.lakera.ai/v2/guard",
10 json={"messages": [{"role": "user", "content": prompt}]},
11 headers={"Authorization": f'Bearer {os.getenv("LAKERA_GUARD_API_KEY")}'},
12)
13
14response_json = response.json()
15print(response_json)

Client libraries for Python and JavaScript are coming soon. If you’d like to see other languages supported, please reach out to support@lakera.ai.

SaaS API Regions

The Lakera Guard SaaS API is available in multiple regions around the world. By default, requests to https://api.lakera.ai are sent to the region closest to you.

You can also use a region-specific subdomain:

  • https://us-east-1.api.lakera.ai (North Virginia, USA)
  • https://us-west-2.api.lakera.ai (Oregon, USA)
  • https://eu-west-1.api.lakera.ai (Ireland, EU)
  • https://ap-southeast-1.api.lakera.ai (Singapore, Asia)

Changing the region will affect the latency of your requests. If you’re unsure which region to choose, we recommend using https://api.lakera.ai.

API Responses

The API response will be a JSON object. See the individual endpoint documentation for details.

Developer Info

For relevant endpoints, you can request developer info to use in debugging by adding "dev_info": true to the request. The response will then include a JSON object with information about the build of Lakera Guard that generated the response containing the following properties:

  • git_revision: First 8 characters of the commit hash of the build of Lakera Guard that sent the response
  • git_timestamp: Timestamp of the commit in the ISO 8601 format
  • model_version: The model identifier string of the model type used for analysis. It is currently always lakera-guard-1, but new types of models may be introduced in the future
  • version: The semantic version of Guard used. This tracks both code and detector model training updates