Skip to content

Commit 73a5bd0

Browse files
authored
feat(models): add Perplexity models to openrouter and with the AI SDK (#203)
* feat(models): add Perplexity models to openrouter and local registry * fix: addressed review comments for add perplexity models
1 parent 7ac6db8 commit 73a5bd0

File tree

14 files changed

+991
-493
lines changed

14 files changed

+991
-493
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ MISTRAL_API_KEY=your_mistral_api_key
1212
GOOGLE_GENERATIVE_AI_API_KEY=your_gemini_api_key
1313
ANTHROPIC_API_KEY=your_anthropic_api_key
1414
XAI_API_KEY=your_xai_api_key
15+
PERPLEXITY_API_KEY=your_perplexity_api_key
1516
OPENROUTER_API_KEY=your_openrouter_api_key
1617

1718
# Ollama Configuration (for local AI models)

app/api/providers/route.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export async function POST(request: NextRequest) {
3737
const envKeyMap: Record<ProviderWithoutOllama, string | undefined> = {
3838
openai: process.env.OPENAI_API_KEY,
3939
mistral: process.env.MISTRAL_API_KEY,
40+
perplexity: process.env.PERPLEXITY_API_KEY,
4041
google: process.env.GOOGLE_GENERATIVE_AI_API_KEY,
4142
anthropic: process.env.ANTHROPIC_API_KEY,
4243
xai: process.env.XAI_API_KEY,

components/icons/perplexity.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as React from "react"
2+
import type { SVGProps } from "react"
3+
4+
export default function PerplexityIcon(props: SVGProps<SVGSVGElement>) {
5+
return (
6+
<svg
7+
width={24}
8+
height={24}
9+
xmlns="http://www.w3.org/2000/svg"
10+
viewBox="0 0 512 509.64"
11+
shapeRendering="geometricPrecision"
12+
textRendering="geometricPrecision"
13+
imageRendering="optimizeQuality"
14+
{...props}
15+
>
16+
<path
17+
fill="#1F1F1F"
18+
d="M115.613 0h280.774C459.974 0 512 52.025 512 115.612v278.415c0 63.587-52.026 115.613-115.613 115.613H115.613C52.026 509.64 0 457.614 0 394.027V115.612C0 52.025 52.026 0 115.613 0z"
19+
/>
20+
<path
21+
fill="#fff"
22+
fillRule="nonzero"
23+
d="M348.851 128.063l-68.946 58.302h68.946v-58.302zm-83.908 48.709l100.931-85.349v94.942h32.244v143.421h-38.731v90.004l-94.442-86.662v83.946h-17.023v-83.906l-96.596 86.246v-89.628h-37.445V186.365h38.732V90.768l95.309 84.958v-83.16h17.023l-.002 84.206zm-29.209 26.616c-34.955.02-69.893 0-104.83 0v109.375h20.415v-27.121l84.415-82.254zm41.445 0l82.208 82.324v27.051h21.708V203.388c-34.617 0-69.274.02-103.916 0zm-42.874-17.023l-64.669-57.646v57.646h64.669zm13.617 124.076v-95.2l-79.573 77.516v88.731l79.573-71.047zm17.252-95.022v94.863l77.19 70.83c0-29.485-.012-58.943-.012-88.425l-77.178-77.268z"
24+
/>
25+
</svg>
26+
)
27+
}

lib/models/data/openrouter.ts

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,4 +482,157 @@ export const openrouterModels: ModelConfig[] = [
482482
apiKey: apiKey || process.env.OPENROUTER_API_KEY,
483483
}).chat("openai/gpt-4.5-preview"),
484484
},
485+
{
486+
id: "openrouter:perplexity/sonar",
487+
name: "Perplexity Sonar",
488+
provider: "OpenRouter",
489+
providerId: "openrouter",
490+
modelFamily: "Sonar",
491+
description:
492+
"Sonar is a fast, affordable QA model with source control and citation support—ideal for lightweight, real-time integrations.",
493+
tags: ["fast", "simple", "affordable", "QA"],
494+
contextWindow: 127072,
495+
inputCost: 1,
496+
outputCost: 1,
497+
priceUnit: "per 1M tokens",
498+
vision: false,
499+
tools: false,
500+
audio: false,
501+
reasoning: true,
502+
openSource: false,
503+
speed: "Fast",
504+
intelligence: "Medium",
505+
website: "https://openrouter.ai",
506+
apiDocs: "https://openrouter.ai/docs",
507+
modelPage: "https://openrouter.ai/perplexity/sonar",
508+
releasedAt: "2025-01-27",
509+
icon: "perplexity",
510+
apiSdk: (apiKey?: string) =>
511+
createOpenRouter({
512+
apiKey: apiKey || process.env.OPENROUTER_API_KEY,
513+
}).chat("perplexity/sonar"),
514+
},
515+
{
516+
id: "openrouter:perplexity/sonar-reasoning",
517+
name: "Perplexity Sonar Reasoning",
518+
provider: "OpenRouter",
519+
providerId: "openrouter",
520+
modelFamily: "Sonar",
521+
description:
522+
"An enhanced version of Sonar optimized for deeper reasoning and more complex tasks, while retaining fast response times.",
523+
tags: ["reasoning", "fast", "QA", "affordable"],
524+
contextWindow: 127072,
525+
inputCost: 1,
526+
outputCost: 5,
527+
priceUnit: "per 1M tokens",
528+
vision: false,
529+
tools: false,
530+
audio: false,
531+
reasoning: true,
532+
openSource: false,
533+
speed: "Medium",
534+
intelligence: "High",
535+
website: "https://openrouter.ai",
536+
apiDocs: "https://openrouter.ai/docs",
537+
modelPage: "https://openrouter.ai/perplexity/sonar-reasoning",
538+
releasedAt: "2025-01-29",
539+
icon: "perplexity",
540+
apiSdk: (apiKey?: string) =>
541+
createOpenRouter({
542+
apiKey: apiKey || process.env.OPENROUTER_API_KEY,
543+
}).chat("perplexity/sonar-reasoning"),
544+
},
545+
{
546+
id: "openrouter:perplexity/sonar-reasoning-pro",
547+
name: "Perplexity Sonar Reasoning Pro",
548+
provider: "OpenRouter",
549+
providerId: "openrouter",
550+
modelFamily: "Sonar",
551+
description:
552+
"Perplexity's most advanced Sonar model with pro-level reasoning, accuracy, and context handling—ideal for complex tasks.",
553+
tags: ["reasoning", "pro", "advanced", "QA", "research"],
554+
contextWindow: 127072,
555+
inputCost: 2,
556+
outputCost: 8,
557+
priceUnit: "per 1M tokens",
558+
vision: false,
559+
tools: false,
560+
audio: false,
561+
reasoning: true,
562+
openSource: false,
563+
speed: "Medium",
564+
intelligence: "High",
565+
website: "https://openrouter.ai",
566+
apiDocs: "https://openrouter.ai/docs",
567+
modelPage: "https://openrouter.ai/perplexity/sonar-reasoning-pro",
568+
releasedAt: "2025-07-25",
569+
icon: "perplexity",
570+
apiSdk: (apiKey?: string) =>
571+
createOpenRouter({
572+
apiKey: apiKey || process.env.OPENROUTER_API_KEY,
573+
}).chat("perplexity/sonar-reasoning-pro"),
574+
},
575+
{
576+
id: "openrouter:perplexity/sonar-pro",
577+
name: "Perplexity Sonar Pro",
578+
provider: "OpenRouter",
579+
providerId: "openrouter",
580+
modelFamily: "Sonar",
581+
description:
582+
"A high-performance version of Sonar optimized for speed and accuracy across general tasks, with solid reasoning capabilities.",
583+
tags: ["fast", "accurate", "QA", "general-purpose"],
584+
contextWindow: 200000,
585+
inputCost: 3,
586+
outputCost: 15,
587+
priceUnit: "per 1M tokens",
588+
vision: false,
589+
tools: false,
590+
audio: false,
591+
reasoning: true,
592+
openSource: false,
593+
speed: "Fast",
594+
intelligence: "High",
595+
website: "https://openrouter.ai",
596+
apiDocs: "https://openrouter.ai/docs",
597+
modelPage: "https://openrouter.ai/perplexity/sonar-pro",
598+
releasedAt: "2025-03-27",
599+
icon: "perplexity",
600+
apiSdk: (apiKey?: string) =>
601+
createOpenRouter({
602+
apiKey: apiKey || process.env.OPENROUTER_API_KEY,
603+
}).chat("perplexity/sonar-pro"),
604+
},
605+
{
606+
id: "openrouter:perplexity/sonar-deep-research",
607+
name: "Perplexity Sonar Deep Research",
608+
provider: "OpenRouter",
609+
providerId: "openrouter",
610+
modelFamily: "Sonar",
611+
description:
612+
"Perplexity's most powerful model for deep research, long-context understanding, and advanced reasoning tasks.",
613+
tags: ["deep research", "advanced", "long-context", "reasoning", "QA"],
614+
contextWindow: 128000,
615+
inputCost: 2,
616+
outputCost: 8,
617+
priceUnit: "per 1M tokens",
618+
vision: false,
619+
tools: false,
620+
audio: false,
621+
reasoning: true,
622+
openSource: false,
623+
speed: "Medium",
624+
intelligence: "High",
625+
website: "https://openrouter.ai",
626+
apiDocs: "https://openrouter.ai/docs",
627+
modelPage: "https://openrouter.ai/perplexity/sonar-deep-research",
628+
releasedAt: "2025-03-07",
629+
icon: "perplexity",
630+
apiSdk: (apiKey?: string) =>
631+
createOpenRouter({
632+
apiKey: apiKey || process.env.OPENROUTER_API_KEY,
633+
}).chat("perplexity/sonar-deep-research"),
634+
}
635+
636+
637+
485638
]

