On our normal North American departures, the flap retraction cycle starts in the third segment climb, usually at 1,000' AAL (above airport level) depending on climb segment obstacle clearance limits. In Europe and under some other noise abatement restrictions, flap retraction is delayed until above 3,000' AAL.
Flap retraction delays may also occur if a minimum radius turn is required in the DP (departure procedure, formerly known as SID [standard instrument departure]). Lower speed means tighter turn.
You might want to check out the Tech Forum if you have other questions like this!