Unquant

Opening your workspace…

Unquant

OpenAI SDKでPythonとJavaScriptからUnquantを呼び出す方法

UnquantはOpenAIのチャット補完形式に対応しているため、公式SDKをそのまま使えます。ベースURLとキーを変更するだけで、残りのコードはそのままです。

セットアップガイド2分で読めます2026年10月1日更新

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);

ストリーミング

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で最終チャンクにトークン数を追加します。使用量は課金されません;独自の監視のためのものです。

画像

画像はPNG、JPEGまたはWebPのbase64データURLとしてインラインで送信してください。リモート画像URLは取得されません。

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

ツール呼び出し

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_contentに返します。reasoning_effortとしてnone、low、またはhighを渡してください(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?"}])

エラー処理

429
同時ストリーム制限に達しました

プランのストリームがすべて使用中です。リクエストは開始されていません;1つ完了したら再試行してください。

503
一時的に利用不可

短時間の再起動中です。Retry-Afterヘッダーを待ってから再試行してください。

完全なリストはエラーリファレンスをご覧ください。

続けて読む