lib/models/data/perplexity.ts

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
import { openproviders } from "@/lib/openproviders"
2+
import { ModelConfig } from "../types"
3+
4+
const perplexityModels: ModelConfig[] = [
5+
{
6+
id: "sonar",
7+
name: "Perplexity Sonar",
8+
provider: "Perplexity",
9+
providerId: "perplexity",
10+
modelFamily: "Sonar",
11+
description:
12+
"Sonar is a fast, affordable QA model with source control and citation support—ideal for lightweight, real-time integrations.",
13+
tags: ["fast", "simple", "affordable", "QA"],
14+
contextWindow: 127072,
15+
inputCost: 1,
16+
outputCost: 1,
17+
priceUnit: "per 1M tokens",
18+
vision: false,
19+
tools: false,
20+
audio: false,
21+
reasoning: true,
22+
openSource: false,
23+
speed: "Fast",
24+
intelligence: "Medium",
25+
website: "https://perplexity.ai",
26+
apiDocs: "https://docs.perplexity.ai/home",
27+
modelPage: "https://docs.perplexity.ai/models/models/sonar",
28+
releasedAt: "2025-01-27",
29+
icon: "perplexity",
30+
apiSdk: (apiKey?: string) => openproviders("sonar", undefined, apiKey),
31+
},
32+
{
33+
id: "sonar-reasoning",
34+
name: "Perplexity Sonar Reasoning",
35+
provider: "Perplexity",
36+
providerId: "perplexity",
37+
modelFamily: "Sonar",
38+
description:
39+
"An enhanced version of Sonar optimized for deeper reasoning and more complex tasks, while retaining fast response times.",
40+
tags: ["reasoning", "fast", "QA", "affordable"],
41+
contextWindow: 127072,
42+
inputCost: 1,
43+
outputCost: 5,
44+
priceUnit: "per 1M tokens",
45+
vision: false,
46+
tools: false,
47+
audio: false,
48+
reasoning: true,
49+
openSource: false,
50+
speed: "Medium",
51+
intelligence: "High",
52+
website: "https://docs.perplexity.ai/home",
53+
apiDocs: "https://docs.perplexity.ai/api-reference/chat-completions-post",
54+
modelPage: "https://docs.perplexity.ai/models/models/sonar-reasoning",
55+
releasedAt: "2025-01-29",
56+
icon: "perplexity",
57+
apiSdk: (apiKey?: string) =>
58+
openproviders("sonar-reasoning", undefined, apiKey),
59+
},
60+
{
61+
id: "sonar-reasoning-pro",
62+
name: "Perplexity Sonar Reasoning Pro",
63+
provider: "Perplexity",
64+
providerId: "perplexity",
65+
modelFamily: "Sonar",
66+
description:
67+
"Perplexity's most advanced Sonar model with pro-level reasoning, accuracy, and context handling—ideal for complex tasks.",
68+
tags: ["reasoning", "pro", "advanced", "QA", "research"],
69+
contextWindow: 127072,
70+
inputCost: 2,
71+
outputCost: 8,
72+
priceUnit: "per 1M tokens",
73+
vision: false,
74+
tools: false,
75+
audio: false,
76+
reasoning: true,
77+
openSource: false,
78+
speed: "Medium",
79+
intelligence: "High",
80+
website: "https://docs.perplexity.ai/home",
81+
apiDocs: "https://docs.perplexity.ai/api-reference/chat-completions-post",
82+
modelPage: "https://docs.perplexity.ai/models/models/sonar-reasoning-pro",
83+
releasedAt: "2025-07-25",
84+
icon: "perplexity",
85+
apiSdk: (apiKey?: string) =>
86+
openproviders("sonar-reasoning-pro", undefined, apiKey),
87+
},
88+
{
89+
id: "sonar-pro",
90+
name: "Perplexity Sonar Pro",
91+
provider: "Perplexity",
92+
providerId: "perplexity",
93+
modelFamily: "Sonar",
94+
description:
95+
"A high-performance version of Sonar optimized for speed and accuracy across general tasks, with solid reasoning capabilities.",
96+
tags: ["fast", "accurate", "QA", "general-purpose"],
97+
contextWindow: 200000,
98+
inputCost: 3,
99+
outputCost: 15,
100+
priceUnit: "per 1M tokens",
101+
vision: false,
102+
tools: false,
103+
audio: false,
104+
reasoning: true,
105+
openSource: false,
106+
speed: "Fast",
107+
intelligence: "High",
108+
website: "https://docs.perplexity.ai/home",
109+
apiDocs: "https://docs.perplexity.ai/api-reference/chat-completions-post",
110+
modelPage: "https://docs.perplexity.ai/models/models/sonar-pro",
111+
releasedAt: "2025-03-27",
112+
icon: "perplexity",
113+
apiSdk: (apiKey?: string) => openproviders("sonar-pro", undefined, apiKey),
114+
},
115+
{
116+
id: "sonar-deep-research",
117+
name: "Perplexity Sonar Deep Research",
118+
provider: "Perplexity",
119+
providerId: "perplexity",
120+
modelFamily: "Sonar",
121+
description:
122+
"Perplexity's most powerful model for deep research, long-context understanding, and advanced reasoning tasks.",
123+
tags: ["deep research", "advanced", "long-context", "reasoning", "QA"],
124+
contextWindow: 128000,
125+
inputCost: 2,
126+
outputCost: 8,
127+
priceUnit: "per 1M tokens",
128+
vision: false,
129+
tools: false,
130+
audio: false,
131+
reasoning: true,
132+
openSource: false,
133+
speed: "Medium",
134+
intelligence: "High",
135+
website: "https://docs.perplexity.ai/home",
136+
apiDocs: "https://docs.perplexity.ai/api-reference/chat-completions-post",
137+
modelPage: "https://docs.perplexity.ai/models/model-cards",
138+
releasedAt: "2025-03-07",
139+
icon: "perplexity",
140+
apiSdk: (apiKey?: string) =>
141+
openproviders("sonar-deep-research", undefined, apiKey),
142+
},
143+
]
144+
145+
export { perplexityModels }

