API setup
OpenAI-Compatible Chat API
Most OpenAI-compatible integrations need only three changes: API key, base URL, and model name. The hard part is choosing the correct plan and endpoint.
Who this is for
Developers migrating an existing OpenAI-style application.
Configuration reference
Values to confirm before setup
International / Singapore
https://dashscope-intl.aliyuncs.com/compatible-mode/v1
United States / Virginia
https://dashscope-us.aliyuncs.com/compatible-mode/v1
China / Beijing
https://dashscope.aliyuncs.com/compatible-mode/v1
China / Hong Kong
https://cn-hongkong.dashscope.aliyuncs.com/compatible-mode/v1
Token Plan Team Edition
https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1
Token Plan Anthropic-compatible
https://token-plan.ap-southeast-1.maas.aliyuncs.com/apps/anthropic
Setup flow
Practical steps
- 01Install or keep the OpenAI-compatible SDK.
- 02Set the API key in an environment variable.
- 03Replace the base URL with the correct Model Studio or Token Plan endpoint.
- 04Replace the model name with a supported Qwen/model identifier.
- 05Run non-streaming first, then enable streaming or tools if needed.
- 06Add error logging for 401, model-not-found, rate-limit, and quota errors.
The three values that must match
Most connection failures come from mixing a key, endpoint, and model from different plans or regions. Confirm the API key source first, then choose the matching base URL, then use a model name supported by that route.
- API key: Model Studio pay-as-you-go, Token Plan, and Coding Plan keys are not interchangeable.
- Base URL: region-specific endpoints are not universal.
- Model name: use the exact published model identifier, including suffixes such as qwen3.7-plus or glm-5.1 where required.
Security baseline
Use environment variables or an application secret manager. Do not paste production API keys into public code, screenshots, frontend JavaScript, or customer-facing support tickets.
SDK vs HTTP endpoint
SDK clients usually use a base URL ending in `/compatible-mode/v1`. Raw HTTP chat completions calls append `/chat/completions` to the endpoint.
Examples
Copy the structure, not the secrets
Node.js OpenAI-compatible client
ts
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.DASHSCOPE_API_KEY,
baseURL: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
});
const completion = await client.chat.completions.create({
model: "qwen3.7-plus",
messages: [{ role: "user", content: "Create a concise onboarding checklist." }],
});
console.log(completion.choices[0]?.message?.content);Common mistakes
Check these before escalating
- Do not mix Token Plan keys with pay-as-you-go endpoints.
- Some models support Responses API while others need Chat Completions.
- Tool clients may require a different protocol such as Anthropic-compatible.
Related guides
OpenAI-Compatible Responses API
Responses API is useful for newer agent-style clients and models that support the OpenAI Responses wire format. Confirm support before choosing it for a tool.
First Qwen API Call
A first API call needs an activated account, Model Studio API key, region-specific base URL, OpenAI SDK or HTTP client, and a model that is available in the chosen region.
Rate Limits and Quota Errors
Rate limits are calculated by account, model, and aggregate API-key usage. A customer quote should include traffic assumptions and an escalation path.
Codex
Configure Codex with Model Studio or Token Plan credentials, then verify the selected model before handing it to developers.