This is an n8n community node that integrates OpenCode as a chat model for use with n8n's AI Agent and LangChain workflows.
n8n is a fair-code licensed workflow automation platform.
OpenCode is an open-source AI coding agent built for the terminal with support for multiple LLM providers.
Follow the installation guide in the n8n community nodes documentation.
npm install n8n-nodes-opencode- Clone this repository
- Run
npm installandnpm run build - Copy the
distfolder to~/.n8n/custom/(create if it doesn't exist) - Restart n8n
- n8n version 1.0.0 or later
- OpenCode server running (see OpenCode documentation)
# Install OpenCode CLI
npm install -g @opencode-ai/cli
# Start the server
opencode serveBy default, OpenCode server runs on http://localhost:4096.
This node requires OpenCode API credentials:
- In n8n, go to Credentials → New
- Search for "OpenCode API"
- Configure:
- Base URL: Your OpenCode server URL (default:
http://localhost:4096) - API Key: (Optional) If your OpenCode instance requires authentication
- Base URL: Your OpenCode server URL (default:
- Add the OpenCode Chat Model node to your workflow
- Select or create OpenCode API credentials
- Configure the model:
- Agent: Choose the OpenCode agent type (
build,chat,debug) - Model Provider: Select provider (Anthropic, OpenAI, Google, Groq, Ollama)
- Model ID: Specify the model (e.g.,
claude-3-5-sonnet-20241022)
- Agent: Choose the OpenCode agent type (
- Connect to an AI Agent node or other LangChain-compatible nodes
┌─────────────────┐ ┌──────────────────┐ ┌────────────────┐
│ Chat Trigger │────→│ AI Agent │────→│ Respond │
└─────────────────┘ └──────────────────┘ └────────────────┘
│
↓
┌──────────────────┐
│ OpenCode Chat │
│ Model │
└──────────────────┘
The node supports models from these providers (via models.dev):
claude-sonnet-4-5-20250929(latest)claude-sonnet-4-20250514claude-3-7-sonnet-20250219claude-3-5-sonnet-20241022claude-3-5-sonnet-20240620claude-opus-4-1-20250805claude-opus-4-20250514claude-haiku-4-5-20251001claude-3-5-haiku-20241022
gpt-5(latest)gpt-5-minigpt-5-nanoo3o3-minigpt-4.1gpt-4.1-minigpt-4ogpt-4o-minio1o1-minigpt-4-turbo
gemini-2.5-pro(latest)gemini-2.5-flashgemini-2.5-flash-litegemini-2.0-flashgemini-2.0-flash-litegemini-1.5-progemini-1.5-flashgemini-1.5-flash-8b
llama-3.3-70b-versatilellama3-70b-8192llama-3.1-8b-instantqwen-qwq-32bmistral-saba-24bgemma2-9b-it
mistral-large-latestmistral-medium-latestmistral-small-latestpixtral-large-latestcodestral-latestministral-8b-latestministral-3b-latest
llama-4-maverick-17bllama-4-scout-17bllama-3.3-70b-instructllama-3.2-1b-instructllama-3.1-70b-instructllama-3.1-8b-instruct
deepseek-chatdeepseek-reasoner
qwen3-maxqwen3-32bqwen3-14bqwen3-8bqwen-maxqwen-plus
kimi-k2-0905-previewkimi-k2-0711-preview
- Any model available in your Ollama instance
- Examples:
qwen2.5-coder:32b,codellama:34b,llama3:70b
- Build: Optimized for implementing features and writing code
- Chat: General-purpose conversational agent
- Debug: Specialized for debugging and troubleshooting
- Temperature: Control randomness (0-2, default: 0.7)
- Maximum Tokens: Limit response length (-1 for unlimited)
- ✅ Full LangChain integration
- ✅ Multiple model providers (Anthropic, OpenAI, Google, Groq, Ollama)
- ✅ Session management with automatic cleanup
- ✅ Tool calling support (via OpenCode's native capabilities)
- ✅ Comprehensive error handling and validation
- ✅ TypeScript support with full type definitions
Problem: "Failed to create OpenCode session" Solution: Verify OpenCode server is running and accessible at the configured base URL.
# Test connection
curl http://localhost:4096/appProblem: "Unauthorized" errors Solution: If your OpenCode server requires authentication, ensure the API key is correctly configured in credentials.
Problem: Model ID not recognized Solution: Ensure the specified model is configured in your OpenCode server and the corresponding provider API keys are set.
npm install
npm run buildnpm run devnpm run lint
npm run lintfixThis node implements a custom LangChain BaseChatModel that:
- Session Management: Creates and manages OpenCode sessions via REST API
- Message Handling: Converts LangChain messages to OpenCode prompt format
- Streaming: Implements Server-Sent Events (SSE) for real-time responses
- Event Parsing: Processes
message.part.updatedandsession.updatedevents
OpenCodeChatModel.ts: Custom LangChain chat model implementationLmChatOpenCode.node.ts: n8n node wrapperOpenCodeApi.credentials.ts: Credentials definition
POST /session: Create new sessionPOST /session/:id/prompt: Send prompt with message partsGET /event: Server-Sent Events stream for responsesDELETE /session/:id: Clean up session
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
For issues and questions: