Search SEC filing text across companies with JavaScript

Query official SEC document matches with a phrase, form filter, and filing-date bounds while preserving pagination and match identity.

WHAT YOU WILL BUILD

Use the full-text endpoint for document matches across issuers. Keep each result’s accession and document identity; multiple matches can belong to one filing.

Requirements: Node.js 22 or later; no extra packages. An API key from your dashboard, stored in the SEC_API_KEY environment variable.

Run the workflow

Save this as workflow.mjs and run node workflow.mjs. The production base URL is used by default. Keep credentials out of source control.

// Node.js 22+. Set SEC_API_KEY before running.
const key = process.env.SEC_API_KEY;
if (!key) throw new Error("Set SEC_API_KEY first");
const base = process.env.SEC_API_BASE_URL || "https://sec-api.dev";
async function request(path) {
  const response = await fetch(base + path, {
    headers: { Authorization: "Bearer " + key }
  });
  if (!response.ok) {
    throw new Error("HTTP " + response.status + ": " + await response.text());
  }
  return response.json();
}
const result = await request("/api/v1/search?" + new URLSearchParams({
  query: "artificial intelligence", form: "10-K",
  from: "2026-01-01", to: "2026-10-23", limit: "20"
}));
const accessions = new Set(result.data.map(row => row.accessionNumber));
console.log(JSON.stringify({matches:result.data, distinctAccessionsOnPage:accessions.size,
  pagination:result.pagination, source:result.meta}, null, 2));

Distinguish documents from filings

Search returns document matches from the official SEC search source, which covers filings since2001. Source form filters can include related forms and amendments; inspect returned form values rather than assuming strict equality. A filing can contain several documents, and several matched documents can share an accession. The script reports the number of distinct accessions on this page separately from the result count. Neither number is automatically the number of companies mentioning a topic. Keep document identity and CIK arrays when building downstream aggregation.

Make time boundaries reproducible

The example fixes its date range rather than using a moving window. Store the query, form filter, date bounds, and source retrieval metadata with exported results. Search indexes can change as the source updates. A saved query plus retrieval time is useful provenance, but it does not promise an immutable search snapshot.

Handle the search window honestly

Inspect totalRelation together with total, and follow nextOffset only within documented bounds. The service limits deep result access to10,000matches. Narrow date ranges or forms for a practical research sample rather than claiming an oversized search enumerates the entire SEC corpus. Text matches do not establish materiality or sentiment; review the original filing before interpreting a mention.

Sources and further reading

The underlying SEC dataset behavior is documented in the official SEC API reference and SEC technical specifications. Response-field names shown here belong to the sec-api.dev endpoint contract. The scripts print actual results and do not embed fabricated filing or financial data.

All tutorials ←