# pi-extension-qwen-token-plan-cn-ex

> **[中文版](./README.md)**

An **enhanced** "Qwen Token Plan (CN)" model provider for
[pi](https://github.com/earendil-works/pi). Same platform and same `/login` as
the built-in `qwen-token-plan-cn`, but it uses the **Responses API**, which
unlocks the platform's built-in **web search, code execution, web extraction,
and image search** — capabilities the built-in provider cannot offer. The
supported model list is **kept up to date with each release**.

## What it gives you

- 🌐 **Web search**: ask real-time questions like "what's the weather in
  Hangzhou today?" and the model searches the web and answers **with source
  links**.
- 🧮 **Code execution / web extraction / image search**: server-side platform
  capabilities the model calls automatically as needed.
- 🧠 **Reasoning**: supports every `reasoning.effort` level (incl. `xhigh` /
  `max`).
- 🔧 **Full pi toolchain**: pi tools like `read`/`write`/`bash` round-trip
  correctly.
- 🖼️ **Image input**: image-capable models can see images (qwen3.7-max is
  text-only).

## Supported models

| Model | Reasoning | Images | Context | Max output | Harness tools |
| --- | --- | --- | --- | --- | --- |
| `qwen3.8-max` | ✓ | ✓ | 1M | 131072 | all 5 |
| `qwen3.8-max-preview` | ✓ | ✓ | 1M | 131072 | all 5 |
| `qwen3.7-max` | ✓ | ✗ | 1M | 131072 | core 3 |
| `qwen3.7-plus` | ✓ | ✓ | 1M | 131072 | all 5 |
| `qwen3.6-flash` | ✓ | ✓ | 1M | 65536 | all 5 |

> All 5 = `web_search`, `code_interpreter`, `web_extractor`, `web_search_image`,
> `image_search`; core 3 = the first three. New models are picked up by
> upgrading this extension.

## Install

```bash
pi install npm:pi-extension-qwen-token-plan-cn-ex
```

Restart pi and the provider appears in the `/login` list.

## Getting started

**1. Log in** (provider id is `qwen-token-plan-cn-ex`; use a Token-Plan
`sk-sp-…` key, generated in the Aliyun console under "我的订阅"):

```
/login qwen-token-plan-cn-ex
```

Or set an environment variable (no interactive login needed):

```bash
export QWEN_TOKEN_PLAN_CN_EX_API_KEY=sk-sp-...
```

**2. Pick a model**:

```
/model qwen3.7-plus
```

**3. Try web search**: just ask "what's the weather in Hangzhou today?" — the
model searches automatically and answers, with source links appended, e.g.:

```
Hangzhou: light rain, 27–36°C …

---
[web_search] queries: "杭州天气"
sources:
  - https://www.weather.com.cn/...
```

## Toggling the web tools

Web/Harness tools are **on by default**. Three modes:

| Mode | Meaning |
| --- | --- |
| `auto` | Default. Declares all tools the model supports; the model decides when to use them. |
| `none` | Turn everything off (no Harness Credit spent). |
| `web_search,code_interpreter`, … | A comma-list: use only the named tools (intersected with what the model supports). |

**Precedence**: CLI flag > project config > global config > default `auto`.

**One-off (CLI, per run)**:

```bash
pi --qwen-harness=none            # no web access this run
pi --qwen-harness=web_search      # web search only this run
```

**Persistent (config file, pick one)**:

```bash
# Applies to all projects (global):
echo '{"harness":"none"}' > ~/.pi/agent/qwen-token-plan-cn-ex.json

# Applies to the current project only:
echo '{"harness":"none"}' > .pi/qwen-token-plan-cn-ex.json
```

> ℹ️ Prefer the built-in `qwen-token-plan-cn` (no web access, saves Credit)?
> Just switch with `/model` — no config change needed.

## Cost

Token Plan is billed by **Credit**, so the per-token cost shown in pi is 0; but
input / output / reasoning / cache token usage is still tracked normally.

## Docs & feedback

- Full design: [DESIGN.md](https://github.com/shamiao/pi-extension-qwen-token-plan-cn-ex/blob/master/DESIGN.md)
- Issues & suggestions: [GitHub Issues](https://github.com/shamiao/pi-extension-qwen-token-plan-cn-ex/issues)

## License

[MIT](./LICENSE) © SHA Miao
