From 4723ea99ab6900d39a0ba4c5f1ca76f024873be6 Mon Sep 17 00:00:00 2001 From: Saleh Alghusson <1331721+qirh@users.noreply.github.com> Date: Mon, 12 Oct 2026 13:21:04 +0000 Subject: [PATCH] Add X-Pplx-Integration header to Perplexity sample client --- .../perplexity/sample-agent/src/perplexityClient.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/nodejs/perplexity/sample-agent/src/perplexityClient.ts b/nodejs/perplexity/sample-agent/src/perplexityClient.ts index 26520061..6ddfddfc 100644 --- a/nodejs/perplexity/sample-agent/src/perplexityClient.ts +++ b/nodejs/perplexity/sample-agent/src/perplexityClient.ts @@ -32,6 +32,9 @@ interface ChatCompletionResponse { [key: string]: unknown; } +const PERPLEXITY_API_HOST = "api.perplexity.ai"; +const PERPLEXITY_INTEGRATION = "agent365-samples"; + /** * Client for interacting with the Perplexity AI SDK. */ @@ -41,7 +44,14 @@ export class PerplexityClient { private systemPrompt: string; constructor(apiKey: string, model: string, systemPrompt: string) { - this.client = new Perplexity({ apiKey }); + const client = new Perplexity({ apiKey }); + // Identify this sample to Perplexity only when targeting the public API host. + this.client = + new URL(client.baseURL).hostname === PERPLEXITY_API_HOST + ? client.withOptions({ + defaultHeaders: { "X-Pplx-Integration": PERPLEXITY_INTEGRATION }, + }) + : client; this.model = model; this.systemPrompt = systemPrompt; }