Call Unquant from Python and JavaScript with the OpenAI SDK
Unquant speaks the OpenAI chat completions format, so the official SDKs work unchanged. Change the base URL and key, keep the rest of your code.
Python
pip install openaiimport os
from openai import OpenAI
client = OpenAI(base_url="https://api.unquant.io/v1", api_key=os.environ["UNQUANT_API_KEY"])
reply = client.chat.completions.create(
model="glm-5.3-flash",
messages=[{"role": "user", "content": "Write a noir opening line."}],
)
print(reply.choices[0].message.content)JavaScript and TypeScript
npm install openaiimport OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.unquant.io/v1", apiKey: process.env.UNQUANT_API_KEY });
const reply = await client.chat.completions.create({
model: "qwen-3.8-flash-next",
messages: [{ role: "user", content: "Summarise this chapter in three lines." }],
});
console.log(reply.choices[0].message.content);Streaming
stream = client.chat.completions.create(
model="glm-5.3-flash",
messages=[{"role": "user", "content": "Tell me a long story."}],
stream=True,
stream_options={"include_usage": True},
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)include_usage adds a final chunk with token counts. Usage is never billed; it is there for your own monitoring.
Images
Send images inline as base64 data URLs (PNG, JPEG or WebP). Remote image URLs are not fetched.
import base64
data = base64.b64encode(open("photo.jpg", "rb").read()).decode()
client.chat.completions.create(
model="glm-5.3-flash",
messages=[{"role": "user", "content": [
{"type": "text", "text": "What is in this picture?"},
{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{data}"}},
]}],
)Tool calling
tools = [{"type": "function", "function": {
"name": "get_weather",
"description": "Current weather for a city",
"parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]},
}}]
reply = client.chat.completions.create(model="glm-5.3-flash", tools=tools,
messages=[{"role": "user", "content": "Weather in Lisbon?"}])
print(reply.choices[0].message.tool_calls)Reasoning control
Both models reason before answering and return their thinking in reasoning_content, separate from the answer. Pass reasoning_effort as none, low or high (GLM-5.3-Flash also takes max):
client.chat.completions.create(model="glm-5.3-flash", reasoning_effort="none",
messages=[{"role": "user", "content": "Quick answer: capital of Peru?"}])Handling errors
429
Concurrent stream limit reached
All your plan's streams are busy. The request was not started; retry when one finishes.
503
Temporarily unavailable
A brief restart. Wait for the Retry-After header, then retry.
The full list is in the error reference.
Keep reading
- How to use Claude Code with an uncensored, unlimited modelRun Claude Code on GLM-5.3-Flash or Qwen 3.8 Flash Next through Unquant's Anthropic-compatible endpoint: two environment variables, no proxy, unlimited tokens and 262K context.
- How to connect Open WebUI to UnquantAdd Unquant to Open WebUI as an OpenAI API connection: the URL, key and model list. A private, ChatGPT-style interface on uncensored GLM-5.3-Flash and Qwen 3.8 Flash Next.
- Uncensored AI for coding and agentsWhy developers use an uncensored model for coding and agents: no refusals on security work, reverse engineering or edgy content pipelines, plus 262K context and unlimited tokens for long agent loops.