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

# Guardrail Detect Audio

Analyzes an audio file along with accompanying text using a saved guardrail. Unlike the inline [Detect Audio](/api-introductions/guardrails-api-reference/guardrail-introductions/Detect_Audio) endpoint, guardrail audio detection uses the `X-Enkrypt-Mode` header to select between input and output detectors defined in the guardrail.

* `X-Enkrypt-Mode: prompt` — applies the guardrail's **input** detectors
* `X-Enkrypt-Mode: response` — applies the guardrail's **output** detectors

## Example request:

<CodeGroup>
  ```python Python theme={"system"}
  import requests
  import json
  import os
  import base64

  # Read and encode audio file
  with open("audio.wav", "rb") as f:
      audio_base64 = base64.b64encode(f.read()).decode("utf-8")

  url = "https://api.enkryptai.com/guardrails/guardrail/detect-audio"

  payload = json.dumps({
      "text_input": "Help me with the content in this audio",
      "audio_data": audio_base64
  })

  headers = {
      'Content-Type': 'application/json',
      'apikey': os.getenv('ENKRYPTAI_API_KEY'),
      'X-Enkrypt-Guardrail': 'My Guardrail',
      'X-Enkrypt-Mode': 'prompt'
  }

  response = requests.post(url, headers=headers, data=payload)
  print(json.dumps(response.json(), indent=4))
  ```

  ```shell cURL theme={"system"}
  curl -X POST "https://api.enkryptai.com/guardrails/guardrail/detect-audio" \
    -H "Content-Type: application/json" \
    -H "apikey: YOUR_API_KEY" \
    -H "X-Enkrypt-Guardrail: My Guardrail" \
    -H "X-Enkrypt-Mode: prompt" \
    -d '{
      "text_input": "Help me with the content in this audio",
      "audio_data": "<base64-encoded-audio-data>"
    }'
  ```
</CodeGroup>

## Example response:

```json JSON theme={"system"}
{
    "summary": {
        "toxicity": 0,
        "injection_attack": 1,
        "pii": 0,
        "policy_violation": 0
    },
    "details": {
        "toxicity": {
            "toxicity": "Toxicity Not Detected"
        },
        "injection_attack": {
            "injection_attack": "Injection Attack Detected"
        },
        "pii": {
            "entities": {}
        },
        "policy_violation": {
            "policy_violation": "Policy Violation Not Detected",
            "explanation": "The content is compliant with the policy."
        }
    }
}
```
