From 6eb7ebe0eff93fcc1bc231dd0990e750d233f40f Mon Sep 17 00:00:00 2001 From: Paul DESREUX Date: Mon, 12 Oct 2026 18:43:32 +0200 Subject: [PATCH 1/4] feat(gen-api) Add OCR docs MTA-7591 --- .../how-to/query-ocr-models.mdx | 117 ++++++++++++++++++ pages/generative-apis/menu.ts | 4 + 2 files changed, 121 insertions(+) create mode 100644 pages/generative-apis/how-to/query-ocr-models.mdx diff --git a/pages/generative-apis/how-to/query-ocr-models.mdx b/pages/generative-apis/how-to/query-ocr-models.mdx new file mode 100644 index 0000000000..c1937d0b22 --- /dev/null +++ b/pages/generative-apis/how-to/query-ocr-models.mdx @@ -0,0 +1,117 @@ +--- +title: How to query OCR models +description: Learn how to interact with powerful OCR models using Scaleway's Generative APIs service. +tags: generative-apis ai-data ocr-models chat-completions-api +dates: + validation: 2025-10-13 + posted: 2026-10-13 +--- +import Requirements from '@macros/iam/requirements.mdx' + +Scaleway's Generative APIs service allows users to interact with powerful OCR (Optical Character Recognition) models hosted on the platform. + + + - OCR models are designed specifically to detect and extract text from images. They focus on identifying characters, words, and text layout within an image. + - They are different from [vision models](/generative-apis/how-to/query-vision-models/), who are designed to analyze visual content, like objects, scenes, activities. + + +There are several ways to interact with OCR models: + +- **Scaleway console playground**: The Scaleway [console](https://console.scaleway.com) provides a complete [playground](/generative-apis/quickstart/#interacting-with-generative-apis-via-the-playground) for Generative APIs. This visual interface allows you to test models, adapt query parameters, and observe how these changes affect the output in real-time. +- **[Chat Completions API](https://www.scaleway.com/en/developers/api/generative-apis/chat-completions)**: Use the chat completions API to query vision models programmatically. +- **Your own [dedicated deployment](/generative-apis/how-to/create-deployment/)**: Deploy a model on your own Instance and interact with the model in an isolated environment + + + +- A Scaleway account logged into the [console](https://console.scaleway.com) +- [Owner](/iam/concepts/glossary/#owner) status or [IAM permissions](/iam/concepts/glossary/#permission) allowing you to perform actions in the intended Organization +- A valid [API key](/iam/credentials/create-api-keys/) for API authentication +- Python 3.7+ installed on your system + +## Accessing the playground + +Scaleway provides a web playground for vision models hosted on Generative APIs. + +1. Navigate to **Generative APIs** under the **AI** section of the [Scaleway console](https://console.scaleway.com/) side menu. The list of models you can query displays. Select the **Serverless** toggle button. +2. Click the name of the vision model you want to try. Alternatively, click **Try** next to the model's name. + +The web playground displays. + +## Using the playground +1. Upload a `.pdf` file to the prompt area at the bottom of the page, or click **Analyze sample document**. The model starts detecting your document and rendering text. +2. Scroll down the rendered text to find an estimation of the number of input/output tokens, and the total amount of consumed tokens for this task. +3. Click **Use**, to see the code snippets configured according to your settings in the playground. + + +## Querying OCR models via the API + +You can query OCR models programmatically using your favorite tools or languages. + +OCR models take both text and images as inputs. + +In the example that follows, we will use the OpenAI Python client. + + + Unlike traditional language models, OCR models will take a single file as input. + + +### Installing the OpenAI SDK + +Install the OpenAI SDK using pip: + +```bash +pip install openai +``` + +### Initializing the client + +Initialize the OpenAI client with your base URL and API key, and define the file that you want to analyze. For the example, we will use this file: https://genapi-documentation-assets.s3.fr-par.scw.cloud/scaleway-impact-report-3-pages.pdf. + + + In the case of a dedicated Generative APIs deployment, the `base_url` value is the **Public Endpoint URL** displayed on the Overview tab of the deployment's dashboard. + + +```python +from openai import OpenAI +import base64 +import os +import urllib.request + +# Define the FILE that the OCR model will analyze. Here we use a public scaleway document for the example +FILE = "https://genapi-documentation-assets.s3.fr-par.scw.cloud/scaleway-impact-report-3-pages.pdf" + +# Initialize the client with your base URL and API key +client = OpenAI( + base_url = "https://api.scaleway.ai/999d23ea-7afa-485f-9d6c-27db078f1527/v1", + api_key = os.getenv"" # Replace with your IAM API key +) + +with urllib.request.urlopen(FILE) as response: + encoded_file = base64.b64encode(response.read()).decode("utf-8") +``` + +### Generating a chat completion + +You can now create a chat completion: + +```python +response = client.chat.completions.create( + model="lightonocr-3-0.8b", + messages=[ + { + "role": "user", + "content": [{ + "type": "file", + "file": { + "file_data": f"data:application/pdf;base64,{encoded_file}" + } + } + ] + } + ], + stream=False, +) + +if response.choices and response.choices[0].message.content: + print(response.choices[0].message.content) +``` diff --git a/pages/generative-apis/menu.ts b/pages/generative-apis/menu.ts index 163f7fc546..350dbddea9 100644 --- a/pages/generative-apis/menu.ts +++ b/pages/generative-apis/menu.ts @@ -30,6 +30,10 @@ export const generativeApisMenu = { label: 'Query vision models', slug: 'query-vision-models', }, + { + label: 'Query OCR models', + slug: 'query-ocr-models', + }, { label: 'Query embedding models', slug: 'query-embedding-models', From 059ea5202ef601e812b52ea0295ebe69062105a4 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 13 Oct 2026 09:31:20 +0200 Subject: [PATCH 2/4] Apply batched suggestions from code review Co-authored-by: mmfrayssens Co-authored-by: Paul --- .../how-to/query-ocr-models.mdx | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/pages/generative-apis/how-to/query-ocr-models.mdx b/pages/generative-apis/how-to/query-ocr-models.mdx index c1937d0b22..9b44035155 100644 --- a/pages/generative-apis/how-to/query-ocr-models.mdx +++ b/pages/generative-apis/how-to/query-ocr-models.mdx @@ -1,6 +1,6 @@ --- title: How to query OCR models -description: Learn how to interact with powerful OCR models using Scaleway's Generative APIs service. +description: Learn how to interact with powerful OCR models using Scaleway Generative APIs. tags: generative-apis ai-data ocr-models chat-completions-api dates: validation: 2025-10-13 @@ -8,18 +8,17 @@ dates: --- import Requirements from '@macros/iam/requirements.mdx' -Scaleway's Generative APIs service allows users to interact with powerful OCR (Optical Character Recognition) models hosted on the platform. +The Scaleway Generative APIs service allows users to interact with powerful OCR (Optical Character Recognition) models hosted on the platform. - OCR models are designed specifically to detect and extract text from images. They focus on identifying characters, words, and text layout within an image. - - They are different from [vision models](/generative-apis/how-to/query-vision-models/), who are designed to analyze visual content, like objects, scenes, activities. + - They are different from [vision models](/generative-apis/how-to/query-vision-models/), which are designed to analyze visual content, such as objects, scenes, and activities. There are several ways to interact with OCR models: - **Scaleway console playground**: The Scaleway [console](https://console.scaleway.com) provides a complete [playground](/generative-apis/quickstart/#interacting-with-generative-apis-via-the-playground) for Generative APIs. This visual interface allows you to test models, adapt query parameters, and observe how these changes affect the output in real-time. -- **[Chat Completions API](https://www.scaleway.com/en/developers/api/generative-apis/chat-completions)**: Use the chat completions API to query vision models programmatically. -- **Your own [dedicated deployment](/generative-apis/how-to/create-deployment/)**: Deploy a model on your own Instance and interact with the model in an isolated environment +- **[Chat Completions API](https://www.scaleway.com/en/developers/api/generative-apis/chat-completions)**: Use the chat completions API to query the OCR models programmatically. @@ -28,22 +27,23 @@ There are several ways to interact with OCR models: - A valid [API key](/iam/credentials/create-api-keys/) for API authentication - Python 3.7+ installed on your system -## Accessing the playground +## Access the playground Scaleway provides a web playground for vision models hosted on Generative APIs. -1. Navigate to **Generative APIs** under the **AI** section of the [Scaleway console](https://console.scaleway.com/) side menu. The list of models you can query displays. Select the **Serverless** toggle button. -2. Click the name of the vision model you want to try. Alternatively, click **Try** next to the model's name. +1. In the [Scaleway console](https://console.scaleway.com/) side menu, go to **AI** > **Generative APIs**. The list of models you can query appears. Select the **Serverless** toggle button. +2. Click the name of the OCR model you want to try. Alternatively, click **Try** next to the name of the model. -The web playground displays. +The web playground opens. + +## Use the playground -## Using the playground 1. Upload a `.pdf` file to the prompt area at the bottom of the page, or click **Analyze sample document**. The model starts detecting your document and rendering text. 2. Scroll down the rendered text to find an estimation of the number of input/output tokens, and the total amount of consumed tokens for this task. 3. Click **Use**, to see the code snippets configured according to your settings in the playground. -## Querying OCR models via the API +## Query OCR models via the API You can query OCR models programmatically using your favorite tools or languages. @@ -52,10 +52,10 @@ OCR models take both text and images as inputs. In the example that follows, we will use the OpenAI Python client. - Unlike traditional language models, OCR models will take a single file as input. + Unlike traditional language models, OCR models take a single file as input. -### Installing the OpenAI SDK +### Install the OpenAI SDK Install the OpenAI SDK using pip: @@ -63,13 +63,10 @@ Install the OpenAI SDK using pip: pip install openai ``` -### Initializing the client +### Initialize the client Initialize the OpenAI client with your base URL and API key, and define the file that you want to analyze. For the example, we will use this file: https://genapi-documentation-assets.s3.fr-par.scw.cloud/scaleway-impact-report-3-pages.pdf. - - In the case of a dedicated Generative APIs deployment, the `base_url` value is the **Public Endpoint URL** displayed on the Overview tab of the deployment's dashboard. - ```python from openai import OpenAI @@ -90,7 +87,7 @@ with urllib.request.urlopen(FILE) as response: encoded_file = base64.b64encode(response.read()).decode("utf-8") ``` -### Generating a chat completion +### Generate a chat completion You can now create a chat completion: From be35547b526c594b180bbaa5b3580cab323e244c Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 13 Oct 2026 09:35:30 +0200 Subject: [PATCH 3/4] Apply batched suggestions from code review Co-authored-by: vanda-scw Co-authored-by: Paul --- pages/generative-apis/how-to/query-ocr-models.mdx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pages/generative-apis/how-to/query-ocr-models.mdx b/pages/generative-apis/how-to/query-ocr-models.mdx index 9b44035155..d1f15c82e8 100644 --- a/pages/generative-apis/how-to/query-ocr-models.mdx +++ b/pages/generative-apis/how-to/query-ocr-models.mdx @@ -29,10 +29,11 @@ There are several ways to interact with OCR models: ## Access the playground -Scaleway provides a web playground for vision models hosted on Generative APIs. +Scaleway provides a web playground for OCR models hosted on Generative APIs. -1. In the [Scaleway console](https://console.scaleway.com/) side menu, go to **AI** > **Generative APIs**. The list of models you can query appears. Select the **Serverless** toggle button. -2. Click the name of the OCR model you want to try. Alternatively, click **Try** next to the name of the model. +1. In the [Scaleway console](https://console.scaleway.com/) side menu, go to **AI** > **Generative APIs**. The list of models you can query appears. +2. Select the **Serverless** toggle button. +3. Click the name of the OCR model you want to try. Alternatively, click **Try** next to the name of the model. The web playground opens. @@ -40,7 +41,7 @@ The web playground opens. 1. Upload a `.pdf` file to the prompt area at the bottom of the page, or click **Analyze sample document**. The model starts detecting your document and rendering text. 2. Scroll down the rendered text to find an estimation of the number of input/output tokens, and the total amount of consumed tokens for this task. -3. Click **Use**, to see the code snippets configured according to your settings in the playground. +3. Click **Use** to see the code snippets configured according to your settings in the playground. ## Query OCR models via the API @@ -52,7 +53,7 @@ OCR models take both text and images as inputs. In the example that follows, we will use the OpenAI Python client. - Unlike traditional language models, OCR models take a single file as input. + Unlike traditional language models, OCR models take a single file as input. See the `python` example below to understand the expected requested format. ### Install the OpenAI SDK @@ -74,7 +75,7 @@ import base64 import os import urllib.request -# Define the FILE that the OCR model will analyze. Here we use a public scaleway document for the example +# Define the FILE that the OCR model will analyze. Here we use a public Scaleway document for the example FILE = "https://genapi-documentation-assets.s3.fr-par.scw.cloud/scaleway-impact-report-3-pages.pdf" # Initialize the client with your base URL and API key From 7728a8f003011dbae3237e83a72106276c973635 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 13 Oct 2026 09:38:17 +0200 Subject: [PATCH 4/4] Apply batched suggestions from code review Co-authored-by: Paul --- pages/generative-apis/how-to/query-ocr-models.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/generative-apis/how-to/query-ocr-models.mdx b/pages/generative-apis/how-to/query-ocr-models.mdx index d1f15c82e8..3ebfe78056 100644 --- a/pages/generative-apis/how-to/query-ocr-models.mdx +++ b/pages/generative-apis/how-to/query-ocr-models.mdx @@ -18,7 +18,7 @@ The Scaleway Generative APIs service allows users to interact with powerful OCR There are several ways to interact with OCR models: - **Scaleway console playground**: The Scaleway [console](https://console.scaleway.com) provides a complete [playground](/generative-apis/quickstart/#interacting-with-generative-apis-via-the-playground) for Generative APIs. This visual interface allows you to test models, adapt query parameters, and observe how these changes affect the output in real-time. -- **[Chat Completions API](https://www.scaleway.com/en/developers/api/generative-apis/chat-completions)**: Use the chat completions API to query the OCR models programmatically. +- **[Chat Completions API](https://www.scaleway.com/en/developers/api/generative-apis/chat-completions)**: Use the Chat Completions API to query OCR models programmatically.