### Project Setup and Installation Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/CONTRIBUTING.md Clone the repository, install dependencies, and set up environment variables. ```bash git clone https://github.com/aptdnfapt/qwen-code-oai-proxy cd qwen-code-oai-proxy npm install cp .env.example .env ``` -------------------------------- ### Local Development Setup for qwen-proxy Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/README.md Installs dependencies, adds a default account, and starts the qwen-proxy server locally. Supports both TUI and headless modes. ```bash npm install npm run auth:add myaccount qwen-proxy serve ``` ```bash # or headless: npm run serve:headless ``` -------------------------------- ### Install qwen-proxy Globally via npm Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/README.md Recommended installation method for global access. After installation, run `qwen-proxy` to start the TUI. ```bash npm install -g qwen-proxy ``` ```bash qwen-proxy # and then add some accounts from the tui . full mouse Supported ``` -------------------------------- ### Docker Compose Setup for qwen-proxy Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/README.md Clones the repository, copies the environment example, and starts the qwen-proxy service in detached mode using Docker Compose. ```bash git clone https://github.com/aptdnfapt/qwen-code-oai-proxy cd qwen-code-oai-proxy cp .env.example .env docker compose up -d ``` -------------------------------- ### Start the Proxy Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/default-account.md Start the Qwen OpenAI Proxy using `npm start`. The proxy will indicate the configured default account on startup. ```bash npm start ``` -------------------------------- ### API Key Authentication Examples Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/README.md Examples of how to set API keys for authentication, either a single key or multiple comma-separated keys. Supported headers include 'Authorization: Bearer' and 'X-API-Key'. ```bash # Single key API_KEY=your-secret-key # Multiple keys API_KEY=key1,key2,key3 ``` -------------------------------- ### Write File Example Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/sys-prompt.txt Use the `write_file` tool to create or overwrite a file with specified content. Provide the `path` for the file. ```shell /path/to/someFile.test.ts ``` -------------------------------- ### Live Screen Layout Example Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/spec/rewrite/tui-and-rezi.md Illustrates the suggested layout for the 'Live' screen, showing status information, control buttons, and a live log stream. ```text ┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ Live │ │ host 127.0.0.1:38471 uptime 00:21:44 rotation RR accounts 10 req 2 streams 1 │ ├──────────────────────────────────────────────────────────────────────────────────────────────┤ │ [ Start ] [ Stop ] [ Restart ] log: [ off ] [ error ] [ err-debug ] [ debug ] │ ├──────────────────────────────────────────────────────────────────────────────────────────────┤ │ live stream │ │ 10:36:08 server started │ │ 10:36:10 POST /v1/chat/completions 200 4809+1 tok │ │ 10:36:11 cache create 4805 │ │ 10:36:18 cache hit 4805 │ │ 10:36:20 req-a4783f17 created │ │ │ └──────────────────────────────────────────────────────────────────────────────────────────────┘ ``` -------------------------------- ### Web Search with Specific Account Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/web-search-api.md This example demonstrates how to perform a web search using a specific account by providing the `X-Qwen-Account` header. ```APIDOC ## POST /v1/web/search with X-Qwen-Account Header ### Description Performs a web search associated with a specific account. ### Method POST ### Endpoint /v1/web/search ### Headers - **X-Qwen-Account** (string) - Required - The account identifier. ### Parameters #### Request Body - **query** (string) - Required - The search query. ### Request Example ```json { "query": "climate change news" } ``` ### Request Example (cURL) ```bash curl -X POST http://localhost:8080/v1/web/search \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "X-Qwen-Account: my-account" \ -d '{"query": "climate change news"}' ``` ``` -------------------------------- ### qwen-proxy CLI Commands Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/README.md Common command-line interface commands for managing the qwen-proxy server, including starting, authentication, and usage monitoring. ```bash qwen-proxy serve # TUI dashboard ``` ```bash qwen-proxy serve --headless # headless server ``` ```bash qwen-proxy auth list ``` ```bash qwen-proxy auth add ``` ```bash qwen-proxy auth remove ``` ```bash qwen-proxy auth counts ``` ```bash qwen-proxy usage ``` -------------------------------- ### Read File Example Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/sys-prompt.txt Use the `read_file` tool to read the content of a file. You can specify an `offset` and `limit` to read only a portion of the file. ```shell /path/to/tests/test_auth.py ``` ```shell /path/to/requirements.txt ``` ```shell /path/to/someFile.ts ``` ```shell /path/to/existingTest.test.ts ``` -------------------------------- ### Example Token Usage Report Output Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/token-usage-tracking.md This is an example of the terminal output for the token usage report, showing daily and total input, output, and total tokens. ```text 📊 Qwen Token Usage Report ═══════════════════════════════════════════════════════════════════════════════ ┌────────────┬───────────────┬────────────────┬───────────────┐ │ Date │ Input Tokens │ Output Tokens │ Total Tokens │ ├────────────┼───────────────┼────────────────┼───────────────┤ │ 2025-08-20 │ 12,500 │ 8,300 │ 20,800 │ │ 2025-08-21 │ 15,200 │ 9,100 │ 24,300 │ │ 2025-08-22 │ 8,750 │ 5,400 │ 14,150 │ ├────────────┼───────────────┼────────────────┼───────────────┤ │ TOTAL │ 36,450 │ 22,800 │ 59,250 │ └────────────┴───────────────┴────────────────┴───────────────┘ Total Requests: 127 ``` -------------------------------- ### Run Shell Command Example Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/sys-prompt.txt Use this tool to execute shell commands. The `is_background` parameter can be set to `true` to run the command in the background. ```shell node server.js & ``` -------------------------------- ### Commit Message Examples Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/CONTRIBUTING.md Illustrative examples of commit messages following the specified format. ```text feat: add multi-account rotation with round-robin scheduling fix: handle token refresh edge case on 401 response docs: add web search API usage guide ``` -------------------------------- ### Integrate Web Search with Chat Completions Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/web-search-api.md This example demonstrates how to use the web search API to fetch current information and then incorporate it into a chat completion request. ```javascript // 1. Search for current information const searchResults = await fetch('/v1/web/search', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ query: 'latest bitcoin price' }) }); // 2. Use results in chat completion const chatResponse = await fetch('/v1/chat/completions', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ model: 'qwen3-coder-plus', messages: [ { role: 'user', content: `Based on this current data: ${JSON.stringify(searchResults.data.docs)}, what's your analysis of bitcoin's current position?` } ] }) }); ``` -------------------------------- ### Web Search API Example Request (cURL) Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/web-search-api.md Demonstrates how to make a POST request to the web search API using cURL. Ensure to replace YOUR_API_KEY with your actual key. ```bash curl -X POST http://localhost:8080/v1/web/search \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ -d '{ "query": "latest AI developments", "page": 1, "rows": 5 }' ``` -------------------------------- ### Run Packaged Install Smoke Test Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/testing-clean-home.md Execute the smoke test for the packaged installation. This verifies that the npm artifact installs correctly, boots up, responds to the /health endpoint, and can be stopped. ```bash npm run test:install-smoke ``` -------------------------------- ### Run Headless Server Explicitly (npm) Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/codebase_analysis.md Explicitly run the headless server command using npm. This is an alternative to `npm start` for headless operation. ```bash npm run serve:headless ``` -------------------------------- ### Edit File Example Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/sys-prompt.txt Use the `edit` tool to modify the content of a file. Provide the `path`, `old_content`, and `new_content` parameters. ```shell src/auth.py ``` -------------------------------- ### Glob File Search Example Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/sys-prompt.txt Use the `glob` tool to find files matching a specified path pattern. This is often used to locate test files or configuration files. ```shell tests/test_auth.py ``` -------------------------------- ### Run Shell Command for Testing Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/sys-prompt.txt Execute shell commands to run project tests. This example uses `npm run test`. ```shell npm run test ``` -------------------------------- ### TUI Main Shell Layout Example Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/spec/rewrite/tui-and-rezi.md Illustrates the structure of the main TUI shell, including sidebar, header, and active screen area. This serves as a visual reference for layout and content placement. ```text ┌──────── sidebar ────────┬──────────────────────────────────────────────────────────────────────┐ │ qwen-proxy │ RUNNING · up 00:21:44 · 127.0.0.1:38471 · RR · 10 acc · req 2 │ │ │ streams 1 │ │ 󰍹 Live │ │ │ 󰉋 Artifacts │ active screen area │ │ 󰀉 Accounts │ │ │ 󰕾 Usage │ │ │ │ │ │ 󰒓 Settings │ │ │ 󰞋 Help │ │ │ │ │ │ [⟨] collapse │ │ ├─────────────────────────┼──────────────────────────────────────────────────────────────────────┤ │ Tab pane Shift+Tab back Enter open Click supported Wheel scroll Q quit │ └─────────────────────────┴──────────────────────────────────────────────────────────────────────┘ ``` -------------------------------- ### Install Production Dependencies Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/codebase_analysis.md Install only production dependencies for the Node.js application. Excludes development dependencies. ```bash npm install --production ``` -------------------------------- ### Example OAuth Credentials Files Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/api-endpoint-resolution.md These files store OAuth credentials, including the `resource_url` which determines the API endpoint. Ensure the `resource_url` is correct for your account. ```json ~/.qwen/oauth_creds_account1.json # resource_url: "portal.qwen.ai" ``` ```json ~/.qwen/oauth_creds_account2.json # resource_url: "custom.endpoint.com" ``` -------------------------------- ### Run Shell Command for Linting and Testing Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/sys-prompt.txt Execute shell commands to lint code and run tests. This example uses `ruff check` for linting and `pytest` for testing. ```shell ruff check src/auth.py && pytest ``` -------------------------------- ### Proxy Startup Output Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/default-account.md On startup, the proxy logs the default account that has been configured. ```text Default account configured: primary ``` -------------------------------- ### Add Multiple Accounts via CLI Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/README.md Demonstrates how to add multiple authentication accounts using the qwen-proxy CLI. Accounts are rotated round-robin. ```bash qwen-proxy auth add account1 ``` ```bash qwen-proxy auth add account2 ``` ```bash qwen-proxy auth add account3 ``` -------------------------------- ### List Configured Accounts (npm) Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/codebase_analysis.md Build the TypeScript runtime and list all currently configured accounts. Useful for managing multiple authentication credentials. ```bash npm run auth:list ``` -------------------------------- ### Run Build and Tests Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/spec/rewrite/phase5-agent-prompt.md Execute these commands to verify the project's baseline health before making any code changes. Document any failures encountered. ```bash npm run build:core npm run typecheck npm run test ``` -------------------------------- ### Run Clean-Home Auth Probe Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/testing-clean-home.md Execute the test suite for authentication in a clean home environment. This verifies that the proxy does not produce excessive warnings when essential authentication files are missing. ```bash npm run test:auth-clean-home ``` -------------------------------- ### Runtime Logging Control Handler Endpoints Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/codebase_analysis.md Exposes endpoints for getting and setting the runtime log level, with validation for changes and optional persistence. ```typescript Exposes `GET /runtime/log-level` Exposes `POST /runtime/log-level` Validates runtime log level changes and optional persistence ``` -------------------------------- ### Run First-Run Storage/Bootstrap Regression Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/testing-clean-home.md Execute the test suite for first-run storage and bootstrap processes in a clean home environment. This ensures that SQLite/database bootstrapping functions correctly without pre-existing data. ```bash npm run test:first-run ``` -------------------------------- ### OAuth Token Response with resource_url Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/api-endpoint-resolution.md Example of an OAuth token response that includes the `resource_url` field, which the proxy uses to dynamically set the API endpoint. ```json { "access_token": "...", "refresh_token": "...", "token_type": "Bearer", "expires_in": 3600, "resource_url": "portal.qwen.ai" } ``` -------------------------------- ### Directory Structure of Qwen OpenAI Proxy Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/codebase_analysis.md Overview of the project's directory structure, highlighting key configuration, source code, documentation, and utility directories. ```bash /home/idc/proj/qwen-code-oai-proxy/ ├── .env.example # Environment configuration example ├── .gitignore # Git ignore patterns ├── authenticate.ts # Authentication CLI tool ├── usage.ts # Usage reporting CLI tool ├── package.json # Project metadata and dependencies ├── README.md # Project documentation ├── scripts/ # Validation and helper scripts ├── debug/ # Debug log files (git-ignored) ├── docs/ # Documentation files ├── node_modules/ # Dependencies (git-ignored) ├── qwen-code/ # Qwen code directory (git-ignored) ├── src/ # Main source code │ ├── config.ts # TS runtime config │ ├── index.ts # TS runtime entry │ ├── cli/ # TS CLI entry (`qwen-proxy`) │ ├── server/ # TS runtime controllers/lifecycle │ ├── core/ # Typed core rewrite foundation │ ├── qwen/ # Qwen-specific modules │ │ ├── api.ts # TS Qwen API runtime │ │ └── auth.ts # TS auth runtime │ └── utils/ # Utility modules │ ├── logger.ts # Debug logging utility │ └── tokenCounter.ts # Token counting utility ``` -------------------------------- ### Token Refresh Logging Output Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/token-refresh-issues.md Provides examples of the clear terminal output generated by the enhanced implementation, indicating the status of token refresh and retry operations. ```text - 🟡 "Refreshing Qwen access token..." - Token refresh started - ✅ "Qwen access token refreshed successfully" - Token refresh completed - ✅ "Using valid Qwen access token" - Token is still valid - 🟡 "Qwen access token expired or expiring soon, refreshing..." - Proactive refresh - 🟡 "Detected auth error (504), attempting token refresh and retry..." - Error-triggered refresh - 🔵 "Retrying request with refreshed token..." - Retry in progress - ✅ "Request succeeded after token refresh" - Retry successful - ❌ "Request failed even after token refresh" - Retry failed ``` -------------------------------- ### Set Environment Variables for Qwen Proxy Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/README.md Configure server port, host, API keys, and logging levels using environment variables or a `.env` file. Ensure API keys are comma-separated if multiple are provided. ```bash LOG_LEVEL=debug MAX_DEBUG_LOGS=10 API_KEY=your-secret-key DEFAULT_ACCOUNT=my-primary-account ``` -------------------------------- ### Inspect Qwen Proxy Runtime Log Level Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/README.md Send a GET request to this endpoint to inspect the current runtime log level without making any changes. ```http GET /runtime/log-level ``` -------------------------------- ### Add Account via Docker Exec Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/README.md Executes a command inside the running qwen-proxy Docker container to add a new authentication account. ```bash docker compose exec qwen-proxy node dist/src/cli/qwen-proxy.js auth add myaccount ``` -------------------------------- ### Get Current Log Level Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/logging-runtime-controls-phase4.md Retrieves the current log level, persisted log level, log directory, configuration file path, and allowed log levels. ```APIDOC ## GET /runtime/log-level ### Description Returns the current runtime log level, persisted log level, log directory, configuration file path, and a list of allowed log levels. ### Method GET ### Endpoint /runtime/log-level ### Response #### Success Response (200) - **current_level** (string) - The currently active log level. - **persisted_level** (string) - The log level saved in the configuration. - **log_dir** (string) - The directory where logs are stored. - **config_file_path** (string) - The path to the configuration file. - **allowed_levels** (array of strings) - A list of valid log level values. ``` -------------------------------- ### Development Workflow Commands Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/CONTRIBUTING.md Common commands for type checking, building, testing, and running the development server. ```bash # Typecheck npm run typecheck # Build npm run build:core # Run tests (simple validation) npm run test:simple # Run full test suite npm run test # Run dev server (headless) npm run dev # Start with TUI npm run build:core node dist/src/cli/qwen-proxy.js serve ``` -------------------------------- ### Add Multiple Accounts Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/default-account.md Use the `npm run auth:add` command to add multiple accounts to the proxy. Ensure the name used here matches the `DEFAULT_ACCOUNT` if you intend to set it as default. ```bash npm run auth:add primary npm run auth:add secondary npm run auth:add backup ``` -------------------------------- ### Run QR Code Authentication Script Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/qr-authentication.md Execute this command to initiate the QR code authentication flow. The script manages credential checks, refresh attempts, and initiates a new flow if necessary. ```bash npm run auth ``` -------------------------------- ### Basic Web Search API Usage (cURL) Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/web-search-api.md A simple example of using the web search API with only the query parameter specified. The API will use default values for page and rows. ```bash curl -X POST http://localhost:8080/v1/web/search \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ -d '{"query": "python programming tutorial"}' ``` -------------------------------- ### Manage Accounts via Docker Exec Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/README.md Commands to list, add, or remove authentication accounts within the running qwen-proxy Docker container. ```bash docker compose exec qwen-proxy node dist/src/cli/qwen-proxy.js auth list ``` ```bash docker compose exec qwen-proxy node dist/src/cli/qwen-proxy.js auth add ``` ```bash docker compose exec qwen-proxy node dist/src/cli/qwen-proxy.js auth remove ``` -------------------------------- ### TUI Auth Modal Example Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/spec/rewrite/tui-and-rezi.md This text-based modal displays the authentication status, verification URL, user code, and a QR code for account linking in the TUI. It includes interactive elements for opening the browser and closing the modal. ```text ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ░ Add account · acc-2 ░ ░──────────────────────────────────────────░ ░ stage: waiting ░ ░ ░ ░ link: https://... ░ ░ code: ABCD-EFGH ░ ░ ░ ░ █▀▀▀▀▀█ ▄▀▀ ▄ █▀▀▀▀▀█ ░ ░ █ ███ █ ▀▄▀█▄ █ ███ █ ░ ░ █ ▀▀▀ █ ▄█ ▄█ █ ▀▀▀ █ ░ ░ ▀▀▀▀▀▀▀ ▀ ▀ ▀ ▀▀▀▀▀▀▀ ░ ░ ░ ░ [ Open browser ] [ Close ] ░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ``` -------------------------------- ### Build Core Project Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/spec/rewrite/phase5-agent-prompt.md Build the core project components. This is a prerequisite for launching the TUI in PTY validation mode. ```bash npm run build:core ``` -------------------------------- ### Run Proxy Server (Node.js) Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/codebase_analysis.md Run the proxy server using Node.js directly from the compiled JavaScript files. Assumes the project has been built. ```bash node dist/src/index.js ``` -------------------------------- ### Add New Account (npm) Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/codebase_analysis.md Build the TypeScript runtime and add a new account using its account ID. Requires the account ID as an argument. ```bash npm run auth:add ``` -------------------------------- ### Launch Review Sub-Agent with Task Tool Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/spec/rewrite/phase5-agent-prompt.md Use the `task` tool with `subagent_type: "general"` to launch the review agent. Replace `[TARGET]` with your specific sub-sector name. ```python task( description: "Review Phase 5 [TARGET]", subagent_type: "general", prompt: "" ) ``` -------------------------------- ### Runtime Storage Behavior Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/typescript-core-foundation.md Details the default storage paths for application data and logs, and lists environment variables that can override these defaults. Useful for configuring runtime behavior. ```text packaged default app home: ~/.local/share/qwen-proxy packaged default logs: ~/.local/share/qwen-proxy/log development default logs: ./log env overrides supported: - QWEN_PROXY_HOME - QWEN_PROXY_CONFIG_DIR - QWEN_PROXY_LOG_DIR ``` -------------------------------- ### qwen-proxy Development Test Scripts Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/README.md Scripts for running automated tests that simulate a clean machine environment by using a temporary HOME directory. Useful for regression testing. ```bash npm run test:auth-clean-home ``` ```bash npm run test:first-run ``` ```bash npm run test:install-smoke ``` -------------------------------- ### CLI Help Command Execution Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/spec/rewrite/progress.md Executes command-line interface help commands for various project scripts. Verifies that the help messages are displayed correctly. ```bash node dist/src/cli/qwen-proxy.js help ``` ```bash node dist/src/cli/qwen-proxy.js serve --headless --help ``` ```bash node dist/authenticate.js --help ``` ```bash node dist/usage.js --help ``` -------------------------------- ### Manage Qwen Proxy Accounts with npm Scripts Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/CHANGELOG.md Use these npm scripts to manage authentication accounts for the Qwen proxy server. Ensure accounts are added and removed correctly to manage access and usage. ```bash npm run auth:list ``` ```bash npm run auth:add ``` ```bash npm run auth:remove ``` ```bash npm run auth:counts ``` -------------------------------- ### Run Tests and Typecheck Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/spec/rewrite/phase5-agent-prompt.md Execute type checking and run all tests from the project root. Ensure all type errors and test failures are resolved before proceeding. ```bash npm run typecheck npm test ``` -------------------------------- ### Test 'qwen3.5-plus' with curl Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/model-discovery.md Send a POST request to the local proxy to test the 'qwen3.5-plus' endpoint, which is expected to return a 400 error with an OAuth token. ```bash # Test qwen3.5-plus (returns 400 with OAuth) curl -X POST http://localhost:8082/v1/chat/completions \ -H "Authorization: Bearer fake-key" \ -d '{"model":"qwen3.5-plus","messages":[{"role":"user","content":"hi"}]}' ``` -------------------------------- ### MCP Configuration for Qwen Web Search Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/README.md Configure opencode to use the Qwen web search tool via MCP. Provide the remote URL and any necessary headers for authentication. ```json { "$schema": "https://opencode.ai/config.json", "mcp": { "qwen-web-search": { "type": "remote", "url": "http://localhost:8080/mcp", "headers": { "Authorization": "Bearer your-api-key" } } } } ``` -------------------------------- ### Web Search with Specific Account Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/web-search-api.md Perform a web search and associate the request with a specific Qwen account using the X-Qwen-Account header. ```bash curl -X POST http://localhost:8080/v1/web/search \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "X-Qwen-Account: my-account" \ -d '{"query": "climate change news"}' ``` -------------------------------- ### Testing Direct API Calls to Portal Endpoint Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/api-endpoint-resolution.md This `curl` command demonstrates how to make a direct POST request to the Qwen chat completions API using the common portal endpoint. Replace `YOUR_TOKEN` with your actual access token. ```bash # Using the portal endpoint (most common) curl -X POST https://portal.qwen.ai/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_TOKEN" \ -d '{"model": "qwen3-coder-plus", "messages": [{"role": "user", "content": "hi"}]}' ``` -------------------------------- ### Find Coding Plan Models Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/docs/model-discovery.md Use grep to locate Coding Plan models, which may have a different baseUrl and authentication requirements. ```bash # Location: qwen-code/packages/cli/src/constants/codingPlan.ts grep -B2 -A10 "baseUrl" qwen-code/packages/cli/src/constants/codingPlan.ts ``` -------------------------------- ### opencode Configuration for Qwen Source: https://github.com/aptdnfapt/qwen-code-oai-proxy/blob/main/README.md Configure opencode to use the Qwen provider via the OAI-compatible proxy. Specify the baseURL and model details, including modalities and limits. ```json { "$schema": "https://opencode.ai/config.json", "provider": { "qwen": { "npm": "@ai-sdk/openai-compatible", "name": "proxy", "options": { "baseURL": "http://localhost:8080/v1" }, "models": { "coder-model": { "name": "qwen3.6-plus" , "reasoning": true, "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "attachment": true, "limit": { "context": 195000, "output": 60000 } } } } } } ```