Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>AI Usage ExtensionNew to Visual Studio Code? Get it now.
AI Usage Extension

AI Usage Extension

zls3434

|
37 installs
| (0) | Free
Monitor cloud AI platform API usage in status bar. Supports Ollama, DeepSeek and BigModel.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

English | 中文

🦙 AI Usage Extension

Monitor cloud AI platform API usage in your VSCode/Trae CN status bar. Supports Ollama, DeepSeek and BigModel (Zhipu), with one active provider displayed at a time.

✨ Features

  • Multi-Provider — Ollama (official /api/usage), DeepSeek (/user/balance) and BigModel (account balance + GLM Coding Plan quota); enable the ones you use, "add one, show one"
  • Single Active Provider — the status bar shows one provider's group at a time; switch via the menu, or let Trae auto-switch follow the model selected in the AI chat (Trae IDE only)
  • Quota & Balance Windows — quota windows (Session 5h / Weekly / Monthly, rendered dynamically per account) plus balance display with precise amounts (¥9.99)
  • Color-coded Alerts — quota windows: Session (<50% normal, 50-80% yellow, ≥80% red), Weekly (75/90), Monthly (80/95); balances: ≤0 red, <¥10 (or <$2) yellow
  • Hover Tooltip — usage windows, reset countdown, per-model breakdown (Top 3), balance breakdown (granted / topped-up)
  • QuickPick Menu — left-click the status bar item for all actions: switch/add/remove provider, keys, refresh, settings
  • Auto & Manual Refresh — configurable intervals (5–60 min), all enabled providers refreshed in parallel (switching is instant)
  • Secure Storage — API keys encrypted via VSCode SecretStorage, namespaced per provider
  • Rate-limit Aware — 5-minute minimum polling + cached-data fallback on HTTP 429

📸 Preview

Status Bar Display

One active provider is displayed at a time (1 label item + N dynamic items):

$(cloud) Ollama    S: 45%    W: 30%        ← quota provider
$(whale) DeepSeek  ¥9.99                     ← balance provider
$(zap) BigModel    S: 12%  W: 5%  ¥2.73     ← Coding Plan + balance
$(cloud) AI Usage: Add Provider              ← no provider enabled yet
  • $(icon) Name — label item (shows full tooltip on hover)
  • S: xx% / W: yy% / M: zz% — quota windows, rendered dynamically based on your account (legacy subscriptions show S/W, credit-based plans show M)
  • ¥9.99 — account balance with fixed-threshold alerts

Switch providers via the QuickPick menu (Switch Provider) — all enabled providers are refreshed in parallel, so switching is instant.

Color-coded Alerts

Usage Level Session Weekly Monthly Balance (CNY / USD) Status Bar Background
Normal < 50% < 75% < 80% ≥ ¥10 / ≥ $2 Default (no highlight)
Warning 50% ~ 79% 75% ~ 89% 80% ~ 94% < ¥10 / < $2 Yellow (statusBarItem.warningBackground)
Critical ≥ 80% ≥ 90% ≥ 95% ≤ 0 Red (statusBarItem.errorBackground)

Hover Tooltip

