JSPM

@asframe/opencode-iflow-auth

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 28
  • Score
    100M100P100Q59602F
  • License MIT

OpenCode plugin for iFlow.cn - Access Qwen, DeepSeek, Kimi, GLM-5 models with OAuth 2.0, API Key, and CLI Proxy support

Package Exports

  • @asframe/opencode-iflow-auth
  • @asframe/opencode-iflow-auth/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@asframe/opencode-iflow-auth) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

OpenCode iFlow Auth Plugin

npm version npm downloads license GitHub

OpenCode plugin for iFlow.cn providing access to Qwen, DeepSeek, Kimi, GLM, and iFlow ROME models with dual authentication and CLI Proxy support.

Features

  • Dual authentication: OAuth 2.0 (PKCE) and API Key support.
  • CLI Proxy mode: Support GLM-5 through iflow CLI with automatic proxy server.
  • Multi-account rotation: Sticky and round-robin strategies.
  • Automated token refresh: Rate limit handling with exponential backoff.
  • Native thinking mode: Support for GLM-4.x, GLM-5 and DeepSeek R1 models.
  • Configurable timeout: Request timeout and iteration limits to prevent hangs.
  • Automatic port selection: OAuth callback server port conflict avoidance.

Two Plugin Modes

This package exports two plugins:

1. IFlowPlugin - Direct API Mode

Direct API calls to iFlow.cn for standard models.

Property Value
Provider iflow
baseURL https://apis.iflow.cn/v1
Models deepseek-v3.2, glm-4.6, kimi-k2.5, qwen3-coder-plus, etc.

2. IFlowProxyPlugin - CLI Proxy Mode

Routes requests through iflow CLI for GLM-5 support. The proxy server starts automatically when OpenCode loads the plugin.

Property Value
Provider iflow-proxy
Proxy Port 127.0.0.1:19998
Models glm-5, glm-5-free, glm-5-thinking

How it works:

  1. Plugin detects if model requires CLI (glm-5, glm-5-free, glm-5-thinking)
  2. Starts a local proxy server on port 19998
  3. Routes CLI-required models through iflow CLI via stdin
  4. Routes other models directly to iFlow API

Installation

Add the plugin to your opencode.json or opencode.jsonc:

{
  "plugin": ["@asframe/opencode-iflow-auth"],
  "provider": {
    "iflow": {
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "https://apis.iflow.cn/v1"
      },
      "models": {
        "deepseek-v3.2": {
          "name": "DeepSeek V3.2",
          "limit": { "context": 128000, "output": 64000 },
          "modalities": { "input": ["text"], "output": ["text"] }
        },
        "glm-4.6": {
          "name": "GLM-4.6",
          "limit": { "context": 128000, "output": 64000 },
          "modalities": { "input": ["text"], "output": ["text"] }
        },
        "kimi-k2.5": {
          "name": "Kimi K2.5",
          "limit": { "context": 256000, "output": 64000 },
          "modalities": { "input": ["text"], "output": ["text"] }
        },
        "qwen3-coder-plus": {
          "name": "Qwen3 Coder Plus",
          "limit": { "context": 1000000, "output": 64000 },
          "modalities": { "input": ["text"], "output": ["text"] }
        }
      }
    },
    "iflow-proxy": {
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "http://127.0.0.1:19998/v1"
      },
      "models": {
        "glm-5": {
          "name": "GLM-5 (via CLI Proxy)",
          "limit": { "context": 202000, "output": 64000 },
          "modalities": { "input": ["text"], "output": ["text"] }
        },
        "glm-5-free": {
          "name": "GLM-5 Free (via CLI Proxy)",
          "limit": { "context": 202000, "output": 64000 },
          "modalities": { "input": ["text"], "output": ["text"] }
        },
        "glm-5-thinking": {
          "name": "GLM-5 Thinking (via CLI Proxy)",
          "limit": { "context": 202000, "output": 64000 },
          "modalities": { "input": ["text"], "output": ["text"] }
        }
      }
    }
  }
}

Setup

Direct API Mode

  1. Run opencode auth login.
  2. Select Other, type iflow, and press enter.
  3. Choose authentication method:
    • OAuth 2.0: Follow browser flow for secure token-based authentication.
    • API Key: Enter your iFlow API key (starts with sk-).

CLI Proxy Mode (for GLM-5)

  1. Install iflow CLI: npm install -g iflow-cli
  2. Login to iflow CLI: iflow login
  3. The proxy server will start automatically when using iflow-proxy provider.

