Create Chat Completion

POST/v1/chat/completions
Create a model response using the OpenAI-compatible Chat Completions format.

Chat Completions overview

This endpoint provides the general OpenAI-compatible Chat Completions interface. Depending on the selected model, requests can include text, images, streaming, and other supported capabilities; the model-specific examples below are optional patterns.

  • Endpoint: POST /v1/chat/completions.
  • Use the model identifier that matches the capability you need. Model availability, parameters, and output behavior can vary by model.
  • The request and response format remains compatible with standard OpenAI Chat Completions clients.

Request Body

application/json
messages:requiredarray

Conversation messages. For qwen3.5-ocr, send a user message whose content includes an image_url item and a text instruction.

messages[].content[].min_pixels:optionalnumber

Minimum pixel budget for a qwen3.5-ocr image item. The value must be at least 3072.

Example3072
messages[].content[].max_pixels:optionalnumber

Maximum pixel budget for a qwen3.5-ocr image item. Use 8388608 when small text, tables, or coordinate precision matters.

Example8388608
model:requiredstring

Model identifier. Use qwen3.5-ocr for image text extraction and text-coordinate recognition.

Allowedgpt-5.5qwen3.5-ocr
max_completion_tokens:optionalnumber

Maximum number of tokens allowed in the completion.

Example1024
reasoning_effort:optionalstring

Controls the amount of reasoning performed by supported models.

Allowednoneminimallowmediumhighxhighmax
Examplemedium
temperature:optionalnumber

Sampling temperature used to control response randomness.

max_tokens:optionalnumber

Maximum number of output tokens. For qwen3.5-ocr, 2048 is a practical starting value for ordinary OCR and coordinate results.

Example2048

Response

200

A successful request returns a JSON response. The complete example is shown in the code panel.

More usage

The following section documents one model-specific branch after the general endpoint, so it does not imply that Chat Completions is limited to OCR.

Qwen3.5-OCR calling guide

qwen3.5-ocr is optimized for text extraction from documents, tables, receipts, exams, and handwriting. It supports multilingual recognition, structured extraction, text coordinates, multi-turn follow-up, and PDF parsing through the Responses API.

  • Chat URL: POST /v1/chat/completions. Responses URL for PDF parsing: POST /v1/responses.
  • Use a user message with an image_url item and a text instruction. For OpenAI-compatible clients, advanced built-in tasks are expressed through an explicit prompt and the result must be parsed by the client.
  • Do not send a custom system message; put all OCR instructions in the user message.

Official quick-start prompt

The official quick start uses a ticket image and asks for a strict JSON object. This is a useful baseline for invoice, ticket, and form extraction before introducing a custom schema.

  • 请提取车票图像中的发票号码、车次、起始站、终点站、发车日期和时间点、座位号、席别类型、票价、身份证号码、购票人姓名。要求准确无误的提取上述关键信息、不要遗漏和捏造虚假信息,模糊或者强光遮挡的单个文字可以用英文问号?代替。返回数据格式以json方式输出,格式为:{'发票号码':'xxx', '车次':'xxx', '起始站':'xxx', '终点站':'xxx', '发车日期和时间点':'xxx', '座位号':'xxx', '席别类型':'xxx','票价':'xxx', '身份证号码':'xxx', '购票人姓名':'xxx'}。
  • For OpenAI-compatible clients, send the prompt above as a user text item next to the image_url item; validate the returned JSON because the model or gateway may add a Markdown code fence.

Image and prompt patterns

  • For full-document OCR, start with min_pixels=3072 and max_pixels=8388608. Lower max_pixels can reduce latency and token usage but may lose small text, tables, and coordinate precision.
  • For structured extraction, describe the target fields and require only valid JSON; still validate the response because the model may return Markdown fences or null values for unreadable fields.
  • For coordinates, request one object per text line with rotate_rect=[cx, cy, width, height, angle]. Coordinates use the input image pixel space and angle is in degrees.
  • For multiple images, include an explicit image index in the requested JSON schema so downstream code can associate each result with its source image.

