Integrate Morpheus AI with OpenCode
Learn how to set up Morpheus AI as a custom provider in OpenCode, giving you access to powerful AI models for coding assistance. This guide walks you through credential setup, provider configuration, and model selection.
What is OpenCode?
OpenCode is an open-source AI coding agent that helps you write code in your terminal, IDE, or desktop application. It’s a powerful alternative to proprietary coding assistants like Claude Code, offering complete flexibility and privacy for developers.Open Source & Free
Over 41,000 GitHub stars and 450 contributors building the future of AI-powered coding.
Privacy First
OpenCode doesn’t store any of your code or context data, making it ideal for sensitive projects.
Any Model, Any Provider
Connect to 75+ LLM providers including Claude, GPT, Gemini, local models, and now Morpheus AI.
Multi-Platform
Available as terminal interface, desktop app (macOS, Windows, Linux), and IDE extensions.
Key Features
- LSP Enabled: Automatically loads the right Language Server Protocols for enhanced LLM understanding
- Multi-Session: Run multiple AI agents in parallel on the same project
- Share Links: Share session links for collaboration and debugging
- Claude Pro Support: Use your existing Claude Pro or Max subscription
- 400,000 Monthly Users: Trusted by developers worldwide for production use
By integrating Morpheus AI with OpenCode, you get access to powerful open-source models with OpenCode’s privacy-first architecture.
Overview
OpenCode supports multiple AI providers. By integrating Morpheus AI, you gain access to models optimized for code generation, reasoning, and development tasks.Base URL:
https://api.mor.org/api/v1Prerequisites
Before you begin, ensure you have:- OpenCode installed on your system opencode.ai/docs
- A Morpheus AI account at app.mor.org
- Basic familiarity with JSON configuration files
- Access to your system’s terminal or command line
Get Your Morpheus AI API Key
Visit app.mor.org and create your API key.
- On the main page (API Keys) Click Create New Key
- Provide a descriptive name for the key
- Copy the generated API key (starts with
sk-)
Install OpenCode
If you haven’t already, install OpenCode on your system:
- macOS
- Linux
- Windows
Verify installation by running
opencode --version in your terminal.Configuring the Provider
Create your OpenCode configuration file to define the Morpheus AI provider and available models.Create the Configuration File
- Global Configuration (Recommended)
- Project Configuration
Create the global configuration directory and file. This makes Morpheus AI available across all your projects.
Full Provider Configuration
Copy and paste the following configuration into youropencode.json file:
opencode.json
Save the file: If using
nano, press Ctrl+O to save, then Ctrl+X to exit. If using vim, press Esc then type :wq and press Enter.Understanding the Configuration
Provider Settings
Provider Settings
- npm: The AI SDK package used (
@ai-sdk/openai-compatiblefor OpenAI-compatible APIs) - name: Display name shown in the OpenCode UI
- options.baseURL: The Morpheus AI API endpoint (
https://api.mor.org/api/v1)
Model Configuration
Model Configuration
Each model includes:
- name: Human-readable model name displayed in the UI
- limit.context: Maximum input tokens the model accepts
- limit.output: Maximum tokens the model can generate
- options.timeout: Optional timeout in milliseconds (used for large models)
Web Model Variants
Web Model Variants
Models with the
:web suffix have enhanced capabilities:- Web search integration
- Current information access
- Browser-optimized responses
:web are optimized for pure reasoning and code generation tasks.Minimal Configuration
If you prefer a simpler setup with just one model to start:opencode.json
Adding Morpheus AI Credentials
OpenCode stores API credentials securely in~/.local/share/opencode/auth.json. Use the /connect command to add your Morpheus AI API key.
Using the /connect Command
Launch OpenCode
Open your terminal and start OpenCode:This will open the OpenCode TUI (terminal user interface).
Start Coding
With Morpheus AI configured, you can now:- Generate code - Ask for implementations, algorithms, or functions
- Debug issues - Get help troubleshooting errors and bugs
- Refactor code - Request improvements and optimizations
- Explain code - Understand complex codebases
- Write tests - Generate test cases and test suites
Available Models
The following models are included in the configuration above:| Model | Context | Output | Best For |
|---|---|---|---|
| GLM 4.7 | 198K | 65K | General purpose, long context, documentation |
| GLM 4.7 Thinking | 198K | 65K | Extended thinking, analysis, reasoning |
| GPT OSS 120B | 128K | 8K | GPT-style responses, function calling |
| Qwen3 Coder 480B | 256K | 16K | Complex code generation, architecture design |
| Kimi K2 Thinking | 256K | 16K | Complex problem solving, multi-step reasoning |
For additional models, see the Available Models page. You can add any model from that page to your configuration by following the same format shown above.
Verifying Your Setup
Check Authentication Status
Verify that your Morpheus AI credentials are stored correctly:morpheus-ai in the list of configured credentials.
If
morpheus-ai appears in the list, your credentials are configured correctly.Test the Connection
Start a conversation in OpenCode and ask a simple question:Troubleshooting
Models not appearing in OpenCode
Models not appearing in OpenCode
Cause: Provider ID mismatch, configuration syntax error, or OpenCode not restarted.Solution:
- Verify the provider ID in both
/connectandopencode.jsonexactly matchesmorpheus-ai - Check that your JSON configuration is valid (no missing commas, brackets)
- Restart OpenCode completely
- Verify credentials with
opencode auth list
Authentication errors when using models
Authentication errors when using models
Cause: Invalid or expired API key, or incorrect provider configuration.Solution:
- Ensure your API key is valid and active at app.mor.org
- Verify the provider ID matches what you used in
/connect - Try regenerating your API key if needed
- Reconfigure credentials using
/connectcommand
Connection errors or timeouts
Connection errors or timeouts
Cause: Network connectivity issues, firewall blocking, or service unavailability.Solution:
- Check your internet connection
- Verify the baseURL is correct:
https://api.mor.org/api/v1 - Ensure your firewall allows HTTPS connections
- Check the Morpheus AI service status
Slow response times
Slow response times
Cause: Large model selected, high marketplace demand, or network latency.Solution:
- Use smaller models for quick tasks (e.g.,
llama-3.3-70b,hermes-4-14b) - Configure a
small_modelin youropencode.jsonfor rapid iterations - Try different models to find the best balance of performance and speed
- Check your network latency to the Morpheus API
Configuration file not found or ignored
Configuration file not found or ignored
Cause: Wrong file location or OpenCode not looking in the right directory.Solution:
- For global configuration:
~/.config/opencode/opencode.json - For project-specific:
./opencode.jsonin your project root - Ensure the file has correct permissions
- Verify JSON syntax is valid
Security Notes
- Local storage: Your API key is stored locally in
~/.local/share/opencode/auth.json - Never commit keys: Don’t commit API keys or configuration files with credentials to public repositories
- Rotate compromised keys: If your API key is compromised, immediately rotate it via the Morpheus AI dashboard
Additional Resources
Morpheus AI Portal
Manage your API keys, view usage, and access your Morpheus AI account.
API Documentation
Complete reference documentation for the Morpheus Inference API.
OpenCode Documentation
Learn more about OpenCode provider configuration and advanced features.
Available Models
See all available models and their capabilities.
Summary
You’ve successfully integrated Morpheus AI with OpenCode! Here’s what you’ve accomplished:Credentials configured: Added your Morpheus AI API key securely to OpenCode
Provider setup: Configured the Morpheus AI provider with access to powerful coding models
Model selection: Learned how to choose and switch between models for different tasks

