Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Image Generation & Vision

OpenCrabs supports image generation (text-to-image and img2img) and vision analysis (image-to-text). Vision works through two paths, pick whichever fits your provider setup.

Vision: Two Paths

Path A: vision_model on Your Active Provider (Preferred)

Set vision_model = "<model>" inside the provider block you’re already using. Works for every built-in and custom provider. No second API key needed, the agent calls analyze_image against the vision model on the same provider endpoint.

# keys.toml
[providers.openrouter]
api_key = "sk-or-..."

# config.toml
[providers.openrouter]
model = "anthropic/claude-sonnet-4"
vision_model = "google/gemini-2.5-flash"   # ← any vision-capable model on the same endpoint

When a user sends an image and the chat model can’t handle it natively, the agent routes the image through vision_model, gets a text description back, and replies with that context.

Example: User sends an image while you’re on MiniMax M2.5 (no native vision). The agent calls the vision tool, which sends the image to MiniMax-Text-01 (or any model you set), gets the description, and M2.5 replies using that context.

Why this is preferred:

  • Single API key, single billing account
  • Works on any OpenAI-compatible endpoint (OpenRouter, Ollama, LM Studio, vLLM, Groq, custom)
  • No extra onboarding step: just add one line to your existing provider block

Path B: Gemini Global Fallback

Use this only when your active provider has no vision-capable model. Gemini acts as a dedicated vision+image backend, independent of your chat provider.

# keys.toml
[image]
api_key = "AIza..."    # ← MUST go here. See gotcha below.

# config.toml
[image.generation]
enabled = true
model = "gemini-3.1-flash-image-preview"

[image.vision]
enabled = true
model = "gemini-3.1-flash-image-preview"

Get a free API key from aistudio.google.com. Configure interactively with /onboard:image.

⚠️ Gotcha: #[serde(skip)] on [image.vision] api_key

The api_key field under [image.vision] in config.toml is silently ignored: it’s marked #[serde(skip)] in the source. Always put the Gemini key in keys.toml under [image], never in config.toml. If vision reports as unavailable despite a key being set, this is almost always the cause.

Diagnostic: Why Is Vision Unavailable?

is_vision_available logs the exact reason at INFO level with target=vision. Search your daily log:

grep 'target=vision' ~/.opencrabs/logs/opencrabs.$(date -u +%Y-%m-%d)

Common causes surfaced:

  • Missing vision_model on active provider (the only field actually required since v0.3.64)
  • Missing api_key for that provider
  • Missing Gemini [image] api_key in keys.toml
  • Key placed in config.toml where #[serde(skip)] drops it

v0.3.64 change: setting vision_model on your active provider is now sufficient to enable vision. The enabled flag under [image.vision] is no longer required. The vision roll-through tries each provider endpoint and falls back to Gemini last.

Génération d’images : deux routes

La génération est un chemin différent de la vision. La vision transforme une image en texte ; la génération transforme un prompt en image. L’outil generate_image est enregistré par la route qui résout en premier, et la génération n’a jamais besoin d’une clé Gemini quand ton propre fournisseur peut la servir.

Route A : generation_model sur un fournisseur (préférée)

Définis generation_model dans un bloc de fournisseur que tu utilises déjà. Le modèle est le modèle d’image de ce fournisseur, et l’endpoint vient du même base_url que le trafic de chat :

# config.toml
[providers.openrouter]
model = "anthropic/"
vision_model = "google/gemini-2.5-flash"
generation_model = "black-forest-labs/flux-1.1-pro"   # ← drives generate_image

Marche pour tous les fournisseurs intégrés et custom. Le protocole est choisi d’après l’endpoint plutôt que deviné : un hôte Gemini utilise l’API Gemini, tout le reste utilise /v1/images/generations avec une authentification Bearer. Donc un fournisseur compatible [OI] qui sert des images n’a besoin que du champ.

Le fournisseur intégré OpenCrabs sert des images au jour 0

Le fournisseur intégré n’est pas que du texte. Le bloc livré nomme déjà un modèle d’image :

# config.toml
[providers.opencrabs]
enabled = false                              # onboarding turns this on when you pick OpenCrabs
default_model = "deepseek-v4.1-flash"
models = ["deepseek-v4.1-flash"]
vision_model = "deepseek-v4.1-flash"
generation_model = "gemini-2.5-flash-image"  # served only on /v1/images/generations
stt_model = "qwen3.8-omni-flash"

Trois choses dans ce bloc valent la peine d’être connues, parce que chacune ressemble à un bug si tu ne les connais pas :

  • gemini-2.5-flash-image n’est pas dans models. Il n’est servi que sur la route image, jamais comme modèle de chat, donc /models ne le proposera jamais et le lister là te valait une requête de chat en échec.
  • context_window est ignoré sur ce fournisseur. L’endpoint est gratuit et fixé à 200k, donc une valeur ici ne change rien.
  • enabled = false est la valeur par défaut livrée. L’onboarding l’active et écrit le token d’installation dans keys.toml sous [providers.opencrabs] api_key. Passer enabled à la main sans ce token te laisse un fournisseur sans identifiant.

