@ai-sdk/perplexity 4.0.50 → 5.0.0
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/CHANGELOG.md +28 -0
- package/README.md +15 -9
- package/dist/index.d.ts +94 -126
- package/dist/index.js +976 -428
- package/dist/index.js.map +1 -1
- package/docs/70-perplexity.mdx +220 -69
- package/package.json +3 -3
- package/src/convert-perplexity-usage.ts +29 -15
- package/src/convert-to-perplexity-input.ts +206 -0
- package/src/index.ts +4 -0
- package/src/map-perplexity-finish-reason.ts +27 -8
- package/src/perplexity-agent-api.ts +206 -0
- package/src/perplexity-embedding-model.ts +5 -2
- package/src/perplexity-language-model-options.ts +91 -115
- package/src/perplexity-language-model-prompt.ts +25 -18
- package/src/perplexity-language-model.ts +641 -291
- package/src/perplexity-options.ts +9 -6
- package/src/perplexity-prepare-tools.ts +48 -0
- package/src/perplexity-provider.ts +3 -3
- package/src/convert-to-perplexity-messages.ts +0 -143
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @ai-sdk/perplexity
|
|
2
2
|
|
|
3
|
+
## 5.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 38fe0e5: BREAKING: Migrate language generation from the Sonar Chat Completions API to the Agent API. Replace Sonar model IDs and provider options with Agent API presets, models, and tools. The new API changes request and response metadata, raw stream events, usage and cost data, and does not support Sonar PDF input or image and video results.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 38fe0e5: Recover missing text from Agent API terminal events and output items, including incomplete responses, without repeating text already received as deltas. Track each message content part separately.
|
|
12
|
+
- 38fe0e5: Accept native Agent API tool traces such as finance results without validating them as web search results. Preserve these traces in raw responses and stream chunks.
|
|
13
|
+
- 38fe0e5: Preserve URL citation annotations as sources in Agent API streams, including completed and incomplete terminal responses.
|
|
14
|
+
- 38fe0e5: Emit each Agent API source URL once while preserving search result IDs for citation correlation when a URL is fetched or annotated before it appears in search results.
|
|
15
|
+
|
|
16
|
+
## 4.0.52
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Updated dependencies [af9597b]
|
|
21
|
+
- Updated dependencies [bc49f78]
|
|
22
|
+
- @ai-sdk/provider-utils@5.0.49
|
|
23
|
+
|
|
24
|
+
## 4.0.51
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- Updated dependencies [be877ff]
|
|
29
|
+
- @ai-sdk/provider-utils@5.0.48
|
|
30
|
+
|
|
3
31
|
## 4.0.50
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
# AI SDK - Perplexity Provider
|
|
2
2
|
|
|
3
3
|
The **[Perplexity provider](https://ai-sdk.dev/providers/ai-sdk-providers/perplexity)** for the [AI SDK](https://ai-sdk.dev/docs)
|
|
4
|
-
contains language model support for Perplexity's
|
|
4
|
+
contains language model support for Perplexity's Agent API, including web search, citations, function tools, and structured output.
|
|
5
5
|
|
|
6
6
|
## Features
|
|
7
7
|
|
|
8
8
|
- Real-time web search grounding for accurate, up-to-date responses
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
- Industry-leading answer quality
|
|
14
|
-
- Data privacy - no training on customer data
|
|
15
|
-
- Self-serve API access with scalable pricing
|
|
9
|
+
- Agent API presets from `fast` through `xhigh`
|
|
10
|
+
- Direct access to supported third-party models through Perplexity
|
|
11
|
+
- Native tools for web search, URL fetching, code execution, finance, MCP, and connectors
|
|
12
|
+
- AI SDK function tools, structured output, reasoning streams, and multi-turn tool calls
|
|
16
13
|
|
|
17
14
|
> **Deploying to Vercel?** With Vercel's AI Gateway you can access Perplexity (and hundreds of models from other providers) — no additional packages, API keys, or extra cost. [Get started with AI Gateway](https://vercel.com/ai-gateway).
|
|
18
15
|
|
|
@@ -47,11 +44,20 @@ import { perplexity } from '@ai-sdk/perplexity';
|
|
|
47
44
|
import { generateText } from 'ai';
|
|
48
45
|
|
|
49
46
|
const { text } = await generateText({
|
|
50
|
-
model: perplexity('
|
|
47
|
+
model: perplexity('low'),
|
|
51
48
|
prompt: 'What are the latest developments in quantum computing?',
|
|
52
49
|
});
|
|
53
50
|
```
|
|
54
51
|
|
|
52
|
+
Version 5 is a breaking migration from Sonar Chat Completions to the Agent API.
|
|
53
|
+
Legacy Sonar model IDs and provider options are not mapped. Review the
|
|
54
|
+
[migration notes](https://ai-sdk.dev/providers/ai-sdk-providers/perplexity#migrating-from-v4-sonar-to-v5-agent-api)
|
|
55
|
+
before upgrading an existing application.
|
|
56
|
+
|
|
57
|
+
Perplexity supports Sonar Chat Completions only until September 27, 2026.
|
|
58
|
+
Remaining on version 4 will not preserve language generation after that date.
|
|
59
|
+
Migrate unsupported Sonar features using the alternatives in the migration notes.
|
|
60
|
+
|
|
55
61
|
## Documentation
|
|
56
62
|
|
|
57
63
|
Please check out the **[Perplexity provider documentation](https://ai-sdk.dev/providers/ai-sdk-providers/perplexity)** for more information.
|
package/dist/index.d.ts
CHANGED
|
@@ -12,15 +12,16 @@ declare const perplexityEmbeddingModelOptions: z.ZodObject<{
|
|
|
12
12
|
}, z.core.$strip>;
|
|
13
13
|
type PerplexityEmbeddingModelOptions = z.infer<typeof perplexityEmbeddingModelOptions>;
|
|
14
14
|
|
|
15
|
-
type
|
|
15
|
+
type PerplexityAgentPreset = 'fast' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
16
|
+
type PerplexityLanguageModelId = PerplexityAgentPreset | 'perplexity/sonar' | (string & {});
|
|
16
17
|
|
|
17
18
|
interface PerplexityProvider extends ProviderV4 {
|
|
18
19
|
/**
|
|
19
|
-
* Creates
|
|
20
|
+
* Creates a Perplexity Agent API model or preset for text generation.
|
|
20
21
|
*/
|
|
21
22
|
(modelId: PerplexityLanguageModelId): LanguageModelV4;
|
|
22
23
|
/**
|
|
23
|
-
* Creates
|
|
24
|
+
* Creates a Perplexity Agent API model or preset for text generation.
|
|
24
25
|
*/
|
|
25
26
|
languageModel(modelId: PerplexityLanguageModelId): LanguageModelV4;
|
|
26
27
|
/**
|
|
@@ -38,7 +39,7 @@ interface PerplexityProvider extends ProviderV4 {
|
|
|
38
39
|
}
|
|
39
40
|
interface PerplexityProviderSettings {
|
|
40
41
|
/**
|
|
41
|
-
* Base URL for
|
|
42
|
+
* Base URL for Perplexity API calls.
|
|
42
43
|
*/
|
|
43
44
|
baseURL?: string;
|
|
44
45
|
/**
|
|
@@ -59,129 +60,36 @@ declare function createPerplexity(options?: PerplexityProviderSettings): Perplex
|
|
|
59
60
|
declare const perplexity: PerplexityProvider;
|
|
60
61
|
|
|
61
62
|
declare const perplexityLanguageModelOptions: z.ZodObject<{
|
|
62
|
-
/**
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
* Return search results published after this date.
|
|
84
|
-
*/
|
|
85
|
-
search_after_date_filter: z.ZodOptional<z.ZodString>;
|
|
86
|
-
/**
|
|
87
|
-
* Return search results published before this date.
|
|
88
|
-
*/
|
|
89
|
-
search_before_date_filter: z.ZodOptional<z.ZodString>;
|
|
90
|
-
/**
|
|
91
|
-
* Return search results last updated after this date.
|
|
92
|
-
*/
|
|
93
|
-
last_updated_after_filter: z.ZodOptional<z.ZodString>;
|
|
94
|
-
/**
|
|
95
|
-
* Return search results last updated before this date.
|
|
96
|
-
*/
|
|
97
|
-
last_updated_before_filter: z.ZodOptional<z.ZodString>;
|
|
98
|
-
/**
|
|
99
|
-
* Source of search results.
|
|
100
|
-
*/
|
|
101
|
-
search_mode: z.ZodOptional<z.ZodEnum<{
|
|
102
|
-
web: "web";
|
|
103
|
-
academic: "academic";
|
|
104
|
-
sec: "sec";
|
|
105
|
-
}>>;
|
|
106
|
-
/**
|
|
107
|
-
* If true, the model decides whether web search is needed.
|
|
108
|
-
*/
|
|
109
|
-
enable_search_classifier: z.ZodOptional<z.ZodBoolean>;
|
|
110
|
-
/**
|
|
111
|
-
* If true, disables web search.
|
|
112
|
-
*/
|
|
113
|
-
disable_search: z.ZodOptional<z.ZodBoolean>;
|
|
114
|
-
/**
|
|
115
|
-
* If true, a list of related questions is included in the response.
|
|
116
|
-
*/
|
|
117
|
-
return_related_questions: z.ZodOptional<z.ZodBoolean>;
|
|
118
|
-
/**
|
|
119
|
-
* If true, image search results are included in the response.
|
|
120
|
-
*/
|
|
121
|
-
return_images: z.ZodOptional<z.ZodBoolean>;
|
|
122
|
-
/**
|
|
123
|
-
* Restrict image results to specific domains.
|
|
124
|
-
* Prefix a domain with "-" to exclude it.
|
|
125
|
-
*/
|
|
126
|
-
image_domain_filter: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
127
|
-
/**
|
|
128
|
-
* Restrict image results to specific file formats.
|
|
129
|
-
*/
|
|
130
|
-
image_format_filter: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
131
|
-
/**
|
|
132
|
-
* Additional media response configuration.
|
|
133
|
-
*/
|
|
134
|
-
media_response: z.ZodOptional<z.ZodObject<{
|
|
135
|
-
overrides: z.ZodOptional<z.ZodObject<{
|
|
136
|
-
/**
|
|
137
|
-
* If true, video results are included in the response.
|
|
138
|
-
*/
|
|
139
|
-
return_videos: z.ZodOptional<z.ZodBoolean>;
|
|
63
|
+
/** Top-level Agent API instructions. */
|
|
64
|
+
instructions: z.ZodOptional<z.ZodString>;
|
|
65
|
+
/**
|
|
66
|
+
* Native Agent API tools. AI SDK function tools can also be supplied through
|
|
67
|
+
* the top-level `tools` option on `generateText` and `streamText`.
|
|
68
|
+
*/
|
|
69
|
+
tools: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
70
|
+
type: z.ZodLiteral<"web_search">;
|
|
71
|
+
filters: z.ZodOptional<z.ZodObject<{
|
|
72
|
+
search_domain_filter: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
73
|
+
search_recency_filter: z.ZodOptional<z.ZodEnum<{
|
|
74
|
+
hour: "hour";
|
|
75
|
+
day: "day";
|
|
76
|
+
week: "week";
|
|
77
|
+
month: "month";
|
|
78
|
+
year: "year";
|
|
79
|
+
}>>;
|
|
80
|
+
search_after_date_filter: z.ZodOptional<z.ZodString>;
|
|
81
|
+
search_before_date_filter: z.ZodOptional<z.ZodString>;
|
|
82
|
+
last_updated_after_filter: z.ZodOptional<z.ZodString>;
|
|
83
|
+
last_updated_before_filter: z.ZodOptional<z.ZodString>;
|
|
140
84
|
}, z.core.$loose>>;
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
*/
|
|
145
|
-
stream_mode: z.ZodOptional<z.ZodEnum<{
|
|
146
|
-
full: "full";
|
|
147
|
-
concise: "concise";
|
|
148
|
-
}>>;
|
|
149
|
-
/**
|
|
150
|
-
* Controls how much effort the model spends on reasoning.
|
|
151
|
-
*/
|
|
152
|
-
reasoning_effort: z.ZodOptional<z.ZodEnum<{
|
|
153
|
-
minimal: "minimal";
|
|
154
|
-
low: "low";
|
|
155
|
-
medium: "medium";
|
|
156
|
-
high: "high";
|
|
157
|
-
}>>;
|
|
158
|
-
/**
|
|
159
|
-
* Preferred response language as an ISO 639-1 language code.
|
|
160
|
-
*/
|
|
161
|
-
language_preference: z.ZodOptional<z.ZodString>;
|
|
162
|
-
/**
|
|
163
|
-
* Additional web search configuration.
|
|
164
|
-
*/
|
|
165
|
-
web_search_options: z.ZodOptional<z.ZodObject<{
|
|
166
|
-
/**
|
|
167
|
-
* Controls the size of search context injected into the model.
|
|
168
|
-
*/
|
|
85
|
+
max_results: z.ZodOptional<z.ZodNumber>;
|
|
86
|
+
max_tokens: z.ZodOptional<z.ZodNumber>;
|
|
87
|
+
max_tokens_per_page: z.ZodOptional<z.ZodNumber>;
|
|
169
88
|
search_context_size: z.ZodOptional<z.ZodEnum<{
|
|
170
89
|
low: "low";
|
|
171
90
|
medium: "medium";
|
|
172
91
|
high: "high";
|
|
173
92
|
}>>;
|
|
174
|
-
/**
|
|
175
|
-
* Controls whether to use fast search, pro search, or automatic routing.
|
|
176
|
-
*/
|
|
177
|
-
search_type: z.ZodOptional<z.ZodEnum<{
|
|
178
|
-
fast: "fast";
|
|
179
|
-
pro: "pro";
|
|
180
|
-
auto: "auto";
|
|
181
|
-
}>>;
|
|
182
|
-
/**
|
|
183
|
-
* User location for search result personalization.
|
|
184
|
-
*/
|
|
185
93
|
user_location: z.ZodOptional<z.ZodObject<{
|
|
186
94
|
latitude: z.ZodOptional<z.ZodNumber>;
|
|
187
95
|
longitude: z.ZodOptional<z.ZodNumber>;
|
|
@@ -189,14 +97,74 @@ declare const perplexityLanguageModelOptions: z.ZodObject<{
|
|
|
189
97
|
city: z.ZodOptional<z.ZodString>;
|
|
190
98
|
region: z.ZodOptional<z.ZodString>;
|
|
191
99
|
}, z.core.$loose>>;
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
100
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
101
|
+
type: z.ZodLiteral<"fetch_url">;
|
|
102
|
+
max_urls: z.ZodOptional<z.ZodNumber>;
|
|
103
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
104
|
+
type: z.ZodLiteral<"people_search">;
|
|
105
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
106
|
+
type: z.ZodLiteral<"finance_search">;
|
|
107
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
108
|
+
type: z.ZodLiteral<"sandbox">;
|
|
109
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
110
|
+
type: z.ZodLiteral<"mcp">;
|
|
111
|
+
server_label: z.ZodString;
|
|
112
|
+
server_url: z.ZodString;
|
|
113
|
+
allowed_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
114
|
+
authorization: z.ZodOptional<z.ZodString>;
|
|
115
|
+
defer_loading: z.ZodOptional<z.ZodBoolean>;
|
|
116
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
117
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
118
|
+
type: z.ZodLiteral<"connector">;
|
|
119
|
+
id: z.ZodString;
|
|
120
|
+
server_label: z.ZodString;
|
|
121
|
+
server_description: z.ZodOptional<z.ZodString>;
|
|
122
|
+
allowed_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
123
|
+
}, z.core.$loose>]>>>;
|
|
124
|
+
/** A fallback model list for Agent API routing. */
|
|
125
|
+
models: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
126
|
+
/** Maximum number of agentic steps. */
|
|
127
|
+
max_steps: z.ZodOptional<z.ZodNumber>;
|
|
128
|
+
/** Maximum number of native tool calls. */
|
|
129
|
+
max_tool_calls: z.ZodOptional<z.ZodNumber>;
|
|
130
|
+
/** Continue a conversation from an earlier Agent API response. */
|
|
131
|
+
previous_response_id: z.ZodOptional<z.ZodString>;
|
|
132
|
+
/**
|
|
133
|
+
* Whether the response can be retrieved later. Setting this to false does
|
|
134
|
+
* not disable persistence or prevent previous_response_id continuations.
|
|
135
|
+
*/
|
|
136
|
+
store: z.ZodOptional<z.ZodBoolean>;
|
|
137
|
+
/** Preferred response language as an ISO 639-1 language code. */
|
|
138
|
+
language_preference: z.ZodOptional<z.ZodString>;
|
|
139
|
+
/** Agent API reasoning configuration. */
|
|
140
|
+
reasoning: z.ZodOptional<z.ZodObject<{
|
|
141
|
+
effort: z.ZodOptional<z.ZodEnum<{
|
|
142
|
+
low: "low";
|
|
143
|
+
medium: "medium";
|
|
144
|
+
high: "high";
|
|
145
|
+
minimal: "minimal";
|
|
146
|
+
xhigh: "xhigh";
|
|
147
|
+
}>>;
|
|
196
148
|
}, z.core.$loose>>;
|
|
149
|
+
/** Agent API skill configuration. */
|
|
150
|
+
skills: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
151
|
+
type: z.ZodLiteral<"builtin">;
|
|
152
|
+
name: z.ZodEnum<{
|
|
153
|
+
office: "office";
|
|
154
|
+
"office/docx": "office/docx";
|
|
155
|
+
"office/pdf": "office/pdf";
|
|
156
|
+
"office/pptx": "office/pptx";
|
|
157
|
+
"office/xlsx": "office/xlsx";
|
|
158
|
+
}>;
|
|
159
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
160
|
+
type: z.ZodLiteral<"inline">;
|
|
161
|
+
name: z.ZodString;
|
|
162
|
+
description: z.ZodString;
|
|
163
|
+
instructions: z.ZodString;
|
|
164
|
+
}, z.core.$loose>]>>>;
|
|
197
165
|
}, z.core.$loose>;
|
|
198
166
|
type PerplexityLanguageModelOptions = z.infer<typeof perplexityLanguageModelOptions>;
|
|
199
167
|
|
|
200
168
|
declare const VERSION: string;
|
|
201
169
|
|
|
202
|
-
export { type PerplexityEmbeddingModelId, type PerplexityEmbeddingModelOptions, type PerplexityLanguageModelOptions, type PerplexityProvider, type PerplexityProviderSettings, VERSION, createPerplexity, perplexity };
|
|
170
|
+
export { type PerplexityAgentPreset, type PerplexityEmbeddingModelId, type PerplexityEmbeddingModelOptions, type PerplexityLanguageModelId, type PerplexityLanguageModelOptions, type PerplexityProvider, type PerplexityProviderSettings, VERSION, createPerplexity, perplexity };
|