Reality Defender Rust SDK
The Reality Defender Rust SDK provides a simple and efficient way to integrate deepfake detection capabilities into your Rust applications.
Features
- Asynchronous API built on Tokio
- Type-safe interfaces with Serde for serialization
- Secure file uploads using presigned URLs
- Comprehensive error handling
- High test coverage
Installation
Add the SDK and Tokio with the full feature set to your Cargo.toml:
Usage
Basic Example
use ;
use env;
async
Processing Multiple Files
use ;
use env;
async
Simplified Detection
use ;
use env;
async
Supported file types and size limits
There is a size limit for each of the supported file types.
| File Type | Extensions | Size Limit (bytes) | Size Limit (MB) |
|---|---|---|---|
| Video | .mp4, .mov | 262,144,000 | 250 MB |
| Image | .jpg, .png, .jpeg, .gif, .webp | 52,428,800 | 50 MB |
| Audio | .flac, .wav, .mp3, .m4a, .aac, .alac, .ogg | 20,971,520 | 20 MB |
| Text | .txt | 5,242,880 | 5 MB |
Supported social media platforms
The Reality Defender API supports analysis of media from the following social media platforms:
- YouTube
- TikTok
Running the Examples
The SDK comes with several examples that demonstrate how to use its features. To run these examples, you need to set your API key as an environment variable:
Then, you can run the examples using Cargo:
# Run the basic example
# Run the batch processing example
# Run the social media example
Required Test Files
To run the examples that require uploading local files successfully, you'll need to add your own image and video files to the files directory:
-
Create an
filesdirectory in the root of the project (if it doesn't already exist): -
Add the following files to this directory:
image1.jpg- Any sample image for testing image analysisimage2.jpg- Another sample imagetest_image.jpg- A third test imagevideo1.mp4- A sample video file for testing video analysis
You can use any JPG files and MP4 videos for testing purposes. The examples are configured to use these specific
filenames from the files directory:
// Using the sample files in your code
let result = client.detect_file.await?;
// For batch processing
let results = client.process_batch.await?;
Note: If you prefer to use different filenames or paths, make sure to update the example code accordingly.
How It Works
The SDK implements the following workflow:
- Authentication: Uses your API key to authenticate all requests to the Reality Defender API.
- File Upload:
- Requests a presigned URL from the Reality Defender API
- Uploads the file directly to the storage provider using the presigned URL
- Returns a request ID for tracking the analysis
- Result Retrieval:
- Polls the API for results using the request ID
- Optionally waits until the analysis is complete
- Returns detailed analysis results including overall and model-specific scores
API Reference
See the documentation for complete API details.
Development
Prerequisites
- Rust 1.56 or later
- Cargo
Setup
- Clone the repository
- Install dependencies:
Running Tests
Running with Coverage