valyu-js 2.7.5 → 2.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +139 -640
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -1,728 +1,227 @@
|
|
|
1
|
-
# Valyu SDK
|
|
1
|
+
# Valyu JavaScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/valyu-js)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
Search and research APIs built for AI agents. Access web and proprietary data sources through Search, extract content from URLs, generate grounded answers, and run multi-step research with DeepResearch - all through a single SDK.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
_No credit card required._
|
|
10
|
-
|
|
11
|
-
## How does it work?
|
|
12
|
-
|
|
13
|
-
We do all the heavy lifting for you - one unified API for all data:
|
|
14
|
-
|
|
15
|
-
- **Academic & Research Content** - Access millions of scholarly papers and textbooks
|
|
16
|
-
- **Real-time Web Search** - Get the latest information from across the internet
|
|
17
|
-
- **Structured Financial Data** - Stock prices, market data, and financial metrics
|
|
18
|
-
- **Intelligent Reranking** - Results across all sources are automatically sorted by relevance
|
|
19
|
-
- **Transparent Pricing** - Pay only for what you use with clear CPM pricing
|
|
8
|
+
[Documentation](https://docs.valyu.ai) | [API Reference](https://docs.valyu.ai/api-reference) | [Platform](https://platform.valyu.ai)
|
|
20
9
|
|
|
21
10
|
## Installation
|
|
22
11
|
|
|
23
|
-
Install the Valyu SDK using npm:
|
|
24
|
-
|
|
25
12
|
```bash
|
|
26
13
|
npm install valyu-js
|
|
27
14
|
```
|
|
28
15
|
|
|
29
16
|
## Quick Start
|
|
30
17
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
```javascript
|
|
34
|
-
const { Valyu } = require("valyu-js");
|
|
35
|
-
|
|
36
|
-
const valyu = new Valyu("your-api-key-here");
|
|
37
|
-
|
|
38
|
-
const response = await valyu.search(
|
|
39
|
-
"Implementation details of agentic search-enhanced large reasoning models",
|
|
40
|
-
{
|
|
41
|
-
maxNumResults: 5, // Limit to top 5 results
|
|
42
|
-
maxPrice: 10, // Maximum price per thousand queries (CPM)
|
|
43
|
-
}
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
console.log(response);
|
|
47
|
-
|
|
48
|
-
// Feed the results to your AI agent as you would with other search APIs
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## API Reference
|
|
52
|
-
|
|
53
|
-
### DeepResearch Method
|
|
54
|
-
|
|
55
|
-
The `deepresearch` namespace provides access to Valyu's AI-powered research agent that conducts comprehensive, multi-step research with citations and cost tracking.
|
|
18
|
+
```typescript
|
|
19
|
+
import { Valyu } from "valyu-js";
|
|
56
20
|
|
|
57
|
-
|
|
58
|
-
// Create a research task
|
|
59
|
-
const task = await valyu.deepresearch.create({
|
|
60
|
-
query: "What are the latest developments in quantum computing?",
|
|
61
|
-
model: "fast", // "fast" (Haiku) or "heavy" (thorough, Sonnet)
|
|
62
|
-
outputFormats: ["markdown", "pdf"], // Output formats
|
|
63
|
-
});
|
|
21
|
+
const valyu = new Valyu(process.env.VALYU_API_KEY);
|
|
64
22
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (status.progress) {
|
|
69
|
-
console.log(
|
|
70
|
-
`Step ${status.progress.current_step}/${status.progress.total_steps}`
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
},
|
|
23
|
+
const response = await valyu.search("latest advances in transformer architectures", {
|
|
24
|
+
maxNumResults: 5,
|
|
25
|
+
searchType: "all",
|
|
74
26
|
});
|
|
75
27
|
|
|
76
|
-
|
|
77
|
-
console.log(result.
|
|
28
|
+
for (const result of response.results) {
|
|
29
|
+
console.log(result.title, result.url);
|
|
30
|
+
}
|
|
78
31
|
```
|
|
79
32
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
| Method | Description |
|
|
83
|
-
| -------------------------------- | ----------------------------------------- |
|
|
84
|
-
| `create(options)` | Create a new research task |
|
|
85
|
-
| `status(taskId)` | Get current status of a task |
|
|
86
|
-
| `wait(taskId, options?)` | Wait for task completion with polling |
|
|
87
|
-
| `stream(taskId, callbacks)` | Stream real-time updates |
|
|
88
|
-
| `list(options)` | List all your research tasks |
|
|
89
|
-
| `update(taskId, instruction)` | Add follow-up instruction to running task |
|
|
90
|
-
| `cancel(taskId)` | Cancel a running task |
|
|
91
|
-
| `delete(taskId)` | Delete a task |
|
|
92
|
-
| `togglePublic(taskId, isPublic)` | Make task publicly accessible |
|
|
93
|
-
|
|
94
|
-
#### DeepResearch Create Options
|
|
95
|
-
|
|
96
|
-
| Parameter | Type | Default | Description |
|
|
97
|
-
| ----------------- | ------------------------- | -------------- | --------------------------------------------- |
|
|
98
|
-
| `input` | `string` | _required_ | Research query or task description |
|
|
99
|
-
| `model` | `"fast" \| "heavy"` | `"fast"` | Research model - fast or heavy (thorough) |
|
|
100
|
-
| `outputFormats` | `("markdown" \| "pdf")[]` | `["markdown"]` | Output formats for the report |
|
|
101
|
-
| `strategy` | `string` | - | Natural language research strategy |
|
|
102
|
-
| `search` | `object` | - | Search configuration (type, sources) |
|
|
103
|
-
| `urls` | `string[]` | - | URLs to extract and analyze |
|
|
104
|
-
| `files` | `FileAttachment[]` | - | PDF/image files to analyze |
|
|
105
|
-
| `mcpServers` | `MCPServerConfig[]` | - | MCP tool server configurations |
|
|
106
|
-
| `codeExecution` | `boolean` | `true` | Enable/disable code execution |
|
|
107
|
-
| `previousReports` | `string[]` | - | Previous report IDs for context (max 3) |
|
|
108
|
-
| `webhookUrl` | `string` | - | HTTPS webhook URL for completion notification |
|
|
109
|
-
| `metadata` | `Record<string, any>` | - | Custom metadata key-value pairs |
|
|
110
|
-
|
|
111
|
-
#### DeepResearch Examples
|
|
112
|
-
|
|
113
|
-
**Basic Research:**
|
|
114
|
-
|
|
115
|
-
```javascript
|
|
116
|
-
const task = await valyu.deepresearch.create({
|
|
117
|
-
query: "Summarize recent AI safety research",
|
|
118
|
-
model: "fast",
|
|
119
|
-
});
|
|
33
|
+
Get **$10 free credits** when you sign up at [platform.valyu.ai](https://platform.valyu.ai). No credit card required.
|
|
120
34
|
|
|
121
|
-
|
|
122
|
-
console.log(result.output);
|
|
123
|
-
```
|
|
35
|
+
## APIs
|
|
124
36
|
|
|
125
|
-
|
|
37
|
+
### Search
|
|
126
38
|
|
|
127
|
-
|
|
128
|
-
const task = await valyu.deepresearch.create({
|
|
129
|
-
query: "Latest transformer architecture improvements",
|
|
130
|
-
search: {
|
|
131
|
-
searchType: "proprietary",
|
|
132
|
-
includedSources: ["valyu/valyu-arxiv"],
|
|
133
|
-
},
|
|
134
|
-
model: "heavy",
|
|
135
|
-
outputFormats: ["markdown", "pdf"],
|
|
136
|
-
});
|
|
137
|
-
```
|
|
39
|
+
Search across web and proprietary data sources with a single query.
|
|
138
40
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
onMessage: (message) => {
|
|
147
|
-
console.log("Agent:", message);
|
|
148
|
-
},
|
|
149
|
-
onComplete: (result) => {
|
|
150
|
-
console.log("Complete! Cost:", result.usage.total_cost);
|
|
151
|
-
},
|
|
41
|
+
```typescript
|
|
42
|
+
const response = await valyu.search("CRISPR gene therapy clinical trials 2026", {
|
|
43
|
+
searchType: "proprietary", // "all", "web", or "proprietary"
|
|
44
|
+
maxNumResults: 10, // 1-20 results
|
|
45
|
+
includedSources: ["valyu/valyu-pubmed"], // filter to specific sources
|
|
46
|
+
startDate: "2026-01-01", // date filtering
|
|
47
|
+
endDate: "2026-12-31",
|
|
152
48
|
});
|
|
153
49
|
```
|
|
154
50
|
|
|
155
|
-
|
|
51
|
+
<details>
|
|
52
|
+
<summary>All search parameters</summary>
|
|
156
53
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
54
|
+
| Parameter | Type | Default | Description |
|
|
55
|
+
|---|---|---|---|
|
|
56
|
+
| `query` | `string` | required | Search query |
|
|
57
|
+
| `searchType` | `string` | `"all"` | `"all"`, `"web"`, or `"proprietary"` |
|
|
58
|
+
| `maxNumResults` | `number` | `10` | Results to return (1-20) |
|
|
59
|
+
| `maxPrice` | `number` | `30` | Max price per thousand queries (CPM) |
|
|
60
|
+
| `relevanceThreshold` | `number` | `0.5` | Min relevance score (0-1) |
|
|
61
|
+
| `includedSources` | `string[]` | `[]` | Sources to search |
|
|
62
|
+
| `excludeSources` | `string[]` | `[]` | Sources to exclude |
|
|
63
|
+
| `startDate` | `string` | - | Start date (YYYY-MM-DD) |
|
|
64
|
+
| `endDate` | `string` | - | End date (YYYY-MM-DD) |
|
|
65
|
+
| `countryCode` | `string` | - | Country filter (e.g. `"US"`, `"GB"`) |
|
|
66
|
+
| `responseLength` | `string \| number` | - | `"short"`, `"medium"`, `"large"`, `"max"`, or character count |
|
|
67
|
+
| `category` | `string` | - | Category filter |
|
|
170
68
|
|
|
171
|
-
|
|
69
|
+
</details>
|
|
172
70
|
|
|
173
|
-
|
|
71
|
+
### Contents
|
|
174
72
|
|
|
175
|
-
|
|
176
|
-
// Create a batch
|
|
177
|
-
const batch = await valyu.batch.create({
|
|
178
|
-
name: "Q4 Research Batch",
|
|
179
|
-
mode: "fast", // "fast", "standard", or "heavy"
|
|
180
|
-
outputFormats: ["markdown"],
|
|
181
|
-
});
|
|
73
|
+
Extract clean, structured content from URLs. Supports sync (1-10 URLs) and async (up to 50 URLs) modes.
|
|
182
74
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
{ query: "What are the latest AI developments?" },
|
|
187
|
-
{ query: "Analyze climate change trends" },
|
|
188
|
-
{ query: "Review quantum computing progress" },
|
|
189
|
-
],
|
|
190
|
-
});
|
|
75
|
+
```typescript
|
|
76
|
+
// Basic extraction
|
|
77
|
+
const response = await valyu.contents(["https://arxiv.org/abs/2301.00001"]);
|
|
191
78
|
|
|
192
|
-
//
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
console.log(`Progress: ${batch.counts.completed}/${batch.counts.total}`);
|
|
197
|
-
},
|
|
79
|
+
// With AI summarization
|
|
80
|
+
const response = await valyu.contents(["https://example.com/article"], {
|
|
81
|
+
summary: true,
|
|
82
|
+
responseLength: "medium",
|
|
198
83
|
});
|
|
199
84
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
| `create(options?)` | Create a new batch |
|
|
208
|
-
| `status(batchId)` | Get batch status and task counts |
|
|
209
|
-
| `addTasks(batchId, options)` | Add tasks to a batch |
|
|
210
|
-
| `listTasks(batchId)` | List all tasks in a batch |
|
|
211
|
-
| `list()` | List all batches |
|
|
212
|
-
| `cancel(batchId)` | Cancel a batch and all pending tasks |
|
|
213
|
-
| `waitForCompletion(batchId, options?)` | Wait for batch completion with polling |
|
|
214
|
-
|
|
215
|
-
#### Batch Create Options
|
|
216
|
-
|
|
217
|
-
| Parameter | Type | Default | Description |
|
|
218
|
-
| --------------- | --------------------------------- | -------------- | ---------------------------------- |
|
|
219
|
-
| `name` | `string` | - | Optional batch name |
|
|
220
|
-
| `mode` | `"fast" \| "standard" \| "heavy"` | `"standard"` | DeepResearch mode for all tasks |
|
|
221
|
-
| `outputFormats` | `("markdown" \| "pdf")[]` | `["markdown"]` | Output formats |
|
|
222
|
-
| `search` | `object` | - | Search configuration for all tasks |
|
|
223
|
-
| `webhookUrl` | `string` | - | HTTPS URL for completion webhook |
|
|
224
|
-
| `metadata` | `object` | - | Custom metadata key-value pairs |
|
|
225
|
-
|
|
226
|
-
#### Batch Status Response
|
|
227
|
-
|
|
228
|
-
```javascript
|
|
229
|
-
{
|
|
230
|
-
success: true,
|
|
231
|
-
batch: {
|
|
232
|
-
batch_id: "batch_xxx",
|
|
233
|
-
status: "processing", // "open", "processing", "completed", "cancelled"
|
|
234
|
-
mode: "standard", // "fast", "standard", or "heavy"
|
|
235
|
-
name: "My Batch",
|
|
236
|
-
counts: {
|
|
237
|
-
total: 10,
|
|
238
|
-
queued: 3,
|
|
239
|
-
running: 2,
|
|
240
|
-
completed: 4,
|
|
241
|
-
failed: 1,
|
|
242
|
-
cancelled: 0
|
|
243
|
-
},
|
|
244
|
-
cost: 0.20, // Total cost (replaces usage object)
|
|
245
|
-
created_at: "2025-01-10T12:00:00Z", // ISO 8601 date-time string
|
|
246
|
-
completed_at: "2025-01-10T12:30:00Z" // ISO 8601 date-time string (when completed)
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
### Search Method
|
|
252
|
-
|
|
253
|
-
The `search()` method is the core of the Valyu SDK. It accepts a query string as the first parameter, followed by optional configuration parameters.
|
|
254
|
-
|
|
255
|
-
```javascript
|
|
256
|
-
valyu.search(
|
|
257
|
-
query, // Your search query
|
|
258
|
-
{
|
|
259
|
-
searchType: "all", // "all", "web", or "proprietary"
|
|
260
|
-
maxNumResults: 10, // Maximum results to return (1-20)
|
|
261
|
-
isToolCall: true, // Whether this is an AI tool call
|
|
262
|
-
relevanceThreshold: 0.5, // Minimum relevance score (0-1)
|
|
263
|
-
maxPrice: 30, // Maximum price per thousand queries (CPM)
|
|
264
|
-
includedSources: [], // Specific sources to search
|
|
265
|
-
excludeSources: [], // Sources/domains to exclude
|
|
266
|
-
category: null, // Category filter
|
|
267
|
-
startDate: null, // Start date (YYYY-MM-DD)
|
|
268
|
-
endDate: null, // End date (YYYY-MM-DD)
|
|
269
|
-
countryCode: null, // Country code filter
|
|
270
|
-
responseLength: null, // Response length control
|
|
271
|
-
}
|
|
272
|
-
);
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
### Parameters
|
|
276
|
-
|
|
277
|
-
| Parameter | Type | Default | Description |
|
|
278
|
-
| -------------------- | ------------------ | ---------- | ---------------------------------------------------------------------- |
|
|
279
|
-
| `query` | `string` | _required_ | The search query string |
|
|
280
|
-
| `searchType` | `string` | `"all"` | Search scope: `"all"`, `"web"`, or `"proprietary"` |
|
|
281
|
-
| `maxNumResults` | `number` | `10` | Maximum number of results to return (1-20) |
|
|
282
|
-
| `isToolCall` | `boolean` | `true` | Whether this is an AI tool call (affects processing) |
|
|
283
|
-
| `relevanceThreshold` | `number` | `0.5` | Minimum relevance score for results (0.0-1.0) |
|
|
284
|
-
| `maxPrice` | `number` | `30` | Maximum price per thousand queries in CPM |
|
|
285
|
-
| `includedSources` | `string[]` | `[]` | Specific data sources or URLs to search |
|
|
286
|
-
| `excludeSources` | `string[]` | `[]` | Data sources or URLs to exclude from search |
|
|
287
|
-
| `category` | `string` | `null` | Category filter for results |
|
|
288
|
-
| `startDate` | `string` | `null` | Start date filter in YYYY-MM-DD format |
|
|
289
|
-
| `endDate` | `string` | `null` | End date filter in YYYY-MM-DD format |
|
|
290
|
-
| `countryCode` | `string` | `null` | Country code filter (e.g., "US", "GB", "JP", "ALL") |
|
|
291
|
-
| `responseLength` | `string \| number` | `null` | Response length: "short", "medium", "large", "max", or character count |
|
|
292
|
-
|
|
293
|
-
### Response Format
|
|
294
|
-
|
|
295
|
-
The search method returns a `SearchResponse` object with the following structure:
|
|
296
|
-
|
|
297
|
-
```javascript
|
|
298
|
-
{
|
|
299
|
-
success: boolean, // Whether the search was successful
|
|
300
|
-
error: string | null, // Error message if any
|
|
301
|
-
tx_id: string, // Transaction ID for feedback
|
|
302
|
-
query: string, // The original query
|
|
303
|
-
results: SearchResult[], // List of search results
|
|
304
|
-
results_by_source: { // Count of results by source type
|
|
305
|
-
web: number,
|
|
306
|
-
proprietary: number
|
|
85
|
+
// Structured data extraction with JSON schema
|
|
86
|
+
const response = await valyu.contents(["https://en.wikipedia.org/wiki/OpenAI"], {
|
|
87
|
+
summary: {
|
|
88
|
+
type: "object",
|
|
89
|
+
properties: {
|
|
90
|
+
company_name: { type: "string" },
|
|
91
|
+
founded_year: { type: "integer" },
|
|
307
92
|
},
|
|
308
|
-
|
|
309
|
-
total_characters: number // Total characters returned
|
|
310
|
-
}
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
Each `SearchResult` contains:
|
|
314
|
-
|
|
315
|
-
```javascript
|
|
316
|
-
{
|
|
317
|
-
title: string, // Result title
|
|
318
|
-
url: string, // Source URL
|
|
319
|
-
content: string, // Full content
|
|
320
|
-
description?: string, // Brief description
|
|
321
|
-
source: string, // Source identifier
|
|
322
|
-
price: number, // Cost for this result
|
|
323
|
-
length: number, // Content length in characters
|
|
324
|
-
relevance_score?: number, // Relevance score (0-1), not available in fast_mode or url_only
|
|
325
|
-
data_type?: string, // "structured" or "unstructured"
|
|
326
|
-
source_type?: string, // Source type identifier
|
|
327
|
-
publication_date?: string, // Publication date (YYYY-MM-DD)
|
|
328
|
-
id?: string, // Unique result identifier
|
|
329
|
-
image_url?: Record<string, string> // Associated images
|
|
330
|
-
}
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
### Contents Method
|
|
334
|
-
|
|
335
|
-
The `contents()` method extracts clean, structured content from web pages with optional AI-powered data extraction and summarization. It accepts an array of URLs as the first parameter, followed by optional configuration parameters.
|
|
336
|
-
|
|
337
|
-
- **Sync mode** (≤10 URLs): Returns results immediately
|
|
338
|
-
- **Async mode** (>10 URLs or `async: true`): Returns a job object; use `getContentsJob()` or `waitForJob()` to get results
|
|
339
|
-
|
|
340
|
-
```javascript
|
|
341
|
-
// Sync (≤10 URLs)
|
|
342
|
-
const response = await valyu.contents(urls, { summary: true });
|
|
343
|
-
|
|
344
|
-
// Async (11-50 URLs) - returns job, then poll or wait
|
|
345
|
-
const job = await valyu.contents(urls, { async: true });
|
|
346
|
-
const final = await valyu.waitForJob(job.jobId, { pollInterval: 5000 });
|
|
347
|
-
```
|
|
348
|
-
|
|
349
|
-
### Parameters
|
|
350
|
-
|
|
351
|
-
| Parameter | Type | Default | Description |
|
|
352
|
-
| ----------------- | ----------------------------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
353
|
-
| `urls` | `string[]` | _required_ | Array of URLs to process (max 10 sync, max 50 with `async: true`) |
|
|
354
|
-
| `summary` | `boolean \| string \| object` | `false` | AI summary configuration: `false` (raw content), `true` (auto summary), string (custom instructions), or JSON schema (structured extraction) |
|
|
355
|
-
| `extractEffort` | `string` | `"normal"` | Extraction thoroughness: `"normal"`, `"high"`, or `"auto"` |
|
|
356
|
-
| `responseLength` | `string \| number` | `"short"` | Content length per URL: `"short"` (25k chars), `"medium"` (50k), `"large"` (100k), `"max"` (no limit), or custom number |
|
|
357
|
-
| `maxPriceDollars` | `number` | `null` | Maximum cost limit in USD |
|
|
358
|
-
| `screenshot` | `boolean` | `false` | Capture page screenshots |
|
|
359
|
-
| `async` | `boolean` | `false` | Force async processing (required for >10 URLs) |
|
|
360
|
-
| `webhookUrl` | `string` | - | HTTPS URL for completion notification (async only). Save `webhookSecret` for signature verification. |
|
|
361
|
-
|
|
362
|
-
### Contents Response Format (Sync)
|
|
363
|
-
|
|
364
|
-
When sync, returns `ContentsResponse`:
|
|
365
|
-
|
|
366
|
-
```javascript
|
|
367
|
-
{
|
|
368
|
-
success: boolean,
|
|
369
|
-
tx_id: string,
|
|
370
|
-
urls_requested: number,
|
|
371
|
-
urls_processed: number,
|
|
372
|
-
urls_failed: number,
|
|
373
|
-
results: ContentResult[],
|
|
374
|
-
total_cost_dollars: number,
|
|
375
|
-
total_characters: number
|
|
376
|
-
}
|
|
377
|
-
```
|
|
378
|
-
|
|
379
|
-
### Contents Async Response
|
|
380
|
-
|
|
381
|
-
When async, returns `ContentsAsyncJobResponse` with `jobId`. Use `getContentsJob(jobId)` or `waitForJob(jobId)` to get results.
|
|
382
|
-
|
|
383
|
-
```javascript
|
|
384
|
-
// Poll for status
|
|
385
|
-
const status = await valyu.getContentsJob(jobId);
|
|
386
|
-
|
|
387
|
-
// Or wait until complete (like DeepResearch wait)
|
|
388
|
-
const final = await valyu.waitForJob(jobId, {
|
|
389
|
-
pollInterval: 5000,
|
|
390
|
-
maxWaitTime: 7200000,
|
|
391
|
-
onProgress: (s) => console.log(`${s.urlsProcessed}/${s.urlsTotal}`)
|
|
93
|
+
},
|
|
392
94
|
});
|
|
393
95
|
```
|
|
394
96
|
|
|
395
|
-
###
|
|
396
|
-
|
|
397
|
-
Each result has a `status` field. Check before accessing success-only fields:
|
|
398
|
-
|
|
399
|
-
```javascript
|
|
400
|
-
for (const r of response.results) {
|
|
401
|
-
if (r.status === 'success') {
|
|
402
|
-
console.log(r.title, r.content);
|
|
403
|
-
} else {
|
|
404
|
-
console.log(`Failed: ${r.url} - ${r.error}`);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
```
|
|
408
|
-
|
|
409
|
-
### Webhook Signature Verification
|
|
97
|
+
### Answer
|
|
410
98
|
|
|
411
|
-
|
|
99
|
+
AI-generated answers grounded by Valyu's search. Supports streaming.
|
|
412
100
|
|
|
413
|
-
```
|
|
414
|
-
const
|
|
101
|
+
```typescript
|
|
102
|
+
const response = await valyu.answer("What are the side effects of metformin?", {
|
|
103
|
+
searchType: "proprietary",
|
|
104
|
+
includedSources: ["valyu/valyu-pubmed"],
|
|
105
|
+
});
|
|
415
106
|
|
|
416
|
-
//
|
|
417
|
-
|
|
418
|
-
rawBody, // Raw request body string
|
|
419
|
-
signatureHeader, // X-Webhook-Signature
|
|
420
|
-
timestampHeader, // X-Webhook-Timestamp
|
|
421
|
-
webhookSecret
|
|
422
|
-
);
|
|
107
|
+
console.log(response.contents); // AI-generated answer
|
|
108
|
+
console.log(response.search_results); // Source citations
|
|
423
109
|
```
|
|
424
110
|
|
|
425
|
-
|
|
111
|
+
### DeepResearch
|
|
426
112
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
```javascript
|
|
430
|
-
const { Valyu } = require("valyu-js");
|
|
431
|
-
|
|
432
|
-
const valyu = new Valyu("your-api-key");
|
|
433
|
-
|
|
434
|
-
// Simple search across all sources
|
|
435
|
-
const response = await valyu.search("What is machine learning?");
|
|
436
|
-
console.log(`Found ${response.results.length} results`);
|
|
437
|
-
```
|
|
113
|
+
Multi-step research agent that produces comprehensive reports with citations.
|
|
438
114
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
includedSources: ["valyu/valyu-arxiv"],
|
|
446
|
-
relevanceThreshold: 0.6,
|
|
447
|
-
maxNumResults: 10,
|
|
115
|
+
```typescript
|
|
116
|
+
// Start a research task
|
|
117
|
+
const task = await valyu.deepresearch.create({
|
|
118
|
+
query: "Compare CRISPR and base editing approaches for sickle cell disease",
|
|
119
|
+
model: "heavy",
|
|
120
|
+
outputFormats: ["markdown", "pdf"],
|
|
448
121
|
});
|
|
449
|
-
```
|
|
450
|
-
|
|
451
|
-
### Web Search with Date Filtering
|
|
452
122
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
endDate: "2024-12-31",
|
|
459
|
-
maxNumResults: 5,
|
|
123
|
+
// Wait for completion with progress
|
|
124
|
+
const result = await valyu.deepresearch.wait(task.deepresearch_id, {
|
|
125
|
+
onProgress: (status) => {
|
|
126
|
+
console.log(`Step ${status.progress.current_step}/${status.progress.total_steps}`);
|
|
127
|
+
},
|
|
460
128
|
});
|
|
461
|
-
```
|
|
462
129
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
```javascript
|
|
466
|
-
// Search both web and proprietary sources
|
|
467
|
-
const response = await valyu.search("quantum computing breakthroughs", {
|
|
468
|
-
searchType: "all",
|
|
469
|
-
category: "technology",
|
|
470
|
-
relevanceThreshold: 0.6,
|
|
471
|
-
maxPrice: 50,
|
|
472
|
-
});
|
|
130
|
+
console.log(result.output); // Markdown report
|
|
131
|
+
console.log(result.pdf_url); // PDF download link
|
|
473
132
|
```
|
|
474
133
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
```javascript
|
|
478
|
-
const response = await valyu.search("climate change solutions");
|
|
479
|
-
|
|
480
|
-
if (response.success) {
|
|
481
|
-
console.log(`Search cost: $${response.total_deduction_dollars.toFixed(4)}`);
|
|
482
|
-
console.log(
|
|
483
|
-
`Sources: Web=${response.results_by_source.web}, Proprietary=${response.results_by_source.proprietary}`
|
|
484
|
-
);
|
|
485
|
-
|
|
486
|
-
response.results.forEach((result, i) => {
|
|
487
|
-
console.log(`\n${i + 1}. ${result.title}`);
|
|
488
|
-
console.log(` Source: ${result.source}`);
|
|
489
|
-
if (result.relevance_score !== undefined) {
|
|
490
|
-
console.log(` Relevance: ${result.relevance_score.toFixed(2)}`);
|
|
491
|
-
}
|
|
492
|
-
console.log(` Content: ${result.content.substring(0, 200)}...`);
|
|
493
|
-
});
|
|
494
|
-
} else {
|
|
495
|
-
console.log(`Search failed: ${response.error}`);
|
|
496
|
-
}
|
|
497
|
-
```
|
|
134
|
+
<details>
|
|
135
|
+
<summary>All DeepResearch methods</summary>
|
|
498
136
|
|
|
499
|
-
|
|
137
|
+
| Method | Description |
|
|
138
|
+
|---|---|
|
|
139
|
+
| `create(options)` | Start a new research task |
|
|
140
|
+
| `status(taskId)` | Get task status |
|
|
141
|
+
| `wait(taskId, options?)` | Poll until completion |
|
|
142
|
+
| `stream(taskId, callbacks)` | Stream real-time updates |
|
|
143
|
+
| `list(options)` | List research tasks |
|
|
144
|
+
| `update(taskId, instruction)` | Add follow-up instruction |
|
|
145
|
+
| `cancel(taskId)` | Cancel a running task |
|
|
146
|
+
| `delete(taskId)` | Delete a task |
|
|
147
|
+
| `togglePublic(taskId, isPublic)` | Toggle public access |
|
|
500
148
|
|
|
501
|
-
|
|
149
|
+
</details>
|
|
502
150
|
|
|
503
|
-
|
|
504
|
-
// Extract raw content from URLs
|
|
505
|
-
const response = await valyu.contents([
|
|
506
|
-
"https://techcrunch.com/2025/08/28/anthropic-users-face-a-new-choice-opt-out-or-share-your-data-for-ai-training/",
|
|
507
|
-
]);
|
|
151
|
+
### Batch
|
|
508
152
|
|
|
509
|
-
|
|
510
|
-
response.results.forEach((result) => {
|
|
511
|
-
console.log(`Title: ${result.title}`);
|
|
512
|
-
console.log(`Content: ${result.content.substring(0, 500)}...`);
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
```
|
|
153
|
+
Run multiple DeepResearch tasks in parallel.
|
|
516
154
|
|
|
517
|
-
|
|
155
|
+
```typescript
|
|
156
|
+
const batch = await valyu.batch.create({
|
|
157
|
+
name: "Q1 Analysis",
|
|
158
|
+
mode: "fast",
|
|
159
|
+
outputFormats: ["markdown"],
|
|
160
|
+
});
|
|
518
161
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
162
|
+
await valyu.batch.addTasks(batch.batch_id, {
|
|
163
|
+
tasks: [
|
|
164
|
+
{ query: "Analyze recent SPAC performance" },
|
|
165
|
+
{ query: "Review semiconductor supply chain trends" },
|
|
166
|
+
],
|
|
524
167
|
});
|
|
525
168
|
|
|
526
|
-
|
|
527
|
-
console.log(
|
|
169
|
+
const result = await valyu.batch.waitForCompletion(batch.batch_id, {
|
|
170
|
+
onProgress: (b) => console.log(`${b.counts.completed}/${b.counts.total}`),
|
|
528
171
|
});
|
|
529
172
|
```
|
|
530
173
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
```javascript
|
|
534
|
-
// Extract structured data using JSON schema
|
|
535
|
-
const companySchema = {
|
|
536
|
-
type: "object",
|
|
537
|
-
properties: {
|
|
538
|
-
company_name: { type: "string" },
|
|
539
|
-
founded_year: { type: "integer" },
|
|
540
|
-
key_products: {
|
|
541
|
-
type: "array",
|
|
542
|
-
items: { type: "string" },
|
|
543
|
-
maxItems: 3,
|
|
544
|
-
},
|
|
545
|
-
},
|
|
546
|
-
};
|
|
547
|
-
|
|
548
|
-
const response = await valyu.contents(
|
|
549
|
-
["https://en.wikipedia.org/wiki/OpenAI"],
|
|
550
|
-
{
|
|
551
|
-
summary: companySchema,
|
|
552
|
-
responseLength: "max",
|
|
553
|
-
}
|
|
554
|
-
);
|
|
555
|
-
|
|
556
|
-
if (response.success) {
|
|
557
|
-
response.results.forEach((result) => {
|
|
558
|
-
if (result.summary) {
|
|
559
|
-
console.log(
|
|
560
|
-
`Structured data: ${JSON.stringify(result.summary, null, 2)}`
|
|
561
|
-
);
|
|
562
|
-
}
|
|
563
|
-
});
|
|
564
|
-
}
|
|
565
|
-
```
|
|
174
|
+
### Data Sources
|
|
566
175
|
|
|
567
|
-
|
|
176
|
+
List available data sources programmatically.
|
|
568
177
|
|
|
569
|
-
```
|
|
570
|
-
|
|
571
|
-
const
|
|
572
|
-
[
|
|
573
|
-
"https://www.valyu.ai/",
|
|
574
|
-
"https://docs.valyu.ai/overview",
|
|
575
|
-
"https://www.valyu.ai/blogs/why-ai-agents-and-llms-struggle-with-search-and-data-access",
|
|
576
|
-
],
|
|
577
|
-
{
|
|
578
|
-
summary:
|
|
579
|
-
"Provide key takeaways in bullet points, and write in very emphasised singaporean english",
|
|
580
|
-
}
|
|
581
|
-
);
|
|
582
|
-
|
|
583
|
-
console.log(
|
|
584
|
-
`Processed ${response.urls_processed}/${response.urls_requested} URLs`
|
|
585
|
-
);
|
|
586
|
-
console.log(`Cost: $${response.total_cost_dollars.toFixed(4)}`);
|
|
178
|
+
```typescript
|
|
179
|
+
const sources = await valyu.datasources.list();
|
|
180
|
+
const categories = await valyu.datasources.categories();
|
|
587
181
|
```
|
|
588
182
|
|
|
589
183
|
## Authentication
|
|
590
184
|
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
1. **Environment variable** (recommended):
|
|
594
|
-
|
|
595
|
-
```bash
|
|
596
|
-
export VALYU_API_KEY="your-api-key-here"
|
|
597
|
-
```
|
|
598
|
-
|
|
599
|
-
2. **Direct initialization**:
|
|
600
|
-
```javascript
|
|
601
|
-
const valyu = new Valyu("your-api-key-here");
|
|
602
|
-
```
|
|
603
|
-
|
|
604
|
-
## Error Handling
|
|
605
|
-
|
|
606
|
-
The SDK handles errors gracefully and returns structured error responses:
|
|
607
|
-
|
|
608
|
-
```javascript
|
|
609
|
-
const response = await valyu.search("test query");
|
|
610
|
-
|
|
611
|
-
if (!response.success) {
|
|
612
|
-
console.log(`Error: ${response.error}`);
|
|
613
|
-
console.log(`Transaction ID: ${response.tx_id}`);
|
|
614
|
-
} else {
|
|
615
|
-
// Process successful results
|
|
616
|
-
response.results.forEach((result) => {
|
|
617
|
-
console.log(result.title);
|
|
618
|
-
});
|
|
619
|
-
}
|
|
185
|
+
```bash
|
|
186
|
+
export VALYU_API_KEY="your-api-key"
|
|
620
187
|
```
|
|
621
188
|
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
The SDK includes full TypeScript support with type definitions for all parameters:
|
|
189
|
+
Or pass directly:
|
|
625
190
|
|
|
626
191
|
```typescript
|
|
627
|
-
import {
|
|
628
|
-
Valyu,
|
|
629
|
-
SearchOptions,
|
|
630
|
-
SearchResponse,
|
|
631
|
-
ContentsOptions,
|
|
632
|
-
ContentsResponse,
|
|
633
|
-
CountryCode,
|
|
634
|
-
ResponseLength,
|
|
635
|
-
} from "valyu";
|
|
636
|
-
|
|
637
192
|
const valyu = new Valyu("your-api-key");
|
|
638
|
-
|
|
639
|
-
// Search API with types
|
|
640
|
-
const searchOptions: SearchOptions = {
|
|
641
|
-
searchType: "proprietary",
|
|
642
|
-
maxNumResults: 10,
|
|
643
|
-
relevanceThreshold: 0.6,
|
|
644
|
-
excludeSources: ["reddit.com", "twitter.com"],
|
|
645
|
-
countryCode: "US" as CountryCode,
|
|
646
|
-
responseLength: "medium" as ResponseLength,
|
|
647
|
-
};
|
|
648
|
-
|
|
649
|
-
const searchResponse: SearchResponse = await valyu.search(
|
|
650
|
-
"machine learning",
|
|
651
|
-
searchOptions
|
|
652
|
-
);
|
|
653
|
-
|
|
654
|
-
// Contents API with types
|
|
655
|
-
const contentsOptions: ContentsOptions = {
|
|
656
|
-
summary: true,
|
|
657
|
-
extractEffort: "high",
|
|
658
|
-
responseLength: "medium",
|
|
659
|
-
maxPriceDollars: 0.1,
|
|
660
|
-
};
|
|
661
|
-
|
|
662
|
-
const contentsResponse: ContentsResponse = await valyu.contents(
|
|
663
|
-
["https://example.com"],
|
|
664
|
-
contentsOptions
|
|
665
|
-
);
|
|
666
193
|
```
|
|
667
194
|
|
|
668
|
-
##
|
|
195
|
+
## TypeScript
|
|
669
196
|
|
|
670
|
-
|
|
197
|
+
Full type definitions are included. All request and response types are exported:
|
|
671
198
|
|
|
672
|
-
```
|
|
673
|
-
|
|
674
|
-
const response = await valyu.context("neural networks basics", {
|
|
675
|
-
searchType: "all",
|
|
676
|
-
maxNumResults: 5,
|
|
677
|
-
queryRewrite: true,
|
|
678
|
-
similarityThreshold: 0.5,
|
|
679
|
-
dataSources: ["valyu/valyu-arxiv"],
|
|
680
|
-
});
|
|
199
|
+
```typescript
|
|
200
|
+
import { Valyu, SearchOptions, SearchResponse, SearchResult } from "valyu-js";
|
|
681
201
|
```
|
|
682
202
|
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
- `context()` → `search()`
|
|
686
|
-
- `similarityThreshold` → `relevanceThreshold`
|
|
687
|
-
- `dataSources` → `includedSources`
|
|
688
|
-
- `queryRewrite` → `isToolCall`
|
|
689
|
-
- Default `relevanceThreshold` changed from `0.4` to `0.5`
|
|
690
|
-
- Default `maxPrice` changed from `1` to `30`
|
|
691
|
-
|
|
692
|
-
## Getting Started
|
|
693
|
-
|
|
694
|
-
1. Sign up for a free account at [Valyu](https://platform.valyu.ai)
|
|
695
|
-
2. Get your API key from the dashboard
|
|
696
|
-
3. Install the SDK: `npm install valyu-js`
|
|
697
|
-
4. Start building with the examples above
|
|
698
|
-
|
|
699
|
-
## Testing
|
|
700
|
-
|
|
701
|
-
Run the integration tests:
|
|
702
|
-
|
|
703
|
-
```bash
|
|
704
|
-
npm run test:integration
|
|
705
|
-
```
|
|
203
|
+
## Error Handling
|
|
706
204
|
|
|
707
|
-
|
|
205
|
+
```typescript
|
|
206
|
+
const response = await valyu.search("test");
|
|
708
207
|
|
|
709
|
-
|
|
710
|
-
|
|
208
|
+
if (!response.success) {
|
|
209
|
+
console.error(response.error);
|
|
210
|
+
console.error(`tx_id: ${response.tx_id}`);
|
|
211
|
+
}
|
|
711
212
|
```
|
|
712
213
|
|
|
713
|
-
|
|
214
|
+
## Integrations
|
|
714
215
|
|
|
715
|
-
|
|
716
|
-
node examples/contents-examples.js
|
|
717
|
-
```
|
|
216
|
+
Valyu works with [Vercel AI SDK](https://www.npmjs.com/package/@valyu/ai-sdk), [LangChain](https://docs.valyu.ai), [MCP](https://docs.valyu.ai), and more. See [docs.valyu.ai](https://docs.valyu.ai) for integration guides.
|
|
718
217
|
|
|
719
|
-
##
|
|
218
|
+
## Links
|
|
720
219
|
|
|
721
|
-
-
|
|
722
|
-
-
|
|
723
|
-
-
|
|
724
|
-
-
|
|
220
|
+
- [Documentation](https://docs.valyu.ai)
|
|
221
|
+
- [Platform & API Keys](https://platform.valyu.ai)
|
|
222
|
+
- [Discord](https://discord.gg/valyu)
|
|
223
|
+
- [GitHub Issues](https://github.com/valyuAI/valyu-js/issues)
|
|
725
224
|
|
|
726
225
|
## License
|
|
727
226
|
|
|
728
|
-
|
|
227
|
+
MIT
|