Hello and welcome to e health forum.
The causes of hemoptysis (coughing out blood), could be due to a viral or bacteria infection induced pneumonia. Such infections need to be diagnosed and treated early, to prevent more complications.
You may consult with your treating doctor, for proper examination and tests including a X ray of the chest. Treatment with prescription antibiotics and supportive medications will help in early recovery.