For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
Perplexity
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.
| Approach | Requests that clients can send | Requests 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 provider | Chat 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
- Install and set up an agentgateway proxy.
- To use the AgentgatewayModel approach, allow the
AgentgatewayModelroute kind on thehttplistener of theagentgateway-proxyGateway. 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.
Get an API key from Perplexity.
Save the API key in an environment variable.
export PERPLEXITY_API_KEY='<your-api-key>'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.
Create an AgentgatewayModel that uses the
Perplexitypreset 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 EOFReview the following table to understand this configuration. For more information, see the API docs.
Setting Description 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 Perplexitypreset. 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. 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.
Create an AgentgatewayBackend that points the
openaiprovider at Perplexity. Perplexity’s chat completions path is/chat/completions, without the/v1prefix that most providers use. The Chat Completions API uses model names without the vendor prefix, such assonarinstead of theperplexity/sonarname 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 EOFCreate an HTTPRoute that routes requests on the
/perplexitypath 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 EOFSend 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