Skip to content

Add Perplexity as a first-class API provider#9762

Open
jliounis wants to merge 1 commit intoKilo-Org:mainfrom
jliounis:add-perplexity-provider
Open

Add Perplexity as a first-class API provider#9762
jliounis wants to merge 1 commit intoKilo-Org:mainfrom
jliounis:add-perplexity-provider

Conversation

@jliounis
Copy link
Copy Markdown

Summary

Adds Perplexity (Sonar Agent API) as a first-class provider in Kilo Code, alongside existing OpenAI-compatible providers like xAI, Cerebras, and Fireworks.

The provider entry already lives in the upstream models.dev snapshot (4 chat models — sonar, sonar-pro, sonar-reasoning-pro, sonar-deep-research; default chat model is sonar-pro; 128k context for the Sonar tier and 200k for sonar-pro). This PR adds the Kilo-side customizations needed to ship it as a first-class integration:

  1. Custom loader in kiloCustomLoaders that:
    • Resolves the API key from config → Auth → PERPLEXITY_API_KEYPPLX_API_KEY fallback chain
    • Auto-loads the provider whenever a key is present
  2. Attribution header wired centrally in patchCustomLoaderResult — every outgoing request carries X-Pplx-Integration: kilo-code/<package-version>. Single point, never sprinkled across call sites.
  3. Unit tests covering: header constants, the patchCustomLoaderResult branch, env-var loading from both PERPLEXITY_API_KEY and the PPLX_API_KEY fallback, and the presence of the attribution header on the merged options.

OpenAI-compatible base URL: https://api.perplexity.ai. Auth: Authorization: Bearer <PERPLEXITY_API_KEY>. Branding follows the Perplexity guidelines — never "Sonar API".

Pattern reference

This mirrors the Perplexity provider PR for Cline, adapted to Kilo Code's opencode-fork architecture (custom loaders + patchCustomLoaderResult rather than a per-provider Handler class). The header injection follows the existing cerebras X-Cerebras-3rd-Party-Integration precedent in the same file.

Co-authored by mirroring sibling provider conventions in this repo.

Docs

Test plan

  • bun test packages/opencode/test/kilocode/perplexity-provider.test.ts (added in this PR)
  • Set PERPLEXITY_API_KEY and verify kilo lists perplexity provider with sonar-pro model
  • Drop PERPLEXITY_API_KEY, set PPLX_API_KEY, confirm fallback path also auto-loads
  • Inspect outgoing request headers — confirm X-Pplx-Integration: kilo-code/<version> is present

Wire Perplexity (Sonar) as a first-class OpenAI-compatible chat
provider. The provider entry already lives in the upstream models.dev
snapshot — this commit adds Kilo-side customization so:

- A `perplexity` custom loader supports `PERPLEXITY_API_KEY` with a
  `PPLX_API_KEY` fallback, and resolves the key from config / Auth /
  env in that order.
- Every outgoing request carries the
  `X-Pplx-Integration: kilo-code/<version>` attribution header, set
  centrally in `patchCustomLoaderResult` so it cannot be missed at a
  call site.
- The provider auto-loads when an API key is present, exposing the
  4 chat models in the snapshot (sonar, sonar-pro, sonar-reasoning-pro,
  sonar-deep-research). Default chat model is `sonar-pro`.

Mirrors the Cline provider PR (cline/cline#10462) and the existing
sibling-provider conventions in this repo (cerebras, anthropic).

See https://docs.perplexity.ai for the API surface.

Co-authored by mirroring sibling provider conventions in this repo.
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented Apr 30, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • packages/opencode/src/kilocode/provider/provider.ts
  • packages/opencode/test/kilocode/perplexity-provider.test.ts

Reviewed by gpt-5.5-2026-04-23 · 1,159,496 tokens

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant