Perplexity

Search-grounded answers with citations as sources.

let model = PerplexityModel("sonar-pro")

Key from PERPLEXITY_API_KEY; base URL https://api.perplexity.ai.

Features

  • Every answer is search-grounded; citations surface as StreamPart.source and collect on result.sources.
  • Structured output and image input ride the chat-completions wire on models that support them.
  • No tool calling — Perplexity's API doesn't offer it, so the library doesn't pretend otherwise. The reasoning parameter is ignored the same way.
let result = try await generateText(
  model: PerplexityModel("sonar-pro"),
  prompt: "What changed in Swift 6.2?"
)
for source in result.sources {
  print(source.title ?? source.url)
}

Models

Three ids cover the lineup: sonar (fast grounded answers), sonar-pro (deeper multi-hop search), and sonar-reasoning-pro (search plus visible reasoning).

On this page