Perplexity with OpenCode
Overview
Section titled “Overview”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.
Install OpenCode
Follow the OpenCode install guide for your platform (macOS, Linux, Windows).
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-..."Configure OpenCode
Add the Perplexity Agent API as a provider in your
opencode.json(or~/.config/opencode/config.json). See the configuration below.Verify
Run
/modelsto confirm the Perplexity Agent models appear in the selector.
Provider Configuration
Section titled “Provider Configuration”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.
{
"$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.
Available Models
Section titled “Available Models”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 |
Use as a Primary Coding Model
Section titled “Use as a Primary Coding Model”Set any Agent API model as your default in opencode.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.
Multi-Agent Setup
Section titled “Multi-Agent Setup”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:
{
"$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 modelsWhy the Agent API
Section titled “Why the Agent API”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.
Links & Resources
Section titled “Links & Resources”Agent API Quickstart
Send your first Agent API request.
Agent API Models
Full model catalog with pricing.
Perplexity SDK
Call the Agent API directly for presets, tools, and full control.
OpenAI Compatibility
Use Agent API with any OpenAI SDK.
OpenCode Providers
OpenCode custom provider reference.
OpenCode Docs
Official OpenCode documentation.
Support
Section titled “Support”Need help with the integration?
- Browse the OpenCode documentation
- Review our FAQ