Unquant

Opening your workspace…

Unquant

เรียกใช้ Unquant จาก Python และ JavaScript ด้วย OpenAI SDK

Unquant รองรับรูปแบบ OpenAI chat completions ดังนั้น SDK อย่างเป็นทางการทำงานได้โดยไม่ต้องเปลี่ยนแปลง เปลี่ยน base URL และ key แล้วโค้ดที่เหลือใช้เดิม

คู่มือการตั้งค่าอ่าน 2 นาทีอัปเดตเมื่อ 1 ตุลาคม 2026

Python

pip install openai
import 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 openai
import 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 แล้วลองใหม่

รายการเต็มอยู่ในข้อมูลอ้างอิงข้อผิดพลาด

อ่านเพิ่มเติม