valyu-js 2.0.2 → 2.1.1
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 +209 -63
- package/dist/index.d.mts +125 -1
- package/dist/index.d.ts +125 -1
- package/dist/index.js +433 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +433 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Valyu SDK
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**Search for AIs**
|
|
4
4
|
|
|
5
5
|
Valyu's Deepsearch API gives AI the context it needs. Integrate trusted, high-quality public and proprietary sources, with full-text multimodal retrieval.
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ Get **$10 free credits** for the Valyu API when you sign up at [Valyu](https://p
|
|
|
10
10
|
|
|
11
11
|
## How does it work?
|
|
12
12
|
|
|
13
|
-
We do all the heavy lifting for you -
|
|
13
|
+
We do all the heavy lifting for you - one unified API for all data:
|
|
14
14
|
|
|
15
15
|
- **Academic & Research Content** - Access millions of scholarly papers and textbooks
|
|
16
16
|
- **Real-time Web Search** - Get the latest information from across the internet
|
|
@@ -36,7 +36,11 @@ const { Valyu } = require('valyu');
|
|
|
36
36
|
const valyu = new Valyu("your-api-key-here");
|
|
37
37
|
|
|
38
38
|
const response = await valyu.search(
|
|
39
|
-
"Implementation details of agentic search-enhanced large reasoning models"
|
|
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
|
+
}
|
|
40
44
|
);
|
|
41
45
|
|
|
42
46
|
console.log(response);
|
|
@@ -81,7 +85,7 @@ valyu.search(
|
|
|
81
85
|
| `relevanceThreshold` | `number` | `0.5` | Minimum relevance score for results (0.0-1.0) |
|
|
82
86
|
| `maxPrice` | `number` | `30` | Maximum price per thousand queries in CPM |
|
|
83
87
|
| `includedSources` | `string[]` | `[]` | Specific data sources or URLs to search |
|
|
84
|
-
| `excludeSources` | `string[]` | `[]` |
|
|
88
|
+
| `excludeSources` | `string[]` | `[]` | Data sources or URLs to exclude from search |
|
|
85
89
|
| `category` | `string` | `null` | Category filter for results |
|
|
86
90
|
| `startDate` | `string` | `null` | Start date filter in YYYY-MM-DD format |
|
|
87
91
|
| `endDate` | `string` | `null` | End date filter in YYYY-MM-DD format |
|
|
@@ -126,6 +130,67 @@ Each `SearchResult` contains:
|
|
|
126
130
|
}
|
|
127
131
|
```
|
|
128
132
|
|
|
133
|
+
### Contents Method
|
|
134
|
+
|
|
135
|
+
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.
|
|
136
|
+
|
|
137
|
+
```javascript
|
|
138
|
+
valyu.contents(
|
|
139
|
+
urls, // Array of URLs to process (max 10)
|
|
140
|
+
{
|
|
141
|
+
summary: false, // AI processing: false, true, string, or JSON schema
|
|
142
|
+
extractEffort: "normal", // Extraction effort: "normal" or "high"
|
|
143
|
+
responseLength: "short", // Content length control
|
|
144
|
+
maxPriceDollars: null // Maximum cost limit in USD
|
|
145
|
+
}
|
|
146
|
+
)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Parameters
|
|
150
|
+
|
|
151
|
+
| Parameter | Type | Default | Description |
|
|
152
|
+
|-----------|------|---------|-------------|
|
|
153
|
+
| `urls` | `string[]` | *required* | Array of URLs to process (maximum 10 URLs per request) |
|
|
154
|
+
| `summary` | `boolean \| string \| object` | `false` | AI summary configuration: `false` (raw content), `true` (auto summary), string (custom instructions), or JSON schema (structured extraction) |
|
|
155
|
+
| `extractEffort` | `string` | `"normal"` | Extraction thoroughness: `"normal"` (fast) or `"high"` (more thorough but slower) |
|
|
156
|
+
| `responseLength` | `string \| number` | `"short"` | Content length per URL: `"short"` (25k chars), `"medium"` (50k), `"large"` (100k), `"max"` (no limit), or custom number |
|
|
157
|
+
| `maxPriceDollars` | `number` | `null` | Maximum cost limit in USD |
|
|
158
|
+
|
|
159
|
+
### Contents Response Format
|
|
160
|
+
|
|
161
|
+
The contents method returns a `ContentsResponse` object with the following structure:
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
{
|
|
165
|
+
success: boolean, // Request success status
|
|
166
|
+
error: string | null, // Error message if any
|
|
167
|
+
tx_id: string, // Transaction ID for tracking
|
|
168
|
+
urls_requested: number, // Total URLs requested
|
|
169
|
+
urls_processed: number, // Successfully processed URLs
|
|
170
|
+
urls_failed: number, // Failed URL count
|
|
171
|
+
results: ContentResult[], // Array of processed results
|
|
172
|
+
total_cost_dollars: number, // Actual cost charged
|
|
173
|
+
total_characters: number // Total characters extracted
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Each `ContentResult` contains:
|
|
178
|
+
|
|
179
|
+
```javascript
|
|
180
|
+
{
|
|
181
|
+
url: string, // Source URL
|
|
182
|
+
title: string, // Page/document title
|
|
183
|
+
content: string | number, // Extracted content
|
|
184
|
+
length: number, // Content length in characters
|
|
185
|
+
source: string, // Data source identifier
|
|
186
|
+
summary?: string | object, // AI-generated summary (if enabled)
|
|
187
|
+
summary_success?: boolean, // Whether summary generation succeeded
|
|
188
|
+
data_type?: string, // Type of data extracted
|
|
189
|
+
image_url?: Record<string, string>, // Extracted images
|
|
190
|
+
citation?: string // APA-style citation
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
129
194
|
## Examples
|
|
130
195
|
|
|
131
196
|
### Basic Search
|
|
@@ -135,24 +200,22 @@ const { Valyu } = require('valyu');
|
|
|
135
200
|
|
|
136
201
|
const valyu = new Valyu("your-api-key");
|
|
137
202
|
|
|
138
|
-
// Simple search
|
|
139
|
-
const response = await valyu.search("
|
|
140
|
-
console.log(response);
|
|
203
|
+
// Simple search across all sources
|
|
204
|
+
const response = await valyu.search("What is machine learning?");
|
|
205
|
+
console.log(`Found ${response.results.length} results`);
|
|
141
206
|
```
|
|
142
207
|
|
|
143
208
|
### Academic Research
|
|
144
209
|
|
|
145
210
|
```javascript
|
|
146
|
-
//
|
|
211
|
+
// Search academic papers on arXiv
|
|
147
212
|
const response = await valyu.search(
|
|
148
|
-
"
|
|
213
|
+
"transformer architecture improvements",
|
|
149
214
|
{
|
|
150
215
|
searchType: "proprietary",
|
|
151
|
-
maxNumResults: 10,
|
|
152
|
-
relevanceThreshold: 0.6,
|
|
153
216
|
includedSources: ["valyu/valyu-arxiv"],
|
|
154
|
-
|
|
155
|
-
|
|
217
|
+
relevanceThreshold: 0.7,
|
|
218
|
+
maxNumResults: 10
|
|
156
219
|
}
|
|
157
220
|
);
|
|
158
221
|
```
|
|
@@ -160,62 +223,29 @@ const response = await valyu.search(
|
|
|
160
223
|
### Web Search with Date Filtering
|
|
161
224
|
|
|
162
225
|
```javascript
|
|
163
|
-
//
|
|
226
|
+
// Search recent web content
|
|
164
227
|
const response = await valyu.search(
|
|
165
|
-
"
|
|
228
|
+
"AI safety developments",
|
|
166
229
|
{
|
|
167
230
|
searchType: "web",
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
endDate: "2025-07-25"
|
|
231
|
+
startDate: "2024-01-01",
|
|
232
|
+
endDate: "2024-12-31",
|
|
233
|
+
maxNumResults: 5
|
|
172
234
|
}
|
|
173
235
|
);
|
|
174
236
|
```
|
|
175
237
|
|
|
176
|
-
###
|
|
238
|
+
### Hybrid Search
|
|
177
239
|
|
|
178
240
|
```javascript
|
|
179
|
-
//
|
|
241
|
+
// Search both web and proprietary sources
|
|
180
242
|
const response = await valyu.search(
|
|
181
|
-
"
|
|
182
|
-
{
|
|
183
|
-
searchType: "web",
|
|
184
|
-
maxNumResults: 2,
|
|
185
|
-
countryCode: "UK",
|
|
186
|
-
responseLength: "short"
|
|
187
|
-
}
|
|
188
|
-
);
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
### Search with Source Exclusion
|
|
192
|
-
|
|
193
|
-
```javascript
|
|
194
|
-
// Hybrid search excluding specific sources
|
|
195
|
-
const response = await valyu.search(
|
|
196
|
-
"quantum computing applications in cryptography",
|
|
243
|
+
"quantum computing breakthroughs",
|
|
197
244
|
{
|
|
198
245
|
searchType: "all",
|
|
199
|
-
|
|
200
|
-
relevanceThreshold: 0.
|
|
201
|
-
maxPrice:
|
|
202
|
-
excludeSources: ["paperswithcode.com", "wikipedia.org"],
|
|
203
|
-
responseLength: "large",
|
|
204
|
-
isToolCall: true
|
|
205
|
-
}
|
|
206
|
-
);
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
### Custom Response Length
|
|
210
|
-
|
|
211
|
-
```javascript
|
|
212
|
-
// Search with custom character count
|
|
213
|
-
const response = await valyu.search(
|
|
214
|
-
"State of video generation AI models",
|
|
215
|
-
{
|
|
216
|
-
maxNumResults: 10,
|
|
217
|
-
category: "vLLMs",
|
|
218
|
-
responseLength: 1000 // Limit to 1000 characters per result
|
|
246
|
+
category: "technology",
|
|
247
|
+
relevanceThreshold: 0.6,
|
|
248
|
+
maxPrice: 50
|
|
219
249
|
}
|
|
220
250
|
);
|
|
221
251
|
```
|
|
@@ -240,6 +270,94 @@ if (response.success) {
|
|
|
240
270
|
}
|
|
241
271
|
```
|
|
242
272
|
|
|
273
|
+
### Content Extraction Examples
|
|
274
|
+
|
|
275
|
+
#### Basic Content Extraction
|
|
276
|
+
|
|
277
|
+
```javascript
|
|
278
|
+
// Extract raw content from URLs
|
|
279
|
+
const response = await valyu.contents(
|
|
280
|
+
["https://techcrunch.com/2025/08/28/anthropic-users-face-a-new-choice-opt-out-or-share-your-data-for-ai-training/"]
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
if (response.success) {
|
|
284
|
+
response.results.forEach(result => {
|
|
285
|
+
console.log(`Title: ${result.title}`);
|
|
286
|
+
console.log(`Content: ${result.content.substring(0, 500)}...`);
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
#### Content with AI Summary
|
|
292
|
+
|
|
293
|
+
```javascript
|
|
294
|
+
// Extract content with automatic summarization
|
|
295
|
+
const response = await valyu.contents(
|
|
296
|
+
["https://docs.python.org/3/tutorial/"],
|
|
297
|
+
{
|
|
298
|
+
summary: true,
|
|
299
|
+
responseLength: "max"
|
|
300
|
+
}
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
response.results.forEach(result => {
|
|
304
|
+
console.log(`Summary: ${result.summary}`);
|
|
305
|
+
});
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
#### Structured Data Extraction
|
|
309
|
+
|
|
310
|
+
```javascript
|
|
311
|
+
// Extract structured data using JSON schema
|
|
312
|
+
const companySchema = {
|
|
313
|
+
type: "object",
|
|
314
|
+
properties: {
|
|
315
|
+
company_name: { type: "string" },
|
|
316
|
+
founded_year: { type: "integer" },
|
|
317
|
+
key_products: {
|
|
318
|
+
type: "array",
|
|
319
|
+
items: { type: "string" },
|
|
320
|
+
maxItems: 3
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
const response = await valyu.contents(
|
|
326
|
+
["https://en.wikipedia.org/wiki/OpenAI"],
|
|
327
|
+
{
|
|
328
|
+
summary: companySchema,
|
|
329
|
+
responseLength: "max"
|
|
330
|
+
}
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
if (response.success) {
|
|
334
|
+
response.results.forEach(result => {
|
|
335
|
+
if (result.summary) {
|
|
336
|
+
console.log(`Structured data: ${JSON.stringify(result.summary, null, 2)}`);
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
#### Multiple URLs
|
|
343
|
+
|
|
344
|
+
```javascript
|
|
345
|
+
// Process multiple URLs with a cost limit
|
|
346
|
+
const response = await valyu.contents(
|
|
347
|
+
[
|
|
348
|
+
"https://www.valyu.network/",
|
|
349
|
+
"https://docs.valyu.network/overview",
|
|
350
|
+
"https://www.valyu.network/blogs/why-ai-agents-and-llms-struggle-with-search-and-data-access"
|
|
351
|
+
],
|
|
352
|
+
{
|
|
353
|
+
summary: "Provide key takeaways in bullet points, and write in very emphasised singaporean english"
|
|
354
|
+
}
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
console.log(`Processed ${response.urls_processed}/${response.urls_requested} URLs`);
|
|
358
|
+
console.log(`Cost: $${response.total_cost_dollars.toFixed(4)}`);
|
|
359
|
+
```
|
|
360
|
+
|
|
243
361
|
## Authentication
|
|
244
362
|
|
|
245
363
|
Set your API key in one of these ways:
|
|
@@ -277,11 +395,20 @@ if (!response.success) {
|
|
|
277
395
|
The SDK includes full TypeScript support with type definitions for all parameters:
|
|
278
396
|
|
|
279
397
|
```typescript
|
|
280
|
-
import {
|
|
398
|
+
import {
|
|
399
|
+
Valyu,
|
|
400
|
+
SearchOptions,
|
|
401
|
+
SearchResponse,
|
|
402
|
+
ContentsOptions,
|
|
403
|
+
ContentsResponse,
|
|
404
|
+
CountryCode,
|
|
405
|
+
ResponseLength
|
|
406
|
+
} from 'valyu';
|
|
281
407
|
|
|
282
408
|
const valyu = new Valyu("your-api-key");
|
|
283
409
|
|
|
284
|
-
|
|
410
|
+
// Search API with types
|
|
411
|
+
const searchOptions: SearchOptions = {
|
|
285
412
|
searchType: "proprietary",
|
|
286
413
|
maxNumResults: 10,
|
|
287
414
|
relevanceThreshold: 0.6,
|
|
@@ -290,7 +417,20 @@ const options: SearchOptions = {
|
|
|
290
417
|
responseLength: "medium" as ResponseLength
|
|
291
418
|
};
|
|
292
419
|
|
|
293
|
-
const
|
|
420
|
+
const searchResponse: SearchResponse = await valyu.search("machine learning", searchOptions);
|
|
421
|
+
|
|
422
|
+
// Contents API with types
|
|
423
|
+
const contentsOptions: ContentsOptions = {
|
|
424
|
+
summary: true,
|
|
425
|
+
extractEffort: "high",
|
|
426
|
+
responseLength: "medium",
|
|
427
|
+
maxPriceDollars: 0.10
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
const contentsResponse: ContentsResponse = await valyu.contents(
|
|
431
|
+
["https://example.com"],
|
|
432
|
+
contentsOptions
|
|
433
|
+
);
|
|
294
434
|
```
|
|
295
435
|
|
|
296
436
|
## Backward Compatibility
|
|
@@ -321,7 +461,7 @@ const response = await valyu.context(
|
|
|
321
461
|
|
|
322
462
|
## Getting Started
|
|
323
463
|
|
|
324
|
-
1. Sign up for a free account at [Valyu](https://
|
|
464
|
+
1. Sign up for a free account at [Valyu](https://platform.valyu.network)
|
|
325
465
|
2. Get your API key from the dashboard
|
|
326
466
|
3. Install the SDK: `npm install valyu`
|
|
327
467
|
4. Start building with the examples above
|
|
@@ -334,10 +474,16 @@ Run the integration tests:
|
|
|
334
474
|
npm run test:integration
|
|
335
475
|
```
|
|
336
476
|
|
|
337
|
-
Run the
|
|
477
|
+
Run the Search API examples:
|
|
478
|
+
|
|
479
|
+
```bash
|
|
480
|
+
node examples/search-examples.js
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
Run the Contents API examples:
|
|
338
484
|
|
|
339
485
|
```bash
|
|
340
|
-
node examples/
|
|
486
|
+
node examples/contents-examples.js
|
|
341
487
|
```
|
|
342
488
|
|
|
343
489
|
## Support
|
package/dist/index.d.mts
CHANGED
|
@@ -27,6 +27,7 @@ interface SearchOptions {
|
|
|
27
27
|
endDate?: string;
|
|
28
28
|
countryCode?: CountryCode;
|
|
29
29
|
responseLength?: ResponseLength;
|
|
30
|
+
fastMode?: boolean;
|
|
30
31
|
}
|
|
31
32
|
interface SearchResponse {
|
|
32
33
|
success: boolean;
|
|
@@ -46,6 +47,80 @@ interface FeedbackResponse {
|
|
|
46
47
|
success: boolean;
|
|
47
48
|
error?: string;
|
|
48
49
|
}
|
|
50
|
+
type ExtractEffort = "normal" | "high" | "auto";
|
|
51
|
+
type ContentResponseLength = "short" | "medium" | "large" | "max" | number;
|
|
52
|
+
interface ContentsOptions {
|
|
53
|
+
summary?: boolean | string | object;
|
|
54
|
+
extractEffort?: ExtractEffort;
|
|
55
|
+
responseLength?: ContentResponseLength;
|
|
56
|
+
maxPriceDollars?: number;
|
|
57
|
+
}
|
|
58
|
+
interface ContentResult {
|
|
59
|
+
url: string;
|
|
60
|
+
title: string;
|
|
61
|
+
content: string | number;
|
|
62
|
+
length: number;
|
|
63
|
+
source: string;
|
|
64
|
+
summary?: string | object;
|
|
65
|
+
summary_success?: boolean;
|
|
66
|
+
data_type?: string;
|
|
67
|
+
image_url?: Record<string, string>;
|
|
68
|
+
citation?: string;
|
|
69
|
+
}
|
|
70
|
+
interface ContentsResponse {
|
|
71
|
+
success: boolean;
|
|
72
|
+
error?: string | null;
|
|
73
|
+
tx_id?: string;
|
|
74
|
+
urls_requested?: number;
|
|
75
|
+
urls_processed?: number;
|
|
76
|
+
urls_failed?: number;
|
|
77
|
+
results?: ContentResult[];
|
|
78
|
+
total_cost_dollars?: number;
|
|
79
|
+
total_characters?: number;
|
|
80
|
+
isProvisioning?: boolean;
|
|
81
|
+
}
|
|
82
|
+
interface AnswerOptions {
|
|
83
|
+
structuredOutput?: Record<string, any>;
|
|
84
|
+
systemInstructions?: string;
|
|
85
|
+
searchType?: SearchType;
|
|
86
|
+
dataMaxPrice?: number;
|
|
87
|
+
countryCode?: CountryCode;
|
|
88
|
+
includedSources?: string[];
|
|
89
|
+
excludedSources?: string[];
|
|
90
|
+
startDate?: string;
|
|
91
|
+
endDate?: string;
|
|
92
|
+
fastMode?: boolean;
|
|
93
|
+
}
|
|
94
|
+
interface SearchMetadata {
|
|
95
|
+
tx_ids: string[];
|
|
96
|
+
number_of_results: number;
|
|
97
|
+
total_characters: number;
|
|
98
|
+
}
|
|
99
|
+
interface AIUsage {
|
|
100
|
+
input_tokens: number;
|
|
101
|
+
output_tokens: number;
|
|
102
|
+
}
|
|
103
|
+
interface Cost {
|
|
104
|
+
total_deduction_dollars: number;
|
|
105
|
+
search_deduction_dollars: number;
|
|
106
|
+
ai_deduction_dollars: number;
|
|
107
|
+
}
|
|
108
|
+
interface AnswerSuccessResponse {
|
|
109
|
+
success: true;
|
|
110
|
+
ai_tx_id: string;
|
|
111
|
+
original_query: string;
|
|
112
|
+
contents: string | Record<string, any>;
|
|
113
|
+
data_type: "structured" | "unstructured";
|
|
114
|
+
search_results: SearchResult[];
|
|
115
|
+
search_metadata: SearchMetadata;
|
|
116
|
+
ai_usage: AIUsage;
|
|
117
|
+
cost: Cost;
|
|
118
|
+
}
|
|
119
|
+
interface AnswerErrorResponse {
|
|
120
|
+
success: false;
|
|
121
|
+
error: string;
|
|
122
|
+
}
|
|
123
|
+
type AnswerResponse = AnswerSuccessResponse | AnswerErrorResponse;
|
|
49
124
|
|
|
50
125
|
declare class Valyu {
|
|
51
126
|
private baseUrl;
|
|
@@ -55,6 +130,26 @@ declare class Valyu {
|
|
|
55
130
|
* Validates date format (YYYY-MM-DD)
|
|
56
131
|
*/
|
|
57
132
|
private validateDateFormat;
|
|
133
|
+
/**
|
|
134
|
+
* Validates if a string is a valid URL
|
|
135
|
+
*/
|
|
136
|
+
private validateUrl;
|
|
137
|
+
/**
|
|
138
|
+
* Validates if a string is a valid domain (with optional path)
|
|
139
|
+
*/
|
|
140
|
+
private validateDomain;
|
|
141
|
+
/**
|
|
142
|
+
* Validates if a string is a valid dataset identifier (provider/datasetname)
|
|
143
|
+
*/
|
|
144
|
+
private validateDatasetId;
|
|
145
|
+
/**
|
|
146
|
+
* Validates source strings (domains, URLs, or dataset IDs)
|
|
147
|
+
*/
|
|
148
|
+
private validateSource;
|
|
149
|
+
/**
|
|
150
|
+
* Validates an array of source strings
|
|
151
|
+
*/
|
|
152
|
+
private validateSources;
|
|
58
153
|
/**
|
|
59
154
|
* Search for information using the Valyu DeepSearch API
|
|
60
155
|
* @param query - The search query string
|
|
@@ -71,9 +166,38 @@ declare class Valyu {
|
|
|
71
166
|
* @param options.endDate - End date filter (YYYY-MM-DD format)
|
|
72
167
|
* @param options.countryCode - Country code filter for search results
|
|
73
168
|
* @param options.responseLength - Response content length: "short"/"medium"/"large"/"max" or integer character count
|
|
169
|
+
* @param options.fastMode - Fast mode for quicker but shorter results (default: false)
|
|
74
170
|
* @returns Promise resolving to search results
|
|
75
171
|
*/
|
|
76
172
|
search(query: string, options?: SearchOptions): Promise<SearchResponse>;
|
|
173
|
+
/**
|
|
174
|
+
* Extract content from URLs with optional AI processing
|
|
175
|
+
* @param urls - Array of URLs to process (max 10)
|
|
176
|
+
* @param options - Content extraction configuration options
|
|
177
|
+
* @param options.summary - AI summary configuration: false (raw), true (auto), string (custom), or JSON schema
|
|
178
|
+
* @param options.extractEffort - Extraction thoroughness: "normal" or "high"
|
|
179
|
+
* @param options.responseLength - Content length per URL
|
|
180
|
+
* @param options.maxPriceDollars - Maximum cost limit in USD
|
|
181
|
+
* @returns Promise resolving to content extraction results
|
|
182
|
+
*/
|
|
183
|
+
contents(urls: string[], options?: ContentsOptions): Promise<ContentsResponse>;
|
|
184
|
+
/**
|
|
185
|
+
* Get AI-powered answers using the Valyu Answer API
|
|
186
|
+
* @param query - The question or query string
|
|
187
|
+
* @param options - Answer configuration options
|
|
188
|
+
* @param options.structuredOutput - JSON Schema object for structured responses
|
|
189
|
+
* @param options.systemInstructions - Custom system-level instructions (max 2000 chars)
|
|
190
|
+
* @param options.searchType - Type of search: "web", "proprietary", or "all"
|
|
191
|
+
* @param options.dataMaxPrice - Maximum spend (USD) for data retrieval
|
|
192
|
+
* @param options.countryCode - Country code filter for search results
|
|
193
|
+
* @param options.includedSources - List of specific sources to include
|
|
194
|
+
* @param options.excludedSources - List of URLs/domains to exclude from search results
|
|
195
|
+
* @param options.startDate - Start date filter (YYYY-MM-DD format)
|
|
196
|
+
* @param options.endDate - End date filter (YYYY-MM-DD format)
|
|
197
|
+
* @param options.fastMode - Fast mode for quicker but shorter results (default: false)
|
|
198
|
+
* @returns Promise resolving to answer response
|
|
199
|
+
*/
|
|
200
|
+
answer(query: string, options?: AnswerOptions): Promise<AnswerResponse>;
|
|
77
201
|
}
|
|
78
202
|
|
|
79
|
-
export { type CountryCode, type FeedbackResponse, type FeedbackSentiment, type ResponseLength, type SearchOptions, type SearchResponse, type SearchType, Valyu };
|
|
203
|
+
export { type AIUsage, type AnswerErrorResponse, type AnswerOptions, type AnswerResponse, type AnswerSuccessResponse, type ContentResponseLength, type ContentResult, type ContentsOptions, type ContentsResponse, type Cost, type CountryCode, type ExtractEffort, type FeedbackResponse, type FeedbackSentiment, type ResponseLength, type SearchMetadata, type SearchOptions, type SearchResponse, type SearchType, Valyu };
|
package/dist/index.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ interface SearchOptions {
|
|
|
27
27
|
endDate?: string;
|
|
28
28
|
countryCode?: CountryCode;
|
|
29
29
|
responseLength?: ResponseLength;
|
|
30
|
+
fastMode?: boolean;
|
|
30
31
|
}
|
|
31
32
|
interface SearchResponse {
|
|
32
33
|
success: boolean;
|
|
@@ -46,6 +47,80 @@ interface FeedbackResponse {
|
|
|
46
47
|
success: boolean;
|
|
47
48
|
error?: string;
|
|
48
49
|
}
|
|
50
|
+
type ExtractEffort = "normal" | "high" | "auto";
|
|
51
|
+
type ContentResponseLength = "short" | "medium" | "large" | "max" | number;
|
|
52
|
+
interface ContentsOptions {
|
|
53
|
+
summary?: boolean | string | object;
|
|
54
|
+
extractEffort?: ExtractEffort;
|
|
55
|
+
responseLength?: ContentResponseLength;
|
|
56
|
+
maxPriceDollars?: number;
|
|
57
|
+
}
|
|
58
|
+
interface ContentResult {
|
|
59
|
+
url: string;
|
|
60
|
+
title: string;
|
|
61
|
+
content: string | number;
|
|
62
|
+
length: number;
|
|
63
|
+
source: string;
|
|
64
|
+
summary?: string | object;
|
|
65
|
+
summary_success?: boolean;
|
|
66
|
+
data_type?: string;
|
|
67
|
+
image_url?: Record<string, string>;
|
|
68
|
+
citation?: string;
|
|
69
|
+
}
|
|
70
|
+
interface ContentsResponse {
|
|
71
|
+
success: boolean;
|
|
72
|
+
error?: string | null;
|
|
73
|
+
tx_id?: string;
|
|
74
|
+
urls_requested?: number;
|
|
75
|
+
urls_processed?: number;
|
|
76
|
+
urls_failed?: number;
|
|
77
|
+
results?: ContentResult[];
|
|
78
|
+
total_cost_dollars?: number;
|
|
79
|
+
total_characters?: number;
|
|
80
|
+
isProvisioning?: boolean;
|
|
81
|
+
}
|
|
82
|
+
interface AnswerOptions {
|
|
83
|
+
structuredOutput?: Record<string, any>;
|
|
84
|
+
systemInstructions?: string;
|
|
85
|
+
searchType?: SearchType;
|
|
86
|
+
dataMaxPrice?: number;
|
|
87
|
+
countryCode?: CountryCode;
|
|
88
|
+
includedSources?: string[];
|
|
89
|
+
excludedSources?: string[];
|
|
90
|
+
startDate?: string;
|
|
91
|
+
endDate?: string;
|
|
92
|
+
fastMode?: boolean;
|
|
93
|
+
}
|
|
94
|
+
interface SearchMetadata {
|
|
95
|
+
tx_ids: string[];
|
|
96
|
+
number_of_results: number;
|
|
97
|
+
total_characters: number;
|
|
98
|
+
}
|
|
99
|
+
interface AIUsage {
|
|
100
|
+
input_tokens: number;
|
|
101
|
+
output_tokens: number;
|
|
102
|
+
}
|
|
103
|
+
interface Cost {
|
|
104
|
+
total_deduction_dollars: number;
|
|
105
|
+
search_deduction_dollars: number;
|
|
106
|
+
ai_deduction_dollars: number;
|
|
107
|
+
}
|
|
108
|
+
interface AnswerSuccessResponse {
|
|
109
|
+
success: true;
|
|
110
|
+
ai_tx_id: string;
|
|
111
|
+
original_query: string;
|
|
112
|
+
contents: string | Record<string, any>;
|
|
113
|
+
data_type: "structured" | "unstructured";
|
|
114
|
+
search_results: SearchResult[];
|
|
115
|
+
search_metadata: SearchMetadata;
|
|
116
|
+
ai_usage: AIUsage;
|
|
117
|
+
cost: Cost;
|
|
118
|
+
}
|
|
119
|
+
interface AnswerErrorResponse {
|
|
120
|
+
success: false;
|
|
121
|
+
error: string;
|
|
122
|
+
}
|
|
123
|
+
type AnswerResponse = AnswerSuccessResponse | AnswerErrorResponse;
|
|
49
124
|
|
|
50
125
|
declare class Valyu {
|
|
51
126
|
private baseUrl;
|
|
@@ -55,6 +130,26 @@ declare class Valyu {
|
|
|
55
130
|
* Validates date format (YYYY-MM-DD)
|
|
56
131
|
*/
|
|
57
132
|
private validateDateFormat;
|
|
133
|
+
/**
|
|
134
|
+
* Validates if a string is a valid URL
|
|
135
|
+
*/
|
|
136
|
+
private validateUrl;
|
|
137
|
+
/**
|
|
138
|
+
* Validates if a string is a valid domain (with optional path)
|
|
139
|
+
*/
|
|
140
|
+
private validateDomain;
|
|
141
|
+
/**
|
|
142
|
+
* Validates if a string is a valid dataset identifier (provider/datasetname)
|
|
143
|
+
*/
|
|
144
|
+
private validateDatasetId;
|
|
145
|
+
/**
|
|
146
|
+
* Validates source strings (domains, URLs, or dataset IDs)
|
|
147
|
+
*/
|
|
148
|
+
private validateSource;
|
|
149
|
+
/**
|
|
150
|
+
* Validates an array of source strings
|
|
151
|
+
*/
|
|
152
|
+
private validateSources;
|
|
58
153
|
/**
|
|
59
154
|
* Search for information using the Valyu DeepSearch API
|
|
60
155
|
* @param query - The search query string
|
|
@@ -71,9 +166,38 @@ declare class Valyu {
|
|
|
71
166
|
* @param options.endDate - End date filter (YYYY-MM-DD format)
|
|
72
167
|
* @param options.countryCode - Country code filter for search results
|
|
73
168
|
* @param options.responseLength - Response content length: "short"/"medium"/"large"/"max" or integer character count
|
|
169
|
+
* @param options.fastMode - Fast mode for quicker but shorter results (default: false)
|
|
74
170
|
* @returns Promise resolving to search results
|
|
75
171
|
*/
|
|
76
172
|
search(query: string, options?: SearchOptions): Promise<SearchResponse>;
|
|
173
|
+
/**
|
|
174
|
+
* Extract content from URLs with optional AI processing
|
|
175
|
+
* @param urls - Array of URLs to process (max 10)
|
|
176
|
+
* @param options - Content extraction configuration options
|
|
177
|
+
* @param options.summary - AI summary configuration: false (raw), true (auto), string (custom), or JSON schema
|
|
178
|
+
* @param options.extractEffort - Extraction thoroughness: "normal" or "high"
|
|
179
|
+
* @param options.responseLength - Content length per URL
|
|
180
|
+
* @param options.maxPriceDollars - Maximum cost limit in USD
|
|
181
|
+
* @returns Promise resolving to content extraction results
|
|
182
|
+
*/
|
|
183
|
+
contents(urls: string[], options?: ContentsOptions): Promise<ContentsResponse>;
|
|
184
|
+
/**
|
|
185
|
+
* Get AI-powered answers using the Valyu Answer API
|
|
186
|
+
* @param query - The question or query string
|
|
187
|
+
* @param options - Answer configuration options
|
|
188
|
+
* @param options.structuredOutput - JSON Schema object for structured responses
|
|
189
|
+
* @param options.systemInstructions - Custom system-level instructions (max 2000 chars)
|
|
190
|
+
* @param options.searchType - Type of search: "web", "proprietary", or "all"
|
|
191
|
+
* @param options.dataMaxPrice - Maximum spend (USD) for data retrieval
|
|
192
|
+
* @param options.countryCode - Country code filter for search results
|
|
193
|
+
* @param options.includedSources - List of specific sources to include
|
|
194
|
+
* @param options.excludedSources - List of URLs/domains to exclude from search results
|
|
195
|
+
* @param options.startDate - Start date filter (YYYY-MM-DD format)
|
|
196
|
+
* @param options.endDate - End date filter (YYYY-MM-DD format)
|
|
197
|
+
* @param options.fastMode - Fast mode for quicker but shorter results (default: false)
|
|
198
|
+
* @returns Promise resolving to answer response
|
|
199
|
+
*/
|
|
200
|
+
answer(query: string, options?: AnswerOptions): Promise<AnswerResponse>;
|
|
77
201
|
}
|
|
78
202
|
|
|
79
|
-
export { type CountryCode, type FeedbackResponse, type FeedbackSentiment, type ResponseLength, type SearchOptions, type SearchResponse, type SearchType, Valyu };
|
|
203
|
+
export { type AIUsage, type AnswerErrorResponse, type AnswerOptions, type AnswerResponse, type AnswerSuccessResponse, type ContentResponseLength, type ContentResult, type ContentsOptions, type ContentsResponse, type Cost, type CountryCode, type ExtractEffort, type FeedbackResponse, type FeedbackSentiment, type ResponseLength, type SearchMetadata, type SearchOptions, type SearchResponse, type SearchType, Valyu };
|