Unquant

Opening your workspace…

Unquant

Panggil Unquant dari Python dan JavaScript dengan OpenAI SDK

Unquant menggunakan format chat completions OpenAI, sehingga SDK resmi dapat langsung digunakan. Ubah base URL dan kunci, kode lainnya tidak perlu diubah.

Panduan penyiapan2 menit bacaDiperbarui 1 Oktober 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 dan 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 menambahkan chunk terakhir dengan jumlah token. Penggunaan tidak pernah ditagih; ini tersedia untuk pemantauan Anda sendiri.

Gambar

Kirim gambar sebagai data URL base64 inline (PNG, JPEG, atau WebP). URL gambar jarak jauh tidak akan diambil.

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}"}},
    ]}],
)

Pemanggilan alat

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)

Kendali penalaran

Setiap model berpikir sebelum menjawab dan mengembalikan pemikirannya dalam reasoning_content, terpisah dari jawaban. Kirim reasoning_effort sebagai none, low, atau high (GLM-5.3-Flash dan DeepSeek V4.1 Flash 1017 juga menerima max):

client.chat.completions.create(model="glm-5.3-flash", reasoning_effort="none",
    messages=[{"role": "user", "content": "Quick answer: capital of Peru?"}])

Menangani error

429
Batas stream bersamaan tercapai

Semua stream pada paket Anda sedang sibuk. Permintaan tidak dimulai; coba lagi saat salah satu selesai.

503
Sementara tidak tersedia

Restart singkat. Tunggu header Retry-After, lalu coba lagi.

Daftar lengkapnya ada di referensi error.

Lanjut membaca