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.
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 dan 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 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
Semua stream pada paket Anda sedang sibuk. Permintaan tidak dimulai; coba lagi saat salah satu selesai.
Restart singkat. Tunggu header Retry-After, lalu coba lagi.
Daftar lengkapnya ada di referensi error.
Lanjut membaca
- Cara menggunakan Claude Code dengan model tidak tersensor dan tak terbatasJalankan Claude Code pada GLM-5.3-Flash, Qwen 3.8 Flash Next, atau DeepSeek V4.1 Flash 1017 melalui endpoint yang kompatibel dengan Anthropic dari Unquant: dua variabel lingkungan, tanpa proxy, token tak terbatas, dan konteks 262K.
- Cara menghubungkan Open WebUI ke UnquantTambahkan Unquant ke Open WebUI sebagai koneksi API OpenAI: URL, kunci, dan daftar model. Antarmuka bergaya ChatGPT yang bersifat pribadi pada GLM-5.3-Flash, Qwen 3.8 Flash Next, dan DeepSeek V4.1 Flash 1017 yang tidak tersensor.
- AI tidak tersensor untuk pemrograman dan agenAlasan pengembang menggunakan model tidak tersensor untuk pemrograman dan agen: tanpa penolakan pada pekerjaan keamanan, reverse engineering, atau pipeline konten dewasa, ditambah konteks 262K dan token tak terbatas untuk jalankan agen panjang.