Unquant

Opening your workspace…

Unquant

Roep Unquant aan vanuit Python en JavaScript met de OpenAI SDK

Unquant spreekt het OpenAI chat completions-formaat, waardoor de officiële SDK's ongewijzigd werken. Verander de basis-URL en sleutel, laat de rest van je code staan.

Installatiehandleiding2 min lezenBijgewerkt 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 en 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 voegt een afsluitend chunk toe met tokentelling. Gebruik wordt nooit gefactureerd; het is er voor je eigen monitoring.

Afbeeldingen

Stuur afbeeldingen inline als base64-data-URL's (PNG, JPEG of WebP). Externe afbeeldings-URL's worden niet opgehaald.

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)

Redeneercontrole

Elk model redeneert voordat het antwoordt en geeft zijn denkproces terug in reasoning_content, apart van het antwoord. Geef reasoning_effort mee als none, low of high (GLM-5.3-Flash en DeepSeek V4.1 Flash 1017 accepteren ook max):

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

Fouten afhandelen

429
Limiet voor gelijktijdige streams bereikt

Alle streams van je abonnement zijn bezet. Het verzoek is niet gestart; probeer het opnieuw als er een vrij komt.

503
Tijdelijk niet beschikbaar

Een korte herstart. Wacht op de Retry-After-header en probeer het dan opnieuw.

De volledige lijst staat in de foutreferentie.

Verder lezen