> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://hiddenlayer.ferndocs.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://hiddenlayer.ferndocs.com/_mcp/server.

# Interactions

POST https://api.hiddenlayer.ai/detection/v1/interactions
Content-Type: application/json

Performs a detailed security analysis of the input and/or output of LLM interactions.

Reference: https://hiddenlayer.ferndocs.com/api-reference/llm-proxy-api/interactions/analyze

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Servers

- `https://api.hiddenlayer.ai` (ProdUs, default)
- `https://api.eu.hiddenlayer.ai` (ProdEu)

## Request

### Headers

- `HL-Project-Id` (string, optional) — The ID or alias for the Project to govern the request processing.

### Body (application/json)

This endpoint expects an InteractionsRequest.

- `metadata` (InteractionsMetadata, required)
- `input` (InteractionsInput, optional)
- `output` (InteractionsOutput, optional)

## Response

### 200

Successful Response

- `metadata` (EnrichedMetadata, required)
- `analysis` (list of EnrichedAnalysis, required)
- `analyzed_data` (EnrichedAnalyzedData, required) — The language model input and/or output that was analyzed.
- `modified_data` (EnrichedModifiedData, required) — The potentially modified language model input and output after applying any redactions or modifications based on the analysis.
- `evaluation` (EnrichedEvaluation, optional) — The evaluation of the analysis results.

## Errors

### 422 Unprocessable Entity Error

Validation Error

- `detail` (list of ValidationError, optional)

## Types

### InteractionsMetadata

- `model` (string, required) — The language model for the interactions.
- `requester_id` (string, required) — The identifier for the entity making the interactions.
- `provider` (string, optional) — The provider of the language model.

### InteractionsInput

- `messages` (list of InteractionsTextContent, optional) — The list of messages as input to a language model.

### InteractionsOutput

- `messages` (list of InteractionsTextContent, optional) — The list of messages as output from a language model.

### EnrichedMetadata

- `provider` (string, required) — The provider of the language model from the request.
- `model` (string, required) — The language model from the request.
- `requester_id` (string, required) — The identifier for the entity from the request.
- `project` (Project, required)
- `processing_time_ms` (double, required) — The total time taken to perform the analysis.
- `event_id` (string, optional) — The unique identifier for the analysis event.
- `analyzed_at` (datetime, optional) — The timestamp when the analysis was performed.

### EnrichedAnalysis

- `name` (string, required) — The name of the analysis performed.
- `phase` (string, required) — The phase of the analysis (i.e. input or output).
- `version` (string, required) — The version of the analysis performed.
- `detected` (boolean, required) — Indicates the analysis resulted in a detection.
- `configuration` (EnrichedAnalysisConfiguration, required) — The configuration settings used for the analyzer.
- `findings` (EnrichedAnalysisFindings, required) — The frameworks and associated findings for the analysis.
- `processing_time_ms` (double, required) — The time taken to perform this specific analysis.
- `id` (string, required) — The unique identifier for the analyzer.

### EnrichedAnalyzedData

The language model input and/or output that was analyzed.

- `input` (InteractionsInput, required)
- `output` (InteractionsOutput, optional)

### EnrichedModifiedData

The potentially modified language model input and output after applying any redactions or modifications based on the analysis.

- `input` (InteractionsInput, required)
- `output` (InteractionsOutput, required)

### EnrichedEvaluation

The evaluation of the analysis results.

- `action` (enum, required, default: Allow) — The action based on interaction analysis and configured tenant security rules.
  - Allowed values: `Allow`, `Alert`, `Redact`, `Block`
- `has_detections` (boolean, required, default: false) — Indicates if any detections were found during the analysis.
- `threat_level` (enum, required, default: None) — The threat level based on interaction analysis and configured tenant security rules.
  - Allowed values: `None`, `Low`, `Medium`, `High`, `Critical`

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)

### InteractionsTextContent

- `content` (string, required) — The textual content of the message.
- `role` (string, optional) — The role of the message sender (e.g., user, assistant, system).

### Project

- `project_id` (string, optional) — The unique identifier for the Project.
- `project_alias` (string, optional) — A custom alias for the Project.
- `ruleset_id` (string, optional) — The unique identifier for the Ruleset associated with the Project.

### EnrichedAnalysisConfiguration

The configuration settings used for the analyzer.

### EnrichedAnalysisFindings

The frameworks and associated findings for the analysis.

