https://github.com/cfryerdev/opencode-plugin-credit-switcher
A plugin that switches your Github Copilot subscription to hosted AI Foundry models when you run out of credits
https://github.com/cfryerdev/opencode-plugin-credit-switcher
ai-foundry github-copilot opencode opencode-plugin
Last synced: 3 days ago
JSON representation
A plugin that switches your Github Copilot subscription to hosted AI Foundry models when you run out of credits
- Host: GitHub
- URL: https://github.com/cfryerdev/opencode-plugin-credit-switcher
- Owner: cfryerdev
- Created: 2026-01-31T02:07:56.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2026-01-31T02:24:54.000Z (5 months ago)
- Last Synced: 2026-01-31T17:38:53.239Z (5 months ago)
- Topics: ai-foundry, github-copilot, opencode, opencode-plugin
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# OpenCode Credit Switcher Plugin
This plugin retries a session with a fallback model when the primary provider reports a credit exhaustion error, and switches back after a daily credit check.
## Files
- `.opencode/plugins/credit-switcher.js` - Plugin implementation.
- `.opencode/credit-switcher.json` - Plugin configuration.
- `.opencode/credit-switcher.state.json` - Plugin state (last exhausted time and original model).
## Install
### From npm
Add the plugin to your OpenCode config:
```jsonc
// opencode.jsonc
{
"plugin": ["opencode-credit-switcher@latest"]
}
```
### From local files
Copy `.opencode/plugins/credit-switcher.js` into one of:
- `.opencode/plugins/` (project)
- `~/.config/opencode/plugins/` (global)
## Configure
1. Update `.opencode/credit-switcher.json` with your primary and fallback models.
2. Ensure your providers are configured in `opencode.json` and credentials are stored via `/connect`.
Example `opencode.json` for a self-hosted OpenAI-compatible endpoint:
```json
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"llama.cpp": {
"npm": "@ai-sdk/openai-compatible",
"name": "llama-server (local)",
"options": {
"baseURL": "http://127.0.0.1:8080/v1"
},
"models": {
"qwen3-coder:a3b": {
"name": "Qwen3-Coder a3b"
}
}
}
}
}
```
## How it works
- Listens for `session.error` events.
- Detects credit exhaustion via status codes, error codes, or message text.
- Replays the last user message using `fallbackModel`.
- If `confirmOnFallback` is enabled and the confirm dialog is available, asks before retrying.
- Once per day, attempts to switch sessions back to the original model after credits likely reset.
## Notes
- The plugin only retries once per session to avoid loops.
- Fallback requires your providers to exist in OpenCode config.
- Customize matching via `.opencode/credit-switcher.json`.