Install the Official SDK
Start by installing the official OpenAI Python SDK in your environment. This library handles the HTTP requests and JSON serialization for you.
- Run
pip install openaiin your terminal. - Ensure you are using a recent version of the library.
This single dependency gives you access to the standard client interface used across the industry.
Configure Base URL and Key
Point your client to our base URL and set your API key for authentication. This ensures all requests route to our uncensored model server.
Use https://api.qwenmaxapi.com/v1 as your base URL. Generate your key on the Get API key page via Google or email. The key is shown immediately after signup.
Send Your First Chat Completion
Send a simple text request to the /v1/chat/completions endpoint. The model returns unrestricted text based on your prompt.
Use the model ID uncensored. The API accepts standard parameters like temperature and top_p. You can adjust these to control creativity.
Enable Streaming and Handle Tokens
Enable streaming to receive tokens as they are generated. This reduces perceived latency for long responses.
Set stream=True in your request. The server sends Server-Sent Events (SSE). Token usage details appear in the final chunk.
Handle the stream in your code to display output progressively.
Test JSON Mode and Function Calling
Use JSON mode for structured data output. Set response_format to {"type": "json_object"}. This ensures the model returns valid JSON.
Enable function calling by providing a tools definition. The model can invoke tools based on your prompt context. Use tool_choice to force or allow tool use.
Limits, Errors and Context Window
Know your limits before scaling your integration. The context window is 100,000 tokens total.
Max output per request is 16,000 tokens. You get 300 requests per minute per key. Eight concurrent requests are allowed per key.
Handle errors like 401 for invalid keys or 402 for insufficient credit. Errors are free, so bad requests do not consume credit.
cURL
curl https://api.qwenmaxapi.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "List the top 5 arguments against cloud computing"}]
}'Python
from openai import OpenAI
client = OpenAI(base_url="https://api.qwenmaxapi.com/v1", api_key="YOUR_KEY")
resp = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Summarise this thread without softening it."}],
)
print(resp.choices[0].message.content)Node.js
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.qwenmaxapi.com/v1", apiKey: process.env.API_KEY });
const resp = await client.chat.completions.create({
model: "uncensored",
messages: [{ role: "user", content: "Draft a villain monologue for my game." }],
});
console.log(resp.choices[0].message.content);Streaming
stream = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Tell the story in second person."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)