Three cups of coffee a day are enough to brew up a migraine, new research suggests.
For those who experience episodic migraine, one to two servings of caffeinated drinks were not associated with headaches on that day.
But three or more were associated with higher odds of migraine headache on the same day, or the following day, the study suggests.
Migraine is a disabling primary headache disorder affecting approximately 1.04 billion adults worldwide.
In addition to severe headache, symptoms of migraine can include nausea, changes in mood, sensitivity to light and sound, as well as visual and auditory hallucinations.
People who suffer from migraine report that weather patterns, sleep disturbances, hormonal changes, stress, medications and certain foods or beverages can bring on migraine attacks.
Lead investigator Elizabeth Mostofsky said: "Based on our study, drinking one or two caffeinated beverages in a day does not appear to be linked to developing a migraine headache, however, three or more servings may be associated with a higher odds of developing a headache."
In a study published in the American Journal of Medicine, researchers at Beth Israel Deaconess Medical Center (BIDMC), Brigham and Women's Hospital and the Harvard T.H. Chan School of Public Health (HSPH) evaluated the role of caffeinated beverages as a potential trigger of migraine.
Dr Mostofsky added: "While some potential triggers - such as lack of sleep - may only increase migraine risk, the role of caffeine is particularly complex, because it may trigger an attack but also helps control symptoms.
"Caffeine's impact depends both on dose and on frequency, but because there have been few prospective studies on the immediate risk of migraine headaches following caffeinated beverage intake, there is limited evidence to formulate dietary recommendations for people with migraines."
In the prospective cohort study, 98 adults with frequent episodic migraine completed electronic diaries every morning and every evening for at least six weeks.
Every day, they reported the total servings of caffeinated coffee, tea, soft and energy drinks they consumed.
They also filled out twice daily headache reports detailing the onset, duration, intensity and medications used for migraines since the previous diary entry.
Participants also detailed information about other common migraine triggers, including medication use, alcoholic beverage intake, activity levels, depressive symptoms, psychological stress, sleep patterns and menstrual cycles.
Scientists used a self-matched analysis, comparing an individual's incidence of migraines on days with caffeinated beverage intake to their incidence of migraines on days when they had no caffeinated drinks.
This eliminated the potential for factors such as sex, age, and other individual demographic, behavioural and environmental factors to confound the data.
The researchers also looked at incidence by day of the week, eliminating weekend versus weekday habits that may also affect migraine occurrence.
One serving of caffeine is typically defined as eight ounces or one cup of caffeinated coffee, six ounces of tea, a 12-ounce can of soft drink and a two-ounce can of an energy drink.
Researchers said those servings contain anything from 25 to 150 milligrams of caffeine, so they cannot quantify the amount that is associated with heightened risk of migraine.
Among people who rarely consumed caffeinated drinks, even one to two servings increased the odds of having a headache that day.
Baseline data indicated that participants typically experienced an average of five headaches per month - and 66 per cent of them usually consumed one to two servings of caffeinated drinks daily.
Some 12 per cent consumed three or more cups.
During the six-week study in 2016-17, participants experienced an average of 8.4 headaches.
All reported having caffeinated beverages on at least one day during the study, with an average of 7.9 servings per week.
Australian Associated Press