Introduction

The Tinfoil Private Inference API enables you to perform image analysis using Mistral’s vision capabilities while ensuring complete privacy. Unlike traditional cloud AI services, your images never leave the secure enclave environment, protecting sensitive visual data from exposure.

Prerequisites

For this tutorial, you’ll need:

  • A Tinfoil API key (get one at tinfoil.sh)
  • Python 3.7 or higher
  • An image file to analyze (e.g., apple.png)

You’re billed for all usage of the Tinfoil Inference API. See the Tinfoil Pricing for current pricing information.

Security Warning Never share your API key, be careful to not include it in version control systems, and never bundle it in with front-end client code.

Install the Tinfoil SDK

First, install the Tinfoil Python SDK:

pip install tinfoil

Image Analysis Example

Here’s a complete example that demonstrates how to analyze an image using Mistral’s vision capabilities through Tinfoil:

import os
import base64
import mimetypes
from tinfoil import TinfoilAI

# Initialize the Tinfoil client
client = TinfoilAI(
    enclave="mistral-s-3-1-24b-p.model.tinfoil.sh",
    repo="tinfoilsh/confidential-mistral-small-3-1",
    api_key=os.getenv("TINFOIL_API_KEY"),
)

# Prepare the image
image_path = "apple.png"
with open(image_path, "rb") as image_file:
    base64_image = base64.b64encode(image_file.read()).decode('utf-8')
mime_type, _ = mimetypes.guess_type(image_path)

# Create the completion request
completion = client.chat.completions.create(
    model="mistral-small-3-1-24b",
    messages=[{
        "role": "user",
        "content": [
            {"type": "text", "text": "What is this?"},
            {
                "type": "image_url",
                "image_url": {
                    "url": f"data:{mime_type};base64,{base64_image}"
                }
            }
        ]
    }]
)

# Print the analysis result
print(completion.choices[0].message.content)

Supported Image Formats

Mistral’s vision model supports common image formats including:

  • JPEG (.jpg, .jpeg)
  • PNG (.png)
  • GIF (.gif)
  • WebP (.webp)

Best Practices For optimal results, use high-quality images with clear subjects. The model performs better on images with good contrast and resolution.

Next Steps