Skip to content

Chat Completions ​

Use Chat Completions for text chat, vision input, streaming, JSON output, and tool calling.

text
POST https://api.rout.my/v1/chat/completions

Request ​

bash
curl https://api.rout.my/v1/chat/completions \
  -H "Authorization: Bearer $ROUTMY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-5.4",
    "messages": [
      { "role": "system", "content": "Answer briefly." },
      { "role": "user", "content": "What does this endpoint do?" }
    ],
    "temperature": 0.7,
    "max_tokens": 256
  }'

Request fields ​

FieldTypeRequiredNotes
modelstringYesExact model ID from /v1/models.
messagesarrayYesConversation messages with role and content.
streambooleanNoSet true for Server-Sent Events.
temperaturenumberNoSampling temperature.
top_pnumberNoNucleus sampling.
max_tokensintegerNoMaximum generated tokens.
max_completion_tokensintegerNoOpenAI-compatible alias for maximum generated tokens.
max_output_tokensintegerNoAccepted for Gemini-style clients.
stopstring or arrayNoStop sequence or sequences.
logprobs / top_logprobsboolean / integerNoForwarded when the upstream supports log probability output.
store / service_tierboolean / stringNoForwarded for OpenAI-compatible upstreams.
prompt_cache_key / prompt_cache_retentionstringNoForwarded for OpenAI-compatible prompt caching.
safety_identifierstringNoAccepted for client compatibility but stripped before upstream requests.
modalities / audioarray / objectNoForwarded for multimodal output-capable upstreams.
image_configobjectNoImage aspect ratio and resolution for image-capable chat models; see below.
predictionobjectNoForwarded for providers that support predicted outputs.
response_formatobjectNoOpenAI-style response format, for example JSON object mode.
toolsarrayNoOpenAI-style function tools.
tool_choicestring or objectNoControls tool selection.
parallel_tool_callsbooleanNoControls parallel tool calls when supported.
reasoningobjectNoProvider-compatible reasoning controls when supported.
reasoning_effortstringNoOpenAI-style reasoning effort; mapped to internal reasoning controls.
metadataobjectNoClient metadata passed through when supported.

Unknown fields are preserved and forwarded when the upstream provider accepts them.

Message content ​

Text-only messages can use a string:

json
{
  "role": "user",
  "content": "Summarize this in one paragraph."
}

Vision-capable models can receive an array of content parts:

json
{
  "role": "user",
  "content": [
    { "type": "text", "text": "Describe this image." },
    {
      "type": "image_url",
      "image_url": {
        "url": "https://example.com/image.png"
      }
    }
  ]
}

Data URLs are accepted for image inputs:

text
data:image/png;base64,...

Streaming ​

Set stream to true to receive Server-Sent Events:

json
{
  "model": "openai/gpt-5.4",
  "messages": [{ "role": "user", "content": "Write three short lines." }],
  "stream": true
}

The stream ends with:

text
data: [DONE]

Tool calling ​

json
{
  "model": "openai/gpt-5.4",
  "messages": [
    { "role": "user", "content": "What is the status of order 123?" }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_order",
        "description": "Look up an order by ID.",
        "parameters": {
          "type": "object",
          "properties": {
            "order_id": { "type": "string" }
          },
          "required": ["order_id"]
        }
      }
    }
  ],
  "tool_choice": "auto"
}

Image-capable chat models ​

Some models generate images through the chat endpoint. For those models, include image output in modalities:

json
{
  "model": "provider/image-chat-model-id",
  "messages": [
    { "role": "user", "content": "Create a square icon of a blue glass cube." }
  ],
  "modalities": ["image", "text"],
  "image_config": {
    "aspect_ratio": "1:1",
    "image_size": "1K"
  }
}

Generated images can appear on the assistant message in an images array with image URLs or data URLs.

image_config ​

Pass this object at the top level of the /v1/chat/completions request, alongside model and messages.

FieldTypeNotes
aspect_ratiostringCommon values include 1:1, 16:9, 9:16, 4:3, 3:4, 4:5, 5:4, and 21:9.
image_sizestringCommon values include 1K, 2K, and 4K. Values are forwarded to the provider when supported.

Both fields are optional. For example, "image_config": {"aspect_ratio": "16:9", "image_size": "2K"} requests a landscape image at 2K resolution. Resolution is separate from the provider's quality hint.

For image models routed through the Images API, all message text is joined into one prompt. Image references from the conversation select image editing; the same image_config is forwarded for generation and editing. With stream: true, completed images arrive in delta.images after generation finishes. Images returned through this bridge use image_url.url: "data:image/<type>;base64,..." in both JSON and SSE; temporary provider storage links are downloaded by GoRouter.

Response ​

json
{
  "id": "chatcmpl_abc123",
  "object": "chat.completion",
  "created": 1744000000,
  "model": "openai/gpt-5.4",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "This endpoint creates model responses from chat messages."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 28,
    "completion_tokens": 12,
    "total_tokens": 40
  }
}

API documentation for rout.my.