Skip to content

fix: perplexity responses api compatibility - #4813

Merged
Pratham-Mishra04 merged 1 commit into
devfrom
07-01-fix_perplexity_responses_api_compatibility
Jul 2, 2026
Merged

fix: perplexity responses api compatibility#4813
Pratham-Mishra04 merged 1 commit into
devfrom
07-01-fix_perplexity_responses_api_compatibility

Conversation

@TejasGhatte

@TejasGhatte TejasGhatte commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

Perplexity's /v1/responses endpoint does not support all Sonar model variants. Previously, all Responses and ResponsesStream calls fell back unconditionally to /chat/completions. This PR adds model-aware routing so that models supported on /v1/responses are sent there via the OpenAI-compatible handler, while sonar-* variants (excluding the base sonar model) continue to fall back to /chat/completions.

Changes

  • Added isPerplexityResponsesSupported to detect whether a model can use Perplexity's /v1/responses endpoint. Any model with a sonar- prefix (after stripping an optional perplexity/ namespace) is considered unsupported and falls back to /chat/completions.
  • Responses now conditionally calls openai.HandleOpenAIResponsesRequest for supported models instead of always converting to a chat request.
  • ResponsesStream now conditionally calls openai.HandleOpenAIResponsesStreaming for supported models, only setting the IsResponsesToChatCompletionFallback context flag when the fallback path is actually taken.

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (React)
  • Docs

How to test

Send a Responses request using a supported model (e.g. sonar) and verify it is routed to /v1/responses. Send a request using an unsupported variant (e.g. sonar-pro, sonar-reasoning) and verify it falls back to /chat/completions.

go test ./core/providers/perplexity/...
go test ./...

Breaking changes

  • Yes
  • No

Related issues

Security considerations

No new auth mechanisms introduced. API key is passed via the existing Bearer token header, consistent with other OpenAI-compatible providers.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 48 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6b992b8a-a084-47de-917e-14411c122bf1

📥 Commits

Reviewing files that changed from the base of the PR and between df11d15 and d43eeec.

📒 Files selected for processing (3)
  • core/providers/perplexity/perplexity.go
  • core/providers/perplexity/responses.go
  • framework/modelcatalog/models.go
📝 Walkthrough

Walkthrough

Perplexity now refines nested model names, resolves /v1/models, and routes /v1/responses or chat-completions based on model support for both standard and streaming responses.

Changes

Perplexity Responses endpoint routing

Layer / File(s) Summary
Perplexity model refinement
framework/modelcatalog/models.go
RefineModelForProvider now routes schemas.Perplexity through nested-provider refinement.
Responses support helper
core/providers/perplexity/responses.go
Adds isPerplexityResponsesSupported(model string) and the strings import used to strip the perplexity/ prefix and exclude sonar- models.
List-models wiring
core/providers/perplexity/perplexity.go
ListModels now calls the OpenAI-compatible list-models handler against Perplexity’s /v1/models with provider client, extra headers, and raw forwarding settings.
Responses and streaming routing
core/providers/perplexity/perplexity.go
Responses and ResponsesStream now branch on model support, calling OpenAI-compatible /v1/responses handlers for supported models and falling back to chat-completions with conversion or fallback context handling for unsupported models.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: akshaydeo, danpiths

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: Perplexity Responses API compatibility.
Description check ✅ Passed The description covers the required summary, changes, type, testing, breaking changes, security, and checklist sections.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 07-01-fix_perplexity_responses_api_compatibility

Comment @coderabbitai help to get the list of available commands.

@CLAassistant

CLAassistant commented Jul 1, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@TejasGhatte
TejasGhatte marked this pull request as ready for review July 1, 2026 05:38

TejasGhatte commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai
coderabbitai Bot requested a review from akshaydeo July 1, 2026 05:39
Comment thread core/providers/perplexity/responses.go
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 1, 2026
@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 3/5

The core routing logic is sound, but the addition of Perplexity to RefineModelForProvider introduces a model-name mangling risk that could silently break all Perplexity API calls when catalog entries carry a perplexity/ prefix.

The Responses/ResponsesStream routing change is well-reasoned and the streaming path uses the correct client. The concern is the unexplained addition of schemas.Perplexity to RefineModelForProvider: that helper is designed for providers whose APIs accept a leading provider/ segment (Groq, Replicate). Perplexity's API does not — any pool model stored as perplexity/sonar-pro would cause the governance plugin to set request.Model to that prefixed string, producing model-not-found errors on every call to both the /v1/responses and /chat/completions paths.

framework/modelcatalog/models.go — the new Perplexity case in RefineModelForProvider needs justification or removal; core/providers/perplexity/perplexity_test.go — ListModels scenario should be enabled now that the operation is implemented.

Important Files Changed

