@@ -31,7 +31,7 @@ const client = new Perplexity({
3131
3232const search = await client .search .create ({
3333 query: " latest AI developments 2024" ,
34- maxResults : 5
34+ max_results : 5
3535});
3636
3737for (const result of search .results ) {
@@ -71,7 +71,7 @@ const search = await client.search.create({
7171 " solar power innovations" ,
7272 " wind energy developments"
7373 ],
74- maxResults : 10
74+ max_results : 10
7575});
7676```
7777
@@ -82,13 +82,13 @@ Limit search results to specific trusted domains:
8282``` js
8383const search = await client .search .create ({
8484 query: " climate change research" ,
85- searchDomainFilter : [
85+ search_domain_filter : [
8686 " science.org" ,
8787 " pnas.org" ,
8888 " cell.com" ,
8989 " nature.com"
9090 ],
91- maxResults : 10
91+ max_results : 10
9292});
9393```
9494
@@ -100,14 +100,14 @@ Filter results by recency or specific date ranges:
100100// Get results from the past week
101101const recentSearch = await client .search .create ({
102102 query: " latest AI developments" ,
103- searchRecencyFilter : " week"
103+ search_recency_filter : " week"
104104});
105105
106106// Search within a specific date range
107107const dateRangeSearch = await client .search .create ({
108108 query: " AI developments" ,
109- searchAfterDateFilter : " 01/01/2024" ,
110- searchBeforeDateFilter : " 12/31/2024"
109+ search_after_date_filter : " 01/01/2024" ,
110+ search_before_date_filter : " 12/31/2024"
111111});
112112```
113113
@@ -118,24 +118,8 @@ Search academic sources for research purposes:
118118``` js
119119const academicSearch = await client .search .create ({
120120 query: " machine learning algorithms" ,
121- searchMode: " academic" ,
122- maxResults: 10
123- });
124- ```
125-
126- #### Location-Based Search
127-
128- Get geographically relevant results:
129-
130- ``` js
131- const localSearch = await client .search .create ({
132- query: " local restaurants" ,
133- userLocationFilter: {
134- latitude: 37.7749 ,
135- longitude: - 122.4194 ,
136- radius: 10 // km
137- },
138- maxResults: 10
121+ search_mode: " academic" ,
122+ max_results: 10
139123});
140124```
141125
@@ -175,16 +159,17 @@ const client = new Perplexity({
175159// Search API types
176160const searchParams: Perplexity .Search .SearchCreateParams = {
177161 query: " artificial intelligence trends" ,
178- maxResults : 5 ,
179- searchMode : " web"
162+ max_results : 5 ,
163+ search_mode : " web"
180164};
181165const searchResponse: Perplexity .Search .SearchCreateResponse = await client .search .create (searchParams );
182166
183- // Content API types
184- const contentParams: Perplexity .Content .ContentCreateParams = {
185- urls: [" https://example.com/article" ]
167+ // Responses API types
168+ const responseParams: Perplexity .ResponseCreateParams = {
169+ input: " What is the capital of France?" ,
170+ model: " sonar" ,
186171};
187- const contentResponse : Perplexity .Content . ContentCreateResponse = await client .content .create (contentParams );
172+ const response : Perplexity .ResponseCreateResponse = await client .responses .create (responseParams );
188173
189174// Chat Completions types
190175const chatParams: Perplexity .Chat .CompletionCreateParams = {
@@ -205,7 +190,7 @@ a subclass of `APIError` will be thrown:
205190``` ts
206191// Search API error handling
207192const search = await client .search
208- .create ({ query: " AI developments" , maxResults : 5 })
193+ .create ({ query: " AI developments" , max_results : 5 })
209194 .catch (async (err ) => {
210195 if (err instanceof Perplexity .APIError ) {
211196 console .log (err .status ); // 400
@@ -261,7 +246,7 @@ const client = new Perplexity({
261246});
262247
263248// Or, configure per-request:
264- await client .search .create ({ query: " AI developments" , maxResults : 5 }, {
249+ await client .search .create ({ query: " AI developments" , max_results : 5 }, {
265250 maxRetries: 5 ,
266251});
267252
@@ -281,7 +266,7 @@ const client = new Perplexity({
281266});
282267
283268// Override per-request:
284- await client .search .create ({ query: " AI developments" , maxResults : 5 }, {
269+ await client .search .create ({ query: " AI developments" , max_results : 5 }, {
285270 timeout: 5 * 1000 ,
286271});
287272
@@ -309,13 +294,13 @@ const client = new Perplexity();
309294
310295// With search API
311296const searchResponse = await client .search
312- .create ({ query: " AI developments" , maxResults : 5 })
297+ .create ({ query: " AI developments" , max_results : 5 })
313298 .asResponse ();
314299console .log (searchResponse .headers .get (' X-My-Header' ));
315300console .log (searchResponse .statusText ); // access the underlying Response object
316301
317302const { data : search, response : rawSearchResponse } = await client .search
318- .create ({ query: " AI developments" , maxResults : 5 })
303+ .create ({ query: " AI developments" , max_results : 5 })
319304 .withResponse ();
320305console .log (rawSearchResponse .headers .get (' X-My-Header' ));
321306console .log (search .results .length );
0 commit comments