lib/models/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { deepseekModels } from "./data/deepseek"
44
import { geminiModels } from "./data/gemini"
55
import { grokModels } from "./data/grok"
66
import { mistralModels } from "./data/mistral"
7+
import {perplexityModels } from "./data/perplexity"
78
import { getOllamaModels, ollamaModels } from "./data/ollama"
89
import { openaiModels } from "./data/openai"
910
import { openrouterModels } from "./data/openrouter"
@@ -16,6 +17,7 @@ const STATIC_MODELS: ModelConfig[] = [
1617
...deepseekModels,
1718
...claudeModels,
1819
...grokModels,
20+
...perplexityModels,
1921
...geminiModels,
2022
...ollamaModels, // Static fallback Ollama models
2123
...openrouterModels,

lib/openproviders/env.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export const env = {
22
OPENAI_API_KEY: process.env.OPENAI_API_KEY!,
33
MISTRAL_API_KEY: process.env.MISTRAL_API_KEY!,
44
GOOGLE_GENERATIVE_AI_API_KEY: process.env.GOOGLE_GENERATIVE_AI_API_KEY!,
5+
PERPLEXITY_API_KEY: process.env.PERPLEXITY_API_KEY!,
56
ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY!,
67
XAI_API_KEY: process.env.XAI_API_KEY!,
78
OPENROUTER_API_KEY: process.env.OPENROUTER_API_KEY!,
@@ -13,6 +14,7 @@ export function createEnvWithUserKeys(
1314
return {
1415
OPENAI_API_KEY: userKeys.openai || env.OPENAI_API_KEY,
1516
MISTRAL_API_KEY: userKeys.mistral || env.MISTRAL_API_KEY,
17+
PERPLEXITY_API_KEY: userKeys.perplexity || env.PERPLEXITY_API_KEY,
1618
GOOGLE_GENERATIVE_AI_API_KEY:
1719
userKeys.google || env.GOOGLE_GENERATIVE_AI_API_KEY,
1820
ANTHROPIC_API_KEY: userKeys.anthropic || env.ANTHROPIC_API_KEY,

0 commit comments

Comments
 (0)