Auto-install CLI:

If iflow CLI is not installed, the plugin can automatically install it for you. Enable this feature by setting the environment variable:

# PowerShell
$env:IFLOW_AUTO_INSTALL_CLI = "true"

# Bash
export IFLOW_AUTO_INSTALL_CLI=true

Requirements for CLI Proxy:

  • Node.js 18+
  • iflow CLI installed and logged in (or set IFLOW_AUTO_INSTALL_CLI=true to auto-install)
  • Port 19998 available (or will use existing proxy if already running)

Usage

# Direct API mode
opencode run "你好" --model iflow/deepseek-v3.2
opencode run "你好" --model iflow/glm-4.6
opencode run "你好" --model iflow/kimi-k2.5

# CLI Proxy mode (GLM-5)
opencode run "你好" --model iflow-proxy/glm-5
opencode run "你好" --model iflow-proxy/glm-5-thinking

Configuration

Edit ~/.config/opencode/iflow.json:

{
  "default_auth_method": "oauth",
  "account_selection_strategy": "round-robin",
  "auth_server_port_start": 8087,
  "auth_server_port_range": 10,
  "max_request_iterations": 50,
  "request_timeout_ms": 300000,
  "enable_log_api_request": false
}

Configuration Options

  • default_auth_method: Default authentication method (oauth, apikey)
  • account_selection_strategy: Account rotation strategy (sticky, round-robin)
  • auth_server_port_start: Starting port for OAuth callback server (1024-65535)
  • auth_server_port_range: Number of ports to try (1-100)
  • max_request_iterations: Maximum loop iterations to prevent hangs (10-1000)
  • request_timeout_ms: Request timeout in milliseconds (60000-600000ms)
  • enable_log_api_request: Enable API request/response logging (errors always logged)

Environment Variables

  • IFLOW_AUTH_DEBUG: Enable debug logging for auth plugin (true/false)
  • IFLOW_PROXY_DEBUG: Enable debug logging for proxy plugin (true/false)
  • IFLOW_AUTO_INSTALL_CLI: Auto-install iflow CLI if not installed (true/false)
  • IFLOW_DEFAULT_AUTH_METHOD
  • IFLOW_ACCOUNT_SELECTION_STRATEGY
  • IFLOW_AUTH_SERVER_PORT_START
  • IFLOW_AUTH_SERVER_PORT_RANGE
  • IFLOW_MAX_REQUEST_ITERATIONS
  • IFLOW_REQUEST_TIMEOUT_MS
  • IFLOW_ENABLE_LOG_API_REQUEST

Storage

Linux/macOS:

  • Credentials: ~/.config/opencode/iflow-accounts.json
  • Plugin Config: ~/.config/opencode/iflow.json

Windows:

  • Credentials: %APPDATA%\opencode\iflow-accounts.json
  • Plugin Config: %APPDATA%\opencode\iflow.json

Thinking Models

iFlow supports thinking models with customizable thinking budgets via variants:

GLM-4.6, GLM-5 & DeepSeek R1

{
  "variants": {
    "low": { "thinkingConfig": { "thinkingBudget": 1024 } },
    "medium": { "thinkingConfig": { "thinkingBudget": 8192 } },
    "max": { "thinkingConfig": { "thinkingBudget": 32768 } }
  }
}

Troubleshooting

CLI Proxy Issues

If you encounter issues with the CLI proxy:

  1. Check if iflow CLI is installed:

    iflow --version
  2. Check if you're logged in:

    iflow login
  3. Test iflow CLI directly:

    echo "你好" | iflow -m glm-5
  4. Enable debug logging:

    $env:IFLOW_PROXY_DEBUG = "true"
    opencode run "你好" --model iflow-proxy/glm-5

Port Already in Use

If port 19998 is already in use, the plugin will detect it and use the existing proxy. If you need to restart the proxy:

# Kill existing process on port 19998
# Windows
Get-Process -Id (Get-NetTCPConnection -LocalPort 19998).OwningProcess | Stop-Process -Force

# Linux/macOS
lsof -i :19998 | grep LISTEN | awk '{print $2}' | xargs kill -9

License

MIT License - see LICENSE for details.

Disclaimer

This plugin is provided strictly for learning and educational purposes. It is an independent implementation and is not affiliated with, endorsed by, or supported by iFlow.cn. Use of this plugin is at your own risk.

Feel free to open a PR to optimize this plugin further.