Skip to content
This repository was archived by the owner on May 20, 2026. It is now read-only.

Add Perplexity as a BYOK provider#5094

Open
jliounis wants to merge 3 commits into
microsoft:mainfrom
jliounis:add-perplexity-byok-provider
Open

Add Perplexity as a BYOK provider#5094
jliounis wants to merge 3 commits into
microsoft:mainfrom
jliounis:add-perplexity-byok-provider

Conversation

@jliounis
Copy link
Copy Markdown

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 extends AbstractOpenAICompatibleLMProvider — 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 — new PerplexityLMProvider extending AbstractOpenAICompatibleLMProvider. Ships a curated list of currently-available models:
    • sonar-pro (default)
    • sonar
    • sonar-reasoning-pro
    • sonar-reasoning
  • src/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 under languageModelChatProviders with the standard apiKey configuration field.

Attribution header

The provider sends X-Pplx-Integration: vscode-copilot/<package-version> on every outgoing request (via BYOKModelCapabilities.requestHeaders, picked up by OpenAIEndpoint.getExtraHeaders) so Perplexity can attribute traffic to this integration. Set centrally in perplexityProvider.ts — not sprinkled across call sites.

Branding & defaults

  • Default model: sonar-pro
  • Branding: Perplexity in user-facing UI/docs (never "Sonar API")
  • Base URL: https://api.perplexity.ai
  • Auth: standard Authorization: Bearer <key> (BYOK key field)

Links

CLA

I'll sign the Microsoft CLA before merge — no blockers expected.

Test plan

  • Build the extension
  • Configure a Perplexity API key under the new "Perplexity" provider in BYOK settings
  • Verify sonar-pro, sonar, sonar-reasoning-pro, and sonar-reasoning show up in the model picker
  • Send a chat message and confirm streaming completion works
  • Confirm requests include X-Pplx-Integration: vscode-copilot/<version> header

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
Copilot AI review requested due to automatic review settings April 30, 2026 22:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 an X-Pplx-Integration attribution header.
  • Registers Perplexity in the BYOK contribution so it becomes an available provider at runtime.
  • Adds a new perplexity vendor entry in package.json to 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';
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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;

Copilot uses AI. Check for mistakes.
Comment on lines +85 to +89
merged[id] = { ...caps, requestHeaders: { ...integrationHeader, ...(caps.requestHeaders ?? {}) } };
}
if (remote) {
for (const [id, caps] of Object.entries(remote)) {
merged[id] = { ...caps, requestHeaders: { ...integrationHeader, ...(caps.requestHeaders ?? {}) } };
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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 } };

Copilot uses AI. Check for mistakes.
Comment on lines +53 to +57
export class PerplexityLMProvider extends AbstractOpenAICompatibleLMProvider {

public static readonly providerName = 'Perplexity';

constructor(
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
jliounis added 2 commits May 7, 2026 12:33
Replace Sonar chat-completions models with the Perplexity Agent API
lineup (OpenAI, Anthropic, Google) at the OpenAI-Responses-compatible
base URL https://api.perplexity.ai/v1.

Also override getAllModels to return the curated list directly (Perplexity
does not expose a stable /models discovery endpoint), and flip the
requestHeaders merge order so X-Pplx-Integration is never overridden by
per-model requestHeaders.
…header

Three cases:
- getAllModels returns the curated Agent API list with the correct base URL
  and asserts no sonar references remain.
- every model carries the X-Pplx-Integration header in merged capabilities.
- per-model requestHeaders cannot override the integration header.
@jliounis
Copy link
Copy Markdown
Author

jliounis commented May 7, 2026

@microsoft-github-policy-service agree

@jliounis
Copy link
Copy Markdown
Author

jliounis commented May 7, 2026

Thanks for the review @copilot-pull-request-reviewer. Pushed two commits addressing all three points and refactoring the provider to expose the Perplexity Agent API instead of Sonar models:

Refactor: Sonar → Agent API

  • Base URL is now https://api.perplexity.ai/v1 (Agent API; OpenAI-Responses-compatible at /v1/responses and /v1/agent).
  • Curated list now exposes the Agent API model lineup (OpenAI, Anthropic, Google) under one Perplexity API key, plus access to presets like pro-search.
  • No Sonar references remain.

1. getModelsBaseUrlgetAllModels override (16b00ef04d2ade9f20da0a754b80c1020f0d6fe9)
Override getAllModels to return the curated Agent API list directly with url set to the Agent API base — AbstractOpenAICompatibleLMProvider's default would call ${baseUrl}/models, which Perplexity does not expose stably. No discovery fallback (intentional — would just slow the picker).

2. Header merge order (16b00ef04d2ade9f20da0a754b80c1020f0d6fe9)
Flipped the spread order so X-Pplx-Integration always wins over any model-level requestHeaders. Applied in both the curated and remote-merge loops.

3. Unit tests (61bc734812e2514c5a3d348b7ce94a3dae268ed2)
Added src/extension/byok/vscode-node/test/perplexityProvider.spec.ts with three cases: curated list shape (asserts no sonar substrings), integration header presence, and header-precedence (per-model overrides cannot drop X-Pplx-Integration).

Also signed the CLA in a separate comment. Let me know if you'd like any adjustments to the curated model list.

@jliounis
Copy link
Copy Markdown
Author

CLA is signed. The May 7 push addresses all three Copilot reviewer points (curated model list via getAllModels override, integration header merge order, BYOK provider tests). Could a maintainer authorize Community PR Approvals and take a look? Happy to address any further review feedback.

@alexdima
Copy link
Copy Markdown
Member

Thanks for the contribution! This repository has been archived because the project has moved into the main VS Code repository.

Could you please reopen/recreate this PR against:
https://github.com/microsoft/vscode/tree/main/extensions/copilot

We’ll continue reviewing contributions there. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants