Sounds like the same rate limiting behavior discussed in this earlier API thread — the API allows 60 requests/minute per key, and a script firing requests back to back will hit that ceiling reliably around a few thousand records in. Are you calling the per-contact endpoint, or the bulk endpoint (up to 500 contacts per call)? If it's per-contact, switching to bulk calls, or just adding a short delay between requests, should resolve it.