Normally, if you want a court to appoint a lawyer for you at government expense, you must:
Typically, your first opportunity to ask the court to appoint a lawyer for you will be at your first court appearance, normally called your arraignment or bail hearing. The judge will probably ask you whether you are represented by a lawyer. If you're not, the judge will then ask whether you want to apply for court-appointed counsel. If you say yes, some courts will appoint a lawyer right on the spot and finish your arraignment. Other courts will delay your case and appoint a lawyer only after reviewing and approving your economic circumstances.
Each state (or even county) makes its own rules as to who qualifies for a free lawyer. However, as a general rule, if you are judged to be indigent, and there is actual risk of a jail or prison sentence, the court must appoint free legal counsel.
If you don't qualify for free help but can't afford the full cost of a private lawyer, you may still obtain the services of a court-appointed attorney. Most states provide for "partial indigency," which means that, at the conclusion of the case, the judge will require you to reimburse the state or county for a portion of the costs of representation.