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가 반환한 추론 요약은 표시용 기록으로 함께 전송할 수 있습니다.

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에 전달하세요.

Responses 압축
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을 접근 가능한 이미지 주소로 바꾸세요. 두 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개의 순서가 있는 배열을 사용하세요.

Text to image
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
}'
Single reference
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
}'
Multiple references
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입니다. 요청당 이미지 한 장을 반환합니다. 입력과 출력 이미지는 별도로 과금되며 출력 요금은 실제 픽셀 수에 따라 달라집니다. 결과를 대사해야 할 때는 요청 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을 디코딩합니다.

application/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"
}'
multipart/form-data
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을 디코딩해 최종 이미지를 얻습니다.

stream=true
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 패치 검증 전까지 비활성화됩니다.

기존 edits 디스패치 차이
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/transcriptionsPOST사용 가능
/v1/audio/translationsPOST사용 가능
/v1/audio/speechPOST사용 가능

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

Python 음성 예제
# 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)