Skip to main content
Lesson 10 of 18 · Mistral Agents: Building Autonomous AI

image_generation Tool: Create Images

Lesson 10 of 18 Updated November 2, 2026 Developer
On this page
  1. Generate Images Through Your Agent
  2. Create an Agent with Image Generation
  3. Generate an Image
  4. Download Generated Images
  5. Three Common Use Cases
  6. Combine with Other Tools
  7. Write Good Image Prompts
  8. Manage Generated Files
  9. Key Takeaways

Generate Images Through Your Agent

The image_generation tool lets your agent create images from text descriptions. It complements the tools you’ve already seen: while code_interpreter produces numbers and charts, this one produces visuals. It’s a powerful tool for creative use cases, mockup generation, or illustrating concepts. Like other built-in tools, you enable it when creating the agent, and the model decides whether to call it based on the request.

Create an Agent with Image Generation

from mistralai.client import Mistral
import os

client = Mistral(api_key=os.environ["MISTRAL_API_KEY"])

agent = client.beta.agents.create(
    model="mistral-medium-latest",
    name="Creative Agent",
    instructions="""You are a creative assistant specialized in image generation.
- Rephrase requests into detailed prompts for better results
- Describe the image you are about to generate before creating it
- Propose variations if the result is unsatisfactory""",
    tools=[{"type": "image_generation"}],
    completion_args={"temperature": 0.3, "top_p": 0.95}
)

Instructions carry significant weight here. By asking the agent to rephrase the request into a detailed prompt, you transform a vague “make me an image of a cat” into an actionable description. By having it announce the image before generating it, you give yourself a chance to course-correct before generation happens. A temperature of 0.3 keeps this rephrasing disciplined: you want descriptive precision, not free invention.

Generate an Image

response = client.beta.conversations.start(
    agent_id=agent.id,
    inputs="Generate an image of an orange cat in a modern office."
)

Behind this single call, the agent chains four steps: it analyzes your request, formulates a prompt optimized for the generation model, creates the image, and then returns the file. These steps appear in the conversation outputs, letting you see which prompt produced which image. This is invaluable when a result pleases you and you want to reproduce it.

Download Generated Images

Images don’t return as text in the response: they arrive as ToolFileChunk objects in the content, and you retrieve the actual file via the Files API.

from mistralai.client.models import ToolFileChunk

for i, chunk in enumerate(response.outputs[-1].content):
    if isinstance(chunk, ToolFileChunk):
        # Download the image file
        file_bytes = client.files.download(file_id=chunk.file_id).read()

        # Save locally
        with open(f"image_{i}.png", "wb") as f:
            f.write(file_bytes)
        print(f"Image saved: image_{i}.png")

Three Common Use Cases

The first is documentation illustration, where a diagram explains better than a paragraph.

response = client.beta.conversations.start(
    agent_id=agent.id,
    inputs="Create a visual diagram showing a microservices architecture with an API Gateway, 3 services, and a database."
)

The second is visual mockups, to materialize a direction before engaging a designer.

response = client.beta.conversations.start(
    agent_id=agent.id,
    inputs="Generate a homepage mockup for an online learning website, modern and minimalist style with blue tones."
)

The third is marketing content creation, where the agent produces a tailored visual from a written brief.

response = client.beta.conversations.start(
    agent_id=agent.id,
    inputs="Create a promotional banner for an AI course, with the text 'Master AI in 2026' on a tech background."
)

In all three cases, brief quality determines result quality: a creative agent doesn’t invent your intent, it executes it.

Combine with Other Tools

Image generation reaches its full potential when paired with other tools. Searching for data, analyzing it, and then illustrating it becomes a single seamless flow from the user’s perspective.

agent = client.beta.agents.create(
    model="mistral-large-latest",
    name="Multimodal Agent",
    description="Search, code, and images.",
    instructions="Use search to find data, code to analyze it, and image generation to illustrate it.",
    tools=[
        {"type": "web_search"},
        {"type": "code_interpreter"},
        {"type": "image_generation"}
    ]
)

Write Good Image Prompts

Five levers significantly improve results. First, be descriptive: “A striped orange cat sitting on a wooden desk, natural lighting, photographic style” yields a completely different image than “a cat.” Next, specify the expected style—photographic, illustration, watercolor, minimalist. Indicate the composition, meaning front view, high angle, close-up, or wide shot. Mention the lighting, whether natural, studio, backlit, or golden hour. Finally, specify colors: warm palette, cool tones, monochrome. These five axes are exactly what you write into the agent’s instructions so it can enrich overly short requests from your users.

Manage Generated Files

Generated images are stored temporarily in the Mistral cloud via the Files API. Make it a habit to inventory and clean up: otherwise, your space fills with forgotten drafts, and files you needed disappear because they weren’t downloaded in time.

# List files
files = client.files.list()
for f in files.data:
    print(f"{f.id} — {f.filename} — {f.bytes} bytes")

# Delete a file
client.files.delete(file_id="file-xxxxxxxx")

Key Takeaways

  • image_generation creates images from text descriptions
  • Images return as ToolFileChunk objects and are downloadable via client.files.download()
  • Detailed prompts (style, composition, lighting) significantly improve results
  • The tool can be combined with web_search and code_interpreter
  • Generated files are temporary—download them or they will be deleted