> For the complete documentation index, see [llms.txt](https://neuraldefend.gitbook.io/neural-defend/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://neuraldefend.gitbook.io/neural-defend/api-scripting-and-consumption.md).

# API Scripting & Consumption

## Neural Defend API - Upload Examples

### 🖼️ Image Detection API

#### 🔐 Upload to Image Detection API

📂 **Endpoint**

```
https://deepscan.neuraldefend.com/detect/image
```

#### 🐚 Shell (cURL)

📤 **Image Upload**

```bash
curl -X POST "https://deepscan.neuraldefend.com/detect/image" \
  -H "x-api-key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
  -F "file=@C:/Users/asus/Videos/Demo/tony.png"
```

#### 🐍 Python (using requests)

📤 **Image Upload**

```python
import requests

url = "https://deepscan.neuraldefend.com/detect/image"
headers = {
    'x-api-key': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
}
files = {
    'file': ('tony.png', open('C:/Users/asus/Videos/Demo/tony.png', 'rb'), 'image/png')
}

response = requests.post(url, headers=headers, files=files)
print(response.text)
```

#### 🌐 JavaScript (Fetch API with HTML input)

📤 **Upload (Image)**

```html
<input type="file" id="imageInput" accept="image/*" />
<button onclick="uploadImage()">Upload Image</button>

<script>
async function uploadImage() {
    const fileInput = document.getElementById('imageInput');
    const file = fileInput.files[0];

    const formData = new FormData();
    formData.append('file', file);

    const response = await fetch('https://deepscan.neuraldefend.com/detect/image', {
        method: 'POST',
        headers: {
            'x-api-key': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
        },
        body: formData
    });

    const result = await response.json();
    console.log(result);
}
</script>
```

***

### 🎥 Video Detection API

#### 🔐 Upload to Video Detection API

📂 **Endpoint**

```
https://deepscan.neuraldefend.com/detect/video
```

#### 🐚 Shell (cURL)

📤 **Video Upload**

```bash
curl -X POST "https://deepscan.neuraldefend.com/detect/video" \
  -H "x-api-key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
  -F "file=@C:/Users/asus/Videos/Demo/test_video.mp4" \
  --max-time 300
```

#### 🐍 Python (using requests)

📤 **Video Upload**

```python
import requests

url = "https://deepscan.neuraldefend.com/detect/video"
headers = {
    'x-api-key': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
}
files = {
    'file': ('test_video.mp4', open('C:/Users/asus/Videos/Demo/test_video.mp4', 'rb'), 'video/mp4')
}

response = requests.post(url, headers=headers, files=files, timeout=300)
print(response.text)
```

#### 🌐 JavaScript (Fetch API with HTML input)

📤 **Upload (Video)**

```html
<input type="file" id="videoInput" accept="video/*" />
<button onclick="uploadVideo()">Upload Video</button>
<div id="videoStatus"></div>

<script>
async function uploadVideo() {
    const fileInput = document.getElementById('videoInput');
    const file = fileInput.files[0];
    const statusDiv = document.getElementById('videoStatus');

    if (!file) {
        statusDiv.innerHTML = 'Please select a video file';
        return;
    }

    statusDiv.innerHTML = 'Uploading and analyzing video... This may take a few minutes.';

    const formData = new FormData();
    formData.append('file', file);

    try {
        const response = await fetch('https://deepscan.neuraldefend.com/detect/video', {
            method: 'POST',
            headers: {
                'x-api-key': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
            },
            body: formData
        });

        const result = await response.json();
        console.log(result);
        statusDiv.innerHTML = 'Analysis complete! Check console for results.';
    } catch (error) {
        statusDiv.innerHTML = 'Error: ' + error.message;
    }
}
</script>
```

***

### 🎵 Audio Detection API

#### 🔐 Upload to Audio Detection API

📂 **Endpoint**

```
https://deepscan.neuraldefend.com/detect/audio
```

#### 🐚 Shell (cURL)

📤 **Audio Upload**

```bash
curl -X POST "https://deepscan.neuraldefend.com/detect/audio" \
  -H "x-api-key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
  -F "file=@C:/Users/asus/Videos/Demo/voice_sample.mp3" \
  --max-time 120
```

#### 🐍 Python (using requests)

📤 **Audio Upload**

```python
import requests

url = "https://deepscan.neuraldefend.com/detect/audio"
headers = {
    'x-api-key': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
}
files = {
    'file': ('voice_sample.mp3', open('C:/Users/asus/Videos/Demo/voice_sample.mp3', 'rb'), 'audio/mpeg')
}

response = requests.post(url, headers=headers, files=files, timeout=120)
print(response.text)
```

#### 🌐 JavaScript (Fetch API with HTML input)

📤 **Upload (Audio)**

```html
<input type="file" id="audioInput" accept="audio/*" />
<button onclick="uploadAudio()">Upload Audio</button>
<div id="audioStatus"></div>

<script>
async function uploadAudio() {
    const fileInput = document.getElementById('audioInput');
    const file = fileInput.files[0];
    const statusDiv = document.getElementById('audioStatus');

    if (!file) {
        statusDiv.innerHTML = 'Please select an audio file';
        return;
    }

    statusDiv.innerHTML = 'Uploading and analyzing audio...';

    const formData = new FormData();
    formData.append('file', file);

    try {
        const response = await fetch('https://deepscan.neuraldefend.com/detect/audio', {
            method: 'POST',
            headers: {
                'x-api-key': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
            },
            body: formData
        });

        const result = await response.json();
        console.log(result);
        statusDiv.innerHTML = 'Analysis complete! Check console for results.';
    } catch (error) {
        statusDiv.innerHTML = 'Error: ' + error.message;
    }
}
</script>
```

***

### 📋 Complete HTML Example (All Media Types)

#### 🌐 Complete Upload Interface

```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Neural Defend API - Media Upload</title>
    <style>
        .container { max-width: 800px; margin: 0 auto; padding: 20px; }
        .upload-section { margin: 20px 0; padding: 20px; border: 1px solid #ddd; border-radius: 8px; }
        .status { margin-top: 10px; padding: 10px; background: #f5f5f5; border-radius: 4px; }
        button { background: #007bff; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer; margin-top: 10px; }
        button:hover { background: #0056b3; }
        input[type="file"] { margin: 10px 0; }
    </style>
</head>
<body>
    <div class="container">
        <h1>Neural Defend API - Media Upload</h1>
        
        <!-- Image Upload Section -->
        <div class="upload-section">
            <h2>🖼️ Image Detection</h2>
            <input type="file" id="imageInput" accept="image/*" />
            <button onclick="uploadImage()">Upload Image</button>
            <div id="imageStatus" class="status"></div>
        </div>

        <!-- Video Upload Section -->
        <div class="upload-section">
            <h2>🎥 Video Detection</h2>
            <input type="file" id="videoInput" accept="video/*" />
            <button onclick="uploadVideo()">Upload Video</button>
            <div id="videoStatus" class="status"></div>
        </div>

        <!-- Audio Upload Section -->
        <div class="upload-section">
            <h2>🎵 Audio Detection</h2>
            <input type="file" id="audioInput" accept="audio/*" />
            <button onclick="uploadAudio()">Upload Audio</button>
            <div id="audioStatus" class="status"></div>
        </div>
    </div>

    <script>
        const API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
        const BASE_URL = 'https://deepscan.neuraldefend.com/detect';

        async function uploadFile(endpoint, fileInputId, statusDivId) {
            const fileInput = document.getElementById(fileInputId);
            const statusDiv = document.getElementById(statusDivId);
            const file = fileInput.files[0];

            if (!file) {
                statusDiv.innerHTML = 'Please select a file';
                return;
            }

            statusDiv.innerHTML = `Uploading and analyzing ${endpoint}... Please wait.`;

            const formData = new FormData();
            formData.append('file', file);

            try {
                const response = await fetch(`${BASE_URL}/${endpoint}`, {
                    method: 'POST',
                    headers: {
                        'x-api-key': API_KEY
                    },
                    body: formData
                });

                const result = await response.json();
                
                if (response.ok) {
                    // Display results based on media type
                    if (endpoint === 'image') {
                        statusDiv.innerHTML = `
                            <strong>Result:</strong> ${result.prediction}<br>
                            <strong>Confidence:</strong> ${result.confidence}<br>
                            <strong>Message:</strong> ${result.message}
                        `;
                    } else if (endpoint === 'video') {
                        statusDiv.innerHTML = `
                            <strong>Video Analysis:</strong> ${result.video_analysis.prediction}<br>
                            <strong>Video Confidence:</strong> ${result.video_analysis.confidence}<br>
                            <strong>Audio Analysis:</strong> ${result.audio_analysis.prediction}<br>
                            <strong>Audio Confidence:</strong> ${result.audio_analysis.confidence}
                        `;
                    } else if (endpoint === 'audio') {
                        statusDiv.innerHTML = `
                            <strong>Result:</strong> ${result.audio_analysis.prediction}<br>
                            <strong>Confidence:</strong> ${result.audio_analysis.confidence}<br>
                            <strong>Message:</strong> ${result.audio_analysis.message}
                        `;
                    }
                } else {
                    statusDiv.innerHTML = `Error: ${result.error || result.message || 'Unknown error'}`;
                }
                
                console.log('Full response:', result);
                
            } catch (error) {
                statusDiv.innerHTML = `Error: ${error.message}`;
                console.error('Upload error:', error);
            }
        }

        function uploadImage() {
            uploadFile('image', 'imageInput', 'imageStatus');
        }

        function uploadVideo() {
            uploadFile('video', 'videoInput', 'videoStatus');
        }

        function uploadAudio() {
            uploadFile('audio', 'audioInput', 'audioStatus');
        }
    </script>
</body>
</html>
```

***

### 📝 Notes

#### **Supported File Formats:**

* **Images:** JPG, JPEG, PNG, BMP, GIF
* **Videos:** MP4, AVI, MOV, MKV, WMV
* **Audio:** MP3, WAV, FLAC, AAC, OGG

#### **API Timeouts:**

* **Image:** \~30 seconds
* **Video:** \~300 seconds (5 minutes)
* **Audio:** \~120 seconds (2 minutes)

#### **File Size Limits:**

* **Image:** 10MB recommended
* **Video:** 100MB maximum
* **Audio:** 50MB maximum

#### **Response Formats:**

* **Image:** `{prediction, confidence, message}`
* **Video:** `{video_analysis: {...}, audio_analysis: {...}}`
* **Audio:** `{audio_analysis: {prediction, confidence, message}}`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://neuraldefend.gitbook.io/neural-defend/api-scripting-and-consumption.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
