DEV Community

Cover image for How to Use the Qwen 3.8 API
Hassann
Hassann

Posted on • Originally published at apidog.com

How to Use the Qwen 3.8 API

Alibaba released Qwen 3.8-Max in early August 2026, and its hosted API is live on Model Studio. The model provides 2.4T total parameters (95B active), a 1M-token context window, and flat pricing of $2 input / $6 output per million tokens. For model background, see the Qwen 3.8 explainer. This guide focuses on implementation: creating a key, selecting a region, making API calls, streaming responses, and testing both supported protocols.

Try Apidog today

Qwen 3.8-Max supports two protocols from launch:

  • OpenAI-compatible chat completions and responses endpoints
  • Anthropic-compatible Messages endpoint

That means existing OpenAI SDK integrations can use the model with a base URL change, while Claude Code can connect through environment variables. You can also test both request formats in Apidog and inspect their streaming behavior.

What you need before you start

Item Value
Model ID qwen3.8-max
Context window 1,000,000 tokens
Max output 65,536 tokens
Input types Text and images
Pricing $2 input / $6 output per 1M tokens, flat across the full context
Reasoning control reasoning_effort: xhigh (default), medium, low
Protocols OpenAI chat completions + responses, Anthropic Messages
Key environment variable DASHSCOPE_API_KEY

These details come from the official Qwen 3.8 release post and Alibaba Cloud Model Studio documentation. Alibaba promised open weights on Hugging Face and ModelScope for the following week, but as of early August 2026 they were not downloadable. This guide uses the hosted API.

Step 1: Create a Model Studio API key

Open home.qwencloud.com, sign in, and create an API key in the console.

Model Studio still uses the DashScope naming convention internally, so export your key as DASHSCOPE_API_KEY:

export DASHSCOPE_API_KEY="sk-your-key-here"
Enter fullscreen mode Exit fullscreen mode

Store the value in your shell profile, CI secret store, or .env file. Do not commit it to source control.

All examples below read from this environment variable.

New users can test with a free quota of 1M tokens for 90 days. The quota is available only in the Singapore region.

Step 2: Select a regional base URL

The OpenAI-compatible API is available in three regions. Use the endpoint closest to your application servers.

Region Base URL
Beijing https://dashscope.aliyuncs.com/compatible-mode/v1
Singapore https://dashscope-intl.aliyuncs.com/compatible-mode/v1
US (Virginia) https://dashscope-us.aliyuncs.com/compatible-mode/v1

For most international users, Singapore is the default choice:

https://dashscope-intl.aliyuncs.com/compatible-mode/v1
Enter fullscreen mode Exit fullscreen mode

It is also the endpoint that supports the free quota. The Model Studio model list lists qwen3.8-max for text generation plus image and video understanding.

The examples below use Singapore. Replace the base URL if your workload belongs in Beijing or Virginia.

Step 3: Send your first request

Qwen 3.8-Max supports the OpenAI chat completions format. You can use the official openai Python SDK by setting a DashScope-compatible base URL.

Install the SDK:

pip install openai
Enter fullscreen mode Exit fullscreen mode

Then create a request:

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
)

completion = client.chat.completions.create(
    model="qwen3.8-max",
    messages=[
        {"role": "system", "content": "You are a precise technical assistant."},
        {
            "role": "user",
            "content": "Explain idempotency in REST APIs in two sentences.",
        },
    ],
)

print(completion.choices[0].message.content)
Enter fullscreen mode Exit fullscreen mode

The equivalent cURL request is:

curl https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3.8-max",
    "messages": [
      {
        "role": "user",
        "content": "Explain idempotency in REST APIs in two sentences."
      }
    ]
  }'
Enter fullscreen mode Exit fullscreen mode

If you already use an OpenAI-compatible provider, migration is mostly:

  1. Change base_url.
  2. Change the model ID to qwen3.8-max.
  3. Verify provider-specific parameters before production rollout.

The workflow is the same as in the Qwen 3.7 Plus API guide.

Step 4: Stream output and handle reasoning deltas