- `frameworks` (map from string to list of FrameworkItem, required) — The taxonomies for the detections.

### ValidationErrorLocItems

### FrameworkItem

- `name` (string, required) — Name of the framework taxonomy item.
- `label` (string, required) — Unique identifier for the framework taxonomy item.

## Examples

**Request**

```json
{
  "metadata": {
    "model": "gpt-5",
    "requester_id": "user-1234",
    "provider": "openai"
  }
}
```

**Response**

```json
{
  "metadata": {
    "provider": "openai",
    "model": "gpt-5",
    "requester_id": "user-1234",
    "project": {
      "project_id": "ca87b009-90bd-4724-91c2-f23326acd51a",
      "project_alias": "enterprise-search",
      "ruleset_id": "b5d7d261-b7be-451a-b943-0d408ab88aab"
    },
    "processing_time_ms": 15.34,
    "event_id": "d290f1ee-6c54-4b01-90e6-d701748f0851",
    "analyzed_at": "2023-10-10T14:48:00.000Z"
  },
  "analysis": [
    {
      "name": "string",
      "phase": "string",
      "version": "string",
      "detected": true,
      "configuration": {},
      "findings": {
        "frameworks": {}
      },
      "processing_time_ms": 1.1,
      "id": "string"
    }
  ],
  "analyzed_data": {
    "input": {
      "messages": [
        {
          "content": "What the largest moon of jupiter?",
          "role": "user"
        }
      ]
    },
    "output": {
      "messages": [
        {
          "content": "The largest moon of Jupiter is Ganymede.",
          "role": "assistant"
        }
      ]
    }
  },
  "modified_data": {
    "input": {
      "messages": [
        {
          "content": "What the largest moon of jupiter?",
          "role": "user"
        }
      ]
    },
    "output": {
      "messages": [
        {
          "content": "The largest moon of Jupiter is Ganymede.",
          "role": "assistant"
        }
      ]
    }
  },
  "evaluation": {
    "action": "Allow",
    "has_detections": false,
    "threat_level": "None"
  }
}
```

**SDK Code**

```python
import requests

url = "https://api.hiddenlayer.ai/detection/v1/interactions"

payload = { "metadata": {
        "model": "gpt-5",
        "requester_id": "user-1234",
        "provider": "openai"
    } }
headers = {
    "HL-Project-Id": "internal-search-chatbot",
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.hiddenlayer.ai/detection/v1/interactions';
const options = {
  method: 'POST',
  headers: {
    'HL-Project-Id': 'internal-search-chatbot',
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/json'
  },
  body: '{"metadata":{"model":"gpt-5","requester_id":"user-1234","provider":"openai"}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.hiddenlayer.ai/detection/v1/interactions"

	payload := strings.NewReader("{\n  \"metadata\": {\n    \"model\": \"gpt-5\",\n    \"requester_id\": \"user-1234\",\n    \"provider\": \"openai\"\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("HL-Project-Id", "internal-search-chatbot")
	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.hiddenlayer.ai/detection/v1/interactions")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["HL-Project-Id"] = 'internal-search-chatbot'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"metadata\": {\n    \"model\": \"gpt-5\",\n    \"requester_id\": \"user-1234\",\n    \"provider\": \"openai\"\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.hiddenlayer.ai/detection/v1/interactions")
  .header("HL-Project-Id", "internal-search-chatbot")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"metadata\": {\n    \"model\": \"gpt-5\",\n    \"requester_id\": \"user-1234\",\n    \"provider\": \"openai\"\n  }\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.hiddenlayer.ai/detection/v1/interactions', [
  'body' => '{
  "metadata": {
    "model": "gpt-5",
    "requester_id": "user-1234",
    "provider": "openai"
  }
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
    'HL-Project-Id' => 'internal-search-chatbot',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.hiddenlayer.ai/detection/v1/interactions");
var request = new RestRequest(Method.POST);
request.AddHeader("HL-Project-Id", "internal-search-chatbot");
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"metadata\": {\n    \"model\": \"gpt-5\",\n    \"requester_id\": \"user-1234\",\n    \"provider\": \"openai\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "HL-Project-Id": "internal-search-chatbot",
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["metadata": [
    "model": "gpt-5",
    "requester_id": "user-1234",
    "provider": "openai"
  ]] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.hiddenlayer.ai/detection/v1/interactions")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```