Intelligent quota monitoring and automatic model switching for OpenCode with Antigravity.
Zero OpenCode source modifications required - works as a pure plugin!
- 🔍 Real-time Quota Monitoring - Check quota via LLM tools
- 🔄 Automatic Model Switching - Switch models when quota exhausted
- 🎯 Proactive Optimization - Switch before hitting hard limits
- 🔁 Account Rotation - Automatically rotate between accounts
- 🛠️ Plugin-Based - No OpenCode source modifications needed
- 🤖 LLM-Aware - Assistant can check quota and make decisions
Simply copy and paste this prompt to your OpenCode assistant:
Please read the documentation at https://github.com/Gooseware/opencode-antigravity-autopilot#readme to understand the installation steps. Install the
opencode-antigravity-autopilotplugin from npm. Then, configure~/.config/opencode/opencode.jsonto add"opencode-antigravity-autopilot"to thepluginlist. Finally, create a default quota config in~/.config/opencode/quota.jsonwith auto-rotation enabled for models likeantigravity-gemini-3-pro-highandantigravity-claude-sonnet-4-5.
npm install opencode-antigravity-autopilotgit clone https://github.com/Gooseware/opencode-antigravity-autopilot.git
cd opencode-antigravity-autopilot
npm install
npm run build
npm link- Node.js >= 20.0.0
- opencode-antigravity-auth installed and configured
- OpenCode with plugin support
Add to ~/.config/opencode/opencode.json:
{
"plugin": [
"opencode-antigravity-auth",
"opencode-antigravity-autopilot"
]
}Create ~/.config/opencode/quota.json to configure thresholds and models:
{
"quotaThreshold": 0.05,
"preferredModels": [
"antigravity-gemini-3-pro-high", // Try this first
"antigravity-claude-sonnet-4-5", // Then this
"antigravity-gemini-3-flash" // Fallback
],
"autoRotate": true
}That's it! The plugin is now active.
Simply ask your assistant:
"Check my quota status"
"Show detailed quota for all models"
"Can I use antigravity-gemini-3-pro-high right now?"
The LLM will call the appropriate tools and show results like:
# Quota Status
✓ **Current Model:** antigravity-gemini-3-pro-high
**Status:** Quota healthy at 67%
**Accounts:** 1 of 3 active
The plugin exposes three tools to the LLM:
Check current quota with optional detailed view
quota_status()
quota_status({ detailed: true })Check if a specific model has enough quota
quota_check_model({ model: "antigravity-gemini-3-pro-high" })Manually rotate to next available account
quota_rotate_account()import { HardLimitDetector } from 'opencode-antigravity-autopilot';
const detector = new HardLimitDetector({
quotaThreshold: 0.2, // Switch when below 20%
preferredModels: [
'google/antigravity-gemini-3-pro-high',
'google/antigravity-claude-sonnet-4-5'
]
});
// Before using a model
const result = await detector.checkHardLimit('antigravity-gemini-3-pro-high');
if (result.shouldRotate) {
console.log(`Switching to: ${result.nextModel}`);
}┌─────────────────────────────────┐
│ OpenCode (No modifications) │
│ │
│ LLM Tools: │
│ - quota_status │
│ - quota_check_model │
│ - quota_rotate_account │
└────────────┬────────────────────┘
│
▼
┌─────────────────────────────────┐
│ Autopilot Plugin │
│ │
│ ┌──────────────────────┐ │
│ │ ApiQuotaPoller │ │
│ │ Real-time API data │ │
│ └──────────────────────┘ │
│ │
│ ┌──────────────────────┐ │
│ │ HardLimitDetector │ │
│ │ Auto model switch │ │
│ └──────────────────────┘ │
└─────────────────────────────────┘
Configure when to proactively switch models:
import { QuotaManager } from 'opencode-antigravity-autopilot';
const manager = new QuotaManager({
quotaThreshold: 0.2 // Switch when below 20%
});Set model preference order:
import { HardLimitDetector } from 'opencode-antigravity-autopilot';
const detector = new HardLimitDetector({
preferredModels: [
'google/antigravity-gemini-3-pro-high', // Try first
'google/antigravity-claude-sonnet-4-5', // Try second
'google/antigravity-gemini-3-flash' // Fallback
]
});# Test hard limit detection
npm run test:quota
# Run full test suite
npm testclass HardLimitDetector {
constructor(config?: PluginConfig);
checkHardLimit(currentModel: string): Promise<HardLimitCheckResult>;
updateAllQuotas(): Promise<void>;
rotateAccount(): Promise<void>;
}
interface HardLimitCheckResult {
isExhausted: boolean;
shouldRotate: boolean;
nextModel?: string;
message?: string;
}class QuotaManager {
constructor(config?: PluginConfig);
initialize(): Promise<void>;
getQuotaViaApi(modelName?: string): Promise<QuotaInfo | null>;
getAllQuotasViaApi(): Promise<Map<string, QuotaInfo>>;
rotateAccount(): Promise<void>;
}class QuotaCacheUpdater {
constructor(manager: QuotaManager, updateIntervalMs?: number);
updateCache(): Promise<void>;
start(): void;
stop(): void;
}
function startQuotaCacheService(updateIntervalMs?: number): Promise<QuotaCacheUpdater>;Run a background service to keep quota cache updated:
npm run service:startOr programmatically:
import { startQuotaCacheService } from 'opencode-antigravity-autopilot';
const updater = await startQuotaCacheService(60000); // Update every 60s
updater.start();
// Later...
updater.stop();import {
createOhMyOpenCodeIntegration,
QuotaManager
} from 'opencode-antigravity-autopilot';
const manager = new QuotaManager();
await manager.initialize();
const integration = createOhMyOpenCodeIntegration(manager, {
defaultModel: 'google/antigravity-gemini-3-flash'
});
const model = await integration.getModelForAgent('oracle');
console.log(`Oracle will use: ${model}`);# Verify plugin is installed
npm list opencode-antigravity-autopilot
# Check OpenCode config
cat ~/.config/opencode/opencode.json# Verify authentication
cat ~/.config/opencode/antigravity-accounts.json
# Test manually
node -e "const {QuotaManager} = require('opencode-antigravity-autopilot'); const m = new QuotaManager(); m.initialize().then(() => m.getQuotaViaApi().then(console.log));"# Test hard limit detector
npm run test:quotaSee CHANGELOG.md for release history.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT © gooseware
Built on top of:
- opencode-antigravity-auth - Authentication for Antigravity
- opencode-antigravity-quota - Standalone quota checker
- oh-my-opencode - Enhanced OpenCode experience
Made with ❤️ for the OpenCode community