Unquant

Opening your workspace…

Unquant

Llama a Unquant desde Python y JavaScript con el SDK de OpenAI

Unquant utiliza el formato de completions de chat de OpenAI, por lo que los SDK oficiales funcionan sin modificaciones. Cambia la URL base y la clave y conserva el resto de tu código.

Guía de configuración2 min de lecturaActualizado el 1 de octubre de 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 y 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 añade un último fragmento con el recuento de tokens. El uso nunca se factura; estos datos te permiten supervisar tu consumo.

Imágenes

Envía las imágenes integradas en la solicitud como URL de datos en base64 (PNG, JPEG o WebP). No se descargan imágenes desde URL remotas.

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

Llamadas a herramientas

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)

Control del razonamiento

Todos los modelos razonan antes de responder y devuelven su razonamiento en reasoning_content, separado de la respuesta. Establece reasoning_effort en none, low o high (GLM-5.3-Flash y DeepSeek V4.1 Flash 1017 también admiten max):

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

Gestión de errores

429
Se ha alcanzado el límite de flujos simultáneos

Todos los flujos de tu plan están ocupados. La solicitud no se ha iniciado; vuelve a intentarlo cuando termine uno.

503
No disponible temporalmente

Se está realizando un breve reinicio. Espera el tiempo indicado en el encabezado Retry-After y vuelve a intentarlo.

Encontrarás la lista completa en la referencia de errores.

Seguir leyendo