Protect your Flask API with Unkey
This simple Flask application demonstrates how to implement API key verification using the Unkey service. The application has both public and protected routes, with the protected route requiring a valid API key.
API ID
.withAuth
withAuth
permission for the role.Clone this repository:
1git clone https://github.com/harshsbhat/unkey-flask.git2cd unkey-flask34
Set up a virtual environment (optional but recommended): :
1python3 -m venv venv # For Linux/macOS2source venv/bin/activate # For Linux/macOS34python -m venv venv # For Windows5venv\Scripts\activate # For Windows6
Set up your environment variables: Create a .env file in the project root and add the following variables. Get the Unkey API ID and Unkey rootkey from unkey dashboard
1UNKEY_API_ID=your_unkey_api_id2UNKEY_ROOT_KEY=your_unkey_root_key
Install the required dependencies
1pip install -r requirements.txt
Run the project:
1python3 src/main.py # For MacOS/Linux23python src/main.py # For windows
http://localhost:3000/public
to access the public route.http://localhost:3000/protected
with an Authorization
header containing your API key.1curl http://127.0.0.1:3000/public
1curl -H "Authorization: Bearer <api_key>" http://localhost:3000/protected
2500 verifications and 100K successful rate‑limited requests per month. No CC required.