Draft
Call the Official Hosted Qwen3.8-27B API on Alibaba Model Studio
Task
What you will complete
Call the official hosted qwen3.8-27b API on Alibaba Cloud Model Studio in Beijing, stay on that model's own free quota with 免费额度用完即停 / Free Quota Only turned on, and extract five fields from a fixed pytest failure into JSON that a local checker can verify.
Success criteria
- extract_failure.py calls qwen3.8-27b on the Beijing hosted API (model ID qwen3.8-27b, not a Hugging Face or vendor name).
- The response can be parsed as JSON with test_name, file, line, expected, and actual.
- The script's local check passes against the fixture ground truth (test_invoice_total_in_usd in tests/test_billing.py, line 88, expected 1362.99, actual 1350.54), including after stripping a markdown fence if the model wraps the object.
What this is not
Not a local-install or GPU-box guide, not a third-party host walkthrough, and not a fine-tuning or batch path. Model Studio lists fine-tuning and batch as unsupported for qwen3.8-27b, and the free quota does not cover those products. If you already live on the international site, do not follow the Beijing steps and expect a China-site quota in Singapore.
Prerequisites
- A China-site (aliyun.com) Alibaba Cloud account with 实名认证 completed, and a key created in 华北2 / China (Beijing).
- Your Model Studio workspace ID, for the recommended Beijing compatible-mode/v1 base URL.
- 免费额度用完即停 (Free Quota Only) turned on for qwen3.8-27b before the first call.
- Python and the official openai package. requirements.txt is unpinned until a verified run exists.
Environment
- DASHSCOPE_API_KEY
- Beijing Model Studio API key from the same region as QWEN_BASE_URL
- QWEN_BASE_URL
- https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1
- QWEN_MODEL
- qwen3.8-27b (default in the example code)
The Hugging Face card for Qwen3.8-27B is a weight repository. Third-party hosts often want the same Hugging Face ID. This page is about a different path: Alibaba Cloud Model Studio already serves the open 27B model as a hosted API, under the ID qwen3.8-27b. You can do this without standing up a 27B box, and without an overseas company.
This quickstart uses the China site in Beijing, stays on that model’s own free quota, and finishes with a job you can check without trusting a fluent reply: extract five fields from a pytest failure and verify them locally.
What you need in hand:
- The model ID is
qwen3.8-27b. A Model Studio key will not acceptQwen/Qwen3.8-27B, andqwen3.6-27bis a different listing. - Work from aliyun.com, finish 实名认证 (real-name verification), and make the key in 华北2 / China (Beijing). That combination is the one you can complete from mainland China.
qwen3.8-27bcarries a separate 1,000,000-token allowance on the China site in Beijing, good for 90 days. It does not share that pool withqwen4-max. Input, output, and thinking tokens all draw from it. Before any call, enable 免费额度用完即停 — Free Quota Only in the English console. The control is off by default. Leave it off, and an exhausted quota flips to ordinary pay-as-you-go. Turn it on, and a request past the grant is refused instead.- Use
https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1with the OpenAI SDK. Docs still mention the older hosthttps://dashscope.aliyuncs.com/compatible-mode/v1as usable. - Thinking starts on. Disable it for the first request (
enable_thinking: false) so the allowance pays for the JSON you will check, not a hidden chain of thought. Then run the pytest extraction.
Numeric limits and response fields below were taken from official Model Studio pages retrieved on 2026-11-17 (Asia/Shanghai). This site has no live qwen3.8-27b transcript, no screenshot, and no measured latency or token count. Planned commands are marked as such.
No live run sits behind these commands yet
The companion script is in examples/. It passed python -m py_compile. It has not been executed against Model Studio.
When a section describes a response field, it cites the docs and calls the shape documented, not observed. A later revision will replace this banner with the run date, the SDK version, and the actual output.
Is this the same thing as running Qwen3.8-27B on your own machine?
No. This tutorial calls the official hosted API. It does not install the weights, start Ollama, or tune YaRN.
On Hugging Face, Qwen/Qwen3.8-27B is a 27-billion-parameter dense vision-language checkpoint. The card lists a native context of 262,144 tokens, extensible to 1,000,000 with RoPE scaling. Serving it yourself is a hardware and framework job. A later tutorial in this cluster may cover a local install; this one does not.
On Model Studio, the same generation is already a managed inference service. The official model page, read on 2026-11-17, lists a 1,000,000-token context window for qwen3.8-27b without asking you to pass engine flags. Maximum input is 991,808 tokens (983,616 in thinking mode). Maximum output is 131,072 tokens in either mode, with a separate chain-of-thought cap of 262,144 tokens. The page also lists image, text, and video input, text output, function calling, structured outputs, web search, prefix completion, and context caching. The capability table marks batch inference and fine-tuning as not available.
The Hugging Face card still mentions an official Qwen Cloud hosted service as “coming soon.” Model Studio’s newly released models list already added qwen3.8-27b on 2026-08-17. If you came here from the card, you do not have to wait on that line to make a Beijing API call.
Other companies also host this checkpoint, usually under Qwen/Qwen3.8-27B or a vendor-specific name, at their own prices and limits. Those are not this endpoint, and they are not this free quota. If your goal is the official Alibaba-hosted API, use Model Studio and the ID qwen3.8-27b.
Which model ID should you send?
qwen3.8-27b. Lowercase, with a dot after the 3, and no Qwen/ prefix.
That is the ID on the China-site pricing page, the model page, and the newly released models list. It is also the ID on the English Model Studio model card.
Two nearby strings are easy to paste by mistake:
| ID you might type | What it actually is |
|---|---|
qwen3.8-27b |
The hosted open-weight 27B model this tutorial uses. Listed on Model Studio on 2026-08-17. |
Qwen/Qwen3.8-27B |
The Hugging Face repo name, and the ID many third-party APIs expect. Official community write-ups about self-hosting also use this form, sometimes with chat_template_kwargs. A standard Model Studio key is not the place for that string. |
qwen3.6-27b |
An older open 27B listing. On the China-site pricing table, it has no Beijing free quota, and its list output price is not the same as qwen3.8-27b. |
If a 404 or ModelNotFound comes back, check this string before you debug the key or the URL.
The hosted model can do more than this quickstart uses. Function calling is listed as supported; a separate tutorial in this cluster already walks through tool calling with qwen4-max. This page stays on a single, checkable completion so you can confirm the hosted path works before you add tools, images, or search.
What should you turn on before the first Beijing call?
The distinctive move on this model is not “get some Qwen tokens.” It is “use this model’s unused allowance, and stop when that allowance ends.”
On the China site, only the Beijing region grants a new-user free quota. Open aliyun.com, finish 实名认证, then enter the 百炼 console as the primary account or as a RAM user with AliyunBailianFullAccess. Official docs say the first visit activates Model Studio; there is no package you have to purchase first. Stay in 华北2 / China (Beijing). A blue quota bar marks models that still have a grant, but the bar can lag by as much as two hours after activation.
Go to the Beijing free quota page and locate qwen3.8-27b. Switch on 免费额度用完即停. The same toggle exists on the model detail page and in the page’s batch control. Default is off. With it off, traffic past the grant is billed at list price without a prompt. With it on, a request past the grant is refused: HTTP 403, error code AllocationQuota.FreeTierOnly. English-language docs label the control Free Quota Only.
Next, open the Beijing API Key page, create a key, and copy the complete value from the dialog before it closes. Official docs say a newly issued key is shown in full only at creation time. Keys are regional. Official compatibility docs describe a Beijing key used against a Singapore or Virginia URL as HTTP 401, message Incorrect API key provided, code invalid_api_key — the key is fine, the region is not. From 业务空间详情 (the workspace details page), copy the workspace ID. That ID is the first label in the recommended host name.
Rules for this model’s grant, from pages read on 2026-11-17:
- The China-site pricing table gives
qwen3.8-27bits own 1,000,000 tokens in Beijing. Burning theqwen4-maxgrant does not touch this one, and the platform will not silently hop to a model that still has tokens. - The 90-day clock starts at the later of Model Studio activation, the model launch, or approval. Because Model Studio listed
qwen3.8-27bon 2026-08-17, an account that was already open on that day may have a clock that started then. Trust the expiry in the console, not a 90-day count from today. - One pool covers prompt tokens, answer tokens, and chain-of-thought tokens. The console shows a single remainder.
- Only real-time inference is covered. Batch, fine-tuning, and deployment are out of scope, and the model page already marks batch and fine-tuning as unsupported for
qwen3.8-27b. - The primary account and its RAM users share this model’s remainder. A second registration that uses the same real-name identity is documented as ineligible for another new-user grant.
- Dedicated Token Plan or Coding Plan keys are documented as bypassing the new-user grant. Use a regular Model Studio key if you want these free tokens.
The English international-site pages invert the region: they describe a 1,000,000-token grant in Singapore (International scope) and none elsewhere. That is the right reading if your account already lives on the international site. It is the wrong reading if you signed up on aliyun.com from mainland China. A China-site Beijing key does not inherit a Singapore allowance.
For the HTTP host, prefer the workspace domain:
https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1
The compatibility guide still treats https://dashscope.aliyuncs.com/compatible-mode/v1 as a working legacy entry, and the API key guide still hands that older host to third-party tools. The path you put in the SDK stops at /compatible-mode/v1. The client adds /chat/completions.
Watch for a typo that is still on the English overview. Retrieved on 2026-11-17, the English compatibility page lists ap-southeast-1 under the Beijing BASE_URL heading. The migration paragraph on that same page, plus the Chinese overview and the English Chat Completions reference, all name cn-beijing as the Beijing host. Follow those.
export DASHSCOPE_API_KEY="sk-..."
export QWEN_BASE_URL="https://<WorkspaceId>.cn-beijing.maas.aliyuncs.com/compatible-mode/v1"
export QWEN_MODEL="qwen3.8-27b"
To try the legacy host, point QWEN_BASE_URL at https://dashscope.aliyuncs.com/compatible-mode/v1 and keep using the Beijing key.
How do you make a first call you can check without trusting the model?
The task is deliberately small. The script sends a fixed pytest failure, asks for five JSON fields, and then checks those fields in Python. If the model wraps the object in markdown fences, the checker strips them. If a value is wrong, the script exits nonzero. You do not have to read the prose to know whether the call worked.
Install the official openai package. requirements.txt does not pin a version, because no verified run exists yet to pin against.
cd examples
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
extract_failure.py is an ordinary Chat Completions request. The values that belong to Model Studio are the key, the base URL, qwen3.8-27b, and enable_thinking. That last flag is not part of the public OpenAI schema, so the Python SDK takes it in extra_body.
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["DASHSCOPE_API_KEY"],
base_url=os.environ["QWEN_BASE_URL"],
)
completion = client.chat.completions.create(
model=os.environ.get("QWEN_MODEL", "qwen3.8-27b"),
messages=[
{
"role": "system",
"content": "You extract structured fields from test output. Reply with a JSON object only.",
},
{"role": "user", "content": user_prompt}, # full pytest fixture in extract_failure.py
],
extra_body={"enable_thinking": False},
)
print(completion.choices[0].message.content)
print(completion.usage)
The fixture is one failed test, test_invoice_total_in_usd in tests/test_billing.py. The assertion at line 88 expected 1362.99 and saw 1350.54. After the response arrives, the script compares test_name, file, line, expected, and actual with that ground truth.
Planned command. Not run for this draft.
python extract_failure.py
If you already use Codex or Grok Bot, you can paste the script there after the environment variables are set. This walkthrough does not depend on any other coding assistant account.
The same call as HTTP is in extract_failure.request.json. Planned command. Not run for this draft.
curl -sS "$QWEN_BASE_URL/chat/completions" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
--data-binary @extract_failure.request.json
Prefer the Python script when you want the local check. It sends the full traceback and compares the five fields. The curl command only prints the raw response, and it has not been run either.
Documented response shape, not observed output. The compatibility docs describe a standard chat.completion object: an assistant message under choices[0].message, a finish_reason of stop or length, and a usage object with prompt_tokens, completion_tokens, and total_tokens. Their sample payload was produced by a different model, so it is not copied here. The deep-thinking docs put the chain of thought in reasoning_content and leave the answer in content. This first request turns thinking off, and the local check reads content only.
Why can the first call cost more tokens than the answer looks?
Because thinking is on by default.
The official deep-thinking page lists qwen3.8-27b under the Qwen3.8 open-source series as hybrid thinking, with thinking enabled unless you disable it. The pricing table bills output as “chain of thought + answer” at the same yuan-per-million rate. Those thinking tokens still deduct from the shared 1,000,000-token free pool even when your code only prints message.content.
For a cheap, checkable first request, pass "enable_thinking": false. In the official Python SDK that parameter goes in extra_body. In a raw HTTP body it sits at the top level, next to model and messages.
Turn thinking back on when the task is worth it: harder reasoning, longer coding work, or cases where you want to inspect reasoning_content. The deep-thinking docs recommend streaming in that mode so you are not stuck waiting on a long silent request, and they suggest raising the client timeout if you keep a non-streaming call. This site has not verified whether qwen3.8-27b rejects non-streaming thinking requests. Some other open Qwen models do, with the message parameter.enable_thinking only support stream call. If you enable thinking and a non-streaming call fails, retry with stream=true.
This page does not tell you to send reasoning_effort or chat_template_kwargs to Model Studio. Those show up in self-hosting guides that use the Hugging Face model ID. The official Model Studio deep-thinking page discusses reasoning_effort for other models in the 3.8 family, such as qwen3.8-omni-flash. Until a Model Studio parameter table is checked against a live qwen3.8-27b call, treat enable_thinking as the switch this quickstart needs.
What is the Beijing list price once the million tokens are used up?
On the China-site pricing page, read on 2026-11-17, Beijing list prices for qwen3.8-27b are CNY 3 per million input tokens and CNY 12 per million output tokens, including thinking tokens. The same page lists implicit cache hits at CNY 0.6, explicit cache creation at CNY 3.75, and explicit cache hits at CNY 0.3, all per million tokens. The English model card prints USD figures for Beijing (0.424 input, 1.696 output) that match those yuan prices at the page’s conversion rate; this tutorial quotes the China-site yuan numbers.
Singapore, on that same China-site table, is listed at CNY 3.646 input and CNY 21.875 output, with no free quota on the China site. The international-site pricing page lists Singapore (International scope) at USD 0.50 input and USD 3.00 output, and it attaches a 1,000,000-token free quota to that deployment. Use the table that belongs to the site you signed up on.
A worked example, arithmetic only, at the Beijing list price: 20,000 input tokens and 2,000 output tokens with thinking off would be 20,000 × 3 / 1,000,000 + 2,000 × 12 / 1,000,000 = CNY 0.084. If thinking added 8,000 chain-of-thought tokens before a 2,000-token answer, output would be 10,000 tokens and the same input would be CNY 0.18. No one has measured a real bill for this tutorial.
Rate limits in Beijing are documented as dynamic. TPM is tiered by monthly Model Studio spend; the model page says the RPM ceiling is high enough that ordinary use should not hit it. This site has not recorded a 429 from qwen3.8-27b.
Which mistakes usually waste the first call?
- The model ID is a Hugging Face or vendor name.
Qwen/Qwen3.8-27Bis correct for the weight repo and for some third-party APIs. Model Studio wantsqwen3.8-27b.qwen3.6-27bis a different listing. - The English Beijing base URL is copied from the typo. If the host says
ap-southeast-1and the key was created in Beijing, expect a region-mismatch failure. Usecn-beijing. - The key and the URL come from different regions. Official docs describe a Beijing key on a Singapore or Virginia URL as HTTP 401,
Incorrect API key provided, codeinvalid_api_key. - 免费额度用完即停 is still off. The first surprise is not an error. It is a bill. Turn the switch on before you loop a script.
- Thinking is left on for a short extraction. The printed answer can look tiny while
completion_tokensincludes a longreasoning_content. Setenable_thinkingtofalsefor this check, then turn it on when you need it. - The grant is not visible yet, or it already expired. New activations can take up to two hours. The 90-day window can start on the model’s listing date rather than on your first call. If the console shows no blue bar for
qwen3.8-27b, do not keep retrying in the hope that another model will donate tokens. - The checker fails because the model wrapped the JSON in fences, or added a key. The script strips a single markdown fence. It does not guess at renamed fields. Adjust the prompt, or fix the parse, rather than skipping the local check.
- A Token Plan or Coding Plan key is used in place of the regular key. Those dedicated keys are documented as not consuming the new-user free quota.
When is this the wrong tool?
Skip this hosted path if you need to fine-tune the 27B weights, run batch jobs, or keep every token on a machine you own. Model Studio lists fine-tuning and batch as unsupported for qwen3.8-27b, and the free quota does not cover those products in any case.
If you already live on the international site, do not follow the Beijing steps above and then expect a China-site quota to appear in Singapore. Use the English free-quota page and a Singapore workspace URL instead.
If the job is a multi-step tool loop on the flagship hosted model, the Qwen4-Max tool-calling tutorial in this same cluster is the better starting point. Come back here when you specifically want the open 27B API.
How this page will be marked verified later
Verification needs a China-site Beijing key, 免费额度用完即停 enabled for qwen3.8-27b, and one extract_failure.py run whose local check passes. Until that exists, treat every command and every response field on this page as documented, not observed.
Sources
All of the following were read on 2026-11-17 (Asia/Shanghai):
- qwen3.8-27b model page and the English model card: model ID, modalities, context and output limits, Beijing and Singapore prices, dynamic rate limits, no batch and no fine-tuning.
- 模型调用价格: Beijing CNY 3 / 12 list price, 1,000,000-token free quota, Singapore CNY prices with no China-site free quota, and the note that only Beijing has a free quota on the China site.
- 新人免费额度 and the English free-quota article: how long the grant lasts, the per-model pools, 用完即停 / Free Quota Only, 实名认证, and why China-site Beijing is not the same deal as international-site Singapore.
- 模型上架与更新:
qwen3.8-27blisted on 2026-08-17. - OpenAI Chat接口兼容, the English compatibility overview, and OpenAI compatible Chat Completions: workspace and legacy hosts, the English Beijing typo, region-bound keys, and the documented
chat.completionshape. - 深度思考: hybrid thinking, default on for
qwen3.8-27b,enable_thinking,reasoning_content, and the streaming recommendation. - 获取与配置 API Key: how a Beijing key is issued, and the older dashscope compatible-mode URL the tools section still prints.
- 错误码: 401 region mismatch, and
AllocationQuota.FreeTierOnly. - Qwen/Qwen3.8-27B: open weights, native 262,144-token context, and the “coming soon” hosted-service note on the card.
Title tag: Call the Hosted Qwen3.8-27B API on Alibaba Model Studio
Meta description: Call Alibaba Model Studio’s hosted qwen3.8-27b API from Beijing, stay on that model’s own free quota with stop-when-exhausted on, and extract a pytest failure into JSON you can check locally. Drawn from official documentation; no live run yet.
Slug: qwen3.8-27b-hosted-api-quickstart
Evidence it actually ran
This is the shape of the stamp. It has not been earned, and the example date that follows is a placeholder, not a run: Ran on YYYY-MM-DD (Asia/Shanghai) with the pinned versions.
- Command output
- None recorded. A verified revision will quote the output from the run, not a sample written in advance.
- Tests, CI, or Inspector
- Not run for this draft.
- Repository or config
- No link recorded.
Failure modes
Anticipated only. None of these has been checked against a run of this tutorial.
Unchecked
The model ID is a Hugging Face or vendor name
Qwen/Qwen3.8-27B is correct for the weight repo and for some third-party APIs. Model Studio wants qwen3.8-27b. qwen3.6-27b is a different listing.
Unchecked
The English Beijing base URL is copied from the typo
If the host says ap-southeast-1 and the key was created in Beijing, expect a region-mismatch failure. Use cn-beijing.
Unchecked
The key and the URL come from different regions
Official docs describe a Beijing key on a Singapore or Virginia URL as HTTP 401, Incorrect API key provided, code invalid_api_key.
Unchecked
免费额度用完即停 is still off
The first surprise is not an error. It is a bill. Turn the switch on before you loop a script.
Unchecked
Thinking is left on for a short extraction
The printed answer can look tiny while completion_tokens includes a long reasoning_content. The script sets enable_thinking to false for this check.
Unchecked
The grant is not visible yet, or it already expired
New activations can take up to two hours. The 90-day window can start on the model's listing date rather than on your first call. If the console shows no blue bar for qwen3.8-27b, do not keep retrying in the hope that another model will donate tokens.
Unchecked
The checker fails because the model wrapped the JSON in fences, or added a key
The script strips a single markdown fence. It does not guess at renamed fields. Adjust the prompt, or fix the parse, rather than skipping the local check.
Unchecked
A Token Plan or Coding Plan key is used in place of the regular key
Those dedicated keys are documented as not consuming the new-user free quota.
Related
Other tutorials in Integrate.
Connect a Local MCP Server to Cursor and Use It to Finish a Real Repo Task
Start a local MCP server, connect it in Cursor, and complete a repo task that requires that tool.
Not yet verified
1 min read
Add a Second Frontier Model to Claude Code with a Documented Fallback Path
Configure a second model and complete the same task via the fallback after a simulated failure.
Not yet verified
1 min read
Build a TypeScript MCP Server for a Real API, Test It with Inspector, and Call It from Claude Code
Implement the server, pass Inspector, then call it from Claude Code to finish a real API task.
Not yet verified
1 min read
Call Qwen4-Max Through the OpenAI-Compatible API and Finish a Tool-Calling Task
Call qwen4-max from the OpenAI SDK on Alibaba Cloud Model Studio in Beijing by changing only api_key, base_url, and model, stay on that model's official free quota with 免费额度用完即停 / Free Quota Only turned on, then finish a tool-calling job: a checked dependency report for an npm project.
Not yet verified
15 min read