Unquant

Opening your workspace…

Unquant

OpenAI SDK से Python और JavaScript में Unquant call करें

Unquant OpenAI chat completions format में बोलता है, इसलिए official SDKs बिना बदलाव के काम करते हैं। Base URL और key बदलें, बाकी code रखें।

सेटअप गाइड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 token counts के साथ एक final chunk जोड़ता है। Usage कभी bill नहीं होता; यह आपकी खुद की monitoring के लिए है।

Images

Images को base64 data URLs (PNG, JPEG या WebP) के रूप में inline भेजें। Remote image URLs fetch नहीं होते।

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

हर model जवाब देने से पहले reason करता है और अपनी thinking reasoning_content में अलग से return करता है। reasoning_effort को none, low या high pass करें (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?"}])

Errors handle करना

429
Concurrent stream limit पहुँच गई

आपके plan के सभी streams व्यस्त हैं। Request शुरू नहीं हुई; एक finish होने पर retry करें।

503
अस्थायी रूप से अनुपलब्ध

एक brief restart। Retry-After header का इंतज़ार करें, फिर retry करें।

पूरी list error reference में है।

आगे पढ़ें