Class PerplexityClient

All Implemented Interfaces:
com.tnsai.llm.LLMClient

public class PerplexityClient extends AbstractOpenAICompatibleClient
Perplexity LLM client.

Perplexity hosts search-augmented LLMs (the Sonar family). Models fetch web results inline and ground their answers in real-time sources. The API is OpenAI-compatible at https://api.perplexity.ai — same chat-completions wire format as GroqClient / XAIGrokClient / YiClient.

Supported models (at time of writing):

  • sonar — fast / cheap search-grounded answer
  • sonar-pro — higher-quality search + synthesis tier
  • sonar-reasoning — chain-of-thought reasoning over search results
  • sonar-deep-research — multi-hop deep research mode

The catalog evolves; check the live list at docs.perplexity.ai.

About citations. Perplexity's responses include a citations[] array alongside the standard OpenAI choices[].message.content text. The shared

invalid reference
ChatResponse
SPI doesn't carry citation metadata, so v1 of this client preserves only the textual answer — citations are dropped on the floor. Most callers want grounded text without bookkeeping the source URLs themselves, so this is the right v1 default. Surfacing citations is a separate ChatResponse extension and a follow-up issue.

Configuration via environment variable:

  • PERPLEXITY_API_KEY — Required.
See Also:
  • Constructor Details

    • PerplexityClient

      public PerplexityClient(String model)
    • PerplexityClient

      public PerplexityClient(String model, float temperature)
    • PerplexityClient

      public PerplexityClient(String model, float temperature, Integer maxTokens)
    • PerplexityClient

      public PerplexityClient(String model, float temperature, Float topP, Integer maxTokens)
    • PerplexityClient

      public PerplexityClient(String baseUrl, String model, float temperature, Integer maxTokens, String apiKey)
    • PerplexityClient

      public PerplexityClient(String baseUrl, String model, float temperature, Float topP, Integer maxTokens, String apiKey)