เรียกใช้ Unquant จาก Python และ JavaScript ด้วย OpenAI SDK
Unquant รองรับรูปแบบ OpenAI chat completions ดังนั้น SDK อย่างเป็นทางการทำงานได้โดยไม่ต้องเปลี่ยนแปลง เปลี่ยน base URL และ key แล้วโค้ดที่เหลือใช้เดิม
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 และ 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 เพิ่ม chunk สุดท้ายพร้อมจำนวนโทเคน การใช้งานไม่มีการเรียกเก็บเงิน มีไว้สำหรับการติดตามของคุณเอง
ภาพ
ส่งภาพ inline เป็น base64 data URL (PNG, JPEG หรือ WebP) URL ภาพระยะไกลจะไม่ถูกดึงข้อมูล
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
ทุกโมเดลจะ reason ก่อนตอบและส่งคืนการคิดใน reasoning_content แยกจากคำตอบ ส่ง reasoning_effort เป็น none, low หรือ high (GLM-5.3-Flash และ DeepSeek V4.1 Flash 1017 รับ max ด้วย):
client.chat.completions.create(model="glm-5.3-flash", reasoning_effort="none",
messages=[{"role": "user", "content": "Quick answer: capital of Peru?"}])การจัดการข้อผิดพลาด
429
ถึงขีดจำกัด concurrent stream แล้ว
stream ทั้งหมดในแผนของคุณกำลังยุ่ง คำขอไม่ได้เริ่มต้น ลองใหม่เมื่อ stream หนึ่งเสร็จ
503
ไม่พร้อมใช้งานชั่วคราว
มีการรีสตาร์ทสั้นๆ รอ header Retry-After แล้วลองใหม่
รายการเต็มอยู่ในข้อมูลอ้างอิงข้อผิดพลาด
อ่านเพิ่มเติม
- วิธีใช้ Claude Code กับโมเดลที่ไม่ถูกเซ็นเซอร์และไม่จำกัดรัน Claude Code บน GLM-5.3-Flash, Qwen 3.8 Flash Next หรือ DeepSeek V4.1 Flash 1017 ผ่าน endpoint ที่เข้ากันได้กับ Anthropic ของ Unquant: สอง environment variable ไม่มี proxy โทเคนไม่จำกัดและคอนเทกซ์ 262K
- วิธีเชื่อมต่อ Open WebUI กับ Unquantเพิ่ม Unquant ใน Open WebUI เป็นการเชื่อมต่อ OpenAI API: URL, key และรายการโมเดล อินเทอร์เฟสส่วนตัวแบบ ChatGPT บน GLM-5.3-Flash ที่ไม่ถูกเซ็นเซอร์, Qwen 3.8 Flash Next และ DeepSeek V4.1 Flash 1017
- AI ที่ไม่ถูกเซ็นเซอร์สำหรับ coding และ agentเหตุใดนักพัฒนาจึงใช้โมเดลที่ไม่ถูกเซ็นเซอร์สำหรับ coding และ agent: ไม่มีการปฏิเสธงานด้านความปลอดภัย reverse engineering หรือ content pipeline ที่ละเอียดอ่อน บวกกับคอนเทกซ์ 262K และโทเคนไม่จำกัดสำหรับ agent loop ที่ยาว