Qwen 3.8-Max reasons by default. When streaming is enabled, reasoning arrives in reasoning_content deltas before the final answer arrives in normal content deltas.

Your stream consumer should handle both fields:

stream = client.chat.completions.create(
    model="qwen3.8-max",
    messages=[
        {
            "role": "user",
            "content": "Design a rate limiting strategy for a public API.",
        }
    ],
    stream=True,
)

thinking_done = False

for chunk in stream:
    delta = chunk.choices[0].delta
    reasoning = getattr(delta, "reasoning_content", None)

    if reasoning:
        print(reasoning, end="", flush=True)
    elif delta.content:
        if not thinking_done:
            print("\n--- answer ---")
            thinking_done = True

        print(delta.content, end="", flush=True)
Enter fullscreen mode Exit fullscreen mode

Implementation notes:

  • Reasoning tokens are billed as output tokens.
  • Reasoning output can increase latency in interactive interfaces.
  • Do not assume every stream delta contains content.
  • Persist or display reasoning only if it is appropriate for your product and users.

Step 5: Control reasoning_effort and thinking behavior

The API supports three reasoning_effort values:

Value Typical use
xhigh Hard analysis, agentic coding, complex planning
medium Balanced default for mixed workloads
low Classification, extraction, high-volume simple requests

The default is xhigh.

Qwen also supports:

  • enable_thinking: enable or disable reasoning
  • preserve_thinking: preserve reasoning context across turns; enabled by default

Pass these DashScope-specific extensions through extra_body when using the OpenAI SDK:

completion = client.chat.completions.create(
    model="qwen3.8-max",
    messages=[
        {
            "role": "user",
            "content": "Classify this ticket: 'Login page 500s on Safari.'",
        }
    ],
    extra_body={
        "reasoning_effort": "low",
        "enable_thinking": True,
    },
)

print(completion.choices[0].message.content)
Enter fullscreen mode Exit fullscreen mode

Thinking-enabled and thinking-disabled requests use the same per-token pricing. The practical cost difference comes from the number of generated reasoning tokens, which is influenced by reasoning_effort.

A useful starting policy:

  • Use xhigh for coding agents and difficult analysis.
  • Use low for extraction, routing, classification, and high-volume endpoints.
  • Use medium while benchmarking uncertain workloads.

Measure output tokens, latency, and quality on your own prompts before selecting a default.

Use the Anthropic-compatible endpoint

Qwen 3.8-Max also exposes an Anthropic-compatible endpoint:

https://dashscope-intl.aliyuncs.com/apps/anthropic
Enter fullscreen mode Exit fullscreen mode

It uses the Anthropic Messages format, allowing tools built for that ecosystem to connect without rewriting clients.

For Claude Code, configure these environment variables:

export ANTHROPIC_BASE_URL=https://dashscope-intl.aliyuncs.com/apps/anthropic
export ANTHROPIC_AUTH_TOKEN=$DASHSCOPE_API_KEY
export ANTHROPIC_MODEL=qwen3.8-max
Enter fullscreen mode Exit fullscreen mode

After exporting them, launch:

claude
Enter fullscreen mode Exit fullscreen mode

Claude Code will run its agentic workflow against Qwen 3.8-Max.

Alibaba used the Claude Code harness for most of its coding benchmarks, so this endpoint is more than a protocol adapter. For coding benchmark details and other supported harnesses, see the Qwen 3.8 for coding breakdown.

Dual protocol support is useful when your tooling is split across OpenAI- and Anthropic-style clients. You can evaluate Qwen without rewriting all clients before testing.

Understand the pricing model

Qwen 3.8-Max pricing is:

  • $2 per million input tokens
  • $6 per million output tokens
  • One flat price tier from 0 to 1M context tokens

There is no long-context surcharge in the listed pricing. Context cache hits reduce repeated input cost to 10% of the normal input price, while explicit cache creation is billed at 125%.

Check the official Model Studio pricing page for current values.

The launch price is lower than Qwen 3.7-Max's listed $2.5/$7.5 pricing. However, do not estimate cost using only visible final-answer tokens: reasoning tokens count as output, and the default effort level is xhigh.

