credit-pack hint: patch budget-exceeded message at BUILD time (runtime rootfs is read-only; boot-time patch crashed startup)

This commit is contained in:
Inferencebot committed 2026-10-06 14:24:55 -06:00
1 parent 91aa0e0b1d
commit 5389d9acfc
3 files changed
+69 -38

No files matched your search

-38
View File
@@ -172,42 +172,4 @@ echo "Tinfoil proxy PID: $TINFOIL_PROXY_PID"
# Give the proxy a moment to verify the enclave attestation
sleep 3
# Append a co-op-specific hint to LiteLLM's budget-exceeded messages so a
# member who hits their limit is told they can top up with a credit pack.
# LiteLLM hardcodes these strings in
# litellm/proxy/auth/auth_checks.py (not configurable via env/settings), so we
# patch the running copy at boot. Idempotent (checks a marker first) and
# re-applied every start, so it survives upstream file moves on version bumps
# — unlike the old build-time `RUN sed` CORS patch, which broke silently when
# LiteLLM relocated the file.
CREDIT_PACK_HINT='. You can add credit packs at https://opencollective.com/inference-cooperative'
AUTH_CHECKS_PY="$(python3 -c 'import litellm.proxy.auth.auth_checks as m; print(m.__file__)')"
if [ -n "$AUTH_CHECKS_PY" ] && ! grep -q "opencollective.com/inference-cooperative" "$AUTH_CHECKS_PY" 2>/dev/null; then
echo "Patching budget-exceeded messages with credit-pack hint..."
python3 - "$AUTH_CHECKS_PY" <<'PYEOF'
import sys
p = sys.argv[1]
s = open(p).read()
hint = ". You can add credit packs at https://opencollective.com/inference-cooperative"
before = s
# Team budget message (the one that fires for members, enforced at team level)
s = s.replace(
'message=f"Budget has been exceeded! Team={team_object.team_id} Current cost: {spend}, Max budget: {team_object.max_budget}"',
'message=f"Budget has been exceeded! Team={team_object.team_id} Current cost: {spend}, Max budget: {team_object.max_budget}" + "' + hint.replace('"', '\\"') + '"',
)
# Key budget message (a few keys carry individual max_budget)
s = s.replace(
'message=f"Budget has been exceeded! Key={key_descriptor} Current cost: {spend}, Max budget: {valid_token.max_budget}"',
'message=f"Budget has been exceeded! Key={key_descriptor} Current cost: {spend}, Max budget: {valid_token.max_budget}" + "' + hint.replace('"', '\\"') + '"',
)
if s != before:
open(p, "w").write(s)
print("patched")
else:
print("no match (upstream message format changed) — leaving unpatched")
PYEOF
else
echo "Budget-exceeded hint already applied (or auth_checks.py not found); skipping."
fi
exec litellm --config "$CONFIG_FILE" --port 4000 --host 0.0.0.0