Chat Completions
Use Chat Completions for text chat, vision input, streaming, JSON output, and tool calling.
POST https://api.rout.my/v1/chat/completionsRequest
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
| Field | Type | Required | Notes |
|---|---|---|---|
model | string | Yes | Exact model ID from /v1/models. |
messages | array | Yes | Conversation messages with role and content. |
stream | boolean | No | Set true for Server-Sent Events. |
temperature | number | No | Sampling temperature. |
top_p | number | No | Nucleus sampling. |
max_tokens | integer | No | Maximum generated tokens. |
max_completion_tokens | integer | No | OpenAI-compatible alias for maximum generated tokens. |
max_output_tokens | integer | No | Accepted for Gemini-style clients. |
stop | string or array | No | Stop sequence or sequences. |
logprobs / top_logprobs | boolean / integer | No | Forwarded when the upstream supports log probability output. |
store / service_tier | boolean / string | No | Forwarded for OpenAI-compatible upstreams. |
prompt_cache_key / prompt_cache_retention | string | No | Forwarded for OpenAI-compatible prompt caching. |
safety_identifier | string | No | Accepted for client compatibility but stripped before upstream requests. |
modalities / audio | array / object | No | Forwarded for multimodal output-capable upstreams. |
image_config | object | No | Image aspect ratio and resolution for image-capable chat models; see below. |
prediction | object | No | Forwarded for providers that support predicted outputs. |
response_format | object | No | OpenAI-style response format, for example JSON object mode. |
tools | array | No | OpenAI-style function tools. |
tool_choice | string or object | No | Controls tool selection. |
parallel_tool_calls | boolean | No | Controls parallel tool calls when supported. |
reasoning | object | No | Provider-compatible reasoning controls when supported. |
reasoning_effort | string | No | OpenAI-style reasoning effort; mapped to internal reasoning controls. |
metadata | object | No | Client 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:
{
"role": "user",
"content": "Summarize this in one paragraph."
}Vision-capable models can receive an array of content parts:
{
"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:
data:image/png;base64,...Streaming
Set stream to true to receive Server-Sent Events:
{
"model": "openai/gpt-5.4",
"messages": [{ "role": "user", "content": "Write three short lines." }],
"stream": true
}The stream ends with:
data: [DONE]Tool calling
{
"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:
{
"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.
| Field | Type | Notes |
|---|---|---|
aspect_ratio | string | Common values include 1:1, 16:9, 9:16, 4:3, 3:4, 4:5, 5:4, and 21:9. |
image_size | string | Common 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
{
"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
}
}