|
This version is still in development and is not considered stable yet. For the latest stable version, please use Spring AI 2.1.0! |
Perplexity Chat
Perplexity combines its language models with real-time web search, and offers them through an OpenAI-compatible API. Spring AI uses Perplexity through the OpenAI chat model: you point the OpenAI module at Perplexity’s endpoint and choose a Perplexity model.
Configuration
Add the OpenAI starter:
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-openai</artifactId>
</dependency>
Create an API key as described in Getting Started with Perplexity, then set the base URL, the key and a model from the Perplexity models:
spring.ai.openai.base-url=https://api.perplexity.ai
spring.ai.openai.api-key=${PERPLEXITY_API_KEY}
spring.ai.openai.chat.model=sonar
Unlike the other services, Perplexity’s API has no version path, so the base URL ends at the host name.
All other properties and options are those of the OpenAI chat model, see OpenAI Chat.
Differences from OpenAI
-
Perplexity does not support tool calling.
-
Perplexity does not accept images or other media.
-
Answers are based on a web search, which Perplexity runs for each request.
Example
The PerplexityWithOpenAiChatModelIT test shows chat and streaming with Perplexity.