Chaîne de fournisseurs pour la génération

generate_image parcourt une chaîne, comme la vision (#1672) :

  1. Le fournisseur actuel de la session, s’il a un generation_model.
  2. La liste [providers.fallback] generation, dans l’ordre.
  3. La section globale Gemini [image.generation], en dernier.
# config.toml
[providers.fallback]
generation = ["openrouter", "qwen-image"]   # provider section names, tried in order

Chaque entrée est un nom de fournisseur (la clé d’une section [providers.<name>] ou [providers.custom.<name>]). Le modèle est le generation_model de ce fournisseur ; les endpoints sont dérivés du bloc du fournisseur et jamais devinés.

Le flag enabled sous [image.generation] ne contrôle QUE le fallback global Gemini. Une route de fournisseur enregistre generate_image même avec lui éteint. C’est le but du #1672 : un modèle d’image sur un fournisseur que tu paies déjà marche sans seconde clé Gemini et sans activer le fallback.

Route B : Gemini comme backend d’images dédié

Quand aucun fournisseur de ta liste ne sert d’images, utilise la section globale Gemini décrite dans Path B plus haut. Elle gère l’entrée vision et la sortie image en une seule requête, et c’est la seule jambe que contrôle le flag [image.generation] enabled.

Laquelle j’utilise ?

Une génération réussie ne dit pas quelle route elle a prise ; le résultat n’est que le chemin du fichier enregistré. La chaîne est visible quand ça échoue, parce que chaque candidat est tenté et l’erreur agrégée les liste dans l’ordre comme backend(model).

All 2 image generation candidates failed - openai(flux-1.1-pro): 404 ... | gemini(gemini-2.5-flash-image): 400 ...

Donc le diagnostic est : génère une fois, et lis l’erreur si elle revient vide. Une jambe gemini(...) après une jambe openai(...) veut dire que ta route de fournisseur a été tentée d’abord et n’a pas marché. Si l’outil répond avec l’indice de configuration, aucune route n’a résolu du tout :

Image generation is not configured. Options: `/image gemini <GOOGLE_AI_KEY>` for Gemini,
or set `generation_model = "<model>"` on a provider section ...

Agent Tools

When vision or image generation is enabled, these tools become available:

ToolDescription
generate_imageGenerate an image from a text prompt: saves to ~/.opencrabs/images/; walks a provider chain with vision parity, so generation falls back the same way vision does (v0.5.4, #1672)
analyze_imageAnalyze an image file or URL via the active vision path (Path A provider or Gemini fallback)

Example prompts:

  • “Generate a pixel art crab logo”: agent calls generate_image, returns file path
  • “What’s in this image: /tmp/screenshot.png”, agent calls analyze_image

img2img: Edit Images with Context

generate_image accepts an optional image parameter (local file path or HTTPS URL). When provided, the model modifies, restyles, or composites onto that image instead of generating from scratch.

User: "Make this logo darker and add a border"
Agent: generate_image(prompt="dark background with thin white border", image="/tmp/logo.png")
  • Voie Gemini : l’image d’entrée accompagne la requête sous forme de partie inlineData, à côté du prompt.
  • Voie compatible OpenAI : la requête passe de /images/generations à /images/edits, avec une partie image[] par image d’entrée. Tout modèle sur cet endpoint qui accepte les éditions peut restyler ou composer.

Use cases: replace elements, restyle photos, composite logos onto backgrounds, modify user-uploaded images in-place.

Incoming Images from Channels

When a user sends an image from any channel, it arrives as <<IMG:/tmp/path>> in the message. The file is already downloaded, the agent can:

  • See it directly (if the chat model supports vision natively)
  • Pass the path to analyze_image for vision processing
  • Use the path in bash commands or any tool that accepts file paths
  • Reference it in replies with <<IMG:path>> to forward to channels

analyze_video: Frame-Extraction Fallback (v0.3.36)

The analyze_video tool sends the full video to Gemini’s video API for multimodal analysis. When that fails (network error, upload timeout, unsupported format), the agent falls back to ffmpeg frame extraction:

  1. Extract frames at 1 fps via ffmpeg
  2. Cap at 30 frames (one frame per second for the first 30 seconds)
  3. Send each frame to Gemini vision via analyze_image
  4. Combine per-frame descriptions into a chronological summary

This means analyze_video works even when the video API is unreachable, as long as ffmpeg is installed and at least one vision path (Path A or Path B) is configured. The fallback activates automatically. No user configuration needed.

Model Choices

  • Path A: any vision-capable model on your active provider. On OpenRouter: google/gemini-2.5-flash, anthropic/claude-sonnet-4, openai/gpt-4o. On Ollama: llava, bakllava. On custom endpoints: whatever the server offers.
  • Path B: gemini-3.1-flash-image-preview handles both vision input and image output in a single request.