Chat Completions
OpenAI-compatible chat completions for OCR, VQA, and document inference
Models Supported
For available models and aliases, see Models. Standard OpenAI sampling fields (temperature, max_tokens, top_p,
frequency_penalty, presence_penalty, stop, n) are accepted on every
request, but OCR and detection models generally ignore sampling params since
they are not free-form text generators. Check a model’s
supported_parameters via Get Model
if a field you send does not appear to change the output.
response_format accepts {"type":"json_object"} for the JSON response object.
Omitting the field returns the text rendering. See
Methods & Response Format.
Gateway extensions
These fields are accepted at the top level of the request body (or viaextra_body in the OpenAI Python SDK):
video_max_frames, video_fps, video_resolution, video_encoder, and
video_encoder_params apply when the request includes a video_url content
part on a video-capable model. See
Video Inputs.
Video encoding
When a request includes avideo_url, the Gateway encodes it into image(s)
before dispatch so image-only models can read it. video_encoder selects the
strategy and defaults to mosaic (sampled keyframes tiled into a single grid
image); frames and keyframes are also available. Tune the chosen encoder with
video_encoder_params (for example tile_cols, tile_rows, num_frames).
400
(invalid_request_error). See Error Codes.
Document text output
Fordocument_url inputs, text mode (response_format omitted) always
returns one <document> block per input PDF, wrapping one <page> block per
rasterized page. method decides only each page’s payload kind, declared on the
page as format:
content is document.page.blocks for every method: a
whole-page read is one block carrying text, and a region read is one block per
region. See The document block record.
<document> attributes are file_name?, file_hash?, file_bytes?,
mimetype, num_pages, dpi, language?;
<page> attributes are page_index, format, page_width,
page_height, and status?. A page that failed keeps its slot as a self-closing
<page … status="error"/>. A single image returns the payload block alone, and a
multi-document request returns one <document> block per input PDF in request
order.
JSON mode is unaffected by method: response_format={"type":"json_object"}
always returns {"model": …, "method": …, "data": [{"object": "document", "pages": […]}]}, with each page’s content typed by the model and method. See
JSON mode for full examples.
Each model exposes supported method values on
GET /v1/openai/models. See
Methods for a per-model reference with examples.
Content parts
Messages use the standard OpenAI multimodal shape. See Multimodal Inputs for the full content part reference (text, image_url, document_url) and
document-specific limits.
Response extensions
Non-streaming responses follow the OpenAI chat completion shape with one VLM Run Gateway extension:Streaming
Setstream: true on any text-mode chat request. The streamed result is
byte-identical to the non-streaming one. Document requests (document_url) emit SSE
chunks in document order: a <document> open tag, one chunk per <page> block in
ascending page order, then the matching </document> close tag. Each <page>
carries its own format, so a streamed page is self-describing. Other chat
requests (regular chat, single-image
OCR) buffer the full reply and re-chunk it into the same OpenAI
chat.completion.chunk contract (correct SSE, no time-to-first-token benefit yet).
Pass stream_options={"include_usage": true} to receive a terminal chunk carrying
aggregated usage (including usage.cost). A JSON response_format is always
served non-streamed. See Flexible Document OCR
for the full SSE walkthrough.
Document OCR
Stream a document page-by-page
Errors and limits
- Error codes: capability violations, invalid documents, model not found, and sanitized 500 responses.
- Rate limits: 120 requests/min and 1000 requests/hr per IP (anonymous), or 240 requests/min and 10000 requests/hr per user (authenticated).
x-request-id header. You may send your own id on
the request; otherwise the VLM Run Gateway mints one. Sanitized 500 responses also
include the id as error.request_id in the JSON body.
Related
List models
Models
Quickstart
Flexible Document OCR
Multimodal Inputs
MCP Server
Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
OpenAI-compatible chat completion request.
mosaic, frames, keyframes 224x224, 336x336, 384x384, 448x448, 512x512, 768x768 256x192, 320x240, 448x336, 512x384, 640x480 x >= 1Requested serialization of the assistant reply.
Mirrors the OpenAI response_format object so existing client code
keeps working:
{"type": "text"}(the default) returns the reply verbatim.{"type": "json_object"}returns the reply as a single valid JSON object string: structured results (detections, OCR regions, document pages) are emitted as parseable JSON under a top-leveldatakey.{"type": "json_schema"}behaves likejson_object; the suppliedjson_schemais advisory and does not constrain generation.
1 <= x <= 8Response
Successful Response
OpenAI-compatible chat completion response.
Beyond the OpenAI shape we surface two extra fields so clients can audit which model actually produced the output:
served_model_id— the canonical id of the deployment that ran the request (e.g."rednote-hilab/dots.ocr"), even when the caller used a short alias. Mirrors the"id"echoed inGET /v1/openai/models.backend— static label naming the inference runtime that served the request ("vllm"/"transformers"/"llama.cpp"/"paddleocr"/ ...). Lets clients see the runtime without opening a separate /models RPC.
The OpenAI-standard model field still echoes the canonical
id (matching OpenAI's own behaviour where a generic alias like
gpt-4 resolves to the dated snapshot gpt-4-0613 in the
response).