opencode-chat-model/
├── credentials/
│ └── OpenCodeApi.credentials.ts # n8n credentials definition
├── nodes/
│ └── LmChatOpenCode/
│ ├── LmChatOpenCode.node.ts # n8n node wrapper
│ ├── OpenCodeChatModel.ts # Custom LangChain chat model
│ └── opencode.svg # Node icon
├── package.json # Package configuration
├── tsconfig.json # TypeScript configuration
├── README.md # Full documentation
├── LICENSE # MIT License
└── .gitignore # Git ignore rules
npm installnpm run buildThis will:
- Compile TypeScript to JavaScript
- Copy the icon to the dist folder
- Generate type definitions
# Copy to n8n custom nodes directory
mkdir -p ~/.n8n/custom
cp -r dist ~/.n8n/custom/n8n-nodes-opencode# From this directory
npm link
# In your n8n directory
cd ~/.n8n
npm link n8n-nodes-opencode# Update package.json with your details first
npm publishThen in n8n: Settings → Community Nodes → Install n8n-nodes-opencode
# If running via npm
n8n start
# If running via Docker
docker restart n8n# Install OpenCode
npm install -g @opencode-ai/cli
# Set up API keys
export ANTHROPIC_API_KEY=your_key_here
export OPENAI_API_KEY=your_key_here
# Start server
opencode serveSee README.md for Kubernetes deployment YAML.
In n8n:
- Go to Credentials → New
- Search for "OpenCode API"
- Enter:
- Base URL:
http://localhost:4096(or your Kubernetes service URL) - API Key: (leave empty if not required)
- Base URL:
- Click Test to verify connection
- Save
- Add Chat Trigger node
- Add AI Agent node
- Add OpenCode Chat Model node:
- Connect to AI Agent
- Select credentials
- Choose Agent:
build - Provider:
anthropic - Model ID:
claude-3-5-sonnet-20241022
- Connect AI Agent → Chat Trigger response
Start the workflow and send a message through the chat interface:
- "Write a Python function to calculate fibonacci numbers"
- "Explain how async/await works in JavaScript"
- "Debug this error: TypeError: Cannot read property 'length' of undefined"
# Clean and rebuild
rm -rf dist node_modules
npm install
npm run build- Check n8n logs for errors
- Verify the build completed successfully
- Ensure
dist/nodes/LmChatOpenCode/LmChatOpenCode.node.jsexists - Restart n8n completely
# Test OpenCode server directly
curl http://localhost:4096/app
# Should return app infoIf using API key authentication:
- Verify the key in OpenCode server configuration
- Update credentials in n8n
- Test credentials again
# Terminal 1: Watch TypeScript compilation
npm run dev
# Terminal 2: Run n8n in development mode
n8n startChanges to .ts files will automatically recompile. Restart n8n to pick up changes.
- Make code changes
- Save files (watch mode compiles automatically)
- Restart n8n
- Test in n8n UI
- Customize: Modify
OpenCodeChatModel.tsto add features - Extend: Add support for file attachments or tool calling
- Deploy: Push to Kubernetes alongside n8n
- Share: Publish to npm for community use
Edit nodes/LmChatOpenCode/LmChatOpenCode.node.ts:
{
displayName: 'Model ID',
name: 'modelID',
type: 'options', // Change from 'string' to 'options'
options: [
{ name: 'Claude 3.5 Sonnet', value: 'claude-3-5-sonnet-20241022' },
{ name: 'Claude 3 Opus', value: 'claude-3-opus-20240229' },
// Add more...
],
}Add to the agent dropdown in the same file.
Edit OpenCodeChatModel.ts to change how sessions are created/reused.
- GitHub Issues: Report bugs and request features
- n8n Community: Get help from the community
- OpenCode Discord: Ask OpenCode-specific questions