OpenAI 互換
設定されている場合、テキスト、画像、音声、埋め込み、リアルタイム、リランキング、モデレーション、Responses API に OpenAI 互換ルートを使用します。
POST /v1/chat/completions
例の <MODEL_ID> は、API キーで利用できる、対象のエンドポイントに対応したモデル ID に置き換えてください。
GPT-5.6 Luna(gpt-5.6-luna)と GPT-6 Luna(gpt-6-luna)では、reasoning_effort で推論レベルを指定します。thinking は省略してください。
curl https://www.token168.cc/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-d '{
"model": "<MODEL_ID>",
"messages": [{"role": "user", "content": "Summarize the release notes."}]
}'
Claude Fable 5
Claude Fable 5 の適応型思考には reasoning_effort を low、medium、high のいずれかに設定します。none を指定すると low が、項目を省略するとモデルの既定値が使われます。正の reasoning.max_tokens が優先され、思考レベルに変換されます。このモデルを Chat で使う場合、temperature、top_p、top_k は無視されます。このモデルへのアクセス権がある API キーを使用してください。
curl https://www.token168.cc/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-d '{
"model": "claude-fable-5",
"messages": [{"role": "user", "content": "Summarize the release notes."}],
"reasoning_effort": "high",
"max_tokens": 5000
}'
POST /v1/completions
Completions は、prompt 向けフィールドを使用して同じ token168 テキスト中継パスを呼び出します。
curl https://www.token168.cc/v1/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-d '{
"model": "<MODEL_ID>",
"prompt": "Write a one-line changelog entry.",
"prefix": "",
"suffix": "",
"stream": false,
"stream_options": {"include_usage": true},
"max_tokens": 256,
"temperature": 0.3,
"top_p": 0.9,
"top_k": 40,
"stop": ["\n\n"],
"n": 1,
"frequency_penalty": 0,
"presence_penalty": 0,
"seed": 123,
"logprobs": false,
"top_logprobs": 0,
"user": "user_123",
"metadata": {"trace_id": "trace_123"},
"service_tier": "default",
"store": false
}'
POST /v1/responses
中国本土向けサイトの Kimi モデルは POST /v1/responses に対応していません。Kimi には POST /v1/chat/completions を使用してください。
Responses は、入力配列、ツール、推論、キャッシュ、ストリーミングのオプションに OpenAI 互換のレスポンス形式を使用できます。
Claude Fable 5 で推論を深めるには reasoning.effort を high に設定します。none を明示すると、最低の強度 low が使われます。
Claude Fable 5 でツール呼び出しを続けるときは、元の呼び出し ID と結果を含めてください。Responses が返した推論の要約は、表示用の履歴として送信できます。
curl https://www.token168.cc/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-d '{
"model": "<MODEL_ID>",
"input": [{"role": "user", "content": [{"type": "input_text", "text": "Draft a launch checklist."}]}],
"include": ["usage"],
"conversation": {"id": "conv_123"},
"context_management": {"type": "auto"},
"instructions": "Return concise bullets.",
"max_output_tokens": 800,
"top_logprobs": 0,
"metadata": {"trace_id": "trace_123"},
"parallel_tool_calls": true,
"previous_response_id": "resp_previous",
"reasoning": {"effort": "medium"},
"service_tier": "default",
"store": false,
"prompt_cache_key": "launch-checklist",
"prompt_cache_retention": "24h",
"safety_identifier": "safe_user_123",
"stream": false,
"stream_options": {"include_usage": true},
"temperature": 0.4,
"text": {"format": {"type": "text"}},
"tool_choice": "auto",
"tools": [],
"top_p": 0.9,
"truncation": "auto",
"user": "user_123",
"max_tool_calls": 4,
"prompt": {"id": "prompt_123"},
"enable_thinking": true,
"preset": "default"
}'
POST /v1/responses/compact
Compact に対応するモデルを選択してください。返された output 配列全体を変更せずに、次の /v1/responses リクエストの input に渡します。
curl https://www.token168.cc/v1/responses/compact \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-d '{
"model": "<MODEL_ID>",
"input": [{"role": "user", "content": "Compact this conversation."}]
}'
Image 2.5 の生成と編集
gpt-image-2.5-flare または gpt-image-2.5-sunburst を使用します。画像は data[].b64_json で返され、デコードして PNG として保存できます。response_format は送信しません。
curl https://www.token168.cc/v1/images/generations \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2.5-flare",
"prompt": "A blue circle on a white background",
"n": 1,
"size": "1024x1024",
"quality": "low",
"output_format": "png"
}'
編集には JSON の images と image_url 参照を使用します。以下の URL をアクセス可能な画像 URL に置き換えてください。どちらの Image 2.5 モデルも指定できます。
curl https://www.token168.cc/v1/images/edits \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2.5-sunburst",
"prompt": "Change the blue circle to red",
"images": [
{
"image_url": "https://your-cdn.example/source.png"
}
],
"n": 1,
"size": "1024x1024",
"quality": "low",
"output_format": "png"
}'
Seedream 5.5 の画像生成と参照画像
API キーに Seedream 5.5 のアクセス権がある場合は、POST /v1/images/generations に JSON を送信します。テキストだけの場合は image を省略し、参照画像を使う場合は HTTPS URL、Base64 データ URI、または最大 10 枚の順序付き配列を指定します。
curl https://www.token168.cc/v1/images/generations \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "dola-seedream-5-5-261028",
"prompt": "A blue circle on a white background",
"size": "1024x1024",
"response_format": "b64_json",
"output_format": "png",
"watermark": false
}'
curl https://www.token168.cc/v1/images/generations \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "dola-seedream-5-5-261028",
"prompt": "Keep the composition and turn the blue circle red",
"image": "https://your-cdn.example/source.png",
"size": "1024x1024",
"response_format": "b64_json",
"output_format": "png",
"watermark": false
}'
curl https://www.token168.cc/v1/images/generations \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "dola-seedream-5-5-261028",
"prompt": "Keep the composition and turn the blue circle red",
"image": [
"https://your-cdn.example/source.png",
"https://your-cdn.example/reference.png"
],
"size": "1024x1024",
"response_format": "b64_json",
"output_format": "png",
"watermark": false
}'
サイズは 1K、1.5K、2K(既定値)、または幅と高さを指定できます。返却形式は url(既定値)または b64_json、画像形式は PNG(既定値)または JPEG です。1 回のリクエストで 1 枚を返します。入力と出力は個別に課金され、出力は実際の画素数で区分されます。結果の照合が必要な場合はリクエスト ID を保存し、再送信の前に元のリクエストを確認してください。
POST /v1/images/generations
新しい画像を生成するには application/json で model と prompt を送信します。参照画像の編集には /v1/images/edits を使用します。GPT Image では output_format を指定し、response_format を省略します。data[].b64_json をデコードして画像を取得します。
curl https://www.token168.cc/v1/images/generations \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A blue circle on a white background",
"n": 1,
"size": "1024x1024",
"quality": "low",
"output_format": "png"
}'
POST /v1/images/edits
JSON で画像を編集するには application/json で model、prompt、images を送信します。images の各要素はアクセス可能な image_url を持つオブジェクトです。ローカルファイルには multipart/form-data の image[] を使用します。gpt-image-2 では input_fidelity と response_format を省略します。非ストリーミング応答では data[].b64_json をデコードします。
curl https://www.token168.cc/v1/images/edits \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "Change the blue circle to red",
"images": [
{
"image_url": "https://your-cdn.example/source.png"
}
],
"n": 1,
"size": "1024x1024",
"quality": "low",
"output_format": "png"
}'
curl https://www.token168.cc/v1/images/edits \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-F 'model=gpt-image-2' \
-F 'prompt=Change the blue circle to red' \
-F 'n=1' \
-F 'size=1024x1024' \
-F 'quality=low' \
-F 'output_format=png' \
-F 'image[]=@source.png'
stream=true を設定してサーバー送信イベントを受信します。image_edit.completed まで読み、その b64_json をデコードして最終画像を取得します。
curl -N https://www.token168.cc/v1/images/edits \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "Change the blue circle to red",
"images": [
{
"image_url": "https://your-cdn.example/source.png"
}
],
"stream": true,
"n": 1,
"size": "1024x1024",
"quality": "low",
"output_format": "png"
}'
POST /v1/edits
/v1/edits は中継ルーターに登録されていますが、現在のソースでは RelayModeEdits として扱われ、従来のテキスト編集用 instruction フィールドを検証します。owner の判断または fork パッチの検証が完了するまで無効です。
curl https://www.token168.cc/v1/edits \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-d '{
"model": "<MODEL_ID>",
"input": "The quik brown fox.",
"instruction": "Fix the spelling mistakes."
}'
無効な互換ルート
/v1/edits を multipart 画像編集の成功パスとして記載またはテストしてはいけません。画像編集には /v1/images/edits を使用してください。
POST /v1/embeddings
Embeddings は model、input、output dimensions、encoding、任意の sampling / user metadata フィールドを受け付けます。
curl https://www.token168.cc/v1/embeddings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-d '{
"model": "<MODEL_ID>",
"input": ["Token168 routes native APIs."],
"encoding_format": "float",
"dimensions": 1536,
"user": "user_123",
"seed": 123,
"temperature": 0,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0
}'
POST /v1/audio/*
利用可能な OpenAI 互換音声ルートは、音声合成、文字起こし、翻訳です。音声合成は JSON リクエストボディを使用し、文字起こしと翻訳では通常 multipart アップロードを使用します。
curl https://www.token168.cc/v1/audio/speech \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-d '{
"model": "<MODEL_ID>",
"input": "Token168 unifies native model APIs.",
"voice": "alloy",
"instructions": "Neutral narration.",
"response_format": "mp3",
"speed": 1,
"stream_format": "none",
"metadata": {"trace_id": "trace_123"},
"task_type": "tts",
"language": "en",
"ref_audio": "",
"ref_text": "",
"x_vector_only_mode": false,
"max_new_tokens": 1024,
"initial_codec_chunk_frames": 0
}'
curl https://www.token168.cc/v1/audio/transcriptions \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-F model="qwen3-asr-flash" \
-F file="@speech.wav" \
-F response_format="json" \
-F language="en"
curl https://www.token168.cc/v1/audio/translations \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-F model="<MODEL_ID>" \
-F file="@speech.wav" \
-F input="speech.wav" \
-F response_format="json" \
-F language="en" \
-F speed="1"
| パス | メソッド | ステータス |
|---|---|---|
| /v1/audio/transcriptions | POST | 利用可能 |
| /v1/audio/translations | POST | 利用可能 |
| /v1/audio/speech | POST | 利用可能 |
POST /v1/rerank
Rerank は query、documents、結果制御を受け付けます。
curl https://www.token168.cc/v1/rerank \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-d '{
"model": "<MODEL_ID>",
"query": "native model API docs",
"documents": ["OpenAI-compatible docs", "Billing docs", "Console docs"],
"top_n": 2,
"return_documents": true,
"max_chunk_per_doc": 4,
"overlap_tokens": 32
}'
POST /v1/moderations
互換モデルが設定されている場合、Moderations は OpenAI 互換の中継形式でコンテンツ安全性チェックを実行します。
curl https://www.token168.cc/v1/moderations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-d '{
"model": "<MODEL_ID>",
"input": "User-provided content to check",
"user": "user_123",
"metadata": {"trace_id": "trace_123"}
}'
GET /v1/realtime
シンガポールの Qwen Realtime は独自のイベントプロトコルを使用します。モデル一覧で qwen-realtime と表示されたモデルを選び、例の MODEL を置き換え、Token168 API Key で認証してください。この例は 16kHz・16bit・モノラルの PCM WAV(input.wav)を一つの音声ターンとして送信し、24kHz の応答音声(answer.wav)を保存します。完全なターンと複数ターンの文脈は検証済みです。応答のキャンセルと自動割り込みは未検証です。
wss://service.token168.ai/v1/realtime?model=MODEL_ID
# python3 -m pip install websocket-client==1.9.2
# Set TOKEN168_API_KEY before running. Input: input.wav (16 kHz / 16-bit / mono).
import base64
import json
import os
import time
import wave
from urllib.parse import urlencode
import websocket
MODEL = "qwen3.8-omni-flash-realtime"
# Also verified: qwen3.5-omni-flash-realtime, qwen3.5-omni-plus-realtime.
# Other models with the same qwen-realtime protocol reuse this example.
with wave.open("input.wav", "rb") as source:
assert (source.getframerate(), source.getsampwidth(), source.getnchannels(), source.getcomptype()) == (16000, 2, 1, "NONE")
assert 0 < source.getnframes() <= 8 * 16000 # This example limits input to 8 seconds.
pcm = source.readframes(source.getnframes())
ws = websocket.create_connection(
"wss://service.token168.ai/v1/realtime?" + urlencode({"model": MODEL}),
header={"Authorization": "Bearer " + os.environ["TOKEN168_API_KEY"]},
timeout=10,
)
deadline = time.monotonic() + 45
def send(event):
ws.send(json.dumps(event))
def receive():
remaining = deadline - time.monotonic()
if remaining <= 0:
raise TimeoutError("Session deadline exceeded; check usage before retrying")
ws.settimeout(min(10, remaining))
event = json.loads(ws.recv())
if event.get("type") == "error" or (not event.get("type") and event.get("code")):
raise RuntimeError(event.get("error", event))
return event
def wait_for(event_type):
while True:
event = receive()
if event.get("type") == event_type:
return event
try:
wait_for("session.created")
send({"type": "session.update", "session": {
"modalities": ["text", "audio"], "input_audio_format": "pcm",
"output_audio_format": "pcm", "turn_detection": None, "max_tokens": 64,
"instructions": "Please answer briefly in Chinese, using at most four characters.",
}})
session = wait_for("session.updated")["session"]
assert session.get("turn_detection") is None and session.get("max_tokens") == 64
for offset in range(0, len(pcm), 16000):
send({"type": "input_audio_buffer.append", "audio": base64.b64encode(pcm[offset:offset + 16000]).decode()})
send({"type": "input_audio_buffer.commit"})
wait_for("input_audio_buffer.committed")
send({"type": "response.create"})
audio = bytearray()
while True:
event = receive()
if event.get("type") == "response.audio.delta":
audio.extend(base64.b64decode(event["delta"]))
elif event.get("type") == "response.audio_transcript.done":
print(event["transcript"])
elif event.get("type") == "response.done":
response = event["response"]
if response.get("status") != "completed" or not response.get("usage"):
raise RuntimeError("Turn not confirmed; check usage before retrying")
print(json.dumps(response["usage"]))
break
assert audio, "No audio returned"
with wave.open("answer.wav", "wb") as output:
output.setnchannels(1)
output.setsampwidth(2)
output.setframerate(24000)
output.writeframes(audio)
finally:
ws.close(timeout=1)