You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(provider/perplexity): Add PDF support (#10089)
**Background**
The Perplexity provider currently doesn't support PDF upload
functionality, although the direct Perplexity API supports this feature.
Other providers in the AI SDK like OpenAI, Gemini, and Anthropic already
have this capability, making the Perplexity implementation incomplete
compared to these providers.
**Summary**
Added PDF support to the Perplexity provider, allowing users to:
- Upload PDF files directly using base64 encoding
- Reference PDF files via URLs
- Include optional filename parameter
Implementation includes:
- Updated message conversion logic to handle PDF files
- Modified PerplexityMessageContent type to include file_url type
- Added documentation for PDF support
- Created example files demonstrating PDF usage
Checklist
- [x] Tests have been added / updated (for bug fixes / features)
- [x] Documentation has been added / updated (for bug fixes / features)
- [x] A patch changeset for relevant packages has been added (for bug
fixes / features - run pnpm changeset in the project root)
- [x] I have reviewed this pull request (self-review)
Related Issues
Fixes: #9803
Copy file name to clipboardExpand all lines: content/providers/01-ai-sdk-providers/70-perplexity.mdx
+43Lines changed: 43 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -133,6 +133,48 @@ The metadata includes:
133
133
134
134
You can enable image responses by setting `return_images: true` in the provider options. This feature is only available to Perplexity Tier-2 users and above.
135
135
136
+
### PDF Support
137
+
138
+
The Perplexity provider supports reading PDF files.
139
+
You can pass PDF files as part of the message content using the `file` type:
140
+
141
+
```ts
142
+
const result =awaitgenerateText({
143
+
model: perplexity('sonar-pro'),
144
+
messages: [
145
+
{
146
+
role: 'user',
147
+
content: [
148
+
{
149
+
type: 'text',
150
+
text: 'What is this document about?',
151
+
},
152
+
{
153
+
type: 'file',
154
+
data: fs.readFileSync('./data/ai.pdf'),
155
+
mediaType: 'application/pdf',
156
+
filename: 'ai.pdf', // optional
157
+
},
158
+
],
159
+
},
160
+
],
161
+
});
162
+
```
163
+
164
+
You can also pass the URL of a PDF:
165
+
166
+
```ts
167
+
{
168
+
type: 'file',
169
+
data: newURL('https://example.com/document.pdf'),
170
+
mediaType: 'application/pdf',
171
+
filename: 'document.pdf', // optional
172
+
}
173
+
```
174
+
175
+
The model will have access to the contents of the PDF file and
176
+
respond to questions about it.
177
+
136
178
<Note>
137
179
For more details about Perplexity's capabilities, see the [Perplexity chat
0 commit comments