# Step 1: Check cost before enriching
count_response = requests.get(
f"{BASE_URL}/public/lead-lists/123/enrichment/count/",
headers={"X-API-Key": API_KEY},
params={"enrichment_type": "FIND_EMAIL"}
)
count_data = count_response.json()
# Step 2: Decide whether to proceed based on cost and available credits
if count_data['has_enough_credits']:
# Step 3: Proceed with enrichment
enrich_response = requests.post(
f"{BASE_URL}/public/lead-lists/123/enrichment/",
headers={"X-API-Key": API_KEY},
json={
"enrichment_type": "FIND_EMAIL",
"prospect_limit": count_data['unenriched_count']
}
)
if enrich_response.json()['success']:
print(f"Enriching {count_data['unenriched_count']} prospects...")
else:
print(f"Need {count_data['total_cost']} credits, but only have {count_data['available_credits']}")
print("Please purchase more credits to continue")