> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vlm.run/llms.txt
> Use this file to discover all available pages before exploring further.

# zai-org/glm-ocr

> Document OCR that returns Markdown or structured JSON.

Document OCR to Markdown / HTML (vLLM). Accepts one `image_url` or a `document_url`
PDF; no text-only input. `markdown` is the only method, and it emits a
Markdown / HTML string for an image and for each page of a PDF.

## Output by method

| Method     | Payload kind | Image `content.object` | Payload                                        |
| ---------- | ------------ | ---------------------- | ---------------------------------------------- |
| `markdown` | markdown     | none                   | Reading-order Markdown / HTML string (default) |

Text mode emits the string alone for one image, and one `<document>` / `<page>`
block per PDF, each page carrying `format="markdown"`. In JSON mode an image
`content` is the string, and a document page `content` is
`document.page.blocks`. See [Methods & Response Format](/gateway/methods).

## Request

<CodeGroup>
  ```python Python [expandable] theme={"theme":{"light":"github-light","dark":"dark-plus"}}
  from openai import OpenAI

  client = OpenAI(
      base_url="https://gateway.vlm.run/v1/openai",
      api_key="<VLMRUN_API_KEY>",
  )

  response = client.chat.completions.create(
      model="zai-org/glm-ocr",
      messages=[
          {
              "role": "user",
              "content": [
                  {
                      "type": "document_url",
                      "document_url": {
                          "url": "https://storage.googleapis.com/vlm-data-public-prod/hub/examples/finance.sec-filings/tsla-8k.pdf"
                      },
                  },
              ],
          }
      ],
      extra_body={"method": "markdown"},
  )

  print(response.choices[0].message.content)
  ```

  ```bash cURL [expandable] theme={"theme":{"light":"github-light","dark":"dark-plus"}}
  curl https://gateway.vlm.run/v1/openai/chat/completions \
    -X POST \
    -H "Authorization: Bearer $VLMRUN_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "zai-org/glm-ocr",
      "method": "markdown",
      "messages": [
        {
          "role": "user",
          "content": [
            {
              "type": "document_url",
              "document_url": {
                "url": "https://storage.googleapis.com/vlm-data-public-prod/hub/examples/finance.sec-filings/tsla-8k.pdf"
              }
            }
          ]
        }
      ]
    }'
  ```
</CodeGroup>

## Response

<Tabs>
  <Tab title="Text mode">
    One `<document>` block per PDF, one `<page>` block per page. A failed page is
    self-closing, with `status="error"` and no body:

    ```text theme={"theme":{"light":"github-light","dark":"dark-plus"}}
    <document file_name="tsla-8k.pdf" file_hash="sha256:1b7f…" file_bytes="182417" mimetype="application/pdf" num_pages="2" dpi="72">
    <page page_index="0" format="markdown" page_width="1700" page_height="2200">
    # Annual Report 2024

    ## Overview
    The company reported revenue of $1.2M.
    </page>
    <page page_index="1" format="markdown" page_width="1700" page_height="2200" status="error"/>
    </document>
    ```

    A single image returns the Markdown string alone, with no wrapper.
  </Tab>

  <Tab title="JSON mode">
    One document entry; each page's `content` is one Markdown block. A failed page
    carries `"status": "error"` and no `content`:

    ```json theme={"theme":{"light":"github-light","dark":"dark-plus"}}
    {
      "model": "zai-org/GLM-OCR",
      "method": "markdown",
      "data": [
        {
          "object": "document",
          "file_name": "tsla-8k.pdf",
          "file_hash": "sha256:1b7f...",
          "file_bytes": 182417,
          "mimetype": "application/pdf",
          "num_pages": 2,
          "dpi": 72,
          "pages": [
            {
              "object": "document.page",
              "page_index": 0,
              "page_width": 1700,
              "page_height": 2200,
              "content": {
                "object": "document.page.blocks",
                "items": [
                  {"index": 0, "text": "# Annual Report 2024\n\n## Overview\nThe company reported revenue of $1.2M."}
                ]
              }
            },
            {"object": "document.page", "page_index": 1, "page_width": 1700, "page_height": 2200, "status": "error"}
          ]
        }
      ]
    }
    ```
  </Tab>
</Tabs>
