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 |
|---|
| Default execution — chat/completions request, streaming, output save |
references/execution-guide.md
| Fallback: curl, Python SDK, function calling, thinking mode |
| API supplement and full code examples |
references/prompt-guide.md
| Prompt engineering: CO-STAR framework, CoT, few-shot, task steps |
| 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 (
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
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
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 (
). Coding Plan keys (
) 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
keys at startup and prints a warning. If qwencloud-ops-auth is installed,
see its
for details on key types, endpoint mapping, and error codes.
Model Selection
| Model | Use Case |
|---|
| Recommended default — balanced performance, cost, speed, 1M context |
| Fast, low-cost, 1M context |
| Strongest capability |
| General purpose |
| Cheapest, low latency |
| Recommended code model — best balance of quality, speed, cost; agentic coding |
| Code generation — highest quality for complex tasks |
| Code generation — fast responses, lower cost |
| Reasoning / chain-of-thought |
| Machine translation — best quality, 92 languages |
| Machine translation — fast, low cost, 92 languages |
| Machine translation — real-time chat, fastest, 31 languages |
| Role-playing — recommended for Singapore |
| Role-playing — character restoration, empathetic dialog |
| Role-playing — fast, lower cost |
- 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 → (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 (or ) 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 file
(echo 'DASHSCOPE_API_KEY=sk-your-key-here' >> .env
in project root or current directory) or environment variable.
The script searches for 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:
bash
python3 --version # must be 3.9+
If
is not found, try
or
. 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
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
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.
bash
python3 <this-skill-dir>/scripts/text.py \
--request '{"messages":[{"role":"user","content":"Hello!"}],"model":"qwen3.5-plus"}' \
--output output/qwencloud-text/ --print-response
For streaming (recommended for interactive use):
bash
python3 <this-skill-dir>/scripts/text.py \
--request '{"messages":[{"role":"user","content":"Write a poem about the sea"}],"model":"qwen3.5-plus"}' \
--stream --print-response
| Argument | Description |
|---|
| JSON request body |
| Load request from file (alternative to ) |
| Enable streaming output |
| Save response JSON to directory |
| Print response to stdout |
| Override model (also settable in request JSON) |
Verify Result
- Exit code + output contains valid JSON with field → success
- Non-zero exit, HTTP error, empty response, or JSON with / error → fail
- If agent cannot read exit codes, scan output for error patterns (, , , )
- Post-execution check: When is used, verify the response JSON file exists and contains
- MANDATORY — stderr signal check: After confirming the result, scan the command's stderr output for
or . 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 |
|---|
command not found: python3
| Python not on PATH | Try or ; install Python 3.9+ if missing |
| Script version check failed | Upgrade Python to 3.9+ |
| 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 : echo 'DASHSCOPE_API_KEY=sk-...' >> .env
; or run qwencloud-ops-auth if available |
| 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 env var |
| / | Network unreachable | Check internet; set if behind proxy |
| Rate limited | Wait and retry with backoff |
| Server error | Retry with backoff |
| Can't write output | Use to specify writable directory |
Quick Reference
Request Fields
| Field | Type | Description |
|---|
| / | string | array | User input or message list |
| string | Model ID (e.g. ) |
| string | System prompt (optional) |
| float | 0–2, controls randomness |
| int | Max output tokens |
| array | Function definitions for tool calling |
| bool | Enable streaming (recommended for interactive use) |
| bool | Enable thinking mode. Model defaults apply: / 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 |
|---|
| Generated text content |
| Model used |
| Token usage (prompt_tokens, completion_tokens) |
| Function call requests (if tools used) |
Advanced Features
These are API-level features supported through request parameters. All use the same
endpoint.
| Feature | How to Enable | Notes |
|---|
| Structured output | response_format: {"type": "json_schema", "json_schema": {...}}
| Force JSON output conforming to schema |
| Web search | | Real-time web search augmented responses |
| Deep thinking | | Extended reasoning; only when user requests it |
| Function calling | | Define functions for tool use |
| Context cache | Automatic for repeated prefixes; or explicit session-based | Reduces cost for repeated context |
| Partial mode | | 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 |
|---|
| Invalid or missing API key | Run qwencloud-ops-auth if available; else prompt user to set key (non-plaintext check only) |
| Rate limit exceeded | Retry with backoff |
| / / | Server error | Retry; check status page |
| Model ID not found | Verify model name against Model Selection table |
| Bad request body | Validate JSON and field types |
| 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
is used:
.
Write prohibition: NEVER write output files into this skill's installation directory or any
hierarchy. All generated content must go to
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.
- Install now — I'll run the install command for you
- Skip for now — do nothing this time
- Never remind me — permanently suppress this prompt
After the user responds:
- User chooses 1 → run:
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:
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
nor
, 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"):
- 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
- execution-guide.md — Fallback paths (curl, SDK, autonomous), function calling,
thinking mode
- api-guide.md — API supplementary guide with full code examples
- sources.md — Official documentation URLs