Call Qwen3.7 Plus with the OpenAI SDK via DashScope Compatible Mode
July 23, 2026 · 25 min read · Claude / GPT / Gemini

Qwen3.7 Plus is cheap enough to test seriously: as of July 23, 2026, Qwen Cloud lists qwen3.7-plus at $0.40 per 1M input tokens and $1.60 per 1M output tokens up to 256K input tokens, then $1.20 input and $4.80 output from 256K to 1M (Qwen Cloud pricing). That is the main reason this port is worth doing before you rewrite anything.
The useful part is the API shape. Qwen Cloud documents an OpenAI-compatible Chat Completions endpoint at:
https://dashscope-intl.aliyuncs.com/compatible-mode/v1
Its own migration page says existing OpenAI SDK code can switch by changing base_url, api_key, and model, and its examples use model="qwen3.7-plus" (Qwen Cloud OpenAI compatibility). That means most chat apps, eval scripts, small agents, and internal tools can be ported in minutes. The parts that need care are thinking parameters, ignored OpenAI fields, long-context pricing, and cache behavior.

1. Set Up the Client
Install the official OpenAI Python SDK:
python -m pip install --upgrade openai
Set your DashScope key:
export DASHSCOPE_API_KEY="sk-your-dashscope-key"
Then make the smallest possible Chat Completions call:
# qwen_chat.py
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["DASHSCOPE_API_KEY"],
base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
model="qwen3.7-plus",
messages=[
{"role": "system", "content": "You are a concise senior Python engineer."},
{"role": "user", "content": "Write a Python function that chunks a list into size-n batches."},
],
temperature=0.2,
)
print(completion.choices[0].message.content)
print(completion.usage)
Run it:
python qwen_chat.py
The same pattern works in Node. Qwen Cloud’s quick migration page shows baseURL: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1" with model: "qwen3.7-plus" for the JavaScript SDK too (Qwen Cloud OpenAI compatibility).
If you maintain code that switches across providers, keep the provider settings outside the call site:
PROVIDERS = {
"qwen": {
"api_key_env": "DASHSCOPE_API_KEY",
"base_url": "https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
"model": "qwen3.7-plus",
}
}
def make_client(provider_name: str) -> tuple[OpenAI, str]:
cfg = PROVIDERS[provider_name]
return (
OpenAI(
api_key=os.environ[cfg["api_key_env"]],
base_url=cfg["base_url"],
),
cfg["model"],
)
The OpenAI SDK itself supports base_url, custom timeouts, retries, and raw response access; its README documents automatic retries for connection errors, 408, 409, 429, and 500-level errors, plus max_retries and timeout options (openai-python).
2. Port the Parameters, Not Just the URL
The happy path is easy. The rough edges are parameter differences.
Qwen Cloud says the Chat Completions API is largely compatible with OpenAI’s Chat API, but Qwen-specific parameters must be passed through extra_body in the Python SDK (Qwen Cloud OpenAI compatibility). That matters for thinking, search, and some sampling controls.
Example with thinking enabled:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["DASHSCOPE_API_KEY"],
base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
)
stream = client.chat.completions.create(
model="qwen3.7-plus",
messages=[
{"role": "user", "content": "Find the bug in this retry loop and explain the fix."}
],
extra_body={
"enable_thinking": True,
"thinking_budget": 500,
},
stream=True,
)
for chunk in stream:
if not chunk.choices:
continue
delta = chunk.choices[0].delta
if getattr(delta, "reasoning_content", None):
print(delta.reasoning_content, end="", flush=True)
if getattr(delta, "content", None):
print(delta.content, end="", flush=True)
Qwen’s thinking guide says enable_thinking turns on reasoning for hybrid models, thinking_budget caps thinking tokens, and thinking tokens are billed as output tokens (Qwen Cloud thinking). That last point is the one developers miss. A model that thinks for 2,000 tokens before writing a 300-token answer is not a 300-token output call.
Also check unsupported OpenAI fields before porting production code. Qwen Cloud says fields including reasoning_effort, max_completion_tokens, metadata, store, verbosity, prompt_cache_key, and several others are silently ignored in Chat Completions compatible mode (Qwen Cloud OpenAI compatibility). If your OpenAI app depends on one of those fields for cost control or product behavior, replace it explicitly.
3. Price the Long Context Before You Send It
The qwen3.7-plus price break is simple, but it has teeth.
| Input tokens in one request | Input price / 1M | Output price / 1M |
|---|---|---|
| ≤ 256K | $0.40 | $1.60 |
| 256K to 1M | $1.20 | $4.80 |
Source: Qwen Cloud pricing.
The model marketplace page for the May 26 snapshot lists qwen3.7-plus-2026-05-26 as a text, image, and video input model with text output, and identifies it as a May 26, 2026 snapshot (Qwen Cloud model page). The Qwen Cloud changelog separately lists qwen3.7-plus and qwen3.7-plus-2026-05-26 under June 1, 2026, describing the Plus series as adding upgraded vision-language abilities while keeping coding, tool use, and productivity workflows (Qwen Cloud model releases).
For product code, add a preflight estimator. You do not need perfect tokenization to prevent accidental 900K-token calls from landing in the expensive tier.
def estimate_qwen37_plus_cost(input_tokens: int, output_tokens: int) -> float:
if input_tokens <= 256_000:
input_per_m = 0.40
output_per_m = 1.60
else:
input_per_m = 1.20
output_per_m = 4.80
return (input_tokens / 1_000_000 * input_per_m) + (
output_tokens / 1_000_000 * output_per_m
)
print(estimate_qwen37_plus_cost(180_000, 4_000)) # 0.0784
print(estimate_qwen37_plus_cost(400_000, 4_000)) # 0.4992
That second call is not just “a bit more context.” It crosses a tier boundary.

