2026-09-05 16:15:15 +03:00
# Qflash: OpenAI-compatible gateway for Qwen3.8 models
2026-09-05 15:42:07 +03:00
2026-09-05 15:47:25 +03:00
## About
2026-09-05 15:42:07 +03:00
2026-09-05 16:15:15 +03:00
Qflash is a standalone, single-binary gateway that exposes Qwen3.8 model spaces on Hugging Face through a standard OpenAI-compatible API. It automatically detects and supports multiple upstream protocols:
2026-09-05 16:39:35 +03:00
- gradio `/respond` endpoints (such as `https://microhero-qwen3-8-27b-uncensored-chat.hf.space` , running live on ZeroGPU)
- direct OpenAI `/v1/chat/completions` endpoints (such as `https://wanyamaelis-qwen3-8-27b.hf.space` and `https://apathy-exe-qwen3-8-flash-next.hf.space` , running `llama-server` on CPU)
- gradio `/chat_response` endpoints (such as `https://halvo78-qwen3-8-flash-next-playground.hf.space` )
2026-09-05 16:15:15 +03:00
It translates standard `/v1/chat/completions` and `/v1/models` requests and Server-Sent Events (SSE) stream protocols into upstream formats, allowing any standard OpenAI-compatible client, agent, or IDE to interface with Qwen3.8 models without modification.
2026-09-05 15:42:07 +03:00
## Features
2026-09-05 16:15:15 +03:00
- openai-compatible chat completions (streaming and non-streaming)
2026-09-05 16:39:35 +03:00
- automatic upstream failover across ZeroGPU and non-ZeroGPU endpoints
- smart endpoint cooldown (5 minutes on quota exhaustion, 30 seconds on network errors)
2026-09-05 16:15:15 +03:00
- automatic upstream endpoint detection (`respond` , `openai` , `chat_response` )
- deep reasoning extraction with thinking trace passthrough (`<think>` tags and blockquotes mapped to `reasoning_content` )
- stateful streaming tool call interception (`StreamToolCallFilter` ) with zero XML or JSON leakage into `delta.content`
- real-time token streaming with incremental SSE delivery
- support for instruct mode via standard `reasoning_effort: "none"`
- zero-dependency SOCKS5 proxy client (RFC 1928 / RFC 1929) with domain resolution (`socks5h://` ), IPv4, IPv6, and auth
- bring your own key (BYOK) pass-through support via `Authorization: Bearer` or CLI flags
- zero-gpu quota authentication via free Hugging Face personal tokens (`HF_TOKEN` )
- fibonacci backoff retry on transient upstream errors
- zero external dependencies (Go standard library only)
## Supported upstream spaces
| Space | Model | Hardware | Protocol | Notes |
|---|---|---|---|---|
2026-09-05 16:39:35 +03:00
| `MicroHERO/qwen3.8-27b-uncensored-chat` *(primary)* | Qwen3.8-27B Uncensored | ZeroGPU (A10G) | Gradio `/respond` | Fast live GPU inference (~2s), uncensored weights |
| `Wanyamaelis/Qwen3.8-27B` *(fallback)* | Qwen3.8-27B (MTP) | CPU basic (8 vCPU) | Native OpenAI `/v1` | Non-ZeroGPU, no quota limits, fast speculative decoding (~5s) |
| `apathy-exe/Qwen3.8-27B` | Qwen3.8-27B (MTP) | CPU (OpenMP/AVX512) | Native OpenAI `/v1` | Non-ZeroGPU, no quota limits, speculative decoding |
| `apathy-exe/Qwen3.8-Flash-Next` | Qwen3.8-Flash-Next (~177B) | CPU (OpenMP/AVX512) | Native OpenAI `/v1` | Non-ZeroGPU, no quota limits, full 177B Flash-Next model |
2026-09-05 16:15:15 +03:00
| `Halvo78/qwen3-8-flash-next-playground` | Qwen3.8-Flash-Next | CPU basic | Gradio `/chat_response` | Sandbox client; requires BYOK API key/base URL |
2026-09-05 16:39:35 +03:00
### Auto-failover and ZeroGPU quota handling
2026-09-05 16:15:15 +03:00
2026-09-05 16:39:35 +03:00
Spaces running on ZeroGPU provide free A10G compute, but anonymous requests share a small pool per IP address. When ZeroGPU runs limit is reached, upstream returns a quota error (`429` or `ZeroGPU runs limit` ).
2026-09-05 16:15:15 +03:00
2026-09-05 16:39:35 +03:00
Qflash handles this seamlessly:
2026-09-05 16:15:15 +03:00
2026-09-05 16:39:35 +03:00
- with auto-failover enabled (default), when a ZeroGPU space hits its runs limit, it is placed on a 5-minute cooldown and the gateway automatically fails over to the next configured endpoint (e.g. `wanyamaelis-qwen3-8-27b` , which runs on CPU with zero quota limits)
- transient network errors trigger a shorter 30-second cooldown before retrying
- you can also provide a free Hugging Face personal access token (`https://huggingface.co/settings/tokens` ) via the `HF_TOKEN` environment variable, the `-hf-token` CLI flag, or the `Authorization: Bearer hf_...` header to authenticate ZeroGPU requests directly
2026-09-05 15:42:07 +03:00
2026-09-05 15:45:21 +03:00
## Installation
2026-09-05 15:47:25 +03:00
You need Go 1.22 or newer (tested on Go 1.26). Install the latest release straight from the Git repository with `go install` :
2026-09-05 15:45:21 +03:00
```bash
go install code.luxferre.top/luxferre/qflash@latest
```
2026-09-05 15:47:25 +03:00
This fetches the module from `https://code.luxferre.top/luxferre/qflash.git` and places the `qflash` binary in `$(go env GOPATH)/bin` . Make sure that directory is on your `PATH` .
2026-09-05 15:45:21 +03:00
2026-09-05 15:47:25 +03:00
*(Note: If installing right after a new commit has been pushed, bypass any proxy cache with `GOPROXY=direct go install code.luxferre.top/luxferre/qflash@latest`).*
2026-09-05 15:45:21 +03:00
2026-09-05 15:47:25 +03:00
If you prefer to build from a local checkout instead:
2026-09-05 15:45:21 +03:00
```bash
git clone https://code.luxferre.top/luxferre/qflash.git
cd qflash
2026-09-05 15:47:25 +03:00
go install .
```
Alternatively, build directly from source using `make` :
```bash
2026-09-05 15:45:21 +03:00
make qflash
```
2026-09-05 15:47:25 +03:00
This produces the `bin/qflash` binary for your platform.
2026-09-05 15:45:21 +03:00
2026-09-05 15:47:25 +03:00
## Models served
2026-09-05 15:45:21 +03:00
2026-09-05 15:47:25 +03:00
The gateway advertises the following models under `/v1/models` :
2026-09-05 15:42:07 +03:00
2026-09-05 15:47:25 +03:00
| Model ID | Target model | Description |
2026-09-05 15:42:07 +03:00
|---|---|---|
2026-09-05 16:39:35 +03:00
| `Qwen/Qwen3.8-27B-Uncensored` | `Qwen/Qwen3.8-27B-Uncensored` | Default primary live model |
2026-09-05 16:15:15 +03:00
| `Qwen/Qwen3.8-Flash-Next` | `Qwen/Qwen3.8-Flash-Next` | Flash-Next model identifier |
| `qwen3.8-27b-uncensored` | `Qwen/Qwen3.8-27B-Uncensored` | Standard lowercase alias |
| `qwen3.8-flash-next` | `Qwen/Qwen3.8-Flash-Next` | Flash-Next lowercase alias |
2026-09-05 15:42:07 +03:00
| `qwen-flash-next` | `Qwen/Qwen3.8-Flash-Next` | Shorthand alias |
| `qwen-flash` | `Qwen/Qwen3.8-Flash-Next` | Quick convenience alias |
2026-09-05 16:15:15 +03:00
| `qwen` | Default model | Generic shorthand alias |
2026-09-05 15:42:07 +03:00
Any unlisted custom model name requested by the client is passed through directly.
2026-09-05 15:47:25 +03:00
## Usage
2026-09-05 15:42:07 +03:00
2026-09-05 16:39:35 +03:00
Run the gateway with default auto-failover endpoints:
2026-09-05 15:42:07 +03:00
```bash
2026-09-05 16:15:15 +03:00
qflash
2026-09-05 15:42:07 +03:00
```
2026-09-05 16:39:35 +03:00
By default, this listens on `http://127.0.0.1:8080` with failover configured across `MicroHERO` (ZeroGPU), `wanyamaelis` (CPU non-ZeroGPU), and `apathy-exe` endpoints.
2026-09-05 16:15:15 +03:00
2026-09-05 15:47:25 +03:00
Available flags:
2026-09-05 16:39:35 +03:00
- `-port` — tcp port to listen on (default `8080` )
- `-endpoints` / `-endpoint` — comma-separated upstream space or OpenAI URLs (default list of 4 endpoints, `QFLASH_ENDPOINTS` / `QFLASH_ENDPOINT` env)
- `-failover` / `-auto-failover` — enable automatic failover across endpoints on quota exhaustion or error (default `true` , `QFLASH_FAILOVER` env)
2026-09-05 16:15:15 +03:00
- `-mode` — upstream protocol mode: `auto` , `respond` , `chat_response` , `openai` (default `auto` , `QFLASH_MODE` env)
- `-model` — exposed model name (default `Qwen/Qwen3.8-27B-Uncensored` , `QFLASH_MODEL` env)
2026-09-05 15:47:25 +03:00
- `-thinking` / `-enable-thinking` — enable chain-of-thought reasoning by default (default `true` )
2026-09-05 16:15:15 +03:00
- `-hf-token` / `-token` — Hugging Face API token for ZeroGPU quota or private spaces (`HF_TOKEN` env)
2026-09-05 15:47:25 +03:00
- `-api-key` — upstream inference engine API key for BYOK mode (`OPENAI_API_KEY` / `QWEN_API_KEY` env)
- `-base-url` — upstream inference engine base URL for BYOK mode (`OPENAI_BASE_URL` / `QWEN_BASE_URL` env)
- `-socks` / `-proxy` / `-socks5` — SOCKS5 proxy URL, e.g. `socks5://127.0.0.1:1080` (`ALL_PROXY` env)
- `-user-agent` / `-ua` — custom User-Agent sent to upstream
Endpoints served:
- `GET /models` and `GET /v1/models`
- `POST /chat/completions` and `POST /v1/chat/completions`
Example request with curl:
2026-09-05 15:42:07 +03:00
```bash
2026-09-05 15:47:25 +03:00
curl http://localhost:8080/v1/chat/completions \
2026-09-05 15:42:07 +03:00
-H "Content-Type: application/json" \
2026-09-05 16:15:15 +03:00
-d '{"model":"qwen","messages":[{"role":"user","content":"Explain quantum superposition in one sentence."}],"stream":false}'
2026-09-05 15:42:07 +03:00
```
2026-09-05 15:47:25 +03:00
Streaming example:
2026-09-05 15:42:07 +03:00
```bash
2026-09-05 15:47:25 +03:00
curl -N http://localhost:8080/v1/chat/completions \
2026-09-05 15:42:07 +03:00
-H "Content-Type: application/json" \
2026-09-05 16:15:15 +03:00
-d '{"model":"qwen","messages":[{"role":"user","content":"Count from 1 to 5."}],"stream":true}'
2026-09-05 15:42:07 +03:00
```
2026-09-05 15:47:25 +03:00
Instruct mode example (disables thinking):
2026-09-05 15:42:07 +03:00
```bash
2026-09-05 15:47:25 +03:00
curl http://localhost:8080/v1/chat/completions \
2026-09-05 15:42:07 +03:00
-H "Content-Type: application/json" \
2026-09-05 16:15:15 +03:00
-d '{"model":"qwen","messages":[{"role":"user","content":"Hello!"}],"reasoning_effort":"none"}'
```
2026-09-05 16:39:35 +03:00
Using custom upstream spaces or a single endpoint:
2026-09-05 16:15:15 +03:00
```bash
2026-09-05 16:39:35 +03:00
# Point to a single CPU llama-server without failover
qflash -endpoint https://wanyamaelis-qwen3-8-27b.hf.space -failover= false
2026-09-05 16:15:15 +03:00
# Point to Halvo78 playground with your own API credentials
qflash -endpoint https://halvo78-qwen3-8-flash-next-playground.hf.space -api-key "sk-..." -base-url "https://api.openai.com/v1"
2026-09-05 15:42:07 +03:00
```
2026-09-05 15:47:25 +03:00
Python OpenAI SDK integration:
2026-09-05 15:42:07 +03:00
```python
from openai import OpenAI
client = OpenAI (
2026-09-05 15:47:25 +03:00
base_url = "http://localhost:8080/v1" ,
2026-09-05 15:42:07 +03:00
api_key = "sk-dummy"
)
stream = client . chat . completions . create (
2026-09-05 16:15:15 +03:00
model = "qwen" ,
2026-09-05 15:42:07 +03:00
messages = [
{ "role" : "user" , "content" : "Prove that the sum of the first n odd numbers is n^2." }
],
stream = True
)
for chunk in stream :
delta = chunk . choices [ 0 ] . delta
if hasattr ( delta , "reasoning_content" ) and delta . reasoning_content :
print ( f "[THINK] { delta . reasoning_content } " , end = "" , flush = True )
if delta . content :
print ( delta . content , end = "" , flush = True )
print ()
```
2026-09-05 15:47:25 +03:00
## Credits
Created by Luxferre in 2026, released into the public domain with no warranties.