diff --git a/README.md b/README.md index 357c21c..af62af7 100644 --- a/README.md +++ b/README.md @@ -235,10 +235,18 @@ LibreChat (chat) does **not** talk to this gateway directly — it routes throug ## Audio keep-alive -The gateway pings the Tinfoil TTS model every 15 minutes (`audio_keepalive.py`, +The gateway pings the Tinfoil TTS model every 30 minutes (`audio_keepalive.py`, started by the loop in `start.sh`) to keep the TEE audio enclave warm — voice mode then skips the ~24s cold-start after idle. TTS-only: an STT ping would cost -$0.01/request (~$52/mo at 6/hr) versus $0.002 for TTS — about **$0.19/day**. +$0.01/request (~$52/mo at 6/hr) versus $0.002 for TTS — about **$0.096/day +(~$2.88/mo)**. + +The 30-minute interval is measured, not assumed: an idle sweep on 2026-11-28 +(gaps 5–60 min through this gateway) found warm latency (0.38–0.99s) through +45 minutes idle and no cold-start cliff. The earlier 15-minute cadence cost +~$5.76/mo for warmth that was already there; 30 min halves it and stays inside +the proven-warm window. Re-run that sweep if the provider's behaviour changes — +the script and probe notes live in this repo's history. **Billing is the point of the key split.** The ping authenticates with the keepalive team's own key, read from `/app/data/.keepalive_key`: team @@ -257,4 +265,4 @@ the returned key to `/app/data/.keepalive_key`. Verify after deploys: `cloudron exec --app -- python3 /app/code/audio_keepalive.py` exits 0 silently, and a fresh `$0.002` SpendLogs row appears under -`agent:audio-keepalive` within 15 minutes. +`agent:audio-keepalive` within 30 minutes. diff --git a/audio_keepalive.py b/audio_keepalive.py index e1b6cfe..1250c37 100644 --- a/audio_keepalive.py +++ b/audio_keepalive.py @@ -3,7 +3,7 @@ so voice mode doesn't pay the ~24s cold-start after idle. Runs INSIDE the gateway container, invoked by the keep-alive loop in -start.sh (every 15 min; the Cloudron scheduler task was removed +start.sh (every 30 min; the Cloudron scheduler task was removed 2026-11-09 so the loop is the only warm path). TTS-only (STT pings cost $0.01/request each; TTS $0.002 — see docs, keep-alive economics). Silent on success; prints + exits non-zero on failure so keepalive.log captures it. @@ -28,7 +28,7 @@ def _read(path): def warn_once(msg): """keepalive.log must only grow on failures; a standing config warning would - repeat every 15 min. Note it once per container generation instead.""" + repeat every 30 min. Note it once per container generation instead.""" marker = "/app/data/.keepalive_warned" if os.path.exists(marker): return diff --git a/start.sh b/start.sh index c46e3b6..6552d5d 100644 --- a/start.sh +++ b/start.sh @@ -284,18 +284,22 @@ echo "Tinfoil proxy is up on 127.0.0.1:3301" # could not be proven to reach 127.0.0.1:4000 and /app/data, and two warm # paths billed twice for the same ping. The warm path is owned HERE — the # app container, where the network namespace, the master key and the -# sidecar are all proven. Every 15 minutes ping tinfoil/voxtral-tts +# sidecar are all proven. Every 30 minutes ping tinfoil/voxtral-tts # ($0.002/request) so voice mode skips the ~24s Tinfoil cold-start after -# idle. The script uses the keepalive team's key (/app/data/.keepalive_key) -# so the spend bills to agent:audio-keepalive instead of landing in -# SpendLogs with no team. audio_keepalive.py is silent on success and prints -# on failure, so /app/data/keepalive.log only ever grows on failure. +# idle. 30 min (not 15) because a measured idle sweep on 2026-11-28 found +# warm latency through 45 minutes idle — no cold-start cliff — so the +# 15-minute cadence was buying nothing and cost ~$5.76/mo; 30 min halves +# it to ~$2.88/mo while staying inside the proven-warm window. The script +# uses the keepalive team's key (/app/data/.keepalive_key) so the spend +# bills to agent:audio-keepalive instead of landing in SpendLogs with no +# team. audio_keepalive.py is silent on success and prints on failure, so +# /app/data/keepalive.log only ever grows on failure. ( while true; do python3 /app/code/audio_keepalive.py >> /app/data/keepalive.log 2>&1 || true - sleep 900 + sleep 1800 done ) & -echo "Audio keep-alive loop started (every 900s)" +echo "Audio keep-alive loop started (every 1800s)" exec litellm --config "$CONFIG_FILE" --port 4000 --host 0.0.0.0 \ No newline at end of file