For examples and free-quota details, see the Qwen 3.8 pricing breakdown.

Test and debug Qwen 3.8-Max in Apidog

A multi-region API with two protocols and SSE reasoning streams benefits from saved, repeatable requests. Set up Apidog as an evaluation workspace.

1. Add both protocol shapes

Create one request for the OpenAI-compatible endpoint:

POST /chat/completions
Enter fullscreen mode Exit fullscreen mode

Import an OpenAI-compatible specification if you already have one, then update the server URL.

Add the Anthropic Messages endpoint as a separate request in the same project. Keeping both formats together makes it easier to compare responses and validate migration paths.

2. Model regions as environments

Create environments for:

  • Beijing
  • Singapore
  • US-Virginia

For each environment, define:

base_url
DASHSCOPE_API_KEY
Enter fullscreen mode Exit fullscreen mode

Set base_url to the matching regional endpoint and store the key as a secret. Switching regions then becomes an environment change instead of a request edit.

Use this to compare latency from your deployment location before selecting a production region.

3. Inspect the raw SSE stream

Set streaming in the request body:

{
  "model": "qwen3.8-max",
  "stream": true,
  "messages": [
    {
      "role": "user",
      "content": "Design a rate limiting strategy for a public API."
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Inspect the raw server-sent events. You should see:

  1. reasoning_content deltas
  2. content deltas for the final answer

This is useful when a production stream parser fails. Compare the raw provider events with your application's parsed output to isolate whether the issue is in your code or upstream behavior.

4. Compare models with the same prompt

Duplicate a request and change only the model ID:

qwen3.8-max
qwen3.7-max
Enter fullscreen mode Exit fullscreen mode

Run both against the same prompts and record:

  • Latency
  • Input and output token counts
  • Reasoning length
  • Output quality
  • Tool or agent success rate

You can also keep a Kimi K3 API request in the same project and compare models using your actual workload rather than vendor benchmark tables.

Download Apidog to build the setup.

FAQ

Is there a free way to try the Qwen 3.8 API?

Yes. New Model Studio accounts receive a 1M-token free quota for qwen3.8-max, valid for 90 days in the Singapore region only.

Route evaluation requests through:

https://dashscope-intl.aliyuncs.com/compatible-mode/v1
Enter fullscreen mode Exit fullscreen mode

Can I run Qwen 3.8 locally instead of using the API?

Not yet, as of early August 2026. Alibaba promised open weights on Hugging Face and ModelScope for the following week, but they were not downloadable at that time.

At 2.4T total parameters, self-hosting would also require a multi-node deployment even with quantization. The hosted API is currently the available option.

Does the Anthropic endpoint support the same features as the OpenAI endpoint?

The Anthropic endpoint uses the Anthropic Messages protocol and is primarily documented for ecosystem tools such as Claude Code.

For direct application integrations, the OpenAI-compatible endpoint is the better-documented path for:

  • reasoning_effort
  • enable_thinking
  • Streaming reasoning_content

How does qwen3.8-max compare to Qwen3-Coder for coding?

They target different use cases.

Qwen3-Coder is a specialized coding model line. qwen3.8-max is the general flagship model and posted strong agentic coding results in Alibaba's vendor-run benchmarks, including 86.6 on Terminal Bench 2.1.

Test both with the same prompts, harness, and API settings. The request format is identical apart from the model ID.

Wrap up

Qwen 3.8-Max is straightforward to evaluate:

  1. Create a DASHSCOPE_API_KEY.
  2. Start with the Singapore endpoint and free quota.
  3. Use the OpenAI-compatible endpoint for direct application code.
  4. Stream requests and verify your handling of reasoning_content.
  5. Tune reasoning_effort based on measured latency, token use, and quality.
  6. Use the Anthropic-compatible endpoint when integrating Claude Code or related tooling.

The main operational considerations are reasoning-token output costs, the default xhigh effort level, and the regional restriction on the free quota.

Save both protocols and all regional environments in Apidog so your team can rerun the same evaluation whenever models or pricing change.

Top comments (0)