Skip to main content
Perplexity

Search documentation

Type to search this documentation.

On this pageOverview

Perplexity with OpenCode

OpenCode is an open-source AI coding agent for your terminal, IDE, or desktop. The Perplexity Agent API is compatible with the OpenAI Responses API and exposes frontier models from OpenAI, Anthropic, Google, xAI, and Perplexity through a single endpoint.

Wiring OpenCode to the Agent API means you can swap any frontier model into your coding agent or research subagent — without juggling separate provider accounts.

The Agent API implements the OpenAI Responses API, so you configure it in OpenCode as a custom provider using @ai-sdk/open-responses pointed at Perplexity's /v1/responses endpoint.

  1. Install OpenCode

    Follow the OpenCode install guide for your platform (macOS, Linux, Windows).

  2. Get a Perplexity API key

    Get API Key

    Generate your Perplexity API key from the API portal.

    Export it in your shell:

    Bash
    export PERPLEXITY_API_KEY="pplx-..."
  3. Configure OpenCode

    Add the Perplexity Agent API as a provider in your opencode.json (or ~/.config/opencode/config.json). See the configuration below.

  4. Verify

    Run /models to confirm the Perplexity Agent models appear in the selector.

The @ai-sdk/open-responses provider is built for servers that implement the OpenAI Responses API — exactly the dialect the Agent API speaks. Point its url at Perplexity's /v1/responses endpoint and declare the models you want in the picker.

JSON
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "perplexity-agent": {
      "npm": "@ai-sdk/open-responses",
      "name": "Perplexity Agent API",
      "options": {
        "name": "perplexity-agent",
        "url": "https://api.perplexity.ai/v1/responses",
        "apiKey": "{env:PERPLEXITY_API_KEY}",
        "headers": {
          "X-Pplx-Integration": "opencode/1.0"
        }
      },
      "models": {
        "openai/gpt-5.6-sol": { "name": "GPT-5.6 Sol" },
        "openai/gpt-5.6-terra": { "name": "GPT-5.6 Terra" },
        "openai/gpt-5.6-luna": { "name": "GPT-5.6 Luna" },
        "anthropic/claude-opus-4-8": { "name": "Claude Opus 4.8" },
        "anthropic/claude-sonnet-5": { "name": "Claude Sonnet 5" },
        "anthropic/claude-haiku-4-5": { "name": "Claude Haiku 4.5" },
        "google/gemini-3.1-pro-preview": { "name": "Gemini 3.1 Pro" },
        "xai/grok-4.5": { "name": "Grok 4.5" },
        "perplexity/kimi-k3": { "name": "Kimi K3" }
      }
    }
  }
}

That's it — one API key, one endpoint, every frontier model.

The Agent API routes to models from multiple providers. The full canonical list lives on the models page; the most useful identifiers for coding work:

Model ID Best for
openai/gpt-5.6-sol Deep reasoning, long-horizon coding tasks
openai/gpt-5.6-terra General-purpose coding agent
openai/gpt-5.6-luna Fast, cheap coding completions
anthropic/claude-opus-4-8 Highest-quality code review and architecture
anthropic/claude-sonnet-5 Balanced coding + tool use
anthropic/claude-haiku-4-5 Fast, low-cost edits
google/gemini-3.1-pro-preview Long-context refactors
xai/grok-4.5 Low-latency edits
perplexity/kimi-k3 Long-horizon reasoning and agentic coding

Set any Agent API model as your default in opencode.json:

JSON
{
  "$schema": "https://opencode.ai/config.json",
  "model": "perplexity-agent/anthropic/claude-opus-4-8"
}

OpenCode addresses each model as <providerId>/<modelId>, so the full identifier is perplexity-agent/anthropic/claude-opus-4-8.

Assign different Agent API models to different OpenCode agents — all through one Perplexity key. Here a primary coder delegates to a lighter, read-only subagent:

JSON
{
  "$schema": "https://opencode.ai/config.json",
  "model": "perplexity-agent/anthropic/claude-opus-4-8",
  "agent": {
    "coder": {
      "description": "Primary coding agent",
      "mode": "primary",
      "model": "perplexity-agent/anthropic/claude-opus-4-8",
      "temperature": 0.2,
      "tools": {
        "write": true,
        "edit": true,
        "bash": true
      }
    },
    "researcher": {
      "description": "Read-only subagent for lookups and summarization",
      "mode": "subagent",
      "model": "perplexity-agent/openai/gpt-5.6-sol",
      "temperature": 0.4,
      "tools": {
        "write": false,
        "edit": false,
        "bash": false
      }
    }
  }
}

The coder owns the filesystem (write, edit, bash) while the read-only researcher runs on a separate model for analysis and summarization. Swap either model for any Agent API model.

Verify the wiring:

/agents   # Should show coder and researcher
/models   # Should include Perplexity Agent models

The Agent API is purpose-built for agent loops:

  • One key, every model — switch between OpenAI, Anthropic, Google, xAI, and Perplexity without managing separate accounts.
  • OpenAI Responses-compatible — drop-in for any OpenCode provider slot that speaks /v1/responses.

Need help with the integration?

Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu