# Nanonets-OCR-s

**Nanonets-OCR-s** is an optical character recognition (OCR) model that converts a document image into structured Markdown. The output keeps the layout of the source, including headings, lists, tables, and basic tags, so another model can parse it. [AI Inference](/en/documentation/platform/ai-inference/) runs it under the id `nanonets/Nanonets-OCR-s`.

## Model details

The model id selects this model in a request, and `Azion.AI.run` takes it as the first argument.

| Detail     | Value                     |
| ---------- | ------------------------- |
| Model name | Nanonets-OCR-s            |
| Model id   | `nanonets/Nanonets-OCR-s` |

## Capabilities

The values here describe the model itself, and none of them is a field in the request body. To look up the fields a request body accepts, with their types, defaults, and bounds, refer to [Model invocation](/en/documentation/platform/ai-inference/model-invocation/).

| Capability     | Value          |
| -------------- | -------------- |
| Input data     | Text and image |
| Context length | 32k tokens     |

---

## Usage

`Azion.AI.run` runs the model from inside a [function](/en/documentation/platform/functions/): the id goes in the first argument, and an OpenAI-compatible request body goes in the second. The example on this page calls it that way. To send the same body over HTTP instead, refer to [Model invocation](/en/documentation/platform/ai-inference/model-invocation/).

### OCR

An OCR request carries the document image and the instruction that tells the model how to transcribe it. Both travel in one user message, as a `content` array whose parts each state a `type`. For the fields each part carries, refer to [Message objects](/en/documentation/platform/ai-inference/model-invocation/#message-objects). This request reads a base64-encoded PNG and caps the answer at 500 tokens:

```ts
const modelResponse = await Azion.AI.run("nanonets/Nanonets-OCR-s", {
  "stream": false,
  "max_tokens": 500,
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "image_url",
          "image_url": {
            "url": "data:image/png;base64,{img_base64}"
          }
        },
        {
          "type": "text",
          "text": "Extract the text from the above document as if you were reading it naturally. Return the tables in html format. Return the equations in LaTeX representation. If there is an image in the document and image caption is not present, add a small description of the image inside the <img></img> tag; otherwise, add the image caption inside <img></img>. Watermarks should be wrapped in brackets. Ex: <watermark>OFFICIAL COPY</watermark>. Page numbers should be wrapped in brackets. Ex: <page_number>14</page_number> or <page_number>9/22</page_number>. Prefer using ☐ and ☑ for check boxes."
        }
      ]
    }
  ]
})
```

The model returns one entry in `choices`, and the transcribed text sits at `choices[0].message.content`:

```json
{
  "id": "chatcmpl-0123456789abcdef0123456789abcdef",
  "object": "chat.completion",
  "created": 1767268800,
  "model": "nanonets/Nanonets-OCR-s",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "reasoning_content": null,
        "content": "E = mc^2",
        "tool_calls": []
      },
      "logprobs": null,
      "finish_reason": "stop",
      "stop_reason": null
    }
  ],
  "usage": {
    "prompt_tokens": 9,
    "total_tokens": 527,
    "completion_tokens": 518,
    "prompt_tokens_details": null
  },
  "prompt_logprobs": null
}
```

---

## Related resources

- [Model invocation](/en/documentation/platform/ai-inference/model-invocation.md): Every field a request body accepts, and the HTTP endpoint that takes the same body.
- [AI models](/en/documentation/platform/ai-inference/models.md): The other models AI Inference runs, and the id each one answers to.
- [AI Inference](/en/documentation/platform/ai-inference.md): The product that runs this model.
- [Functions](/en/documentation/platform/functions.md): The product whose runtime holds the binding the example on this page calls.
- [AI Inference limits](/en/documentation/platform/ai-inference/limits.md): The conditions under which Azion terminates or deprovisions a model.
- [Glossary](/en/documentation/platform/ai-inference/glossary.md): Where model id, context length, and the rest of the AI Inference vocabulary are defined.
