Asguard Face is a robust and scalable facial recognition service built with Go. It provides API endpoints for analyzing images, extracting face embeddings, comparing faces, and managing API keys with usage quotas. The service is designed for easy deployment using Docker.
- Face Detection & Embedding Extraction: Analyze images to detect faces and extract unique facial embeddings.
- Face Comparison: Compare a probe image against a reference embedding to determine a match and confidence score.
- Image Quality Checks: Optional quality checks during analysis for sharpness, brightness, and face size ratio.
- API Key Authentication: Secure access to the service using API keys.
- Usage Quotas: Manage and track monthly API usage for different tenants.
- Admin API: Endpoints for creating and managing API keys.
- Containerized Deployment: Easily deployable with Docker and Docker Compose.
- Go: The primary programming language for the service.
- Gin Web Framework: A high-performance HTTP web framework for Go.
- go-face: Go binding for
dlib's face recognition model. - SQLite: Used for persistent storage of API keys and usage data.
- Docker: For containerization and simplified deployment.
The easiest way to get Asguard Face running is by using Docker Compose.
- Docker
- Docker Compose
-
Clone the repository:
git clone https://github.com/your-repo/asguard-face.git cd asguard-face(Note: Replace
https://github.com/your-repo/asguard-face.gitwith the actual repository URL) -
Prepare environment variables: Create a
.envfile in the root directory with the following content:ADMIN_SECRET=your_admin_secret_key_here PORT=8082Replace
your_admin_secret_key_herewith a strong, unique secret for accessing admin functionalities. -
Run with Docker Compose:
docker-compose up --build -d
This will build the Docker image, start the service, and expose it on port
8082(or the port specified in your.envfile).
The Asguard Face service exposes the following API endpoints:
- GET /health
- Description: Checks the health status of the service.
- Response:
{"status": "healthy", "service": "asguard-face", "version": "1.0.0"}
These endpoints require an API key to be provided in the X-API-Key header or as a Bearer token in the Authorization header.
-
POST /v1/analyze
- Description: Analyzes an image to detect faces and extract a 128-dimensional face embedding. Optionally performs quality checks.
- Request Body:
{ "image": "base64_encoded_image_string", "quality_checks": true } - Response:
AnalyzeResponseobject containingembedding,quality_score,sharpness,brightness,face_size_ratio, andwarnings.
-
POST /v1/compare
- Description: Compares a probe image against a provided reference face embedding.
- Request Body:
{ "probe_image": "base64_encoded_image_string", "reference_embedding": [float32, ... (128 dimensions)], "threshold": 0.6 } - Response:
CompareResponseobject indicatingmatch,confidence,distance, andprobe_quality.
These endpoints require the ADMIN_SECRET to be provided in the X-API-Key header.
- POST /admin/keys/create
- Description: Creates a new API key for a tenant with an optional monthly quota.
- Request Body:
{ "name": "Tenant Name", "quota": 10000 } - Response: Object containing
tenantIDand the newly generatedapiKey.
Access to protected API endpoints is controlled via API keys. You can provide your API key in one of two ways:
X-API-KeyHeader: Include your API key directly in theX-API-KeyHTTP header.X-API-Key: your_api_key_hereAuthorizationHeader (Bearer Token): Include your API key as a Bearer token in theAuthorizationHTTP header.Authorization: Bearer your_api_key_here
Admin endpoints require the ADMIN_SECRET (configured via environment variable) to be passed in the X-API-Key header.
The service can be configured using the following environment variables:
ADMIN_SECRET: (Required for admin endpoints) A secret key used to authenticate requests to admin endpoints.PORT: (Optional, default:8082) The port on which the service will listen for incoming requests.MODELS_PATH: (Optional, default:./models) The path to the directory containing thedlibface recognition models. When running with Docker, this is typically/app/models.
(Add contributing guidelines here)
This project is licensed under the MIT License. See the LICENSE file for details.