Hover over the label item to see detailed Markdown-formatted info (incl. the auto: note when the provider was auto-switched by Trae's chat model):

☁ Ollama Usage
auto: glm-5.3
──────────────────────
Session (5h): 45% used
  ↻ Reset in: 2h 30m
...
Balance: ¥2.73
  • Granted: ¥0.00   • Topped up: ¥0.00
──────────────────────
Last updated: 14:30:00

🚀 Getting Started

Prerequisites

  • VSCode ≥ 1.85.0 or Trae CN (compatible IDE)
  • An account on at least one supported platform:
    • Ollama — ollama.com
    • DeepSeek — platform.deepseek.com
    • BigModel (Zhipu) — open.bigmodel.cn

Installation

Option 1: Install from VSIX

  1. Download or build the .vsix file
  2. Open VSCode/Trae CN
  3. Go to Extensions → ··· → Install from VSIX...
  4. Select the .vsix file

Option 2: Build from Source

# Clone the repository
git clone <repository-url>
cd ai-usage-ext

# Install dependencies
npm install

# Compile
npm run compile

# Package as VSIX
npx vsce package --allow-missing-repository

Or use the one-click build script:

chmod +x build.sh
./build.sh

The build script will:

  1. Install dependencies
  2. Run TypeScript type checking
  3. Compile with esbuild
  4. Package into a .vsix file

First-Time Setup

  1. After installation, the extension activates automatically on startup
  2. The status bar shows $(cloud) AI Usage: Add Provider — click it (or run AI Usage: Add Provider)
  3. Pick a platform (Ollama / DeepSeek / BigModel) — it becomes the active provider
  4. When prompted, choose "Open Keys Page" to create an API key on the platform, or "Enter Key Directly"
  5. Paste the key into the password input — usage data appears in the status bar within seconds
  6. Repeat Add Provider to enable more platforms; switch between them via Switch Provider (or let Trae auto-switch — see Configuration)

Upgrading from v0.1.x: if an old Ollama cookie is detected, you'll be prompted to migrate to an API key; it is cleared automatically once the key is set.

📖 Commands

Command Description
AI Usage: Show Menu Open the QuickPick menu with all actions
AI Usage: Switch Provider Switch the active provider shown in the status bar
AI Usage: Add Provider Enable another platform (add one, show one)
AI Usage: Remove Provider Hide a provider from the status bar (API key is kept)
AI Usage: Set API Key Set / replace a provider's API key
AI Usage: Clear Stored API Key Remove a stored API key
AI Usage: Toggle Auto Update Enable/disable automatic refresh
AI Usage: Set Update Interval Choose refresh frequency (5/10/15/30/60 min)
AI Usage: Refresh Now Refresh all enabled providers (throttled within 60s)
AI Usage: Open API Keys Page Open the provider's key management page

⚙️ Configuration

Setting Type Default Description
aiUsage.providers string[] [] Enabled providers (ollama / deepseek / bigmodel). Providers with a stored API key are always enabled
aiUsage.autoSwitchProvider boolean true Auto-switch the active provider based on the model selected in Trae's AI chat (Trae IDE only)
aiUsage.autoUpdate boolean true Enable automatic usage refresh
aiUsage.updateInterval number 300 Auto-update interval in seconds (300–3600; min 5 minutes due to API rate limits)

🏗️ Architecture

Project Structure

ai-usage-ext/
├── src/
│   ├── extension.ts                # Extension entry point (activate/deactivate)
│   ├── controllers/
│   │   └── extensionController.ts  # Core controller — provider set, active provider, commands, timers
│   ├── core/                       # Platform-agnostic core
│   │   ├── usageTypes.ts           # Usage models (quota/balance windows, thresholds, formatters)
│   │   ├── provider.ts             # UsageProvider interface + ProviderRegistry
│   │   └── traeModelParsing.ts     # Trae state.vscdb model extraction + provider mapping (pure)
│   ├── providers/
│   │   ├── ollama/                 # Ollama — official /api/usage (quota windows)
│   │   ├── deepseek/               # DeepSeek — /user/balance (balance window)
│   │   └── bigmodel/               # BigModel — account balance + GLM Coding Plan quota
│   ├── managers/
│   │   ├── credentialManager.ts    # Encrypted per-provider API key storage (SecretStorage)
│   │   ├── configManager.ts        # VSCode settings management & change listeners
│   │   ├── statusBarManager.ts     # Status bar UI — active provider, quota/balance items, tooltips
│   │   └── traeModelMonitor.ts     # Trae chat-model polling → auto provider switching
│   ├── test/                       # Unit tests (mocha, 67 cases)
│   └── utils/
│       └── httpClient.ts           # HTTP client wrapper (bearer/raw auth, 429 detection)
├── package.json                    # Extension metadata, commands, configurations
├── tsconfig.json                   # TypeScript configuration
├── build.sh                        # One-click build & package script
├── docs/                           # Design docs (refactor plan, phase 3 design)
├── .vscodeignore                   # VSIX packaging exclusions
└── LICENSE                         # MIT License

Module Responsibilities

Module Responsibility
ExtensionController Central coordinator — computes the enabled provider set (config ∪ stored keys), manages the active provider, registers commands, drives refresh with throttling
UsageProvider / ProviderRegistry Unified provider interface (isConfigured / fetchUsage / iconId) and registry
OllamaProvider Official GET /api/usage (Bearer) → dynamic quota windows; cached-data fallback
DeepSeekProvider GET /user/balance (Bearer) → balance window (multi-currency, prefers CNY; is_available=false → top-up note)
BigModelProvider Balance (query-customer-account-report, Bearer) + GLM Coding Plan quota (quota/limit, raw key) in parallel; quota failures tolerated
CredentialManager Encrypted API key storage via SecretStorage, namespaced per provider
TraeModelMonitor Watches Trae's state.vscdb via kernel-level fs.watch (shared read, ~sub-second reaction, zero idle load) with a 10s fallback poll; maps the chat-selected model to a provider and triggers auto-switching (Trae only)
StatusBarManager Renders the active provider's group (label + quota/balance items) with independent color alerts and a Markdown tooltip
HttpClient Axios-based HTTP client with bearer/raw auth, timeout, 401/403/429 classification
usageTypes Platform-agnostic types, WINDOW_META, balance thresholds and formatters

Data Flow

┌────────────────────────────────────────────┐
│ TraeModelMonitor (fs.watch on state.vscdb) │
│ chat model → provider auto-switch          │
└──────────────────┬─────────────────────────┘
                   ▼
┌──────────────────────────────┐
│   ExtensionController        │
│  enabled = config ∪ keys     │
│  active provider (persisted) │
└──────┬───────────┬───────────┘
       │           │
       ▼           ▼
┌──────────────────────┐ ┌──────────────┐
│ ProviderRegistry      │ │ Config        │
│  ├ Ollama  (quota)    │ │ Manager      │
│  ├ DeepSeek (balance) │ │ timer prefs  │
│  └ BigModel (both)    │ └──────────────┘
└──────┬────────────────┘
       │ results cached per provider (parallel refresh)
       ▼
┌──────────────────────────────────┐
│ Status Bar (active provider only)│
│ ┌──────────┬───────┬──────┬───┐  │
│ │ $(icon)  │ S:xx% │ W:yy%│¥..│  │
│ │ (tooltip)│(color)│(color)│   │  │
│ └──────────┴───────┴──────┴───┘  │
└──────────────────────────────────┘

🔧 Development

Build & Watch

# Install dependencies
npm install

# Development (watch mode)
npm run watch

# Production build
npm run compile

# Lint
npm run lint

# Type check
npx tsc --noEmit

# Unit tests
npm test

# One-click build & package
./build.sh

Tech Stack

  • Language: TypeScript 5.3+
  • Runtime: VSCode Extension API ≥ 1.85.0
  • Bundler: esbuild
  • HTTP Client: axios
  • Testing: mocha + ts-node
  • Packaging: @vscode/vsce

Adding a New Provider

To support additional AI platforms:

  1. Create src/providers/<platform>/ implementing the UsageProvider interface (src/core/provider.ts):
    • id / displayName / iconId (codicon) / credentialsUrl
    • isConfigured(): check the platform's API key via CredentialManager
    • fetchUsage(): call the platform's API and normalize to ProviderUsage (quota windows kind:'percent' and/or a balance window kind:'balance')
    • Error normalization: auth failures → NoCredentials, 429 → RateLimited, others → Error
  2. Register it via registry.register(...) in extensionController.ts
  3. Add the platform id to the aiUsage.providers enum in package.json (and to mapModelToProvider in core/traeModelParsing.ts if it should support Trae auto-switching)

A survey of usage APIs for more platforms (OpenRouter, SiliconFlow, Kimi, OpenAI, Anthropic...) is available in docs/refactor-plan.md Appendix B.

🔒 Security

  • API key storage: keys are encrypted via VSCode's SecretStorage — never written to logs, settings files, or sent externally
  • HTTPS only: all requests use HTTPS to platform APIs
  • No redirects: HTTP client disables automatic redirects to prevent credential header leakage
  • Timeout protection: requests time out after 15 seconds
  • Rate-limit protection: 5-minute minimum auto-polling; manual refresh throttled to once per 60s; cached-data fallback on 429
  • Read-only Trae state: the auto-switch feature only reads state.vscdb locally (shared read) — nothing is sent anywhere
  • Clear credentials: dedicated commands allow users to remove stored API keys at any time

⚠️ Limitations

  • The status bar displays one active provider at a time (by design) — switching is instant since all enabled providers are refreshed in parallel
  • Ollama's /api/usage and BigModel's two endpoints are not officially documented; all parsing is fault-tolerant (a broken window never affects others)
  • Trae auto-switching relies on internal state.vscdb keys that may drift between Trae versions — it degrades silently to manual switching when reading fails
  • Ollama quota reset times are inferred from global fixed boundaries (5-hour epoch grid / Monday 00:00 UTC) when resets_at is absent — affects only the tooltip countdown
  • BigModel quota windows are only available for GLM Coding Plan subscribers; pay-as-you-go accounts show balance only

🤖 AI Development Statement

This project is entirely developed using AI Coding. I deeply respect the open-source spirit and community. If this project involves any copyright or licensing concerns, please contact me promptly so I can modify or remove the offending content. I sincerely apologize in advance for any unintentional offense.

📄 License

This project is licensed under the MIT License © 2026 zls3434.

The LICENSE file also includes third-party license acknowledgments for all bundled and development dependencies (BSD-2-Clause, ISC, MIT, Apache-2.0).

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft