Skip to content

PerplexityProvider

Namespace: Vercel.AI.Perplexity

public sealed class PerplexityProvider : OpenAICompatibleProvider, IDecisionProvider

Perplexity provider. Language generation uses the Agent API at {base}/v1/agent. Embeddings use {base}/v1/embeddings. Preset ids are fast, low, medium, high, and xhigh; any other id is sent as a model id. Legacy Sonar model ids are not aliased and Sonar provider options are not translated. Sonar PDF input, video input, and image or video results have no Agent API equivalent.

Inheritance: object → ProviderBase → OpenAICompatibleProvider

Implements: IDecisionProvider

View source

PerplexityProvider(HttpClient, OpenAICompatibleOptions?)

Section titled “PerplexityProvider(HttpClient, OpenAICompatibleOptions?)”
public PerplexityProvider(HttpClient httpClient, OpenAICompatibleOptions? options = null)

Creates a provider.

Parameters

Name Type Description
httpClient HttpClient
options OpenAICompatibleOptions

View source

public const string AgentPath = "v1/agent"

Relative Agent API path.

Value: string

View source

public const string ApiKeyVariable = "PERPLEXITY_API_KEY"

Environment variable for the API key.

Value: string

View source

public const string DefaultBaseUrl = "https://api.perplexity.ai"

Default API origin. Language calls append /v1/agent.

Value: string

View source

public const string DefaultIntegration = "vercel-ai-sdk"

Default IntegrationHeader value.

Value: string

View source

public const string IntegrationHeader = "X-Pplx-Integration"

Header Perplexity uses to attribute SDK requests.

Value: string

View source

public const string ProviderId = "perplexity"

Provider id.

Value: string

View source

public Uri AgentUri()

Agent API URL. A custom base URL is prefixed to v1/agent.

Returns: Uri

View source

Create(OpenAICompatibleOptions?, HttpMessageHandler?)

Section titled “Create(OpenAICompatibleOptions?, HttpMessageHandler?)”
public static PerplexityProvider Create(OpenAICompatibleOptions? options = null, HttpMessageHandler? handler = null)

Creates a provider. Pass a handler from tests.

Parameters

Name Type Description
options OpenAICompatibleOptions
handler HttpMessageHandler

Returns: PerplexityProvider

View source

public PerplexityDecisionModel DecisionModel(string modelId)

Decision model. Uses the Decisions API at {base}/v1/decisions. The provider id is perplexity.decision.

Parameters

Name Type Description
modelId string

Returns: PerplexityDecisionModel

View source

public override IEmbeddingModel EmbeddingModel(string modelId)

Returns an embedding model.

Parameters

Name Type Description
modelId string

Returns: IEmbeddingModel

View source

public override ILanguageModel LanguageModel(string modelId)

Returns a language model.

Parameters

Name Type Description
modelId string

Returns: ILanguageModel

View source

Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product