Skip to content

Perplexity API key validation uses deprecated /models endpoint #1894

Description

@gaoliao1688

Summary

In v0.5.4, valid Perplexity API keys can be marked as invalid because provider validation and model listing still call:

https://api.perplexity.ai/models

That endpoint now returns 404. Perplexity's current API reference uses:

https://api.perplexity.ai/v1/models

The Search API endpoint itself still works at https://api.perplexity.ai/search, so this is specifically a validation/model-list endpoint issue.

Impact

A valid pplx-... API key may fail validation with Invalid API key, causing the perplexity provider connection to stay disabled. As a result, /v1/search with provider perplexity cannot be used until the connection is manually re-enabled or the endpoint is patched.

Verification

Tested from a server running 9router@0.5.4 with a valid Perplexity API key. Secret omitted.

GET  https://api.perplexity.ai/models      -> 404
GET  https://api.perplexity.ai/v1/models   -> 200
POST https://api.perplexity.ai/search      -> 200

After changing the validation/model endpoints to /v1/models, the local 9router endpoint succeeds:

POST /v1/search provider=perplexity -> 200

Minimal patch

diff --git a/src/app/api/providers/validate/route.js b/src/app/api/providers/validate/route.js
--- a/src/app/api/providers/validate/route.js
+++ b/src/app/api/providers/validate/route.js
@@
-            perplexity: "https://api.perplexity.ai/models",
+            perplexity: "https://api.perplexity.ai/v1/models",

diff --git a/src/app/api/providers/[id]/test/testUtils.js b/src/app/api/providers/[id]/test/testUtils.js
--- a/src/app/api/providers/[id]/test/testUtils.js
+++ b/src/app/api/providers/[id]/test/testUtils.js
@@
-        const res = await fetchWithConnectionProxy("https://api.perplexity.ai/models", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);
+        const res = await fetchWithConnectionProxy("https://api.perplexity.ai/v1/models", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);

diff --git a/src/app/api/providers/[id]/models/route.js b/src/app/api/providers/[id]/models/route.js
--- a/src/app/api/providers/[id]/models/route.js
+++ b/src/app/api/providers/[id]/models/route.js
@@
-  perplexity: createOpenAIModelsConfig("https://api.perplexity.ai/models"),
+  perplexity: createOpenAIModelsConfig("https://api.perplexity.ai/v1/models"),

Notes

This does not change the Perplexity Search API config, which already points to https://api.perplexity.ai/search. It only updates provider validation and model listing to the current models endpoint.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions