---
title: How to query vision models
description: Learn how to interact with powerful vision models using Scaleway's Generative APIs service.
tags: generative-apis ai-data vision-models chat-completions-api
dates:
  validation: 2025-11-19
  posted: 2024-10-30
---
import Requirements from '@macros/iam/requirements.mdx'

Scaleway's Generative APIs service allows users to interact with powerful vision models hosted on the platform.

<Message type="note">
  Vision models can understand and analyze images, not generate them. 
</Message>

There are several ways to interact with vision 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

<Requirements />

- A Scaleway account logged into the [console](https://console.scaleway.com)
- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization
- A valid [API key](/iam/how-to/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 one or multiple images to the prompt area at the bottom of the page. Enter a prompt, for example, to describe the image(s) you attached.
2. Edit the hyperparameters listed on the right column, for example the default temperature for more or less randomness on the outputs. 
3. Switch models at the top of the page, to observe the capabilities of chat and vision models offered via Generative APIs. 
4. Click **Deploy**, then select the **Serverless** option to get code snippets configured according to your settings in the playground. 
    
    You can also choose to deploy a model on your own dedicated Instance by selecting the **Dedicated** option. In this case, you can access the playground after completing the steps in the deployment wizard. Once in the playground of your deployment, click **View code** to get code snippets that match your settings in the playground. 

## Querying vision models via the API

You can query vision models programmatically using your favorite tools or languages.

Vision models take both text and images as inputs.

In the example that follows, we will use the OpenAI Python client.

<Message type="tip">
  Unlike traditional language models, vision models will take a content array for the user role, structuring text and images as inputs.
</Message>

### 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:

<Message type="tip">
    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.
</Message>

```python
from openai import OpenAI

# Initialize the client with your base URL and API key
client = OpenAI(
    base_url="https://api.scaleway.ai/v1",  # Scaleway's Generative APIs service URL
    api_key="<SCW_SECRET_KEY>"  # Your unique API secret key from Scaleway
)
```

### Generating a chat completion

You can now create a chat completion:

```python
# Create a chat completion using the 'mistral-small-3.2-24b-instruct-2506' model
response = client.chat.completions.create(
    model="mistral-small-3.2-24b-instruct-2506",
    messages=[
    {
        "role": "user",
        "content": [
            {"type": "text", "text": "What is this image?"},
            {"type": "image_url", "image_url": {"url": "https://picsum.photos/id/32/512/512"}},
        ] #  Vision models will take a content array with text and image_url objects.

    }
    ],
    temperature=0.7,  # Adjusts creativity
    max_tokens=2048,   # Limits the length of the output
    top_p=0.9         # Controls diversity through nucleus sampling. You usually only need to use temperature.
)

# Print the generated response
print(response.choices[0].message.content)
```

This code sends messages, prompts and images, to the vision model and returns an answer based on your input. The `temperature`, `max_tokens`, and `top_p` parameters control the response's creativity, length, and diversity, respectively.

A conversation style may include a default system prompt. You may set this prompt by setting the first message with the role system. For example:

```python
[
  {
  	"role": "system",
  	"content": "You are an expert developer."
  }
]
```

### Passing images to the vision model

1. **Image URLs**: If the image is available online, you can just include the image URL in your request as demonstrated above. This approach is simple and does not require any encoding.
2. **Base64 encoded**: image Base64 encoding is a standard way to transform binary data, like images, into a text format, making it easier to transmit over the internet.

The following code sample shows you how to encode an image in Base64 format and pass it to a request payload for the Chat Completions API, with an [example image](https://genapi-documentation-assets.s3.fr-par.scw.cloud/scaleway-illustration-robot.jpg).

```python
import base64

with open("path/to/your/image.png", "rb") as file:
    image_content = file.read()
    encoded_image = base64.b64encode(image_content).decode("utf-8")

response = client.chat.completions.create(
    model="mistral-small-3.2-24b-instruct-2506",
    messages=[
      {
          "role": "user",
          "content": [
              {"type": "text", "text": "What is this image?"},
              {"type": "image_url",
                  "image_url": {
                  "url": f"data:image/jpeg;base64,{encoded_image}"}
              },
          ]
      }
    ],
    temperature=0.7,
    max_tokens=2048,
    top_p=0.9
)

```

### Model parameters and their effects 

When using the Chat Completions API, the following parameters will influence the output of the model:

- **`messages`**: A list of message objects that represent the conversation history. Each message should have a `role` (e.g., "system", "user", "assistant") and `content`. The content is an array that can contain text and/or image objects.
- **`temperature`**: Controls the output's randomness. Lower values (e.g., 0.2) make the output more deterministic, while higher values (e.g., 0.8) make it more creative.
- **`max_tokens`**: The maximum number of tokens (words or parts of words) in the generated output.
- **`top_p`**: Recommended for advanced use cases only. You usually only need to use temperature. `top_p` controls the diversity of the output, using nucleus sampling, where the model considers the tokens with top probabilities until the cumulative probability reaches `top_p`.
- **`stop`**: A string or list of strings where the model will stop generating further tokens. This is useful for controlling the end of the output.

### Passing videos to the vision model

Videos can also be sent to vision models with this capability, such as `qwen3.5-397b-a17b`.
To analyze a video, edit the message content field:
```python
    messages=[
      {
          "role": "user",
          "content": [
              {"type": "text", "text": "What is this video?"},
              {"type": "video_url",
                  "video_url": {
                  "url": f"data:video/mp4;base64,{encoded_video}"}
              },
          ]
      }
    ],
```


## Streaming

By default, the outputs are returned to the client only after the generation process is complete. However, a common alternative is to stream the results back to the client as they are generated. This is particularly useful in chat applications, where it allows the client to view the results incrementally as each token is produced.

An example for the Chat Completions API is provided below:

```python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.scaleway.ai/v1",  # Scaleway's Generative APIs service URL
    api_key="<SCW_API_KEY>"  # Your unique API key from Scaleway
)
response = client.chat.completions.create(
  model="mistral-small-3.2-24b-instruct-2506",
  messages=[{
      "role": "user", 
      "content": [
          {"type": "text", "text": "What is this image?"},
          {"type": "image_url", "image_url": {"url": "https://picsum.photos/id/32/512/512"}},
      ]
  }],
  stream=True,
)

for chunk in response:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")
```


## Async

The service also supports asynchronous mode for any chat completion. An example for the Chat Completions API is provided below:

```python

import asyncio
from openai import AsyncOpenAI

client = AsyncOpenAI(
    base_url="https://api.scaleway.ai/v1",  # Scaleway's Generative APIs service URL
    api_key="<SCW_API_KEY>"  # Your unique API key from Scaleway
)

async def main():
    stream = await client.chat.completions.create(
        model="mistral-small-3.2-24b-instruct-2506",
        messages=[{
            "role": "user", 
            "content": [
                {"type": "text", "text": "What is this image?"},
                {"type": "image_url", "image_url": {"url": "https://picsum.photos/id/32/512/512"}},
            ]
        }],
        stream=True,
    )
    async for chunk in stream:
        if chunk.choices and chunk.choices[0].delta.content:
            print(chunk.choices[0].delta.content, end="")

asyncio.run(main())
```

## Frequently Asked Questions

#### Is there a limit to the size of each image?
The only limitation are the tokens context window and the maximum resolution supported by the model (images will be automatically downscaled to fit within maximum resolution). Refer to our [model catalog](/generative-apis/reference-content/supported-models/##model-details) for more information about supported formats and token dimensions for each model.

#### What is the maximum amount of images per conversation?
Each conversation can handle up to 12 images (per request). Attempting to add a 13th image will result in a `400 Bad Request` error.
