Skip to content
Help guide the future of agentgateway — Take the survey

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

Perplexity

Page as Markdown

Route agentgateway LLM traffic to models available through Perplexity.

Configure Perplexity as an LLM provider in agentgateway. Perplexity serves search-augmented models through an OpenAI-compatible API.

You can connect to Perplexity with an AgentgatewayModel or an AgentgatewayBackend. The two approaches accept different request formats. Choose the approach that matches the requests that your clients send.

ApproachRequests that clients can sendRequests that fail
AgentgatewayModel with provider: Perplexity/v1/responses, sent to Perplexity unchanged. /v1/messages, converted to the Responses format./v1/chat/completions, embeddings, and rerank. Perplexity receives only Responses requests from this model.
AgentgatewayBackend with the openai providerChat Completions requests on the route path, such as /perplexity.Requests in other formats. Perplexity receives Chat Completions requests at https://api.perplexity.ai/chat/completions.

Before you begin

  1. Install and set up an agentgateway proxy.
  2. To use the AgentgatewayModel approach, allow the AgentgatewayModel route kind on the http listener of the agentgateway-proxy Gateway. For the steps, see Enable LLM serving on a listener.

Set up provider credentials

Store your Perplexity API key in a Secret. The model and backend examples both reference this Secret.

  1. Get an API key from Perplexity.

  2. Save the API key in an environment variable.

    export PERPLEXITY_API_KEY='<your-api-key>'
  3. Create a Kubernetes Secret to store your API key.

    kubectl apply -f- <<EOF
    apiVersion: v1
    kind: Secret
    metadata:
      name: perplexity-secret
      namespace: agentgateway-system
    type: Opaque
    stringData:
      Authorization: $PERPLEXITY_API_KEY
    EOF

Responses requests with an AgentgatewayModel

The model attaches directly to the Gateway listener, so you do not create an AgentgatewayBackend or an HTTPRoute.

  1. Create an AgentgatewayModel that uses the Perplexity preset and references the Secret.

    kubectl apply -f- <<EOF
    apiVersion: agentgateway.dev/v1alpha1
    kind: AgentgatewayModel
    metadata:
      name: perplexity
      namespace: agentgateway-system
    spec:
      parentRefs:
      - group: gateway.networking.k8s.io
        kind: Gateway
        name: agentgateway-proxy
        sectionName: http
      match:
        model: perplexity/sonar
      provider: Perplexity
      policies:
        auth:
          secretRef:
            name: perplexity-secret
    EOF

    Review the following table to understand this configuration. For more information, see the API docs.

    SettingDescription
    spec.match.modelThe model name that clients send in requests. Perplexity’s Responses API uses model names with a vendor prefix, such as perplexity/sonar.
    spec.providerThe Perplexity preset. The preset supplies the default URL, https://api.perplexity.ai/v1, and the Responses request format.
    spec.policies.auth.secretRefThe Secret that holds your Perplexity API key.
  2. Send a Responses request to the model. Chat Completions requests to this model fail.

    curl "http://$INGRESS_GW_ADDRESS/v1/responses" \
      -H 'Content-Type: application/json' \
      -d '{"model": "perplexity/sonar", "input": "Explain retrieval-augmented generation in one sentence."}' | jq

Chat Completions requests with an AgentgatewayBackend

Use this approach to select the backend with an HTTPRoute.

  1. Create an AgentgatewayBackend that points the openai provider at Perplexity. Perplexity’s chat completions path is /chat/completions, without the /v1 prefix that most providers use. The Chat Completions API uses model names without the vendor prefix, such as sonar instead of the perplexity/sonar name that the Responses API uses.

    kubectl apply -f- <<EOF
    apiVersion: agentgateway.dev/v1alpha1
    kind: AgentgatewayBackend
    metadata:
      name: perplexity
      namespace: agentgateway-system
    spec:
      ai:
        provider:
          openai:
            model: sonar
          host: api.perplexity.ai
          port: 443
          path: /chat/completions
      policies:
        auth:
          secretRef:
            name: perplexity-secret
        tls:
          sni: api.perplexity.ai
    EOF
  2. Create an HTTPRoute that routes requests on the /perplexity path to the AgentgatewayBackend.

    kubectl apply -f- <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: perplexity
      namespace: agentgateway-system
    spec:
      parentRefs:
        - name: agentgateway-proxy
          namespace: agentgateway-system
      rules:
      - matches:
        - path:
            type: PathPrefix
            value: /perplexity
        backendRefs:
        - name: perplexity
          namespace: agentgateway-system
          group: agentgateway.dev
          kind: AgentgatewayBackend
    EOF
  3. Send a Chat Completions request to the route.

    curl "http://$INGRESS_GW_ADDRESS/perplexity" \
      -H 'Content-Type: application/json' \
      -d '{
        "model": "sonar",
        "messages": [{"role": "user", "content": "Explain retrieval-augmented generation in one sentence."}]
      }' | jq

Next steps

To connect other providers that expose an OpenAI-compatible API, see OpenAI-compatible providers.

Cleanup

You can remove the resources that you created in this guide.
kubectl delete AgentgatewayModel perplexity -n agentgateway-system
kubectl delete HTTPRoute perplexity -n agentgateway-system
kubectl delete AgentgatewayBackend perplexity -n agentgateway-system
kubectl delete secret perplexity-secret -n agentgateway-system
Was this page helpful?
Agentgateway assistant

Ask me anything about agentgateway configuration, features, or usage.

Note: AI-generated content might contain errors; please verify and test all returned information.

Tip: one topic per conversation gives the best results. Use the + button in the chat header to start a new conversation.

Switching topics? Starting a new conversation improves accuracy.
↑↓ navigate ↵ select esc dismiss

What could be improved?

Your feedback helps us improve assistant answers and identify docs gaps we should fix.

Need more help? Join us on Discord: https://discord.gg/y9efgEmppm

Want to use your own agent? Add the Solo MCP server to query our docs directly. Get started here: https://search.solo.io/.