qwen2API: Turning Qwen Web Chat into OpenAI, Claude, and Gemini Compatible APIs

The qwen2API project offers a FastAPI backend and React+Vite frontend that expose the Qwen web chat as OpenAI Chat Completions, Anthropic Messages, and Gemini GenerateContent interfaces, featuring tool calling, image generation, account pool management, multiple deployment options, and various execution engines.

CodeTrend
CodeTrend
CodeTrend
qwen2API: Turning Qwen Web Chat into OpenAI, Claude, and Gemini Compatible APIs

Overview

qwen2API converts the web chat capabilities of 通义千问 (chat.qwen.ai) into APIs compatible with OpenAI Chat Completions, Anthropic Claude Messages, and Google Gemini GenerateContent, providing a unified interface for developers.

Architecture diagram
Architecture diagram

Capabilities

Expose Qwen web chat as an OpenAI Chat Completions endpoint.

Expose Qwen web chat as an Anthropic Messages endpoint.

Expose Qwen web chat as a Gemini GenerateContent endpoint.

Provide a dedicated image generation endpoint POST /v1/images/generations.

Support tool calling and tool result callbacks.

Include a management console for account handling, API key management, image generation testing, and runtime status monitoring.

Implement multi‑account rotation, rate‑limit cooling, retry logic, and a hybrid Browser/Httpx engine.

Architecture

Backend: Python FastAPI (directory backend/) – single router handling protocol adaptation and upstream calls.

Frontend: React management console (directory frontend/) – serves static build artifacts.

Deployment options: Docker (recommended), local execution, Vercel, Zeabur.

Core Features

Unified routing kernel: all protocol entry points converge on a single FastAPI router.

Protocol conversion bridge: Claude and Gemini requests are normalized, forwarded upstream, then transformed back to the original protocol response.

Tool‑calling support: compatible with OpenAI, Claude, and Gemini formats; automatic parsing and conversion.

Account pool management: multi‑account rotation, concurrency control, rate‑limit cooling, automatic retries.

File attachment handling: upload, temporary local storage, and context injection.

Image generation endpoint supporting multiple size ratios.

Health‑check and readiness endpoints.

Chat ID warm‑up pool: pre‑creates conversation queues, saving 500 ms–3 s per request.

Schema compression: converts JSON Schema to TypeScript‑like signatures, reducing tool prompt size by ~90%.

Tool‑name obfuscation: prefixes client tool names with u_ or aliases to bypass Qwen built‑in function checks.

Tool‑call hallucination protection: blocks auto‑agents, intercepts duplicate calls, retries on empty responses, and detects toxicity refusals.

Automatic truncation continuation for unclosed #TOOL_CALL## patterns.

File content caching: caches real content of Claude Code “Unchanged since last read” responses.

Historical refusal cleaning: scans past assistant messages for refusal or self‑limiting text to prevent cascading repeats.

Incremental streaming warm‑up: buffers 96 characters before emitting, filtering apology prefixes and incomplete tool calls.

Topic isolation: measures Jaccard similarity of user message entities and discards irrelevant history when a new task is detected.

Few‑shot tool injection: selects representative tools per namespace to construct synthetic few‑shot examples, improving MCP/Skill tool hit rates.

Edit/StrReplace fuzzy matching: automatically fixes smart quotes, whitespace, and backslash differences that cause exact‑match failures.

CLIProxy protocol conversion layer: funnels all protocol entries into a standard request object, avoiding behavior drift.

Running Claude Code

export ANTHROPIC_BASE_URL=http://127.0.0.1:7860/anthropic
export ANTHROPIC_API_KEY=admin
claude
Claude code execution
Claude code execution

Obtaining the Token

Open browser to https://chat.qwen.ai and log in
Open DevTools (F12) → Application → Cookies
Find the cookie named "token"; its value is the required token
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LLMReactGeminiFastAPItool callingAnthropicOpenAI APIqwen2API
CodeTrend
Written by

CodeTrend

Capture the daily pulse of global open-source tech. Real-time tracking of GitHub Trending and curated selections of the hottest projects worldwide, including C++, Python and other verticals. Avoid information overload and keep tech trends within reach.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.