OpenFDA Query Builder
Test your OpenFDA API queries before implementing them in your code. This tool helps you construct valid queries using Elasticsearch syntax described in the article.
What OpenFDA and FAERS Actually Are
OpenFDA is a free, government-run API that gives developers and researchers direct access to FDA public data, including the FDA Adverse Event Reporting System (FAERS). It was launched in 2014 to make complex safety data easy to use - no more downloading massive XML files or wrestling with outdated formats. OpenFDA doesn’t collect new data. Instead, it takes the raw reports submitted to FAERS, cleans them up, and serves them as clean, searchable JSON over the internet.
FAERS is the real-world database where doctors, patients, and drug companies report side effects from medications, vaccines, and medical devices. Every report includes details like the drug name, the adverse event (like liver damage or dizziness), patient age, gender, and outcome (recovered, hospitalized, died). But without OpenFDA, you’d need to manually download these reports as huge, unstructured files - a nightmare for anyone trying to find patterns.
OpenFDA turns FAERS from a paper archive into a live tool. You can now ask questions like: "How many people reported seizures after taking this antidepressant?" or "Which drug has the most reports of heart palpitations in people over 65?" - and get answers in seconds.
Why This Matters for Researchers and Developers
Before OpenFDA, finding side effect trends took weeks. Researchers had to request data manually, clean it themselves, and often hit dead ends because the data wasn’t standardized. Now, with OpenFDA, you can run queries in minutes.
For example, a team at a university used OpenFDA to spot a spike in kidney injury reports linked to a common painkiller. They published their findings, which led the FDA to update its safety warning - all because they could pull and analyze data fast.
OpenFDA isn’t just for scientists. Developers have built apps that help patients check side effect risks before starting a new medication. One tool, MedWatcher, uses OpenFDA data to show users real-time reports about drugs they’re taking. These tools don’t replace doctors - they just give people better information to talk to them.
How to Access the Data: The OpenFDA API Endpoints
OpenFDA doesn’t have one big database. It’s split into endpoints - each one gives you a different kind of data. For side effect reports, you use the drug/events endpoint. That’s where all the FAERS drug reports live.
Here are the main endpoints you’ll work with:
drug/events- drug side effect reports (this is the one you’ll use most)device/events- reports about medical device problemsfood/enforcement- food safety recallsndc- National Drug Code directory (for identifying medications)
Each endpoint works the same way: you send a search query, and OpenFDA returns JSON. No login needed for basic use, but you’ll want to register for an API key to avoid hitting limits.
How to Build a Query: Elasticsearch Syntax Made Simple
OpenFDA uses Elasticsearch for searching - which sounds technical, but it’s just a way to ask precise questions. You don’t need to be a programmer to get started.
Here’s the basic format:
https://api.fda.gov/drug/event.json?search=openfda.generic_name:"ibuprofen"
This query asks: "Show me all drug event reports where the generic name is ibuprofen."
You can add filters:
&limit=100- return only 100 results (max is 1,000 per call)&skip=100- skip the first 100 to get the next batch (for pagination)&search=patient.drug.openfda.generic_name:"ibuprofen" AND patient.reaction.reactionmeddrapt:"dizziness"- find reports where ibuprofen caused dizziness
Common search fields:
openfda.generic_name- the generic drug name (e.g., "sertraline")patient.reaction.reactionmeddrapt- the side effect term (using standardized MedDRA codes)patient.patientsex- "1" for male, "2" for femalepatient.age- patient’s age in years
Pro tip: Use quotes around drug names and reaction terms. No quotes = partial matches that might give you wrong results.
API Limits and How to Get an API Key
OpenFDA is free, but it’s not unlimited. Without a key, you’re capped at 1,000 requests per day. That sounds like a lot - until you’re running 50 queries an hour for research.
Registering for an API key bumps you up to 120,000 requests per day and 240 per minute. That’s enough for serious work.
To get your key:
- Go to open.fda.gov/apis/authentication/
- Enter your email and accept the terms
- You’ll get a key via email - copy it
- Add it to your requests:
&api_key=yourkeyhere
Example with key:
https://api.fda.gov/drug/event.json?search=openfda.generic_name:"metformin"&limit=50&api_key=yourkeyhere
Most developers use tools like Python, R, or Postman to handle this automatically. The R package openFDA even has a built-in function to store your key so you don’t have to type it every time.
What You Can and Can’t Do With This Data
OpenFDA is powerful - but it’s not perfect. Here’s what you need to know:
- It shows reports, not proven causes. Just because 50 people reported headaches after taking a drug doesn’t mean the drug caused them. The report could be from someone who had a migraine anyway.
- Data is delayed. Reports take 3-6 months to show up in OpenFDA. You’re not seeing real-time alerts.
- No personal info. Names, addresses, medical records - all removed. You can’t track individuals.
- No clinical context. You won’t know if the patient had other illnesses, took other drugs, or was hospitalized.
The FDA is clear: "Do not rely on openFDA to make decisions regarding medical care." This data is for research, awareness, and spotting trends - not for diagnosing or treating patients.
Real-World Use Cases and Tools Built on OpenFDA
People are already using OpenFDA in smart ways:
- Academic research: Over 350 studies used OpenFDA data in 2022 alone - from tracking rare side effects in elderly patients to comparing safety profiles of similar drugs.
- Consumer apps: Tools like MedWatcher and DrugSafety.org use OpenFDA to show users how often others reported side effects for their prescriptions.
- Public health alerts: When a new diabetes drug had a spike in pancreatitis reports, researchers used OpenFDA to confirm the trend within weeks - faster than traditional surveillance.
Even small developers have built simple web tools. One person made a side-by-side comparison tool for two antidepressants - showing users which had more reports of weight gain or insomnia. It’s not medical advice, but it helps people ask better questions at their doctor’s office.
Common Mistakes and How to Avoid Them
Most people run into the same problems:
- Using brand names instead of generic names. Searching for "Zoloft" won’t work. Use "sertraline".
- Forgetting to encode special characters. If your query has a quote or ampersand, it breaks. Use URL encoding or a library that handles it.
- Ignoring rate limits. If you get a 429 error, you’ve hit the limit. Wait or get an API key.
- Assuming correlation = causation. Always check if the report mentions other drugs, pre-existing conditions, or timing.
Test your queries in the browser first. OpenFDA’s website has a search box you can use to try syntax before writing code.
What’s Next for OpenFDA
The FDA is still improving OpenFDA. Recent updates have focused on speeding up data processing and expanding device reports. The goal is to cut the 3-6 month delay down to under 90 days.
Future plans include better search tools, more detailed patient demographics (without breaking privacy), and expanded data from tobacco and food safety reports. The platform is open-source, so developers can suggest improvements on GitHub - and some have already contributed documentation fixes and code examples.
As more researchers and developers use it, OpenFDA becomes more valuable. It’s not just a database - it’s a public health tool that’s getting smarter every year.
Frequently Asked Questions
Is OpenFDA the same as FAERS?
No. FAERS is the raw database where side effect reports are stored. OpenFDA is the API that makes FAERS data easy to search and use. Think of FAERS as the library and OpenFDA as the online catalog you can search from your phone.
Can I use OpenFDA to report a side effect?
No. OpenFDA is for accessing existing reports, not submitting new ones. To report a side effect, use the FDA’s MedWatch portal at fda.gov/medwatch. OpenFDA only shows reports that have already been submitted and processed.
Why do some drugs have more reports than others?
More reports usually mean the drug is used by more people - not that it’s more dangerous. For example, ibuprofen has thousands of reports because millions take it daily. A rare cancer drug might have only 20 reports, but that doesn’t mean it’s safer - just that fewer people take it.
Do I need to be a coder to use OpenFDA?
Not necessarily. You can test queries directly in your browser. But to use it regularly - like pulling data for a project or building a tool - you’ll need basic programming skills in Python, R, or JavaScript. There are also R packages and Python libraries that simplify the process.
Is OpenFDA data reliable?
It’s reliable as a source of reports, but not as proof of cause. The FDA verifies reports are submitted properly, but they don’t confirm if the drug actually caused the side effect. Many reports are incomplete or vague. Use OpenFDA to spot patterns - then dig deeper with clinical studies.
Medications