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.

Pembuatan gambar: dua rute

Pembuatan adalah jalur berbeda dari vision. Vision mengubah gambar jadi teks; pembuatan mengubah prompt jadi gambar. Tool generate_image didaftarkan oleh rute yang lebih dulu berhasil, dan pembuatan tidak pernah butuh kunci Gemini kalau provider-mu sendiri bisa melayaninya.

Rute A: generation_model pada provider (disarankan)

Set generation_model di dalam blok provider yang sudah kamu pakai. Modelnya adalah model gambar milik provider itu, dan endpoint-nya datang dari base_url yang sama dengan lalu lintas 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

Bekerja untuk semua provider bawaan dan custom. Protokolnya dipilih dari endpoint bukan ditebak: host Gemini memakai API Gemini, sisanya memakai /v1/images/generations dengan autentikasi Bearer. Jadi provider yang kompatibel [OI] yang melayani gambar hanya butuh field itu.

Provider bawaan OpenCrabs melayani gambar di hari ke-0

Provider bawaan bukan hanya teks. Blok yang dikirim sudah menyebut model gambar:

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

Ada tiga hal soal blok itu yang layak diketahui, karena masing-masing terlihat seperti bug kalau kamu tidak tahu:

  • gemini-2.5-flash-image tidak ada di models. Ia hanya dilayani di rute gambar, tidak pernah sebagai model chat, jadi /models tidak akan pernah menawarkannya dan mencantumkannya di sana membelikanmu permintaan chat yang gagal.
  • context_window diabaikan pada provider ini. Endpoint-nya gratis dan tetap di 200k, jadi nilai di sini tidak mengubah apa pun.
  • enabled = false adalah default yang dikirim. Onboarding menyalakannya dan menulis token instalasi ke keys.toml pada [providers.opencrabs] api_key. Mengubah enabled manual tanpa token itu meninggalkanmu dengan provider tanpa kredensial.

Rantai provider untuk pembuatan

generate_image menelusuri rantai, sama seperti vision (#1672):

  1. Provider saat ini milik sesi, kalau ia punya generation_model.
  2. Daftar [providers.fallback] generation, berurutan.
  3. Bagian global Gemini [image.generation], paling akhir.
# config.toml
[providers.fallback]
generation = ["openrouter", "qwen-image"]   # provider section names, tried in order

Tiap entri adalah nama provider (kunci dari bagian [providers.<name>] atau [providers.custom.<name>]). Modelnya adalah generation_model milik provider itu; endpoint diturunkan dari blok provider dan tidak pernah ditebak.

Flag enabled di bawah [image.generation] hanya mengatur fallback global Gemini. Rute provider mendaftarkan generate_image bahkan saat flag itu mati. Itulah tujuan #1672: model gambar pada provider yang sudah kamu bayar bekerja tanpa kunci Gemini kedua dan tanpa menyalakan fallback.

Rute B: Gemini sebagai backend gambar khusus

Saat tidak ada provider di daftarmu yang melayani gambar, pakai bagian global Gemini yang dijelaskan di Path B di atas. Ia menangani input vision dan output gambar dalam satu permintaan, dan hanya kaki itulah yang diatur flag [image.generation] enabled.

Yang mana yang sedang saya pakai?

Pembuatan yang berhasil tidak menyebut rute yang dipakai; hasilnya hanya path file tersimpan. Rantainya terlihat saat gagal, karena tiap kandidat dicoba dan error gabungan mendaftarnya berurutan sebagai backend(model).

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

Jadi diagnostiknya: buat sekali, lalu baca errornya kalau hasilnya kosong. Kaki gemini(...) setelah kaki openai(...) berarti rute provider-mu dicoba lebih dulu dan tidak berhasil. Kalau tool menjawab dengan petunjuk konfigurasi, tidak ada rute yang berhasil sama sekali:

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:

ToolDeskripsi
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")
  • Jalur Gemini: gambar masukan ikut terkirim sebagai bagian inlineData di samping prompt.
  • Jalur kompatibel OpenAI: permintaan beralih dari /images/generations ke /images/edits, dengan satu bagian image[] per gambar masukan. Model apa pun di endpoint itu yang menerima editan bisa mengubah gaya atau menyusun komposisi.

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.