- Qwenapidocumentation
- Qwen 3 API Documentation: Call It via OpenAI Client
Qwen 3 API Documentation: Call It via OpenAI Client
Qwen 3 API documentation for hosted endpoints usually describes the OpenAI chat format. That means a standard OpenAI client can talk to such endpoints, and to compatible hosts, with a changed base URL. Below is a working Python and curl example with streaming and a system prompt.

Straight to the code
This is the shortest working call against our endpoint. It is an independent OpenAI-compatible host running one open-weight model, exposed as the model ID uncensored. It is not the official Qwen API and does not claim to be a specific Qwen release, so use it to test the integration pattern, then swap values if you move to a vendor's endpoint.
from openai import OpenAI
client = OpenAI(
base_url="https://api.qwenapidocumentation.com/v1",
api_key="YOUR_KEY",
)
response = client.chat.completions.create(
model="uncensored",
messages=[
{"role": "system", "content": "You are a calm assistant. Answer in plain language."},
{"role": "user", "content": "What is a context window?"},
],
temperature=0.7,
)
print(response.choices[0].message.content)
print(response.usage)
Install the client first with pip install openai. Get a key on the API key page; new users can claim $0.50 of trial credit with one click, valid for 7 days and no card needed.
The same call in curl
curl https://api.qwenapidocumentation.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [
{"role": "system", "content": "You are a calm assistant. Answer in plain language."},
{"role": "user", "content": "What is a context window?"}
],
"temperature": 0.7
}'
Curl is the best debugging tool when an SDK call fails, because it shows the exact request. If curl works and your code does not, the bug is in your client setup, usually the base URL.
Streaming the answer
For chat interfaces you want tokens as they are produced. Set stream=True and iterate over the chunks:
from openai import OpenAI
client = OpenAI(
base_url="https://api.qwenapidocumentation.com/v1",
api_key="YOUR_KEY",
)
stream = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Write a four-line poem about a night train."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
print()
Streaming uses server-sent events, and usage is reported at the end of the stream. Remember that a streamed request keeps its concurrency slot until the last chunk arrives, so a full key's 8 concurrent requests include open streams that your UI has not finished reading. In Node the call is the same shape, with stream: true and a for await loop over the result.
Using the system prompt well
The system message sets role, tone and constraints for the whole conversation. A few habits make it work better:
- State the job in the first sentence: "You are an editor for short fiction."
- List constraints as short rules, such as length, language and format.
- Put stable instructions in the system message and the changing task in the user message.
- Resend the system message on every call. The API keeps no state between requests.
Because the system prompt is billed as input on every call, a 500-token prompt sent 10,000 times is 5,000,000 input tokens, or $0.75 at $0.15 per 1M. That is small, but a 5,000-token prompt at the same volume is $7.50, which is why long boilerplate deserves a trim.
For multi-turn chat, append each assistant reply to the list before the next user message:
from openai import OpenAI
client = OpenAI(base_url="https://api.qwenapidocumentation.com/v1", api_key="YOUR_KEY")
history = [{"role": "system", "content": "You are a calm assistant."}]
def chat(text):
history.append({"role": "user", "content": text})
r = client.chat.completions.create(model="uncensored", messages=history)
reply = r.choices[0].message.content
history.append({"role": "assistant", "content": reply})
return reply
With a 100,000-token window you have plenty of room, but long histories cost more input tokens per turn, so summarize old turns once a chat grows.
The same call in Node
If your stack is JavaScript, the shape is identical. Install the package with npm install openai.
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.qwenapidocumentation.com/v1",
apiKey: process.env.API_KEY,
});
const stream = await client.chat.completions.create({
model: "uncensored",
messages: [
{ role: "system", content: "You are a calm assistant." },
{ role: "user", content: "Give me three names for a lighthouse cat." },
],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
The key comes from an environment variable so it never lands in your source. If the call fails with 401, the key is wrong or missing. With 404, check that the base URL ends in /v1 and has no extra path. With 429, you have crossed a rate or concurrency limit and should retry after a short wait.
Adding JSON output
When the answer must be machine-readable, add response_format: {"type": "json_object"} and ask for JSON in the prompt. Parse the result in a try block, since any model can occasionally return malformed output. The same option works in Python as response_format={"type": "json_object"}.
Mistakes that break a first call
Most failed first calls come from a short list of setup errors. Check these before you suspect the service.
- Wrong base URL shape. The base URL ends at
/v1. If you paste the full/v1/chat/completionspath intobase_url, the client appends the path again and you get a 404. - A stale key in the environment. The OpenAI client falls back to
OPENAI_API_KEYwhen you do not passapi_key. If that variable holds a key from another provider, you get a 401. Passingapi_keyexplicitly removes the ambiguity. - A default model name. Some wrappers send a model name of their own. Set
model="uncensored"in every call. - Reading an empty chunk. In a stream, a chunk can arrive without choices or without text. The streaming example above guards for both, and your code should too.
- Short timeouts. A long completion can take a while. The Python client accepts a
timeoutargument, for exampleOpenAI(base_url=..., api_key=..., timeout=120), so a slow reply is not cut off by a default setting. - Setting both temperature and top_p. Change one at a time, so you can tell which setting changed the output.
When something still fails, send the same request with curl. If curl works, the problem is in your client code. If curl fails too, read the status code: 401 is the key, 404 is the path, 429 is a limit. The X-Request-Id response header identifies a call if you need to ask for help through the support page.
What to check in any provider's Qwen 3 docs
Whichever provider you use, answer these questions from their documentation before you ship.
- Exact model string. Is it a base model, an instruct model, or a specific size? Names are case-sensitive.
- Thinking mode. Check whether the model has a reasoning (thinking) mode that can be turned on or off, and find out how the provider exposes it: whether reasoning tokens are billed as output, and whether they appear in the reply text.
- Context and output caps. Look for both numbers. On our endpoint the window is 100,000 tokens for prompt plus completion, and
max_tokensis optional. - Supported fields. Confirm tool calling, JSON mode and the sampling parameters you rely on. Ours supports tools,
tool_choice,response_formatwith json_object, temperature, top_p, stop, seed and the penalties. - Rate limits. We allow 8 concurrent requests and 300 per minute on a full key, 2 and 60 on a trial key. A 429 with code
rate_limitedorconcurrencytells you which cap you hit. - Price per 1M tokens. Ours is $0.15 input and $0.50 output. For other vendors, check their current pricing.
- Data handling. We do not use prompts for training. Ask the same question of any provider you evaluate.
Next steps
If the test call works, wire up error handling and retries. A 429 with a Retry-After: 5 header means temporary overload: wait five seconds and try again. Read the docs for the full parameter list and the pricing page for top-ups, which run from $20 to $500, with bonuses from $50. For a broader view of where the vendor docs, the open weights and hosted alternatives sit, see our overview of Qwen API documentation and alternatives.
More guides
FAQ
Can I call Qwen 3 with the OpenAI Python library?
Yes, if the provider offers an OpenAI-compatible endpoint. Set the base URL, API key and model ID in the client and use the normal chat completions call.
Is the uncensored model ID Qwen 3?
We do not present it as any specific vendor release. It is one open-weight model run by an independent provider, and it is not the official API of Qwen or any other vendor.
How do I get a streaming response?
Pass stream set to true and iterate over the chunks, printing each delta. Token usage arrives at the end of the stream.
What does a 429 error mean here?
You hit a cap. The code rate_limited means too many requests per minute, concurrency means too many at once, and a Retry-After of 5 seconds means temporary overload.
Get your API key
Register, retrieve the key, update your base URL. Done.
Start with free credit
Sign up with email, get key instantly.
Key points
- Qwen 3 hosted APIs commonly follow the OpenAI chat completions format.
- You need three settings: base URL, key and model ID.
- Streaming and a system prompt take a few extra lines of code.
- Check thinking mode, context and output limits in any provider's docs.