The visa is issued for 30 days and it could be extended, and is valid for 3 months. In order to get a Visa you should refer to your consulate and there is no need for referencing to Iran. But note that the application shouldn’t be outside your country and that would waste your time and to be honest, it takes some time to get an Iranian visa.
As you plan to travel to Iran you should apply for visa a few weeks in advance and depending on your nationality you can contact Iranian embassy to be informed for the exact length of time.
At the end of the trip your visa preparation is by the travel agency. It should also be noted that citizens of six countries can get visa on arrival, these countries are: Macedonia, Bosnia & Herzegovina, Singapore, Slovenia, Saudi Arabia and Turkey.
US citizens must apply in advance for a pre-arranged tour, get a tour guide. Or introduce a relative who can take responsibility, so US citizens cannot travel to Iran individually.
Just make sure that you obtain the necessary information about Persian visa before traveling.