Skip to main content

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:
export PERPLEXITY_API_KEY="your_api_key_here"
Treat PERPLEXITY_API_KEY like a password. Don’t paste it into prompts, share it with Claude Code, or commit it to source control. If a key is exposed, rotate it immediately.

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

npm install @perplexity-ai/perplexity_ai
pnpm and yarn work the same way: pnpm add @perplexity-ai/perplexity_ai / yarn add @perplexity-ai/perplexity_ai.
The Agent API is the recommended surface for most applications. Use the pro-search preset for web-grounded responses with sensible defaults:
import Perplexity from "@perplexity-ai/perplexity_ai";

const client = new Perplexity(); // reads PERPLEXITY_API_KEY from the environment

const response = await client.responses.create({
  preset: "pro-search",
  input: "Summarize the latest changes to the Perplexity Agent API.",
});

console.log(`Model used: ${response.model}`);
console.log(response.output_text);
from perplexity import Perplexity

client = Perplexity()  # reads PERPLEXITY_API_KEY from the environment

response = client.responses.create(
    preset="pro-search",
    input="Summarize the latest changes to the Perplexity Agent API.",
)

print(f"Model used: {response.model}")
print(response.output_text)
Enable the web_search tool for explicit control over when search is used:
import Perplexity from "@perplexity-ai/perplexity_ai";

const client = new Perplexity();

const response = await client.responses.create({
  model: "openai/gpt-5.4",
  input: "What are the latest developments in AI inference hardware?",
  tools: [{ type: "web_search" }],
  instructions:
    "You have access to a web_search tool. Use it for questions about current events, news, or recent developments.",
});

if (response.status === "completed") {
  console.log(response.output_text);
}
Ask Claude Code to scaffold these calls for you — for example, “Add a summarize.ts script that uses @perplexity-ai/perplexity_ai with the pro-search preset and reads PERPLEXITY_API_KEY from the environment.” Claude Code will edit the file, install the package, and run it.
For more presets, tools, and configuration options see the Agent API quickstart and the SDK overview.

Path 2: OpenAI-compatible SDK

If your project already uses an OpenAI client, you can reuse it by pointing the baseURL at https://api.perplexity.ai/v1. Perplexity accepts POST /v1/responses as an alias for the Agent API.

Install

npm install openai

Use it

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.PERPLEXITY_API_KEY,
  baseURL: "https://api.perplexity.ai/v1",
});

const response = await client.responses.create({
  model: "openai/gpt-5.4",
  input: "Explain the key differences between REST and GraphQL APIs.",
});

console.log(response.output_text);
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ.get("PERPLEXITY_API_KEY"),
    base_url="https://api.perplexity.ai/v1",
)

response = client.responses.create(
    model="openai/gpt-5.4",
    input="Explain the key differences between REST and GraphQL APIs.",
)

print(response.output_text)
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 at https://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 the claude mcp add command with the --transport http flag:
Add the server only for the current project (writes to .mcp.json in your repo root):
claude mcp add --transport http --scope project perplexity-docs https://docs.perplexity.ai/mcp
If you’d rather not run the CLI, you can also edit the project’s .mcp.json directly:
{
  "mcpServers": {
    "perplexity-docs": {
      "type": "http",
      "url": "https://docs.perplexity.ai/mcp"
    }
  }
}
Claude Code reads .mcp.json at the repo root for project-scoped servers. Refer to the Claude Code MCP documentation for the canonical schema and any newer transport options.

Verify and use

1

Confirm the server is registered

Run claude mcp list and check that perplexity-docs appears in the output.
2

Restart Claude Code

Quit and relaunch Claude Code (or run /mcp from inside a session) so the new server is loaded.
3

Use it from a prompt

Ask Claude Code something like “Using the Perplexity docs MCP, show me how to enable pro-search in the Agent API.” Claude Code will call the MCP server and ground its answer in current documentation.
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.

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.
This combination gives you Claude Code’s editing and orchestration strengths alongside Perplexity’s search-grounded responses, without depending on undocumented model-override behavior.

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.