Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Include the Redis client so RATELIMIT_STORAGE_URI=redis:// works in the standard image, and document a Redis container for exact limits (#484)

Murtaza Nasir3d06a2bfdc1f
diff --git a/config/env.asr.example b/config/env.asr.example
index 13905010..3a9cd234 100644
--- a/config/env.asr.example
+++ b/config/env.asr.example
@@ -409,11 +409,12 @@ MAX_CONCURRENT_UPLOADS=3
# Active API tokens one account may hold; 0 means no limit. Default: 10.
# API_MAX_TOKENS_PER_USER=10
#
-# Shared storage for the rate-limit counters. By default each gunicorn worker
-# (three in the standard image) counts in its own memory, so every limit,
-# login and registration included, allows up to about three times its value.
-# A Redis or Memcached URI makes the limits exact; the image needs the redis
-# or pymemcache Python package for it.
+# Shared storage for the rate-limit counters. By default the counters are kept
+# in the memory of each gunicorn worker (three in the standard image), so each
+# limit, login and registration included, is in effect up to about three times
+# its value. With a Redis or Valkey URI the limits are exact. The image includes
+# the Redis client; the Redis server is run as a separate container. While the
+# server is unreachable, counting falls back to memory.
# RATELIMIT_STORAGE_URI=redis://redis:6379/0
# Set to true only when the text, chat and embedding models all run on machines
diff --git a/config/env.transcription.example b/config/env.transcription.example
index 2919e3fd..7b889035 100644
--- a/config/env.transcription.example
+++ b/config/env.transcription.example
@@ -577,11 +577,12 @@ MAX_CONCURRENT_UPLOADS=3
# Active API tokens one account may hold; 0 means no limit. Default: 10.
# API_MAX_TOKENS_PER_USER=10
#
-# Shared storage for the rate-limit counters. By default each gunicorn worker
-# (three in the standard image) counts in its own memory, so every limit,
-# login and registration included, allows up to about three times its value.
-# A Redis or Memcached URI makes the limits exact; the image needs the redis
-# or pymemcache Python package for it.
+# Shared storage for the rate-limit counters. By default the counters are kept
+# in the memory of each gunicorn worker (three in the standard image), so each
+# limit, login and registration included, is in effect up to about three times
+# its value. With a Redis or Valkey URI the limits are exact. The image includes
+# the Redis client; the Redis server is run as a separate container. While the
+# server is unreachable, counting falls back to memory.
# RATELIMIT_STORAGE_URI=redis://redis:6379/0
# Files one account can send through the phone's share sheet (installed PWA).
diff --git a/config/env.whisper.example b/config/env.whisper.example
index 3b08adc2..a78536bd 100644
--- a/config/env.whisper.example
+++ b/config/env.whisper.example
@@ -405,11 +405,12 @@ MAX_CONCURRENT_UPLOADS=3
# Active API tokens one account may hold; 0 means no limit. Default: 10.
# API_MAX_TOKENS_PER_USER=10
#
-# Shared storage for the rate-limit counters. By default each gunicorn worker
-# (three in the standard image) counts in its own memory, so every limit,
-# login and registration included, allows up to about three times its value.
-# A Redis or Memcached URI makes the limits exact; the image needs the redis
-# or pymemcache Python package for it.
+# Shared storage for the rate-limit counters. By default the counters are kept
+# in the memory of each gunicorn worker (three in the standard image), so each
+# limit, login and registration included, is in effect up to about three times
+# its value. With a Redis or Valkey URI the limits are exact. The image includes
+# the Redis client; the Redis server is run as a separate container. While the
+# server is unreachable, counting falls back to memory.
# RATELIMIT_STORAGE_URI=redis://redis:6379/0
# Set to true only when the text, chat and embedding models all run on machines
diff --git a/config/env.whisperx.example b/config/env.whisperx.example
index 65c345d2..91515289 100644
--- a/config/env.whisperx.example
+++ b/config/env.whisperx.example
@@ -320,11 +320,12 @@ MAX_CONCURRENT_UPLOADS=3
# Active API tokens one account may hold; 0 means no limit. Default: 10.
# API_MAX_TOKENS_PER_USER=10
#
-# Shared storage for the rate-limit counters. By default each gunicorn worker
-# (three in the standard image) counts in its own memory, so every limit,
-# login and registration included, allows up to about three times its value.
-# A Redis or Memcached URI makes the limits exact; the image needs the redis
-# or pymemcache Python package for it.
+# Shared storage for the rate-limit counters. By default the counters are kept
+# in the memory of each gunicorn worker (three in the standard image), so each
+# limit, login and registration included, is in effect up to about three times
+# its value. With a Redis or Valkey URI the limits are exact. The image includes
+# the Redis client; the Redis server is run as a separate container. While the
+# server is unreachable, counting falls back to memory.
# RATELIMIT_STORAGE_URI=redis://redis:6379/0
# Set to true only when the text, chat and embedding models all run on machines
diff --git a/docs/user-guide/api-reference.md b/docs/user-guide/api-reference.md
index 4720e533..e7c57192 100644
--- a/docs/user-guide/api-reference.md
+++ b/docs/user-guide/api-reference.md
@@ -2069,7 +2069,15 @@ A request over a limit gets `429` with a `Retry-After` header in seconds. The bo
Requests from the web interface keep the per-address limits of the application (1000 per hour and 5000 per day). The [ASR Voice Recorder upload](#asr-voice-recorder-upload) carries its token in the form body, so neither limit applies to it; that endpoint keeps its own per-address limit.
-**Several worker processes.** By default each worker process keeps its own counters in memory. The standard image runs three gunicorn workers, so every limit, the login and registration limits included, allows up to about three times its configured value. Set `RATELIMIT_STORAGE_URI` to a shared backend, for example `redis://redis:6379/0` or `memcached://memcached:11211`, to make the limits exact. The standard image does not include the client library for either backend; an image that uses one needs the `redis` or `pymemcache` Python package, and Speakr does not start with a backend URI whose client is missing. While the backend is unreachable, counting falls back to memory in each process.
+**Several worker processes.** By default the counters are kept in the memory of each worker process. The standard image starts three gunicorn workers, so each limit, the login and registration limits included, is in effect up to about three times its configured value. With `RATELIMIT_STORAGE_URI` set to a Redis or Valkey server, the limits are exact. The image includes the Redis client. The server is run as a separate container, for example in the same Docker Compose file as Speakr:
+
+```yaml
+ redis:
+ image: redis:7.4-alpine
+ restart: unless-stopped
+```
+
+with `RATELIMIT_STORAGE_URI=redis://redis:6379/0` in `.env`. The counters need no persistence, so no volume is required. While the server is unreachable, counting falls back to the memory of each process and requests are served as before. A Memcached URI (`memcached://`) is also accepted, in an image with the `pymemcache` package added; Speakr does not start with a backend URI whose client is missing.
---
diff --git a/docs/user-guide/api-tokens.md b/docs/user-guide/api-tokens.md
index 2baa95bb..76bdad39 100644
--- a/docs/user-guide/api-tokens.md
+++ b/docs/user-guide/api-tokens.md
@@ -216,7 +216,7 @@ Administrators set these limits with environment variables:
| `API_MAX_TOKENS_PER_USER` | `10` | Active tokens per account; `0` means no limit. Tokens above a lowered limit keep working. |
| `API_TOKEN_RATE_LIMIT_READ`, `API_TOKEN_RATE_LIMIT_WRITE`, `API_TOKEN_RATE_LIMIT_PROCESS` | `120 per minute`, `30 per minute`, `10 per minute` | Budget of each token, per endpoint. |
| `API_USER_RATE_LIMIT_READ`, `API_USER_RATE_LIMIT_WRITE`, `API_USER_RATE_LIMIT_PROCESS` | Twice the token limit of the same kind | Budget that all tokens of an account share, per endpoint. |
-| `RATELIMIT_STORAGE_URI` | Memory of each worker process | Shared storage for the counters, such as `redis://redis:6379/0`. Without it, each of the three worker processes of the standard image counts separately, so a limit allows up to about three times its value. |
+| `RATELIMIT_STORAGE_URI` | Memory of each worker process | Shared storage for the counters, such as a Redis server at `redis://redis:6379/0` (see [Rate Limits](api-reference.md#rate-limits)). Without it, the counts of the three worker processes of the standard image are kept separately, so each limit is in effect up to about three times its value. |
## Security Best Practices
diff --git a/requirements-embeddings.lock b/requirements-embeddings.lock
index c69614ff..296e00c0 100644
--- a/requirements-embeddings.lock
+++ b/requirements-embeddings.lock
@@ -11,6 +11,10 @@ anyio==4.15.1 \
# httpx
# httpx2
# openai
+async-timeout==5.0.1 ; python_full_version < '3.11.3' \
+ --hash=sha256:39e3809566ff85354557ec2398b55e096c8364bacac9405a7a1fa429e77fe76c \
+ --hash=sha256:d9321a7a3d5a6a5e187e824d2fa0793ce379a202935782d555d6e9d2735677d3
+ # via redis
authlib==1.6.12 \
--hash=sha256:0656d8482f28fc8221929d5f35b2bde5d13e10555ebc06b4561b0d622e83b1bd \
--hash=sha256:e9229ad7fde610b139dd12f5edbe97eab9ee78bfb85691247e767727850b99ab
@@ -1741,6 +1745,10 @@ pyyaml==6.0.3 \
# via
# huggingface-hub
# transformers
+redis==7.4.1 \
+ --hash=sha256:1a1df5067062cf7cbe677994e391f8ee0840f499d370f1a71266e0dd3aa9308e \
+ --hash=sha256:1fa4647af1c5e93a2c685aa248ee44cce092691146d41390518dabe9a99839b0
+ # via limits
regex==2026.9.29 \
--hash=sha256:01000ddf0e3ffef97f2413ceb514f6313040106b6d18a03ee00a4fe35c1eb1db \
--hash=sha256:0166844493626c5015c6088ee15c9ca2fd060ca15b7641d1657da6a58432ae33 \
diff --git a/requirements.lock b/requirements.lock
index a280a4e4..6d8643a6 100644
--- a/requirements.lock
+++ b/requirements.lock
@@ -11,6 +11,10 @@ anyio==4.15.1 \
# httpx
# httpx2
# openai
+async-timeout==5.0.1 ; python_full_version < '3.11.3' \
+ --hash=sha256:39e3809566ff85354557ec2398b55e096c8364bacac9405a7a1fa429e77fe76c \
+ --hash=sha256:d9321a7a3d5a6a5e187e824d2fa0793ce379a202935782d555d6e9d2735677d3
+ # via redis
authlib==1.6.12 \
--hash=sha256:0656d8482f28fc8221929d5f35b2bde5d13e10555ebc06b4561b0d622e83b1bd \
--hash=sha256:e9229ad7fde610b139dd12f5edbe97eab9ee78bfb85691247e767727850b99ab
@@ -1406,6 +1410,10 @@ pytz==2026.5 \
pywebpush==1.14.0 \
--hash=sha256:6c36e1679268219e693ba940db2bf254c240ca02664de102b7269afc3c545731
# via -r requirements.txt
+redis==7.4.1 \
+ --hash=sha256:1a1df5067062cf7cbe677994e391f8ee0840f499d370f1a71266e0dd3aa9308e \
+ --hash=sha256:1fa4647af1c5e93a2c685aa248ee44cce092691146d41390518dabe9a99839b0
+ # via limits
requests==2.34.2 \
--hash=sha256:2a0d60c172f83ac6ab31e4554906c0f3b3588d37b5cb939b1c061f4907e278e0 \
--hash=sha256:f288924cae4e29463698d6d60bc6a4da69c89185ad1e0bcc4104f584e960b9ed
diff --git a/requirements.txt b/requirements.txt
index be4b0be2..30e73933 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -4,7 +4,7 @@ SQLAlchemy>=2.0,<2.1
flask-login==0.6.3
flask-wtf==1.3.0
flask-bcrypt==1.0.1
-Flask-Limiter==4.1.1
+Flask-Limiter[redis]==4.1.1
flask-openapi3>=3.0.0
pydantic>=2.14.1
# authlib 1.7.x ships an OAuth client change that mis-handles the
diff --git a/src/app.py b/src/app.py
index 8e76008b..ce759b61 100644
--- a/src/app.py
+++ b/src/app.py
@@ -586,7 +586,8 @@ bcrypt.init_app(app)
app.config.setdefault("RATELIMIT_HEADERS_ENABLED", True)
# The default in-memory storage counts in each gunicorn worker separately, so
# every limit is in effect multiplied by the number of workers. A shared
-# backend (redis://, memcached://) makes the limits exact (#484).
+# backend (redis:// with the bundled client; memcached:// needs pymemcache)
+# makes the limits exact (#484).
# While that backend is unreachable, counting falls back to memory instead of
# failing the request.
if os.environ.get("RATELIMIT_STORAGE_URI"):