Add rate limiting support to API keys

This commit is contained in:
Peter Stockings
2025-12-02 17:02:17 +11:00
parent 814691c235
commit d04b7f2120
5 changed files with 152 additions and 44 deletions

4
app.py
View File

@@ -171,6 +171,10 @@ async def execute_http_function(user_id, function):
api_key = db.get_api_key(api_key_value)
if api_key and api_key['user_id'] == user_id:
# Check rate limit
if not db.check_and_increment_api_key_usage(api_key['id']):
return jsonify({'error': 'Rate limit exceeded'}), 429
# Check Scopes
scopes = api_key['scopes']
if isinstance(scopes, str):