Documentation Index
Fetch the complete documentation index at: https://docs.perplexity.ai/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Claude Code is Anthropic’s agentic coding tool that lives in your terminal, IDE, and CI. It can edit files, run commands, and call Model Context Protocol (MCP) servers as part of its workflow. This guide covers three integration paths for Perplexity:Official TypeScript SDK
Let Claude Code write and run application code that calls the Perplexity API directly. Recommended.
OpenAI-Compatible SDK
Reuse an existing OpenAI client by pointing
baseURL at https://api.perplexity.ai/v1.Claude Code MCP
Register the hosted Perplexity Docs MCP with
claude mcp add so Claude Code can look up Perplexity docs while you work.Recommended path: Have Claude Code build features against your project code using the official SDK (or the OpenAI-compatible SDK), and register the Perplexity Docs MCP for in-editor documentation lookup. Claude Code does not officially support swapping its underlying model for the Perplexity API — see Replacing Claude Code’s model (not recommended).
Prerequisites
- Claude Code installed — see the Claude Code quickstart
- Node.js 18+ for the TypeScript examples
- A Perplexity API key
Get API Key
Generate a key from the Perplexity API Portal.
API key handling
Never hardcode your API key in source files or commit it to a repository. Store it in an environment variable and read it at runtime:- macOS/Linux
- Windows
- .env (project-local)
Path 1: Official TypeScript SDK (recommended)
Have Claude Code scaffold and edit code that calls the Perplexity API using the official SDK. This is the most reliable path and gives you full type safety, preset support, and access to every API feature.Install
Agent API with pro-search
The Agent API is the recommended surface for most applications. Use the pro-search preset for web-grounded responses with sensible defaults:
Python equivalent
Python equivalent
Add web search
Enable theweb_search tool for explicit control over when search is used:
Path 2: OpenAI-compatible SDK
If your project already uses an OpenAI client, you can reuse it by pointing thebaseURL at https://api.perplexity.ai/v1. Perplexity accepts POST /v1/responses as an alias for the Agent API.
Install
Use it
Python equivalent
Python equivalent
Use
baseURL (TypeScript) or base_url (Python) — both must include the /v1 suffix. See the OpenAI Compatibility guide for the full list of supported parameters and which Perplexity features are available through this path.Path 3: Claude Code MCP for docs lookup
Claude Code supports the Model Context Protocol (MCP). The hosted Perplexity Docs MCP athttps://docs.perplexity.ai/mcp lets Claude Code search and read Perplexity’s documentation directly — useful for grounding code suggestions in canonical docs without context-switching to a browser.
Add the server
Claude Code can register a remote MCP server over HTTP using theclaude mcp add command with the --transport http flag:
- Project scope
- User scope
Add the server only for the current project (writes to
.mcp.json in your repo root):Verify and use
Confirm the server is registered
Run
claude mcp list and check that perplexity-docs appears in the output.Restart Claude Code
Quit and relaunch Claude Code (or run
/mcp from inside a session) so the new server is loaded.The Docs MCP is read-only and does not require an API key — it only serves Perplexity documentation. To give Claude Code access to Perplexity search and reasoning tools (not just docs), install the Perplexity MCP Server, which uses
@perplexity-ai/mcp-server and requires PERPLEXITY_API_KEY.Replacing Claude Code’s model (not recommended)
Claude Code is designed to run on Anthropic’s Claude models, and the agent’s tool use, prompting, and editing behavior are tuned to those models. Pointing the Claude Code CLI at the Perplexity API as an alternative model provider is not an officially supported configuration. Instead:- Use Perplexity from your project code (Path 1 or Path 2). Claude Code will happily write, edit, and run code that calls Perplexity for web-grounded answers, research, and search.
- Add the Perplexity Docs MCP (Path 3) so Claude Code can look up Perplexity documentation in-session.
Next steps
Agent API quickstart
Presets, tools, and the full Agent API surface used by the examples above.
Perplexity SDK overview
Install, configure, and use the official Python and TypeScript SDKs.
OpenAI compatibility
Drop-in compatibility details, supported parameters, and migration tips.
Perplexity MCP Server
Add Perplexity search, ask, research, and reason tools to Claude Code and other MCP clients.
Need help? Join the Perplexity developer community for support and discussion.