Skip to content

feat(safe): halve API calls and rotate keys#198

Merged
spalen0 merged 1 commit intomainfrom
safe-api-optimization
Mar 31, 2026
Merged

feat(safe): halve API calls and rotate keys#198
spalen0 merged 1 commit intomainfrom
safe-api-optimization

Conversation

@spalen0
Copy link
Copy Markdown
Collaborator

@spalen0 spalen0 commented Mar 31, 2026

Summary

  • Remove redundant get_last_executed_nonce() API call per safe — use cached nonce from file instead (1 call per safe instead of 2)
  • Add round-robin rotation between SAFE_API_KEY and SAFE_API_KEY_2 to distribute quota across two keys
  • Add SAFE_API_KEY_2 to CI workflow and .env.example

Context

Safe is introducing free tier limits: 50k API calls/month and 5 RPS.

Before: 23 safes × 2 calls × 6 runs/hour × 720 hours/month = ~199k calls/month (4x over limit)

After: 23 safes × 1 call × 6 runs/hour × 720 hours/month = ~99k calls/month, split ~50k per key (within limit)

Test plan

  • Verify pending tx detection still works with cached nonce (no regression from removing the executed-tx API call)
  • Verify key rotation works with both keys set
  • Verify fallback works with only SAFE_API_KEY set (no SAFE_API_KEY_2)

🤖 Generated with Claude Code

- Remove redundant get_last_executed_nonce() API call; use cached nonce
  from file instead (1 call per safe instead of 2)
- Add round-robin rotation between SAFE_API_KEY and SAFE_API_KEY_2
- Add SAFE_API_KEY_2 to workflow and .env.example

With 23 safes running every 10 minutes, this drops monthly usage from
~199k to ~99k calls, split ~50k per key (within Safe free tier limit).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@spalen0 spalen0 merged commit b2f1d57 into main Mar 31, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant