跳到正文

ClinicalTrials.gov API: Python Guide, API Key and Pagination

摘要

SciSpace 发布指南,介绍如何用 Python 调用 ClinicalTrials.gov 官方 REST API 以 JSON 获取试验注册数据。NLM 的公开检索示例不提供 API Key,并将该服务描述为开放获取,但官方材料未给出具体速率限制数值。指南演示用 pageToken 翻页,NLM 记录默认每页 10 条研究,并提醒经典 API 已于 2024 年 6 月 25 日退役。

摘要由模型根据原文撰写,以原文为准。

正文 · 原文

The ClinicalTrials.gov API is an official REST API for retrieving trial-registry data as JSON, as described in NLM's overview. Search the studies endpoint with query.cond for a disease, as shown in NLM's examples; this Python example prints identifiers matching the documented NCT identifier format.

Output:

Tested Oct 22, 2026.

The retry settings are client choices, not a stated server allowance. The identifier scan is a quick response check, not a field-by-field study parser. Every snippet retains respect_retry_after_header=True, including both branches of the pagination script. This setting enables handling of the server's Retry-After header; see the urllib3 Retry reference.

ClinicalTrials.gov API at a glance

ClinicalTrials.gov provides an open-access API for retrieving study data without scraping the website's rendered pages. See NLM's retrieval guidance.

Item

What developers need to know

Base URL

https://clinicaltrials.gov/api/v2, the prefix of NLM's documented single-study request. NLM example

Authentication

NLM describes open access and supplies no credentials in its public retrieval example. NLM guidance

Primary response format

JSON. NLM overview

The API's main strength is direct, structured access to registry records. The NIH directory describes access to "the most recent version"; that statement does not establish historical-version retrieval support.

API key, free access and rate limits

NLM's public retrieval example supplies no API key and describes the service as an "open-access API". See NLM's guidance.

Do I need a ClinicalTrials.gov API key?

No key is supplied in NLM's public retrieval example. Study submission is different: it requires a Protocol Registration System account, as explained by NLM support.

Is the ClinicalTrials.gov API free?

NLM describes open access and demonstrates public retrieval without credentials in its retrieval guidance. The paid scraper discussed below charges for third-party automation, not official ClinicalTrials.gov access. See the Actor listing.

What is the rate limit?

The verified official material does not establish a numeric rate limit; consult the current API reference. Use the retry-enabled session above for throttled responses, respect Retry-After, and stop when retries are exhausted rather than immediately restarting the request. See the Requests retry guidance.

Retrieve records and request additional pages in Python

Retrieve an individual study by supplying its NCT identifier to GET /api/v2/studies/{nctId}, as shown in NLM's retrieval example.

Retrieve and save a study record

An NCT identifier consists of NCT followed by eight digits, according to NLM's identifier guidance. This example validates the identifier, retrieves the documented NCT02993146 record, and saves the complete JSON before selecting nested fields.

Output:

Saving the complete response lets you inspect a record when a downstream parser fails. This example does not assume that a particular nested field is present.

For downstream parsing, the modernization standardized dates using "ISO 8601" and rich-text data using "CommonMark Markdown". See NLM's modernization overview. Treat rich text as formatted content rather than assuming it is plain text.

Request another page with pageToken

NLM documents a default of 10 studies per page and directs developers to pageToken for additional pages in its pagination guidance. Consult the official Studies reference for continuation instructions.

This script downloads one page per run. Leave CTG_PAGE_TOKEN unset for the initial request. Open the saved trials-page.json and copy its nextPageToken string, without the surrounding JSON quotation marks, into CTG_PAGE_TOKEN. Keep query.cond unchanged. Rename the saved file before rerunning to preserve the previous page. The script sends the token as pageToken.

Output:

Each run overwrites trials-page.json. This example retrieves one page at a time; it is not an automatic all-results downloader. The default page size is not a maximum result count.

Python libraries

Requests is a general-purpose Python HTTP client, not a ClinicalTrials.gov-specific SDK. See the Requests documentation.

Library

Install command

When to consider it

Requests

python -m pip install requests

Direct HTTP requests with visible parameters, responses and retry behavior. Documentation

pytrials

pip install pytrials

A third-party wrapper whose changelog records migration to the modern ClinicalTrials API. Check package examples rather than copying classic-API tutorials. Package page

Use Requests when you want to inspect the HTTP exchange directly. Evaluate a wrapper against your required searches and record fields before replacing the direct requests in your application.

Common errors and questions

Fetching ClinicalTrials.gov website HTML is not equivalent to retrieving study data because the modern website is a "Single Page Application (SPA)". See NLM's explanation.

Symptom

Cause

Fix

HTML arrives without the expected study data

The website relies on JavaScript rendering.

Retrieve structured records through the API instead of parsing website HTML. NLM guidance

An older tutorial's endpoint fails

The classic API was retired on June 25, 2024.

Migrate to the modern API rather than patching classic-API requests. Retirement notice

