チャット補完
チャット補完エンドポイントは OpenAI 互換です。OpenAI API を使ったことがあれば、ModelMax も同じ感覚で利用できます。
基本リクエスト
curl -X POST https://api.modelmax.io/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $MODELMAX_API_KEY" \
-d '{
"model": "deepseek-v3.2",
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "What is the capital of France?" }
]
}'
from openai import OpenAI
client = OpenAI(
api_key="your-api-key",
base_url="https://api.modelmax.io/v1",
)
response = client.chat.completions.create(
model="deepseek-v3.2",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"},
],
)
print(response.choices[0].message.content)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "your-api-key",
baseURL: "https://api.modelmax.io/v1",
});
const response = await client.chat.completions.create({
model: "deepseek-v3.2",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "What is the capital of France?" },
],
});
console.log(response.choices[0].message.content);
ストリーミング
stream: true を設定すると、Server-Sent Events 経由でトークンを逐次受信できます。生成されたテキストをリアルタイムに表示したいチャット UI に便利です。
curl -X POST https://api.modelmax.io/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $MODELMAX_API_KEY" \
-d '{
"model": "deepseek-v3.2",
"messages": [
{ "role": "user", "content": "Tell me a short story." }
],
"stream": true
}'
stream = client.chat.completions.create(
model="deepseek-v3.2",
messages=[{"role": "user", "content": "Tell me a short story."}],
stream=True,
)
for chunk in stream:
content = chunk.choices[0].delta.content
if content:
print(content, end="", flush=True)
print()
const stream = await client.chat.completions.create({
model: "deepseek-v3.2",
messages: [{ role: "user", content: "Tell me a short story." }],
stream: true,
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content;
if (content) process.stdout.write(content);
}
console.log();
SSE レスポンスの各行は次のようになります。
data: {"id":"...","choices":[{"delta":{"content":"Once"},"index":0}]}
data: {"id":"...","choices":[{"delta":{"content":" upon"},"index":0}]}
...
data: [DONE]
複数ターンの会話
文脈を維持するには、過去のメッセージを含めて送信します。
response = client.chat.completions.create(
model="gemini-3-flash-preview",
messages=[
{"role": "system", "content": "You are a math tutor."},
{"role": "user", "content": "What is 2+2?"},
{"role": "assistant", "content": "2 + 2 = 4."},
{"role": "user", "content": "And if you multiply that by 3?"},
],
)
パラメーター
| パラメーター | 型 | デフォルト | 説明 |
|---|---|---|---|
model | string | — | 必須。 モデル ID(例: deepseek-v3.2) |
messages | array | — | 必須。 会話メッセージ |
stream | boolean | false | SSE ストリーミングを有効化 |
temperature | number | モデル既定値 | サンプリング温度(0–2) |
top_p | number | モデル既定値 | nucleus sampling のしきい値 |
max_tokens | integer | モデル既定値 | 生成する最大トークン数 |
stop | string | array | null | 停止シーケンス |
モデルの切り替え
プロバイダーを切り替えるには model パラメーターを変更します。API 形式は同じです。
# AWS Bedrock model
client.chat.completions.create(model="deepseek-v3.2", messages=[...])
# Google Gemini model
client.chat.completions.create(model="gemini-3-flash-preview", messages=[...])
# Same API, different providers — no code changes needed.
完全な一覧は対応モデルを参照してください。
