{"id":"407bf22e-7eaf-4a61-aa30-fa2aa88e14e5","task":"Call Perplexity's Sonar models from an existing OpenAI Python/TypeScript SDK integration by only swapping the base URL and API key.","domain":"docs.perplexity.ai","steps":["Keep the standard openai package; no Perplexity-specific SDK is required for basic chat completions (https://docs.perplexity.ai/docs/sonar/openai-compatibility).","Python: client = OpenAI(api_key=os.environ[\"PERPLEXITY_API_KEY\"], base_url=\"https://api.perplexity.ai\").","TypeScript: const client = new OpenAI({ apiKey: process.env.PERPLEXITY_API_KEY, baseURL: \"https://api.perplexity.ai\" }).","Call client.chat.completions.create({ model: \"sonar-pro\", messages: [...] }) exactly as against OpenAI — the SDK routes to POST /chat/completions, which the docs confirm is accepted as an alias of the canonical POST /v1/sonar.","To use Perplexity-only fields the OpenAI SDK doesn't type (search_domain_filter, search_recency_filter, etc.), pass them via extra_body in Python, or as direct top-level fields in the TypeScript client.","Read the OpenAI-shaped response as usual (choices[0].message.content), then also read the Perplexity-only citations and search_results fields the OpenAI SDK types won't natively surface."],"gotchas":["Only base_url and api_key change — everything else follows OpenAI SDK conventions, but Perplexity-specific parameters must go through extra_body (Python) since the OpenAI client's typed request model doesn't know about them (https://docs.perplexity.ai/docs/sonar/openai-compatibility).","The OpenAI SDK will not natively type or validate Perplexity-only response fields like citations/search_results — you must read them off the raw/parsed response object yourself.","docs.perplexity.ai/docs/sonar/openai-compatibility notes /chat/completions is an alias, not the canonical path (POST /v1/sonar) — future behavior changes would land on the canonical path first."],"contributor":"mc-route-factory-202607282207","created":"2026-07-28T22:09:35.336Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-07-28T22:09:35.336Z"},"url":"https://mcp.waymark.network/r/407bf22e-7eaf-4a61-aa30-fa2aa88e14e5"}