Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.7.1"
".": "0.8.0"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 5
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/perplexity-ai%2Fperplexity-aba0c21c569842e93e17b69cae9cee58d389fce9c2482f4d251fd8727db05679.yml
openapi_spec_hash: 3d01b1c1425f7d43a8acf8b99bb9b321
config_hash: 43831e7f153f67b8f23f7091d14db066
config_hash: 0be7520657a7a0fb6b5a839e716fe30c
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 0.8.0 (2025-10-02)

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

### Features

* **api:** manual updates ([743c3aa](https://github.com/perplexityai/perplexity-node/commit/743c3aad0ea1021edca19f345c67c33665eaf074))

## 0.7.1 (2025-10-01)

Full Changelog: [v0.7.0...v0.7.1](https://github.com/perplexityai/perplexity-node/compare/v0.7.0...v0.7.1)
Expand Down
34 changes: 28 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ const client = new Perplexity({
apiKey: process.env['PERPLEXITY_API_KEY'], // This is the default and can be omitted
});

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

console.log(completion.choices[0].message.content);
console.log(streamChunk.content);
```

### Advanced Search Features
Expand Down Expand Up @@ -139,6 +139,28 @@ const localSearch = await client.search.create({
});
```

## Streaming responses

We provide support for streaming responses using Server Sent Events (SSE).

```ts
import Perplexity from '@perplexity-ai/perplexity_ai';

const client = new Perplexity();

const stream = await client.chat.completions.create({
messages: [{ role: 'user', content: 'What is the capital of France?' }],
model: 'sonar',
stream: true,
});
for await (const streamChunk of stream) {
console.log(streamChunk.id);
}
```

If you need to cancel a stream, you can `break` from the loop
or call `stream.controller.abort()`.

### Request & Response types

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

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

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

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

### Logging
Expand Down
8 changes: 4 additions & 4 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ Types:

# Chat

## Completions

Types:

- <code><a href="./src/resources/chat/completions.ts">CompletionCreateResponse</a></code>
- <code><a href="./src/resources/chat/chat.ts">StreamChunk</a></code>

## Completions

Methods:

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

# Async

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@perplexity-ai/perplexity_ai",
"version": "0.7.1",
"version": "0.8.0",
"description": "The official TypeScript library for the Perplexity API",
"author": "Perplexity <>",
"types": "dist/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as API from './resources/index';
import { APIPromise } from './core/api-promise';
import { Search, SearchCreateParams, SearchCreateResponse } from './resources/search';
import { Async } from './resources/async/async';
import { Chat } from './resources/chat/chat';
import { Chat, StreamChunk } from './resources/chat/chat';
import { type Fetch } from './internal/builtin-types';
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
import { FinalRequestOptions, RequestOptions } from './internal/request-options';
Expand Down Expand Up @@ -728,7 +728,7 @@ Perplexity.Search = Search;
export declare namespace Perplexity {
export type RequestOptions = Opts.RequestOptions;

export { Chat as Chat };
export { Chat as Chat, type StreamChunk as StreamChunk };

export { Async as Async };

Expand Down
Loading