Unquant

Opening your workspace…

Unquant

Chiama Unquant da Python e JavaScript con l'SDK OpenAI

Unquant parla il formato OpenAI chat completions, quindi gli SDK ufficiali funzionano senza modifiche. Cambia il base URL e la chiave, mantieni il resto del tuo codice.

Guida alla configurazione2 minuti di letturaAggiornato il 1 ottobre 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 e 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 aggiunge un chunk finale con il conteggio dei token. L'utilizzo non viene mai fatturato; è lì per il tuo monitoraggio personale.

Immagini

Invia le immagini inline come data URL base64 (PNG, JPEG o WebP). Gli URL di immagini remote non vengono recuperati.

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

Chiamate agli strumenti

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)

Controllo del ragionamento

Ogni modello ragiona prima di rispondere e restituisce il suo pensiero in reasoning_content, separato dalla risposta. Passa reasoning_effort come none, low o high (GLM-5.3-Flash e DeepSeek V4.1 Flash 1017 accettano anche max):

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

Gestione degli errori

429
Limite degli stream simultanei raggiunto

Tutti gli stream del tuo piano sono occupati. La richiesta non è stata avviata; riprova quando uno si libera.

503
Temporaneamente non disponibile

Un breve riavvio. Aspetta l'intestazione Retry-After, poi riprova.

L'elenco completo si trova nel riferimento sugli errori.

Continua a leggere