OpenCode là AI coding agent chạy trong terminal, hỗ trợ nhiều nhà cung cấp model thông qua cơ chế provider. Tài liệu này hướng dẫn cấu hình OpenCode dùng API OpenAI-compatible của ShopAIKey.
Endpoint
https://api.shopaikey.com/v1
1. Cài đặt OpenCode
Bạn có thể cài bằng npm:
npm install -g opencode
Hoặc dùng Homebrew trên macOS/Linux:
brew install opencode-ai/tap/opencode
Kiểm tra sau khi cài:
opencode --version
2. Thêm API key vào OpenCode
Chạy lệnh:
opencode auth login
Chọn Other, nhập provider id:
shopaikey
Sau đó nhập API key ShopAIKey của bạn.
Provider id
shopaikeyphải trùng với key trong fileopencode.jsonở bước tiếp theo.
3. Tạo file opencode.json
Trong thư mục dự án bạn muốn dùng OpenCode, tạo hoặc cập nhật file:
opencode.json
Nội dung mẫu:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"shopaikey": {
"npm": "@ai-sdk/openai-compatible",
"name": "ShopAIKey",
"options": {
"baseURL": "https://api.shopaikey.com/v1"
},
"models": {
"gpt-5.2": {
"name": "GPT-5.2"
},
"gpt-5.3-codex": {
"name": "GPT-5.3 Codex"
},
"claude-sonnet-4-5": {
"name": "Claude Sonnet 4.5"
},
"claude-opus-4-5": {
"name": "Claude Opus 4.5"
}
}
}
}
}
4. Chọn model
Mở OpenCode:
opencode
Trong giao diện OpenCode, chạy:
/models
Chọn provider ShopAIKey và model bạn muốn dùng.
5. Cấu hình API key trực tiếp trong file
Nếu không muốn dùng opencode auth login, bạn có thể đặt key qua biến môi trường.
macOS / Linux
export SHOPAIKEY_API_KEY="sk-your-api-key"
Windows PowerShell
$env:SHOPAIKEY_API_KEY = "sk-your-api-key"
Sau đó sửa opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"shopaikey": {
"npm": "@ai-sdk/openai-compatible",
"name": "ShopAIKey",
"options": {
"baseURL": "https://api.shopaikey.com/v1",
"apiKey": "{env:SHOPAIKEY_API_KEY}"
},
"models": {
"gpt-5.2": {
"name": "GPT-5.2"
}
}
}
}
}
6. Lưu ý
- Dùng
@ai-sdk/openai-compatiblecho endpointhttps://api.shopaikey.com/v1. - Nếu đổi
opencode.json, hãy khởi động lại OpenCode để chắc chắn cấu hình mới được nạp. - Model id phải đúng với model ShopAIKey đang hỗ trợ.
- Nếu gặp lỗi
Invalid API Key, kiểm tra key còn credit và chưa bị thu hồi. - Nếu gặp lỗi
Model Not Found, thử đổi sang model khác trong trang Models.
7. Kiểm tra nhanh
Trong thư mục dự án, chạy:
opencode
Gửi thử yêu cầu:
Giải thích cấu trúc dự án này và đề xuất điểm cần cải thiện.
Nếu phản hồi trả về bình thường, cấu hình đã hoạt động.