OpenAI-compatible

Active path family

Use OpenAI-compatible routes for text, image, audio, embedding, realtime, rerank, moderation, and response APIs where configured.

POST /v1/chat/completions

Replace <MODEL_ID> in the examples with a model ID available to your API key that supports the endpoint.

For GPT-5.6 Luna (gpt-5.6-luna) and GPT-6 Luna (gpt-6-luna), use reasoning_effort to set the reasoning level. Omit thinking.

chat completions
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

For Claude Fable 5, set reasoning_effort to low, medium, or high for adaptive thinking. An explicit none uses low. Omit the field to use the model default. Positive reasoning.max_tokens takes precedence and is mapped to an effort level. Chat ignores temperature, top_p, and top_k for this model. Use an API key with access to the model.

chat completions
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 uses the same token168 text relay path with prompt-oriented fields.

completions
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

On the domestic site, Kimi models do not support POST /v1/responses. Use POST /v1/chat/completions for Kimi.

Responses supports the OpenAI-compatible response envelope for input arrays, tools, reasoning, caching, and streaming options.

For Claude Fable 5, set reasoning.effort to high for deeper reasoning. An explicit none uses the lowest reasoning level (low).

When continuing a Claude Fable 5 tool call, include its original call ID and the tool result. A reasoning summary returned in Responses can be included as display history.

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

Choose a model that supports Compact. Pass the entire output array unchanged as the input of your next /v1/responses request.

responses compact
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 generation and editing

Use gpt-image-2.5-flare or gpt-image-2.5-sunburst. Generated images are returned in data[].b64_json; decode them to save a PNG. Do not send response_format.

image generation
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"
}'

For edits, send JSON images with image_url references. Replace the source URL below with an accessible image URL. The model name can be either Image 2.5 variant.

image edits
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 generation with optional references

When your API key has access to Seedream 5.5, use POST /v1/images/generations with JSON. Omit image for text only, or send one HTTPS URL, one Base64 data URI, or an ordered array of up to 10 reference images.

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
}'

Choose 1K, 1.5K, 2K (default), or an explicit width and height. Choose url (default) or b64_json and PNG (default) or JPEG. The request returns one image. Input and output images are billed separately using the actual output pixel count. If the result requires reconciliation, save the request ID and check the original request before resubmitting.

POST /v1/images/generations

Send model and prompt as application/json to generate a new image. Use /v1/images/edits for reference images. With GPT Image, use output_format and omit response_format. Decode data[].b64_json to read the image.

image generation
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

For JSON editing, send model, prompt, and images as application/json. Each item in images is an object with an accessible image_url. For local files use image[] with multipart/form-data. For gpt-image-2, omit input_fidelity and response_format. Decode data[].b64_json for a non-streaming response.

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'

Set stream=true to receive server-sent events. Read through image_edit.completed and decode its b64_json for the final image.

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 is registered in the relay router, but current source identifies it as RelayModeEdits and validates a legacy text-edits instruction field. It remains disabled until owner decision or fork patch verification.

legacy edits dispatch gap
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."
  }'

Disabled compatibility route

/v1/edits must not be documented or tested as a multipart image edits success path. Use /v1/images/edits for image edits.

POST /v1/embeddings

Embeddings accepts model, input, output dimensions, encoding, and optional sampling/user metadata fields.

embeddings
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/*

The active OpenAI-compatible audio routes are speech, transcription, and translation. Speech uses a JSON request body; transcription and translation commonly use multipart uploads.

audio examples
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"
PathMethodStatus
/v1/audio/transcriptionsPOSTActive
/v1/audio/translationsPOSTActive
/v1/audio/speechPOSTActive

POST /v1/rerank

Rerank accepts a query, documents, and result controls.

rerank
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 uses the OpenAI-compatible relay envelope for a content safety check when a compatible model is configured.

moderations
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

Singapore Qwen Realtime uses its native event protocol. Select a model marked qwen-realtime in Models and replace MODEL in the example; authenticate with your Token168 API key. The example submits a complete voice turn using 16 kHz, 16-bit mono PCM WAV input (input.wav), and saves 24 kHz audio (answer.wav). Complete turns and multi-turn context are verified; cancellation and automatic interruption are not yet verified.

wss://service.token168.ai/v1/realtime?model=MODEL_ID

Python voice example
# 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)