OpenAI SDKでPythonとJavaScriptからUnquantを呼び出す方法
UnquantはOpenAIのチャット補完形式に対応しているため、公式SDKをそのまま使えます。ベースURLとキーを変更するだけで、残りのコードはそのままです。
Python
pip install openaiimport 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 openaiimport 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ヘッダーを待ってから再試行してください。
完全なリストはエラーリファレンスをご覧ください。
続けて読む
- 検閲なし・無制限モデルでClaude Codeを使う方法UnquantのAnthropicの互換エンドポイント経由でGLM-5.3-Flash、Qwen 3.8 Flash Next、DeepSeek V4.1 Flash 1017でClaude Codeを実行:2つの環境変数、プロキシなし、無制限トークン、262Kコンテキスト。
- Open WebUIをUnquantに接続する方法OpenAI API接続としてUnquantをOpen WebUIに追加:URL、キー、モデルリスト。検閲なしGLM-5.3-Flash、Qwen 3.8 Flash Next、DeepSeek V4.1 Flash 1017でプライベートなChatGPT風インターフェース。
- コーディングとエージェントのための検閲なしAI開発者がコーディングとエージェントに検閲なしモデルを使用する理由:セキュリティ業務、リバースエンジニアリング、またはエッジコンテンツパイプラインでの拒否なし、長いエージェントループのための262Kコンテキストと無制限トークン。