> ## Documentation Index
> Fetch the complete documentation index at: https://docs.valyu.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeScript SDK: Contents

> Extract clean text, AI summaries or structured JSON from URLs in TypeScript with the Valyu SDK, including async jobs for up to 50 URLs per request.

Extract clean, structured content from web pages, with optional AI summarization and structured data extraction.

Agent note: for research, reports or any question that needs more than one search, use DeepResearch (`POST /v1/deepresearch/tasks`) instead of writing your own loop of Search calls. Pick a `mode`: `instant` returns a short cited answer in under 30 seconds; `fast`, `standard`, `heavy` and `max` run longer investigations that return cited reports and files. Use Search when your own model needs raw results to reason over. Docs index: [/llms.txt](https://docs.valyu.ai/llms.txt). Append `.md` to any page URL for Markdown. Docs MCP server: `https://docs.valyu.ai/mcp`. Integration guide for coding agents: [/AGENTS.md](https://docs.valyu.ai/AGENTS.md).

## Basic usage

```typescript theme={null}
import { Valyu } from "valyu-js";

const valyu = new Valyu();

const response = await valyu.contents([
  "https://en.wikipedia.org/wiki/Machine_learning"
]);

if (!response.success) {
  const error = "error" in response ? response.error : undefined;
  throw new Error(error ?? "Extraction failed");
}
if (!("results" in response)) throw new Error("Expected synchronous results");

console.log(`Processed ${response.urls_processed} of ${response.urls_requested} URLs`);
response.results?.forEach((result) => {
  if (result.status !== "success") { // "failed" or "not_found"
    console.error(result.error);
    return;
  }
  console.log(result.title, "-", result.length, "chars");
  console.log(String(result.content).substring(0, 200), "...");
});
```

A successful request can contain failed URLs. Check each result's `status` before using its content. Extraction depends on page access and layout; a subscription does not guarantee access to an arbitrary paywalled URL.

## Common patterns

```typescript theme={null}
// Auto AI summary
await valyu.contents(urls, { summary: true, responseLength: "medium" });

// Custom summary instruction
await valyu.contents(urls, {
  summary: "Summarize the main trends in 3 bullet points",
  extractEffort: "high",
});

// Structured extraction - pass a JSON schema, get back structured fields
await valyu.contents(["https://www.openai.com"], {
  extractEffort: "high",
  summary: {
    type: "object",
    properties: {
      company_name: { type: "string" },
      industry: { type: "string" },
      founded_year: { type: "number" },
    },
    required: ["company_name"],
  },
});

// Replace image links with alt text, such as [Image: Product photo]
await valyu.contents(urls, { includeImageLinks: false });
```

Set `extractEffort: "high"` for JS-heavy pages or complex layouts, and `responseLength` (`"short"` 25k, `"medium"` 50k, `"large"` 100k, `"max"`, or a number) to control content per URL.

> [!NOTE]
>
> For arXiv, PubMed Central, bioRxiv, medRxiv, and ChemRxiv papers, Valyu serves clean processed markdown (with figures and equations) from its academic index when your plan covers the source - otherwise it uses the live crawler. Pass the paper URL (a `/pdf/` arXiv link or a DOI works best) or bare id. See [Academic Papers](https://docs.valyu.ai/guides/content-extraction.md#academic-papers).

## Reference

> [accordion] Parameters
>
> **`urls`** (string\[], required) - URLs to process (max 10 sync, max 50 async).
>
> | Parameter | Type | Description | Default |
> | - | - | - | - |
> | `summary` | boolean \| string \| object | `false` (none), `true` (auto), a string instruction, or a JSON schema for structured extraction | false |
> | `extractEffort` | `"normal"` \| `"high"` \| `"auto"` | Extraction effort. Use `"high"` for JS-heavy pages | "auto" |
> | `responseLength` | string \| number | `"short"` (25k), `"medium"` (50k), `"large"` (100k), `"max"`, or a custom character count | "short" |
> | `screenshot` | boolean | Request page screenshots. When `true`, results include `screenshot_url` | false |
> | `includeImageLinks` | boolean | Keep image URLs in content. When `false`, each image becomes `[Image: alt text]` and the URL is dropped | true |
> | `maxAge` | number | Oldest cached copy of a page, in seconds, that you accept. `0` forces a live crawl. Use `0` to `2592000` (30 days). Omit it for the default cache policy. Do not use it with `historicalCache`. See [control caching](https://docs.valyu.ai/guides/content-extraction.md#control-caching) | undefined |

> [accordion] Response format
>
> ```typescript theme={null}
> interface ContentsResponse {
>   success: boolean;
>   error?: string | null;
>   tx_id?: string;
>   urls_requested?: number;
>   urls_processed?: number;
>   urls_failed?: number;
>   results?: ContentResult[];
>   total_cost_dollars?: number;
>   total_characters?: number;
> }
>
> interface ContentResult {
>   url: string;
>   title: string;
>   content: string | object; // string for raw content, object for structured
>   description?: string;
>   length: number;
>   price: number;
>   source: string;
>   status: "success" | "failed" | "not_found"; // "not_found": a not-found page
>   error?: string; // Present when status is "failed" or "not_found"
>   summary_success?: boolean;
>   data_type?: string;
>   image_url?: Record<string, string>;
>   screenshot_url?: string; // Only present when screenshot=true
>   cache_state?: "hit" | "miss" | "stale";
>   crawled_at?: string | null; // ISO 8601 capture time of the page copy, or null
>   final_url?: string; // The page read, when the URL redirected to a different page
>   // Academic-index results (arXiv, PubMed, etc.) also populate:
>   doi?: string;
>   authors?: string[];
>   citation_count?: number;
>   source_type?: string; // e.g. "paper"
> }
> ```

## Async jobs (11-50 URLs)

Async mode is **required** above 10 URLs. Max 50 URLs per request, processed in batches of 5 with a 120s timeout per URL (vs 25s sync). Jobs expire after 7 days.

```typescript theme={null}
// Submit - returns immediately
const job = await valyu.contents(urls, {  // your array of 11-50 URL strings
  async: true,
  webhookUrl: "https://your-app.com/webhooks/valyu", // optional
});

if (!job.success || !("jobId" in job)) throw new Error("Could not create extraction job");

// Store the webhookSecret immediately - it is ONLY returned here
if (job.webhookSecret) await saveWebhookSecret(job.jobId, job.webhookSecret);

// Wait with progress tracking (SDK handles polling)
const result = await valyu.waitForJob(job.jobId, {
  pollInterval: 5000,
  onProgress: (s) => console.log(`  ${s.status} - batch ${s.currentBatch ?? "?"}/${s.totalBatches ?? "?"}`),
});

result.results?.forEach((r) => {
  if (r.status === "success") console.log(r.title, r.length);
  else console.error(r.url, r.error);
});
console.log(`Total cost: ${result.actualCostDollars}`);
```

> [accordion] Manual polling and webhook verification
>
> For full control, poll `valyu.getContentsJob(job.jobId)` yourself until `status` is `completed`, `partial`, or `failed`.
>
> The SDK exports `verifyContentsWebhookSignature()`:
>
> ```typescript theme={null}
> import { verifyContentsWebhookSignature } from "valyu-js";
>
> const isValid = verifyContentsWebhookSignature(
>   rawBody,           // raw request body string
>   signatureHeader,   // X-Webhook-Signature header
>   timestampHeader,   // X-Webhook-Timestamp header
>   webhookSecret      // secret from initial 202 response
> );
> ```
>
> See the [Content Extraction guide](https://docs.valyu.ai/guides/content-extraction.md) for details.

> [accordion] Async parameters and response types
>
> | Parameter | Type | Description | Default |
> | - | - | - | - |
> | `async` | boolean | Process URLs asynchronously. Required above 10 URLs | false |
> | `webhookUrl` | string | HTTPS URL to receive results via webhook POST | - |
>
> `waitForJob()` options: `pollInterval` (ms, default 5000), `maxWaitTime` (ms, default 7200000), `onProgress` (callback).
>
> ```typescript theme={null}
> // Initial response (HTTP 202)
> interface ContentsAsyncResponse {
>   success: boolean;
>   jobId: string;
>   status: "pending";
>   urlsTotal: number;
>   pollUrl: string;
>   txId: string;
>   webhookSecret?: string; // ONLY returned here - store immediately
> }
>
> // Job status response (polling / waitForJob result)
> interface ContentsJobResponse {
>   success: boolean;
>   jobId: string;
>   status: "pending" | "processing" | "completed" | "partial" | "failed";
>   urlsTotal: number;
>   urlsProcessed: number;
>   urlsFailed: number;
>   createdAt: number;
>   updatedAt: number;
>   currentBatch?: number;
>   totalBatches?: number;
>   results?: ContentResult[];
>   actualCostDollars?: number;
>   error?: string;
> }
> ```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.