Skip to content

Commit f3eda82

Browse files
authored
Merge pull request #5 from perplexityai/release-please--branches--main--changes--next--components--perplexity_ai
2 parents bbfa69f + 18e4e1f commit f3eda82

File tree

21 files changed

+982
-97
lines changed

21 files changed

+982
-97
lines changed

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "0.7.1"
2+
".": "0.8.0"
33
}

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 5
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/perplexity-ai%2Fperplexity-aba0c21c569842e93e17b69cae9cee58d389fce9c2482f4d251fd8727db05679.yml
33
openapi_spec_hash: 3d01b1c1425f7d43a8acf8b99bb9b321
4-
config_hash: 43831e7f153f67b8f23f7091d14db066
4+
config_hash: 0be7520657a7a0fb6b5a839e716fe30c

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 0.8.0 (2025-10-02)
4+
5+
Full Changelog: [v0.7.1...v0.8.0](https://github.com/perplexityai/perplexity-node/compare/v0.7.1...v0.8.0)
6+
7+
### Features
8+
9+
* **api:** manual updates ([743c3aa](https://github.com/perplexityai/perplexity-node/commit/743c3aad0ea1021edca19f345c67c33665eaf074))
10+
311
## 0.7.1 (2025-10-01)
412

513
Full Changelog: [v0.7.0...v0.7.1](https://github.com/perplexityai/perplexity-node/compare/v0.7.0...v0.7.1)

README.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ const client = new Perplexity({
5050
apiKey: process.env['PERPLEXITY_API_KEY'], // This is the default and can be omitted
5151
});
5252

53-
const completion = await client.chat.completions.create({
53+
const streamChunk = await client.chat.completions.create({
5454
messages: [{ role: 'user', content: 'Tell me about the latest developments in AI' }],
5555
model: 'sonar',
5656
});
5757

58-
console.log(completion.choices[0].message.content);
58+
console.log(streamChunk.content);
5959
```
6060

6161
### Advanced Search Features
@@ -139,6 +139,28 @@ const localSearch = await client.search.create({
139139
});
140140
```
141141

142+
## Streaming responses
143+
144+
We provide support for streaming responses using Server Sent Events (SSE).
145+
146+
```ts
147+
import Perplexity from '@perplexity-ai/perplexity_ai';
148+
149+
const client = new Perplexity();
150+
151+
const stream = await client.chat.completions.create({
152+
messages: [{ role: 'user', content: 'What is the capital of France?' }],
153+
model: 'sonar',
154+
stream: true,
155+
});
156+
for await (const streamChunk of stream) {
157+
console.log(streamChunk.id);
158+
}
159+
```
160+
161+
If you need to cancel a stream, you can `break` from the loop
162+
or call `stream.controller.abort()`.
163+
142164
### Request & Response types
143165

144166
This library includes TypeScript definitions for all request params and response fields. You may import and use them like so:
@@ -169,7 +191,7 @@ const chatParams: Perplexity.Chat.CompletionCreateParams = {
169191
messages: [{ role: 'user', content: 'What is the capital of France?' }],
170192
model: 'sonar',
171193
};
172-
const chatResponse: Perplexity.Chat.CompletionCreateResponse = await client.chat.completions.create(chatParams);
194+
const streamChunk: Perplexity.StreamChunk = await client.chat.completions.create(chatParams);
173195
```
174196

175197
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
@@ -195,7 +217,7 @@ const search = await client.search
195217
});
196218

197219
// Chat completions error handling
198-
const completion = await client.chat.completions
220+
const streamChunk = await client.chat.completions
199221
.create({ messages: [{ role: 'user', content: 'What is the capital of France?' }], model: 'sonar' })
200222
.catch(async (err) => {
201223
if (err instanceof Perplexity.APIError) {
@@ -302,11 +324,11 @@ const chatResponse = await client.chat.completions
302324
console.log(chatResponse.headers.get('X-My-Header'));
303325
console.log(chatResponse.statusText); // access the underlying Response object
304326

305-
const { data: completion, response: rawChatResponse } = await client.chat.completions
327+
const { data: streamChunk, response: rawChatResponse } = await client.chat.completions
306328
.create({ messages: [{ role: 'user', content: 'What is the capital of France?' }], model: 'sonar' })
307329
.withResponse();
308330
console.log(rawChatResponse.headers.get('X-My-Header'));
309-
console.log(completion.id);
331+
console.log(streamChunk.id);
310332
```
311333

312334
### Logging

api.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ Types:
1010

1111
# Chat
1212

13-
## Completions
14-
1513
Types:
1614

17-
- <code><a href="./src/resources/chat/completions.ts">CompletionCreateResponse</a></code>
15+
- <code><a href="./src/resources/chat/chat.ts">StreamChunk</a></code>
16+
17+
## Completions
1818

1919
Methods:
2020

21-
- <code title="post /chat/completions">client.chat.completions.<a href="./src/resources/chat/completions.ts">create</a>({ ...params }) -> CompletionCreateResponse</code>
21+
- <code title="post /chat/completions">client.chat.completions.<a href="./src/resources/chat/completions.ts">create</a>({ ...params }) -> StreamChunk</code>
2222

2323
# Async
2424

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@perplexity-ai/perplexity_ai",
3-
"version": "0.7.1",
3+
"version": "0.8.0",
44
"description": "The official TypeScript library for the Perplexity API",
55
"author": "Perplexity <>",
66
"types": "dist/index.d.ts",

src/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import * as API from './resources/index';
1818
import { APIPromise } from './core/api-promise';
1919
import { Search, SearchCreateParams, SearchCreateResponse } from './resources/search';
2020
import { Async } from './resources/async/async';
21-
import { Chat } from './resources/chat/chat';
21+
import { Chat, StreamChunk } from './resources/chat/chat';
2222
import { type Fetch } from './internal/builtin-types';
2323
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
2424
import { FinalRequestOptions, RequestOptions } from './internal/request-options';
@@ -728,7 +728,7 @@ Perplexity.Search = Search;
728728
export declare namespace Perplexity {
729729
export type RequestOptions = Opts.RequestOptions;
730730

731-
export { Chat as Chat };
731+
export { Chat as Chat, type StreamChunk as StreamChunk };
732732

733733
export { Async as Async };
734734

0 commit comments

Comments
 (0)