Agent setup: If your agent doesn't auto-load skills (e.g. Claude Code),
see agent-compatibility.md once per session.
Qwen Text Chat (OpenAI-Compatible)
Generate text, conduct conversations, write code, and invoke tools using Qwen models through the OpenAI-compatible API.
This skill is part of qwencloud/qwencloud-ai.
Skill directory
Use this skill's internal files to execute and learn. Load reference files on demand when the default path fails or you
need details.
| Location | Purpose |
|---|
| INLINECODE0 | Default execution — chat/completions request, streaming, output save |
| INLINECODE1 |
Fallback: curl, Python SDK, function calling, thinking mode |
|
references/api-guide.md | API supplement and full code examples |
|
references/prompt-guide.md | Prompt engineering: CO-STAR framework, CoT, few-shot, task steps |
|
references/sources.md | Official documentation URLs (manual lookup only) |
|
references/agent-compatibility.md | Agent self-check: register skills in project config for agents that don't auto-load |
Security
NEVER output any API key or credential in plaintext. Always use variable references ($DASHSCOPE_API_KEY in shell,
os.environ["DASHSCOPE_API_KEY"] in Python). Any check or detection of credentials must be non-plaintext: report
only status (e.g. "set" / "not set", "valid" / "invalid"), never the value. Never display contents of .env or config
files that may contain secrets.
When the API key is not configured, NEVER ask the user to provide it directly. Instead, help create a .env file with a placeholder (DASHSCOPE_API_KEY=sk-your-key-here) and instruct the user to replace it with their actual key from the QwenCloud Console. Only write the actual key value if the user explicitly requests it.
Key Compatibility
Scripts require a standard QwenCloud API key (sk-...). Coding Plan keys (sk-sp-...) cannot be used for direct
API calls — they are designed exclusively for interactive coding tools (Cursor, Claude Code, Qwen Code) and do not work
on QwenCloud API endpoints. The script detects sk-sp- keys at startup and prints a warning. If qwencloud-ops-auth is installed,
see its references/codingplan.md for details on key types, endpoint mapping, and error codes.
Model Selection
| Model | Use Case |
|---|
| INLINECODE15 | Recommended default — balanced performance, cost, speed, 1M context |
| INLINECODE16 |
Fast, low-cost, 1M context |
|
qwen3-max | Strongest capability |
|
qwen-plus | General purpose |
|
qwen-turbo | Cheapest, low latency |
|
qwen3-coder-next |
Recommended code model — best balance of quality, speed, cost; agentic coding |
|
qwen3-coder-plus | Code generation — highest quality for complex tasks |
|
qwen3-coder-flash| Code generation — fast responses, lower cost |
|
qwq-plus | Reasoning / chain-of-thought |
|
qwen-mt-plus | Machine translation — best quality, 92 languages |
|
qwen-mt-flash | Machine translation — fast, low cost, 92 languages |
|
qwen-mt-lite | Machine translation — real-time chat, fastest, 31 languages |
|
qwen-plus-character-ja | Role-playing — recommended for Singapore |
|
qwen-plus-character | Role-playing — character restoration, empathetic dialog |
|
qwen-flash-character | Role-playing — fast, lower cost |
- 1. User specified a model → use directly.
- Consult the qwencloud-model-selector skill when model choice depends on requirement, scenario, or pricing.
- No signal, clear task →
qwen3.5-plus (default).
Fallback: if model-selector is unavailable, the defaults in the table above apply.
⚠️ Important: The model list above is a point-in-time snapshot and may be outdated. Model availability
changes frequently. Always check the official model list
for the authoritative, up-to-date catalog before making model decisions.
Execution
Prerequisites
- - API Key: Check that
DASHSCOPE_API_KEY (or QWEN_API_KEY) is set using a non-plaintext check only (e.g. in shell:
[ -n "$DASHSCOPE_API_KEY" ]; report only "set" or "not set", never the key value). If not set: run the *
qwencloud-ops-auth* skill if available; otherwise guide the user to obtain a key from
QwenCloud Console and set it via
.env file
(
echo 'DASHSCOPE_API_KEY=sk-your-key-here' >> .env in project root or current directory) or environment variable.
The script searches for
.env in the current working directory and the project root. Skills may be installed independently — do
not assume qwencloud-ops-auth is present.
- - Python 3.9+ (stdlib only, no pip install needed for script execution)
Environment Check
Before first execution, verify Python is available:
CODEBLOCK0
If python3 is not found, try python --version or py -3 --version. If Python is unavailable or below 3.9, skip to *
Path 2 (curl)* in execution-guide.md.
Default: Run Script
Script path: Scripts are in the scripts/ subdirectory of this skill's directory (the directory containing this
SKILL.md). You MUST first locate this skill's installation directory, then ALWAYS use the full absolute path to execute
scripts. Do NOT assume scripts are in the current working directory. Do NOT use cd to switch directories before
execution.
Execution note: Run all scripts in the foreground — wait for stdout; do not background.
Discovery: Run python3 <this-skill-dir>/scripts/text.py --help first to see all available arguments.
CODEBLOCK1
For streaming (recommended for interactive use):
CODEBLOCK2
| Argument | Description |
|---|
| INLINECODE43 | JSON request body |
| INLINECODE44 |
Load request from file (alternative to
--request) |
|
--stream | Enable streaming output |
|
--output dir/ | Save response JSON to directory |
|
--print-response | Print response to stdout |
|
--model ID | Override model (also settable in request JSON) |
Verify Result
- - Exit code
0 + output contains valid JSON with choices field → success - Non-zero exit, HTTP error, empty response, or JSON with
"code"/"message" error → fail - If agent cannot read exit codes, scan output for error patterns (
Error, Traceback, 401, 403) - Post-execution check: When
--output is used, verify the response JSON file exists and contains INLINECODE59 - MANDATORY — stderr signal check: After confirming the result, scan the command's stderr output for
[ACTION_REQUIRED] or
[UPDATE_AVAILABLE]. If either signal is present, you
MUST follow the instructions
in
Update Check below before responding to the user.
On Failure
If the script fails, match the error output against the diagnostic table below to determine the resolution. If no match,
read execution-guide.md for alternative paths: curl commands (Path 2), Python SDK code
generation (Path 3), and autonomous resolution (Path 5).
If Python is not available at all → skip directly to Path 2 (curl)
in execution-guide.md.
| Error Pattern | Diagnosis | Resolution |
|---|
| INLINECODE62 | Python not on PATH | Try python or py -3; install Python 3.9+ if missing |
| INLINECODE65 |
Script version check failed | Upgrade Python to 3.9+ |
|
SyntaxError near type hints | Python < 3.9 | Upgrade Python to 3.9+ |
|
QWEN_API_KEY/DASHSCOPE_API_KEY not found | Missing API key | Obtain key from
QwenCloud Console; add to
.env:
echo 'DASHSCOPE_API_KEY=sk-...' >> .env; or run
qwencloud-ops-auth if available |
|
HTTP 401 | Invalid or mismatched key | Run
qwencloud-ops-auth (non-plaintext check only); verify key is valid |
|
SSL: CERTIFICATE_VERIFY_FAILED | SSL cert issue (proxy/corporate) | macOS: run
Install Certificates.command; else set
SSL_CERT_FILE env var |
|
URLError /
ConnectionError | Network unreachable | Check internet; set
HTTPS_PROXY if behind proxy |
|
HTTP 429 | Rate limited | Wait and retry with backoff |
|
HTTP 5xx | Server error | Retry with backoff |
|
PermissionError | Can't write output | Use
--output to specify writable directory |
Quick Reference
Request Fields
| Field | Type | Description |
|---|
| INLINECODE81 / INLINECODE82 | string \ | array | User input or message list |
| INLINECODE83 |
string | Model ID (e.g.
qwen3.5-plus) |
|
system | string | System prompt (optional) |
|
temperature | float | 0–2, controls randomness |
|
max_tokens | int | Max output tokens |
|
tools | array | Function definitions for tool calling |
|
stream | bool | Enable streaming (recommended for interactive use) |
|
enable_thinking | bool | Enable thinking mode.
Model defaults apply:
qwen3.5-plus/
qwen3.5-flash have thinking
ON by default. Only set explicitly when user requests deep thinking or needs to disable for flash models. Adds latency for real-time tasks. |
Response Fields
| Field | Description |
|---|
| INLINECODE93 | Generated text content |
| INLINECODE94 |
Model used |
|
usage | Token usage (prompt
tokens, completiontokens) |
|
tool_calls | Function call requests (if tools used) |
Advanced Features
These are API-level features supported through request parameters. All use the same chat/completions endpoint.
| Feature | How to Enable | Notes |
|---|
| Structured output | INLINECODE98 | Force JSON output conforming to schema |
| Web search |
enable_search: true | Real-time web search augmented responses |
|
Deep thinking |
enable_thinking: true | Extended reasoning; only when user requests it |
|
Function calling |
tools: [...] | Define functions for tool use |
|
Context cache | Automatic for repeated prefixes; or explicit session-based | Reduces cost for repeated context |
|
Partial mode |
partial_mode: "prefix" | Continue/complete a prefix |
|
Batch inference | Async batch API with JSONL input | 50% cost discount |
For detailed usage of each feature, see api-guide.md and sources.md.
Error Handling
| Error | Cause | Action |
|---|
| INLINECODE103 | Invalid or missing API key | Run qwencloud-ops-auth if available; else prompt user to set key (non-plaintext check only) |
| INLINECODE104 |
Rate limit exceeded | Retry with backoff |
|
500 /
502 /
503 | Server error | Retry; check status page |
|
Invalid model | Model ID not found | Verify model name against Model Selection table |
|
Invalid parameter | Bad request body | Validate JSON and field types |
|
TypeError: ...proxies | openai SDK vs httpx incompatibility |
pip install --upgrade openai (>=1.55.0); or use script (pure stdlib) |
Output Location
Prefer the current working directory for all outputs. Default subdirectory when --output is used:
./output/qwencloud-text/.
Write prohibition: NEVER write output files into this skill's installation directory or any skills/ hierarchy. All generated content must go to output/ under the current working directory or a user-specified path.
Update Check (MANDATORY Post-Execution)
After script execution, check stderr for action signals. The script automatically detects update status and emits
structured signals. You MUST act on them. This section also applies when the user explicitly asks to check for updates.
Signal: [ACTION_REQUIRED] qwencloud-update-check skill is not installed
When stderr contains this signal, you MUST present the following options to the user and wait for their response
before proceeding. Do NOT silently skip this.
The update-check skill is not installed. It keeps you informed about new qwencloud/qwencloud-ai features and bug fixes.
1) Install now — I'll run the install command for you
2) Skip for now — do nothing this time
3) Never remind me — permanently suppress this prompt
After the user responds:
npx skills add QwenCloud/qwencloud-ai --skill qwencloud-update-check -y, then run:
python3 <this-skill-scripts-dir>/gossamer.py --dismiss
- - User chooses 2 → run:
python3 <this-skill-scripts-dir>/gossamer.py --dismiss, then continue normally - User chooses 3 → run:
python3 <this-skill-scripts-dir>/gossamer.py --never-install, then continue normally
Signal: [UPDATE_AVAILABLE]
When stderr contains this signal, you MUST append a brief update notice to your response, including the version info and
the update command shown in the stderr output.
No signal in stderr
If stderr contains neither [ACTION_REQUIRED] nor [UPDATE_AVAILABLE], no action is needed — the skill is installed
and up to date (or cached within 24h).
Explicit user request
When the user explicitly asks to check for updates (e.g. "check for updates", "check version"):
- 1. Look for
qwencloud-update-check/SKILL.md in sibling skill directories. - If found — run:
python3 <qwencloud-update-check-dir>/scripts/check_update.py --print-response and report the result. - If not found — present the install options above.
References
thinking mode
Agent 设置:如果你的代理不会自动加载技能(例如 Claude Code),
请在每个会话中查看一次 agent-compatibility.md。
Qwen 文本对话(兼容 OpenAI)
使用 Qwen 模型通过兼容 OpenAI 的 API 生成文本、进行对话、编写代码和调用工具。
本技能是 qwencloud/qwencloud-ai 的一部分。
技能目录
使用本技能的内部文件来执行和学习。当默认路径失败或需要详细信息时,按需加载参考文件。
| 位置 | 用途 |
|---|
| scripts/text.py | 默认执行 — 聊天/补全请求、流式输出、保存结果 |
| references/execution-guide.md |
备用方案:curl、Python SDK、函数调用、思考模式 |
| references/api-guide.md | API 补充说明和完整代码示例 |
| references/prompt-guide.md | 提示工程:CO-STAR 框架、思维链、少样本、任务步骤 |
| references/sources.md | 官方文档 URL(仅用于手动查阅) |
| references/agent-compatibility.md | 代理自检:为不自加载技能的代理在项目配置中注册技能 |
安全
切勿以明文形式输出任何 API 密钥或凭据。 始终使用变量引用(shell 中使用 $DASHSCOPEAPIKEY,Python 中使用 os.environ[DASHSCOPEAPIKEY])。任何对凭据的检查或检测必须非明文:仅报告状态(例如已设置/未设置、有效/无效),绝不输出值。切勿显示可能包含密钥的 .env 或配置文件内容。
当 API 密钥未配置时,切勿要求用户直接提供密钥。 相反,应帮助创建一个包含占位符(DASHSCOPEAPIKEY=sk-your-key-here)的 .env 文件,并指导用户从 QwenCloud 控制台 替换为实际密钥。仅在用户明确要求时才写入实际的密钥值。
密钥兼容性
脚本需要标准的 QwenCloud API 密钥(sk-...)。编码计划密钥(sk-sp-...)不能用于直接 API 调用——它们专为交互式编码工具(Cursor、Claude Code、Qwen Code)设计,在 QwenCloud API 端点上无法使用。脚本在启动时会检测 sk-sp- 密钥并打印警告。如果安装了 qwencloud-ops-auth,请参阅其 references/codingplan.md 了解密钥类型、端点映射和错误代码的详细信息。
模型选择
| 模型 | 用途 |
|---|
| qwen3.5-plus | 推荐默认值 — 性能、成本、速度均衡,100 万上下文 |
| qwen3.5-flash |
快速、低成本,100 万上下文 |
| qwen3-max | 最强能力 |
| qwen-plus | 通用用途 |
| qwen-turbo | 最便宜、低延迟 |
| qwen3-coder-next |
推荐代码模型 — 质量、速度、成本最佳平衡;智能体编码 |
| qwen3-coder-plus | 代码生成 — 复杂任务最高质量 |
| qwen3-coder-flash| 代码生成 — 快速响应,较低成本 |
| qwq-plus | 推理/思维链 |
| qwen-mt-plus | 机器翻译 — 最佳质量,92 种语言 |
| qwen-mt-flash | 机器翻译 — 快速、低成本,92 种语言 |
| qwen-mt-lite | 机器翻译 — 实时对话,最快,31 种语言 |
| qwen-plus-character-ja | 角色扮演 — 推荐用于新加坡 |
| qwen-plus-character | 角色扮演 — 角色还原,共情对话 |
| qwen-flash-character | 角色扮演 — 快速,较低成本 |
- 1. 用户指定了模型 → 直接使用。
- 当模型选择取决于需求、场景或定价时 → 咨询 qwencloud-model-selector 技能。
- 无明确指示,任务清晰 → qwen3.5-plus(默认)。
备用方案:如果模型选择器不可用,则应用上表中的默认值。
⚠️ 重要提示:以上模型列表是时间点快照,可能已过时。模型可用性会频繁变化。在做出模型决策之前,务必查看官方模型列表以获取权威、最新的目录。
执行
前提条件
- - API 密钥:使用非明文检查确认 DASHSCOPEAPIKEY(或 QWENAPIKEY)已设置(例如在 shell 中:[ -n $DASHSCOPEAPIKEY ];仅报告已设置或未设置,绝不输出密钥值)。如果未设置:运行 qwencloud-ops-auth 技能(如果可用);否则引导用户从 QwenCloud 控制台 获取密钥,并通过 .env 文件(在项目根目录或当前目录执行 echo DASHSCOPEAPI_KEY=sk-your-key-here >> .env)或环境变量进行设置。脚本会在当前工作目录和项目根目录中搜索 .env 文件。技能可能独立安装——不要假设 qwencloud-ops-auth 存在。
- Python 3.9+(仅使用标准库,脚本执行无需 pip 安装)
环境检查
首次执行前,确认 Python 可用:
bash
python3 --version # 必须是 3.9+
如果找不到 python3,请尝试 python --version 或 py -3 --version。如果 Python 不可用或低于 3.9,请跳转到 execution-guide.md 中的路径 2(curl)。
默认:运行脚本
脚本路径:脚本位于本技能目录(包含此 SKILL.md 的目录)的 scripts/ 子目录中。你必须首先找到本技能的安装目录,然后始终使用完整的绝对路径来执行脚本。 不要假设脚本在当前工作目录中。不要在执行前使用 cd 切换目录。
执行说明: 在前台运行所有脚本——等待标准输出;不要后台运行。
发现: 首先运行 python3 <本技能目录>/scripts/text.py --help 查看所有可用参数。
bash
python3 <本技能目录>/scripts/text.py \
--request {messages:[{role:user,content:你好!}],model:qwen3.5-plus} \
--output output/qwencloud-text/ --print-response
流式输出(推荐用于交互式使用):
bash
python3 <本技能目录>/scripts/text.py \
--request {messages:[{role:user,content:写一首关于大海的诗}],model:qwen3.5-plus} \
--stream --print-response
| 参数 | 描述 |
|---|
| --request {...} | JSON 请求体 |
| --file path.json |
从文件加载请求(--request 的替代方案) |
| --stream | 启用流式输出 |
| --output dir/ | 将响应 JSON 保存到目录 |
| --print-response | 将响应打印到标准输出 |
| --model ID | 覆盖模型(也可在请求 JSON 中设置) |
验证结果
- - 退出码 0 + 输出包含有效 JSON 且包含 choices 字段 → 成功
- 非零退出、HTTP 错误、空响应或包含 code/message 错误的 JSON → 失败
- 如果代理无法读取退出码,扫描输出中的错误模式(Error、Traceback、401、403)
- 执行后检查:使用 --output 时,确认响应 JSON 文件存在且包含 choices
- 强制 — 标准错误信号检查:确认结果后,扫描命令的标准错误输出中是否有 [ACTIONREQUIRED] 或 [UPDATEAVAILABLE]。如果存在任一信号,你必须在回复用户之前按照下方更新检查中的说明进行操作。
失败时
如果