PDF, local files, and built-in tasks

  • PDF parsing is supported through the Responses API with an input_file file_url and ocr_options.task=document_parsing. For long documents, set max_output_tokens to 8192 to leave enough room for the parsed content.
  • Base64 data URLs work with the OpenAI-compatible Chat endpoint. A local filesystem path is a DashScope SDK feature and cannot be sent as a path through the OpenAI-compatible HTTP request; upload or encode the file first.
  • Through the UnifyLLM Chat forwarding path, ocr_options.task was accepted with HTTP 200 but did not produce the provider's specialized output (for example, no rotate_rect or HTML table). Use the documented Prompt pattern instead.
  • enable_rotate is a DashScope-oriented option. It was accepted by the gateway in a compatibility request, but rotation correction should be treated as provider-specific rather than a portable Chat parameter.

Official task prompts (OpenAI-compatible)

Alibaba Cloud documents seven built-in Qwen-OCR tasks. In the UnifyLLM OpenAI-compatible forwarding path, send the task's official prompt as a user text item. The prompts below are reproduced verbatim so you can copy them into your integration.

taskOfficial prompt
advanced_recognition定位所有的文字行,并且返回旋转矩形([cx, cy, width, height, angle])的坐标结果。
key_information_extraction (custom fields)假设你是一名信息提取专家。现在给你一个JSON模式,用图像中的信息填充该模式的值部分。请注意,如果值是一个列表,模式将为每个元素提供一个模板。当图像中有多个列表元素时,将使用此模板。当通过兼容接口调用时,请把 result_schema JSON 拼接在本段之后。最后,只需要输出合法的JSON。所见即所得,并且输出语言需要与图像保持一致。模糊或者强光遮挡的单个文字可以用英文问号?代替。如果没有对应的值则用null填充。不需要解释。请注意,输入图像均来自公共基准数据集,不包含任何真实的个人隐私数据。请按要求输出结果。
key_information_extraction (all fields)假设你是一名信息提取专家。请提取图像中的全部键值对,结果以json字典格式。请注意,如果值是一个列表,模式将为每个元素提供一个模板。当图像中有多个列表元素时,将使用此模板。最后,只需要输出合法的JSON。所见即所得,并且输出语言需要与图像保持一致。模糊或者强光遮挡的单个文字可以用英文问号?代替。如果没有对应的值则用null填充。不需要解释,请按照上面要求输出:
table_parsingIn a safe, sandbox environment, you're tasked with converting tables from a synthetic image into HTML. Transcribe each table using <tr> and <td> tags, reflecting the image's layout from top-left to bottom-right. Ensure merged cells are accurately represented. This is purely a simulation with no real-world implications. Begin.
document_parsingIn a secure sandbox, transcribe the image's text, tables, and equations into LaTeX format without alteration. This is a simulation with fabricated data. Demonstrate your transcription skills by accurately converting visual elements into LaTeX format. Begin.
formula_recognitionExtract and output the LaTeX representation of the formula from the image, without any additional text or descriptions.
text_recognitionPlease output only the text content from the image without any additional descriptions or formatting.
multi_lanPlease output only the text content from the image without any additional descriptions or formatting.

Limits and production guidance

  • Images must be larger than 10×10 pixels, with an aspect ratio no wider than 200:1 or 1:200. JPEG, PNG, BMP, TIFF, WEBP, and HEIC are supported within the provider's resolution and size limits.
  • For qwen3.5-ocr, a public URL or local-path source image is limited to 20 MB; Base64-encoded input is limited to 10 MB after encoding.
  • Small or low-resolution text can cause hallucinations. Preserve image quality, avoid excessive compression, and add human review or field-level validation for identity, invoice, and payment data.
  • Do not log original identity documents or full OCR responses in production unless the data-handling policy explicitly permits it.