const headers = { "x-api-key": process.env.SECAPI_API_KEY ?? "" };
if (!headers["x-api-key"]) throw new Error("SECAPI_API_KEY is required");
for (const filingYear of [2023, 2024, 2025]) {
const query = new URLSearchParams({ q: "artificial intelligence regulatory risk", ticker: "MSFT",
form: "10-K", filing_year: String(filingYear), mode: "hybrid", view: "agent", limit: "5" });
const response = await fetch(`https://api.secapi.ai/v1/search/semantic?${query}`, { headers });
if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`);
const payload = await response.json();
console.log(JSON.stringify({ filingYear, requestId: payload.requestId,
citations: (payload.sections?.data ?? []).map(({ accession, source_url, section_key, char_start, char_end, highlighted_snippet }) =>
({ accession, source_url, section_key, char_start, char_end, highlighted_snippet })) }, null, 2));
}