4. Use Cache When Prefixes Repeat
Context caching is where Qwen can get materially cheaper for repeated long prompts. Qwen Cloud documents three cache modes: explicit, implicit, and session cache (Qwen Cloud context cache).
The billing rules are concrete:
| Cache mode | Create cost | Hit cost | Minimum cached tokens |
|---|---|---|---|
| Explicit cache | 125% of standard input | 10% of standard input | 1,024 |
| Implicit cache | 100% of standard input | 20% of standard input | 256 |
| Session cache | 125% of standard input | 10% of standard input | 1,024 |
For qwen3.7-plus at the ≤256K tier, that maps to $0.08 per 1M implicit-cache hit tokens, $0.50 per 1M explicit-cache creation tokens, and $0.04 per 1M explicit-cache read tokens on the model page (Qwen Cloud model page).
Use cache for stable prefixes: policy documents, long system prompts, tool manuals, schemas, or repo summaries. Do not expect it to rescue prompts where every request starts differently. Qwen Cloud also states Batch and cache discounts cannot be combined on the same request (Qwen Cloud pricing).
5. Production Checklist and a Gateway Option
Before you swap traffic, test these cases:
- Basic non-streaming chat.
- Streaming chat.
- Thinking mode with
extra_body. - Tool calling if your app uses functions.
- JSON output, remembering Qwen compatible mode supports
json_object, not OpenAIjson_schema. - Long prompts near 256K input tokens.
- Cache-heavy repeated-prefix calls.
- Retries and timeout behavior.
For fallback routing across model families, onehop is the easy path. Change one OpenAI SDK base URL to https://api.onehop.ai/v1 and use one gateway for GPT, Claude, Gemini, and other models. OneHop documents OpenAI-compatible https://api.onehop.ai/v1, Anthropic-compatible https://api.onehop.ai/anthropic, and Vertex/Gemini-compatible https://api.onehop.ai/vertex-ai endpoints (onehop docs). It is also positioned as cheaper than first-party, and new accounts get $10 free with no card required.
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["ONEHOP_API_KEY"],
base_url="https://api.onehop.ai/v1",
)
response = client.chat.completions.create(
model="openai/gpt-5.5",
messages=[{"role": "user", "content": "Summarize this incident report in 5 bullets."}],
)
print(response.choices[0].message.content)
That does not replace the Qwen-specific work above. It gives you a cleaner route when your app needs Claude for one workflow, GPT for another, and Gemini for multimodal tests without wiring three billing systems and three SDK configurations. Start here to call Claude and other models on onehop, or sign up for $10 free credit.
6. The Practical Port
The port is three lines until it is not: base_url, api_key, model. After that, the real work is removing ignored OpenAI parameters, moving Qwen controls into extra_body, and putting hard guards around long context.
Use qwen3.7-plus when you want a balanced cost model with long context and multimodal input support. Keep thinking off for simple extraction and classification. Turn it on for code review, tool orchestration, or multi-step reasoning, with a thinking_budget so costs do not drift. Cache stable prefixes. Watch the 256K tier boundary.
For teams that also need Claude, GPT, or Gemini in the same product, keep a gateway path ready: call Claude and other models on onehop, then sign up for $10 free credit when you want to run real smoke tests without adding a card.
Related reading

Use Groq GPT-OSS 120B with the OpenAI SDK: Base URL, Pricing, and Caching
Swap one OpenAI SDK base URL to run GPT-OSS 120B on Groq, estimate cached token costs, and avoid tool billing surprises.
June 17, 2026 · 24 min read

Calling the Gemini API with the OpenAI SDK: A Migration Guide Changing Only base_url, API Key, and Model Name
A Gemini-compatible API migration checklist for existing OpenAI SDK projects, with code, parameter mapping, and pricing.
June 14, 2026 · 9 min read

Calling the Gemini API with the OpenAI SDK: An Integration Guide Requiring Only base_url, Key, and Model Name Changes
Connect existing OpenAI SDK code to Gemini with minimal changes to just three configuration fields.
June 14, 2026 · 9 min read