Spaces:
Running
Running
OpenCode Microservice Setup Guide
Your New Architecture
HuggingFace Space (Free Forever)
βββ All browser providers (Copilot, Gemini, HuggingChat)
βββ Main API endpoints
βββ OpenCode calls β AWS
AWS EC2 (t3.micro - Free Tier)
βββ OpenCode Microservice Only
βββ Disposable mode, terminal access
What You Need to Do (Lazy Mode)
Step 1: Remove GitHub Auto-Deploy (2 minutes)
Go to: https://github.com/KiWA001/kai-api-gateway/settings/secrets/actions
Click "Remove" on these 3 secrets:
- EC2_SSH_KEY
- EC2_HOST
- EC2_USER
Step 2: Deploy OpenCode Microservice (5 minutes)
In your terminal (on your Mac), run:
cd /Users/mac/KAI_API
chmod +x deploy-microservice.sh
./deploy-microservice.sh ~/Downloads/kai-api-server.pem
This uploads only the microservice to AWS and starts it.
Step 3: Update HuggingFace Space (5 minutes)
- Go to your HuggingFace Space
- Go to Files β providers/opencode_provider.py
- Edit the file and replace line 11:
AWS_OPENCODE_URL = "http://44.201.146.74:8000" - Save and commit
OR use this easier method:
# On your Mac, edit the file
code providers/opencode_provider.py
# Make sure line 11 has your AWS IP:
# AWS_OPENCODE_URL = "http://44.201.146.74:8000"
# Then push to GitHub
git add providers/opencode_provider.py
git commit -m "Connect OpenCode to AWS microservice"
git push origin main
HuggingFace will auto-deploy from GitHub.
Step 4: Test Everything (2 minutes)
Test AWS Microservice:
curl http://44.201.146.74:8000/healthShould return:
{"status":"healthy"}Test via HuggingFace:
- Go to your HF Space admin portal
- Select OpenCode provider
- Send a message
- Should work!
What Each Part Does
AWS EC2 (t3.micro - FREE)
- Only runs:
opencode_microservice.py - Memory: ~500MB RAM (fits in t3.micro's 1GB)
- Features:
- Disposable mode (auto-reset after 20 messages)
- Anonymous mode (no credentials)
- Direct terminal access to OpenCode
- Cost: $0/month (free tier)
HuggingFace Space (FREE FOREVER)
- Runs: Everything else
- Providers: Copilot, Gemini, HuggingChat, etc.
- For OpenCode: Calls AWS microservice via HTTP
- Cost: $0/month (always free)
Benefits
β HuggingFace: Reliable, working, no terminal issues β AWS: Only handles OpenCode (lightweight, disposable) β Cost: Both are FREE β Simple: No complex deployment, just 2 services β Works: Best of both worlds
Troubleshooting
AWS Microservice Not Responding?
# SSH to EC2 and check
ssh -i ~/Downloads/kai-api-server.pem ubuntu@44.201.146.74
tail -f /tmp/opencode-service.log
HuggingFace Can't Connect to AWS?
- Check AWS security group allows port 8000
- Verify the URL in
opencode_provider.pymatches your EC2 IP
OpenCode Not Working?
- Check if npx is installed:
which npx - Check OpenCode:
opencode --version
Architecture Diagram
User Request
β
βΌ
βββββββββββββββββββ
β HuggingFace β
β Space β
β (Free Forever) β
βββββββββββββββββββ
β
ββ Copilot β Browser (local)
ββ Gemini β Browser (local)
ββ HuggingChat β Browser (local)
ββ OpenCode β HTTP Request
β
βΌ
ββββββββββββββββ
β AWS EC2 β
β t3.micro β
β (Free Tier) β
ββββββββββββββββ
β
βΌ
OpenCode Terminal
(Disposable Mode)
Summary
- HuggingFace: Handles web UI, browsers, API
- AWS: Handles OpenCode terminal only
- Result: Everything works, both are free!
Start with Step 1 now! Remove those GitHub secrets.