Filename Overview
core/providers/perplexity/perplexity.go Adds model-aware routing for Responses/ResponsesStream and enables ListModels via OpenAI-compatible handler. Streaming path correctly uses streamingClient. ListModels test scenario not updated from false to true.
core/providers/perplexity/responses.go Adds isPerplexityResponsesSupported routing predicate; correctly handles perplexity/ prefix and sonar- denylist pattern. ToPerplexityResponsesRequest remains dead code (flagged in prior review).
framework/modelcatalog/models.go Adds schemas.Perplexity to RefineModelForProvider using refineNestedProviderModel. Unlike Groq/Replicate, Perplexity's API does not accept provider-prefixed model names, so this could mangle model names when catalog entries carry a perplexity/ prefix.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Responses / ResponsesStream] --> B[ResolveCanonicalModel]
    B --> C{isPerplexityResponsesSupported?}
    C -->|sonar-* variant| D[ChatCompletion fallback]
    C -->|sonar base or non-sonar| E[HandleOpenAI Responses handler]
    D --> F[chat completions endpoint]
    E --> G[v1 responses endpoint]

    subgraph Governance plugin
    H[RefineModelForProvider NEW] --> I[refineNestedProviderModel for Perplexity]
    I --> J{Catalog entry has perplexity prefix?}
    J -->|Yes| K[Sets model to perplexity slash model-name]
    J -->|No| L[Model unchanged]
    end
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[Responses / ResponsesStream] --> B[ResolveCanonicalModel]
    B --> C{isPerplexityResponsesSupported?}
    C -->|sonar-* variant| D[ChatCompletion fallback]
    C -->|sonar base or non-sonar| E[HandleOpenAI Responses handler]
    D --> F[chat completions endpoint]
    E --> G[v1 responses endpoint]

    subgraph Governance plugin
    H[RefineModelForProvider NEW] --> I[refineNestedProviderModel for Perplexity]
    I --> J{Catalog entry has perplexity prefix?}
    J -->|Yes| K[Sets model to perplexity slash model-name]
    J -->|No| L[Model unchanged]
    end
Loading

Reviews (5): Last reviewed commit: "fix: perplexity responses api compatibil..." | Re-trigger Greptile

Comment thread core/providers/perplexity/responses.go Outdated
Comment thread core/providers/perplexity/responses.go
@TejasGhatte
TejasGhatte force-pushed the 07-01-fix_perplexity_responses_api_compatibility branch from fca4e63 to 707421f Compare July 1, 2026 11:16
@coderabbitai
coderabbitai Bot requested a review from danpiths July 1, 2026 11:17
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 1, 2026
@akshaydeo
akshaydeo dismissed coderabbitai[bot]’s stale review July 1, 2026 12:24

The merge-base changed after approval.

@akshaydeo
akshaydeo requested a review from a team as a code owner July 1, 2026 12:24
@TejasGhatte
TejasGhatte force-pushed the 07-01-fix_perplexity_responses_api_compatibility branch from 707421f to 1d6c19c Compare July 1, 2026 17:40
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 1, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
core/providers/perplexity/perplexity.go (1)

256-291: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add table-driven coverage for Perplexity Responses routing

core/providers/perplexity/perplexity_test.go doesn’t cover the new isPerplexityResponsesSupported split. Add cases for a supported model hitting /v1/responses, a sonar-* model falling back to /chat/completions, and the streaming fallback setting BifrostContextKeyIsResponsesToChatCompletionFallback. Base sonar stays on /v1/responses.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/providers/perplexity/perplexity.go` around lines 256 - 291, Add
table-driven tests around PerplexityProvider.ResponsesStream and
isPerplexityResponsesSupported to cover the new routing split: verify a
supported model goes through openai.HandleOpenAIResponsesStreaming against
/v1/responses, verify a sonar-* model falls back to
provider.ChatCompletionStream with request.ToChatRequest() targeting
/chat/completions, and verify the fallback path sets
BifrostContextKeyIsResponsesToChatCompletionFallback in the BifrostContext. Also
include a case for base sonar to confirm it remains routed to /v1/responses.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@core/providers/perplexity/perplexity.go`:
- Around line 256-291: Add table-driven tests around
PerplexityProvider.ResponsesStream and isPerplexityResponsesSupported to cover
the new routing split: verify a supported model goes through
openai.HandleOpenAIResponsesStreaming against /v1/responses, verify a sonar-*
model falls back to provider.ChatCompletionStream with request.ToChatRequest()
targeting /chat/completions, and verify the fallback path sets
BifrostContextKeyIsResponsesToChatCompletionFallback in the BifrostContext. Also
include a case for base sonar to confirm it remains routed to /v1/responses.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0f070a09-6161-4c9b-a871-6b3f62006e1f

📥 Commits

Reviewing files that changed from the base of the PR and between 1d6c19c and ad975da.

📒 Files selected for processing (3)
  • core/providers/perplexity/perplexity.go
  • core/providers/perplexity/responses.go
  • framework/modelcatalog/models.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • framework/modelcatalog/models.go
  • core/providers/perplexity/responses.go

Pratham-Mishra04 commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Merge activity

  • Jul 2, 1:44 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jul 2, 1:45 PM UTC: Graphite rebased this pull request as part of a merge.
  • Jul 2, 1:47 PM UTC: Graphite rebased this pull request as part of a merge.
  • Jul 2, 1:48 PM UTC: @Pratham-Mishra04 merged this pull request with Graphite.

@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 07-01-fix_perplexity_responses_api_compatibility branch from ad975da to df11d15 Compare July 2, 2026 13:45
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 07-01-fix_perplexity_responses_api_compatibility branch from df11d15 to d43eeec Compare July 2, 2026 13:46
@Pratham-Mishra04
Pratham-Mishra04 merged commit dac21d8 into dev Jul 2, 2026
14 of 16 checks passed
@Pratham-Mishra04
Pratham-Mishra04 deleted the 07-01-fix_perplexity_responses_api_compatibility branch July 2, 2026 13:49
yangtuooc added a commit to yangtuooc/bifrost that referenced this pull request Jul 2, 2026
* upstream/dev:
  feat(mcp): add per-MCP-server tool execution timeout (maximhq#4472)
  fix: billing on failed responses stream requests anthropic and bedrock (maximhq#4842)
  fix: gemini openai through signature compatibility (maximhq#4810)
  fix: cancelled state in logs (maximhq#4831)
  fix: perplexity responses api compatibility (maximhq#4813)
  docs: clarify two-layer token refresh behavior and disabled-client refresh token expiry (maximhq#4849)
  fix: skip background token refresh for disabled/unconfigured MCP clients and guarantee non-nil logger in sync workers (maximhq#4848)
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.

3 participants