Add Perplexity as a BYOK provider#5094
Conversation
Wires up Perplexity as a Bring-Your-Own-Key (BYOK) language model provider in Copilot Chat. Perplexity exposes an OpenAI-compatible chat completions API at https://api.perplexity.ai, so the new provider extends AbstractOpenAICompatibleLMProvider, similar to the existing xAI and OpenRouter providers. - Adds src/extension/byok/vscode-node/perplexityProvider.ts with a curated list of Sonar models (sonar-pro, sonar, sonar-reasoning-pro, sonar-reasoning). sonar-pro is the default. - Registers the provider in byokContribution.ts. - Adds the "perplexity" vendor entry to languageModelChatProviders in package.json so the provider appears in the BYOK dropdown with an API key field. - Sends an X-Pplx-Integration: vscode-copilot/<package-version> header on outgoing requests via BYOKModelCapabilities.requestHeaders so Perplexity can attribute traffic to this integration. Docs: https://docs.perplexity.ai
|
@jliounis please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
There was a problem hiding this comment.
Pull request overview
Adds Perplexity as a new BYOK (Bring-Your-Own-Key) language model provider, integrating it into Copilot Chat’s existing OpenAI-compatible BYOK provider framework and surfacing it in VS Code’s BYOK provider configuration UI.
Changes:
- Introduces
PerplexityLMProvider(OpenAI-compatible) with a curated set of Sonar models and anX-Pplx-Integrationattribution header. - Registers Perplexity in the BYOK contribution so it becomes an available provider at runtime.
- Adds a new
perplexityvendor entry inpackage.jsonto expose API key configuration in the BYOK provider dropdown/settings.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/extension/byok/vscode-node/perplexityProvider.ts | Adds the new Perplexity BYOK provider, model metadata, and integration header wiring. |
| src/extension/byok/vscode-node/byokContribution.ts | Registers Perplexity provider alongside other BYOK providers. |
| package.json | Adds Perplexity as a configurable languageModelChatProviders vendor with an apiKey field. |
| } | ||
|
|
||
| protected getModelsBaseUrl(): string | undefined { | ||
| return 'https://api.perplexity.ai'; |
There was a problem hiding this comment.
getModelsBaseUrl() returns a base URL, which causes AbstractOpenAICompatibleLMProvider to always call ${baseUrl}/models for discovery. That contradicts the comment/PR description that Perplexity doesn't have a stable /models endpoint, and it also means the curated PERPLEXITY_KNOWN_MODELS list will never be shown unless the discovery call succeeds and returns those IDs. Consider overriding getAllModels (like CustomOAI does) to return the curated/merged known-model list with url set to the Perplexity base URL, optionally attempting discovery as a best-effort fallback rather than a hard dependency.
| return 'https://api.perplexity.ai'; | |
| // Perplexity does not provide a stable /models discovery endpoint for this provider. | |
| // Rely on the curated known-model list instead of enabling generic discovery. | |
| return undefined; |
| merged[id] = { ...caps, requestHeaders: { ...integrationHeader, ...(caps.requestHeaders ?? {}) } }; | ||
| } | ||
| if (remote) { | ||
| for (const [id, caps] of Object.entries(remote)) { | ||
| merged[id] = { ...caps, requestHeaders: { ...integrationHeader, ...(caps.requestHeaders ?? {}) } }; |
There was a problem hiding this comment.
The merge order for requestHeaders allows an existing caps.requestHeaders entry to override X-Pplx-Integration, which can accidentally drop or change the attribution header. If the intent is to guarantee the header on every request, apply the integration header last (so it wins) when merging curated and remote model capabilities.
| merged[id] = { ...caps, requestHeaders: { ...integrationHeader, ...(caps.requestHeaders ?? {}) } }; | |
| } | |
| if (remote) { | |
| for (const [id, caps] of Object.entries(remote)) { | |
| merged[id] = { ...caps, requestHeaders: { ...integrationHeader, ...(caps.requestHeaders ?? {}) } }; | |
| merged[id] = { ...caps, requestHeaders: { ...(caps.requestHeaders ?? {}), ...integrationHeader } }; | |
| } | |
| if (remote) { | |
| for (const [id, caps] of Object.entries(remote)) { | |
| merged[id] = { ...caps, requestHeaders: { ...(caps.requestHeaders ?? {}), ...integrationHeader } }; |
| export class PerplexityLMProvider extends AbstractOpenAICompatibleLMProvider { | ||
|
|
||
| public static readonly providerName = 'Perplexity'; | ||
|
|
||
| constructor( |
There was a problem hiding this comment.
A new BYOK provider is introduced but there are no accompanying unit tests under src/extension/byok/vscode-node/test/ (other providers like Ollama/Gemini/Azure have coverage). Adding a Perplexity provider spec would help lock in: the curated model list shown in the picker and that X-Pplx-Integration is present in each model's requestHeaders.
Summary
Adds Perplexity as a Bring-Your-Own-Key (BYOK) language model provider in Copilot Chat. Perplexity exposes an OpenAI-compatible Chat Completions API at
https://api.perplexity.ai, so the new provider extendsAbstractOpenAICompatibleLMProvider— mirroring the existing xAI and OpenRouter providers.After merging, users with a Perplexity API key can pick Perplexity from the BYOK provider dropdown and use Sonar models from Copilot Chat.
Changes
src/extension/byok/vscode-node/perplexityProvider.ts— newPerplexityLMProviderextendingAbstractOpenAICompatibleLMProvider. Ships a curated list of currently-available models:sonar-pro(default)sonarsonar-reasoning-prosonar-reasoningsrc/extension/byok/vscode-node/byokContribution.ts— registers the new provider alongside Anthropic / xAI / OpenRouter / OpenAI / Gemini / Ollama / Azure / customoai.package.json— adds the"perplexity"vendor entry underlanguageModelChatProviderswith the standardapiKeyconfiguration field.Attribution header
The provider sends
X-Pplx-Integration: vscode-copilot/<package-version>on every outgoing request (viaBYOKModelCapabilities.requestHeaders, picked up byOpenAIEndpoint.getExtraHeaders) so Perplexity can attribute traffic to this integration. Set centrally inperplexityProvider.ts— not sprinkled across call sites.Branding & defaults
sonar-prohttps://api.perplexity.aiAuthorization: Bearer <key>(BYOK key field)Links
CLA
I'll sign the Microsoft CLA before merge — no blockers expected.
Test plan
sonar-pro,sonar,sonar-reasoning-pro, andsonar-reasoningshow up in the model pickerX-Pplx-Integration: vscode-copilot/<version>header