What does the ClinicalTrials.gov API provide?

The NIH directory describes registry metadata, statistics and the most recent versions of clinical-trial records.

Do I need an API key?

NLM's public retrieval example supplies no API key and describes the service as open access. See NLM's guidance.

How do I search clinical trials by disease in Python?

Make a GET request to the studies endpoint with the disease in query.cond, then parse the JSON response. See NLM's search example.

Why does my request return only a small number of trials?

Responses are paginated. NLM directs developers to pageToken when retrieving additional pages in its pagination guidance.

What is the ClinicalTrials.gov API rate limit?

A numeric rate limit is not established by the verified official material used here. Consult the current API reference, and handle throttled responses with retries that respect Retry-After.

Can I download data for large-scale trial analysis?

AACT offers a relational representation of ClinicalTrials.gov data, including full database downloads and cloud querying. Its landing page directs users to create an account for access.

Alternatives: bulk data, literature APIs and scrapers

Choose an alternative for wider registry coverage, bulk analysis or literature evidence. AACT and E-utilities complement the official API; SciSpace widens the search beyond one registry.

Beyond one registry: SciSpace API

The ClinicalTrials.gov API covers ClinicalTrials.gov. Trials registered only in other countries need a separate integration for each registry. The SciSpace Task API searches 11 national and regional clinical-trial registries plus the WHO registry in one task, alongside 280M+ papers.

Option

Strength

Access and billing

ClinicalTrials.gov API

The official, direct source for ClinicalTrials.gov records, as JSON

Free, no key

AACT

ClinicalTrials.gov as a relational database, for cloud queries or full download

Free account required

NCBI E-utilities

The publications linked to a trial, via PubMed's [si] field

Where the official API is the better choice: for complete, current ClinicalTrials.gov records with every field, or a pipeline that must match the registry exactly, use the ClinicalTrials.gov API or AACT directly. SciSpace is for research that crosses registries and literature, not for mirroring one registry.

Bulk registry analysis: AACT

AACT's strength is its relational representation of ClinicalTrials.gov data: "Query in the cloud or download the full database." Its landing page directs users to create an account for cloud credentials and full snapshots.

Choose the official API for direct registry retrieval and AACT when your analysis is better served by a database download or cloud queries.

Official scholarly APIs: NCBI E-utilities

The NCBI developer documentation states, "The E-utilities are the public API to the NCBI Entrez system". They provide access to PubMed, PMC and other Entrez databases, making them complementary publication tools rather than replacements for a trial registry.

For an NCT-to-literature handoff, search PubMed's Secondary Source ID field. NLM's example is "nct00000161 [si]" in its linkage guidance. Use NCBI's E-utilities documentation for publication search and retrieval.

Do not assume a unique paper for each trial: NLM documents that a journal article can mention multiple ClinicalTrials.gov identifiers. Keep registry identifiers and publication identifiers separately in your application, and review the relationship before treating a publication as evidence for a particular trial.

Scraper APIs: a community Apify Actor

The ClinicalTrials.gov Search Scraper by brightpath-data is a community-maintained Apify Actor, not the official registry API. Its genuine distinction is packaged third-party automation; the official API remains the direct route to structured registry records.

The pricing table lists $2.00 per 1,000 study records and an additional $0.0001 per Actor Start event, with platform costs marked "Included". Record count alone therefore does not determine the total charge. Prices as of October 22, 2026. See the pricing page.

Terms and compliance

Open access does not establish a blanket redistribution license: general NLM policy says "NLM cannot guarantee the copyright status".

Before storing or redistributing records, review the applicable terms and rights. Preserve source information in your application, and do not present your integration as endorsed by the registry operator. NLM states: "NLM does not endorse or recommend any commercial products, processes, or services."

A registry listing also does not establish government approval of a study. ClinicalTrials.gov states: "The U.S. government does not review or approve the safety and science of all studies listed on this website."

Prefer the documented API over website scraping for study-data retrieval. NLM's scraping guidance specifically explains why fetching website HTML no longer provides the same access to study data.

From trial records to a trial landscape: the SciSpace API

The ClinicalTrials.gov API answers "what is registered here?" Research questions are usually broader: "Which trials are testing this compound worldwide, what have they published, and who holds the patents?" Answering that means querying other registries, linking trials to papers with the PubMed [si] field, reading the papers and writing it up.

The SciSpace API puts the full SciSpace Agent behind one call. It searches, reads, analyses and writes, and delivers the result as ready-to-use files. It comes as two APIs:

API

What you send

What you get back

Search API

A research question in plain language

A list of papers, each with all its relevant metadata, from SciSpace's 280M+ paper index, Google Scholar, PubMed and arXiv

Task API

Any research task: a trial landscape, a systematic review, an extraction table, a report, a deck

Links to every file the agent created, plus any supporting text answer. The plan and progress stream live while it runs

