module pixeltable.functions.vlmrun_gateway
Pixeltable UDFs that wrap the VLM Run Gateway API. The VLM Run Gateway is an OpenAI-compatible API in front of vision and speech models for OCR, visual question answering, detection, segmentation, pose estimation, embeddings and speech-to-text. In order to use it, you must firstpip install openai and configure your VLM Run API key, either as the VLMRUN_API_KEY environment variable
or as api_key in the vlmrun section of the Pixeltable config file. For details, see the
VLM Run Gateway documentation.
udf analyze()
Signatures
vlmrun_gateway, key rate_limit). If no rate limit is
configured, uses a default of 600 RPM, which is above the Gateway’s limits of 240 requests per minute and
10,000 per hour per account; set rate_limit = 160 to stay under both.
Requirements:
pip install openai
image(Image): The image to analyze. A video (pxt.Video) is also accepted by video-capable models, such as'facebook/sam3.1'withmethod='track'or'usyd-community/vitpose-plus-large'.model(String): The model to use, such as'facebook/sam3.1'(segmentation),'microsoft/florence-2-base-ft'(detection and captions),'usyd-community/vitpose-plus-large'(body pose) or'geopavlakos/hamer'(hand pose). For the available models, see https://vlm.run/gateway/models.method(String | None, default:Literal(None)): The model entrypoint to run, such as'segment'or'od'. If omitted, the model’s default method is used. For each model’s methods, see https://docs.vlm.run/gateway/methods.method_params(Json | None, default:Literal(None)): Arguments for the method, such as{'prompt': 'car'}for'facebook/sam3.1'segmentation.model_kwargs(Json | None, default:Literal(None)): Additional Gateway fields, such asprecision,video_fpsorvideo_max_frames.'facebook/sam3.1'withmethod='track'readsvideo_fpsandvideo_max_framesfrommethod_paramsinstead. For details, see https://docs.vlm.run/gateway/extra-kwargs.
pxt.Json: The Gateway’s JSON result, unchanged: the input’s metadata (such asimage_widthandimage_height) andcontent, which is{'object': ..., 'items': [...]}(for a video, alsoframes), or a string for caption methods. Image coordinates are fractions of the image width and height, and pose keypoints can fall outside 0 to 1;'geopavlakos/hamer'also returns metric 3D joints inkpts_xyz. For eachobjecttype, see https://docs.vlm.run/gateway/response-types.
img of the table tbl:
udf chat_completions()
Signature
chat/completions API endpoint.
For additional details, see: https://docs.vlm.run/gateway/api-reference/post-chat-completions
Image columns can be referenced directly in message content parts, as {'type': 'image_url', 'image_url': tbl.img};
they are sent inline as base64. Document and video content parts (document_url, video_url) take an
http(s) or data: URL, which the Gateway fetches itself; for media inserted from a public URL, that is
tbl.doc.fileurl. To read a local document or video column, use ocr() or analyze().
Request throttling:
Applies the rate limit set in the config (section vlmrun_gateway, key rate_limit). If no rate limit is
configured, uses a default of 600 RPM, which is above the Gateway’s limits of 240 requests per minute and
10,000 per hour per account; set rate_limit = 160 to stay under both.
Requirements:
pip install openai
messages(pxt.Json[(Json): A list of messages for the chat conversation. Media content parts may reference Pixeltable columns directly (see above).model(Any): The model to use, such as'qwen/qwen3.5-0.8b'. For the available models, see https://vlm.run/gateway/models.model_kwargs(Any): Additional keyword args for the Gatewaychat/completionsAPI, such asresponse_format,max_tokens, or Gateway fields likemethod,method_paramsanddocument_dpi. For details, see https://docs.vlm.run/gateway/extra-kwargs.tools(Any): An optional list of Pixeltable tools to use for the request. Supported by some models only, such as'qwen/qwen3.8-27b'and the partner Gemini, Kimi, MiniMax and Muse models.tool_choice(Any): An optional Pixeltable tool choice to use for the request.
pxt.Json: A dictionary containing the API response, including the cost of the call in USD inusage.cost.
img of the table tbl:
udf embeddings()
Signatures
embeddings API endpoint.
For additional details, see: https://docs.vlm.run/gateway/api-reference/post-embeddings
Text, images and other media share one vector space, so an index built on an image column can be searched with
a text query. Text and images are sent up to 32 per request. Videos, audio and documents are sent one per
request, so a media column can use more Gateway requests than the configured rate limit suggests. A document that
isn’t a PDF fails every row in its batch.
Request throttling:
Applies the rate limit set in the config (section vlmrun_gateway, key rate_limit). If no rate limit is
configured, uses a default of 600 RPM, which is above the Gateway’s limits of 240 requests per minute and
10,000 per hour per account; set rate_limit = 160 to stay under both.
Requirements:
pip install openai
input(String): The text to embed. Images (pxt.Image), and for models that accept them, videos (pxt.Video), audio (pxt.Audio) and PDF documents (pxt.Document) are also accepted.model(String): The embedding model to use:'qwen/qwen3-vl-embedding-2b'(2048 dimensions; text, images and video) or'google/embeddinggemma-2'(768 dimensions; text, images, video, audio and PDFs). For other models, passdimensionsinmodel_kwargs; it sets the column type and is also sent to the Gateway. An embedding index over 2048-dimensional vectors needsadd_embedding_index()’s defaultprecision='fp16', sincefp32indexes allow at most 2000 dimensions.model_kwargs(Json | None, default:Literal(None)): Additional keyword args for the GatewayembeddingsAPI, such asdimensions(768, 512, 256 or 128 for'google/embeddinggemma-2') andprompt_name.'google/embeddinggemma-2'prefixes text with a task (prompt_name, default'Classification'); for search indexes, use'SentenceSimilarity', since the same function embeds both the query and the indexed values.
pxt.Array[(None,), float32]: An array containing the embedding vector.
img of the table tbl, and search it with text:
udf ocr()
Signatures
vlmrun_gateway, key rate_limit). If no rate limit is
configured, uses a default of 600 RPM, which is above the Gateway’s limits of 240 requests per minute and
10,000 per hour per account; set rate_limit = 160 to stay under both.
Requirements:
pip install openai
document(Document): The PDF document to read. Other document formats raise an error. An image (pxt.Image) is also accepted.model(String, default:Literal('paddlepaddle/paddleocr-vl-1.6')): The OCR model to use, such as'paddlepaddle/paddleocr-vl-1.6'(general purpose),'paddleocr/pp-ocrv6'(text lines with bounding boxes) or'nvidia/nemotron-3.5-parse'(layout boxes, withmethod='layout'). For the available models, see https://vlm.run/gateway/models.method(String | None, default:Literal(None)): The model entrypoint to run, such as'markdown','ocr'or'layout'. If omitted, the model’s default method is used. For each model’s methods, see https://docs.vlm.run/gateway/methods.pages(Json[(Json, ...)] | None, default:Literal(None)): The zero-based pages to read, as page indices and[start, stop]ranges that excludestop, for example[0, [2, 4]]for pages 0, 2 and 3. Selected pages are renumbered from 0. Not available for images.dpi(Int | None, default:Literal(None)): The resolution at which PDF pages are rasterized (Gateway default: 96). Raise it, for example to 150, for small text or dense tables. Not available for images.model_kwargs(Json | None, default:Literal(None)): Additional Gateway fields, such asmethod_paramsorprecision. For details, see https://docs.vlm.run/gateway/extra-kwargs.
-
pxt.Json: The Gateway’s JSON result, unchanged. Its shape depends on the input and the method:- For a PDF,
document_npagesis the number of pages read andpagesis a list of page records, each withpage_id,page_width,page_heightandcontent, wherecontentis{'object': 'doc.page.blocks', 'items': [...]}. A page the Gateway could not read has'status': 'error'and nocontent; the other pages are still returned. - For an image,
contentis a string for text methods such as'markdown', or{'object': ..., 'items': [...]}for region methods such as'ocr'on'paddleocr/pp-ocrv6'. 'vlm-run/ocr:auto'withmethod='markdown'returns the whole PDF as onecontentstring.
- For a PDF,
doc of the table tbl as Markdown:
img:
udf transcriptions()
Signature
audio/transcriptions API endpoint.
For additional details, see: https://docs.vlm.run/gateway/api-reference/post-audio-transcriptions
Request throttling:
Applies the rate limit set in the config (section vlmrun_gateway, key rate_limit). If no rate limit is
configured, uses a default of 600 RPM, which is above the Gateway’s limits of 240 requests per minute and
10,000 per hour per account; set rate_limit = 160 to stay under both.
Requirements:
pip install openai
audio(pxt.Audio): The audio to transcribe.model(pxt.String): The transcription model to use. For the available models, see https://vlm.run/gateway/models.model_kwargs(pxt.Json | None): Additional keyword args for the Gatewayaudio/transcriptionsAPI, such aslanguage,response_format('json','verbose_json','text','srt'or'vtt') andtimestamp_granularities(['segment'],['word']or both; applies toverbose_jsononly).
TranscriptionResponse: A dictionary with the transcript intext, plusdurationandusage(including the cost in USD inusage.cost). Forverbose_json, it also hassegments, andwordswhentimestamp_granularitiesincludes'word'. For thetext,srtandvttformats, the dictionary contains onlytext.
audio of the table tbl: