mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-03 13:52:09 +03:00
fix(perplexity): validate API keys via /v1/models endpoint (#4654)
Integrated into release/v3.8.36 — port (rebuilt from stale base; defining commit cherry-picked clean over release tip, release-green validated)
This commit is contained in:
committed by
GitHub
parent
35a3962cf0
commit
f4fa983a9f
@@ -6,6 +6,11 @@ export const perplexityProvider: RegistryEntry = {
|
||||
format: "openai",
|
||||
executor: "default",
|
||||
baseUrl: "https://api.perplexity.ai/chat/completions",
|
||||
// Perplexity deprecated the unversioned `/models` endpoint (returns 404), so
|
||||
// pin an explicit `modelsUrl` here. Without it, validateOpenAILikeProvider
|
||||
// (src/lib/providers/validation.ts) derives `<baseUrl>/models` via
|
||||
// addModelsSuffix and probes the dead endpoint, misclassifying valid keys.
|
||||
modelsUrl: "https://api.perplexity.ai/v1/models",
|
||||
authType: "apikey",
|
||||
authHeader: "bearer",
|
||||
models: [
|
||||
|
||||
50
tests/unit/perplexity-key-validation-models.test.ts
Normal file
50
tests/unit/perplexity-key-validation-models.test.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
// Regression test for perplexity API key validation.
|
||||
//
|
||||
// Perplexity deprecated the unversioned `/models` endpoint (returns 404), so
|
||||
// our default validation probe — which derives `<baseUrl>/models` from the
|
||||
// perplexity registry entry via `addModelsSuffix` — would always fail to
|
||||
// confirm a valid key, falling through to the chat-completions probe and
|
||||
// often misclassifying live keys as "Invalid". Inspired by upstream
|
||||
// 9router fix (see commit message); we port it OmniRoute-style by
|
||||
// declaring an explicit `modelsUrl` on the perplexity registry entry.
|
||||
|
||||
import { describe, it } from "node:test";
|
||||
import assert from "node:assert";
|
||||
|
||||
describe("perplexity registry — key validation models endpoint", () => {
|
||||
it("declares a modelsUrl pointing at /v1/models (not the deprecated /models)", async () => {
|
||||
const { getRegistryEntry } = await import(
|
||||
"../../open-sse/config/providerRegistry.ts"
|
||||
);
|
||||
const entry = getRegistryEntry("perplexity");
|
||||
assert.ok(entry, "perplexity must be registered in the execution registry");
|
||||
assert.equal(entry.format, "openai");
|
||||
assert.ok(
|
||||
typeof entry.modelsUrl === "string" && entry.modelsUrl.length > 0,
|
||||
"perplexity registry entry must declare an explicit modelsUrl so key " +
|
||||
"validation does not hit the deprecated <baseUrl>/models endpoint"
|
||||
);
|
||||
assert.equal(
|
||||
entry.modelsUrl,
|
||||
"https://api.perplexity.ai/v1/models",
|
||||
"perplexity modelsUrl must point at the versioned /v1/models endpoint " +
|
||||
"(unversioned /models was deprecated and now returns 404)"
|
||||
);
|
||||
});
|
||||
|
||||
it("does not derive a /models URL that ends in /chat/completions/models", async () => {
|
||||
const { getRegistryEntry } = await import(
|
||||
"../../open-sse/config/providerRegistry.ts"
|
||||
);
|
||||
const entry = getRegistryEntry("perplexity");
|
||||
assert.ok(entry?.modelsUrl, "modelsUrl required");
|
||||
assert.ok(
|
||||
!entry.modelsUrl.includes("/chat/completions"),
|
||||
"modelsUrl must not include /chat/completions"
|
||||
);
|
||||
assert.ok(
|
||||
entry.modelsUrl.endsWith("/v1/models"),
|
||||
"modelsUrl must end with /v1/models"
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user