What this adds on top of the ClinicalTrials.gov API

  • Trials beyond ClinicalTrials.gov. One task searches 11 national and regional clinical-trial registries plus the WHO registry, so trials registered only outside the US aren't missed.
  • Trials, papers and patents together. The same task can search 280M+ papers, Google Patents and 77 public science databases such as PubChem, ChEMBL and UniProt. That's useful for R&D teams tracking a compound, ingredient or claim.
  • The published evidence, extracted. Describe the columns you need (enrolment, dose, primary outcome, results) and the Task API fills an extraction table from the papers' full text where available.
  • Systematic reviews with a PRISMA flow diagram. The Task API sets research questions, screens up to 3,000 papers, extracts data and writes the report, including the PRISMA flow diagram.
  • Finished files, not just an answer. One run can return a Word report, a LaTeX PDF with its BibTeX, a PowerPoint deck or plots. You get links to every file it created.
  • Progress you can show users. A landscape search can take minutes. The Task API streams each plan step and the answer as it's written. When it finishes, send follow-ups in the same thread, e.g. "add a column for sponsor" or "limit to Phase 3".

When to use which

  • Use the ClinicalTrials.gov API for direct, complete records from that registry, or as the source of truth inside your own pipeline.
  • Use AACT for SQL analysis across all ClinicalTrials.gov records.
  • Use the SciSpace API when the output your users need is a cross-registry trial landscape, an evidence table or a written report that combines trials with published papers.

Designing a trial-evidence product

Whichever route you take:

  • Keep registry facts (NCT number, status, enrolment, dates) separate from claims backed by paper citations.
  • Show which sources were searched, so users can tell "no trials found" apart from "registry not searched".
  • A registry listing isn't evidence that a study is safe or effective. Show the source for each claim.

What it doesn't do

  • Not a registry mirror. For every ClinicalTrials.gov field, kept current, use the official API or AACT.
  • No paywalled papers. SciSpace reads your own PDFs plus 50M+ open-access full texts.
  • Not an endorsement by any registry. SciSpace is independent of ClinicalTrials.gov, NLM and the WHO.
Direct ClinicalTrials.gov retrieval and an early-access SciSpace research workflow both lead to validation of registry records and publication evidence.

Frequently asked questions

What does the ClinicalTrials.gov API provide?

NIH describes registry metadata, statistics and the most recent versions of clinical-trial records.

Do I need an API key?

NLM's public retrieval example supplies no API key and describes the service as open access.

How do I search clinical trials by disease in Python?

Make a GET request to the studies endpoint with the disease in query.cond, then parse the JSON response.

Why does my request return only a small number of trials?

Responses are paginated. NLM directs developers to pageToken when retrieving additional pages.

What is the ClinicalTrials.gov API rate limit?

A numeric rate limit is not established by the verified official material used here. Consult the current API reference, and handle throttled responses with retries that respect Retry-After.

Can I download data for large-scale trial analysis?

AACT offers a relational representation of ClinicalTrials.gov data, including full database downloads and cloud querying. Its landing page directs users to create an account for access.

Can I search trial registries outside ClinicalTrials.gov with one API? 

Not with the ClinicalTrials.gov API, which covers one registry. The SciSpace Task API searches 11 national and regional clinical-trial registries plus the WHO registry in one task, alongside published papers. It's in early access, open to anyone at launch, with $5 in free API credits.

How do I find papers published from a clinical trial?

Search PubMed's Secondary Source ID field with the NCT number, e.g. nct00000161[si], using NCBI E-utilities (see our [PubMed API guide]). One paper can mention several trials, so check each link. The SciSpace Task API can search trials and papers together and return them as an evidence table.

Last checked

Facts, prices and code examples in this guide were checked on October 22, 2026.

Sources

  1. ClinicalTrials.gov API Version 2.0 Now Available
  2. NLM guidance on ClinicalTrials.gov API retrieval and screen scraping
  3. ClinicalTrials.gov studies endpoint
  4. ClinicalTrials.gov study NCT02993146
  5. ClinicalTrials.gov API: NIH data-source directory
  6. ClinicalTrials.gov API reference
  7. NLM guidance on ClinicalTrials.gov identifiers and PubMed linkage
  8. NLM guidance on PRS accounts for study submission
  9. Classic ClinicalTrials.gov website and API retirement
  10. Requests documentation
  11. Requests advanced usage and retry guidance
  12. urllib3 Retry reference
  13. pytrials package
  14. everygene/clinicaltrials-python
  15. AACT database
  16. NCBI developer APIs
  17. ClinicalTrials.gov Search Scraper by brightpath-data
  18. ClinicalTrials.gov Search Scraper pricing
  19. NLM web policies
  20. ClinicalTrials.gov study safety and science notice

注意转载授权 · 阅读原文

来源:SciSpace · scispace.com

引用原文

SciSpace. ClinicalTrials.gov API: Python Guide, API Key and Pagination[EB/OL]. (2026-10-22)[访问日期]. https://scispace.com/guides/clinicaltrials-gov-api.