Vision-language models#
Every model in rAPIdtools, hosted or local, is created by the same factory
and answers the same run_inference call. Switching providers therefore
never changes the rest of your pipeline.
Choosing a model#
from rapidtools.models import load, list_providers, catalog
list_providers() # every registry key
catalog('gemini') # curated model IDs for a provider, no network
model = load('gemini', api_key='AIza...', model_id='gemini-3.8-flash')
model = load('gemma4', model_id='google/gemma-4-E2B-it')
model = load('hf', model_id='Qwen/Qwen3.5-4B', load_in_4bit=True)
Provider or family |
Key |
Runs |
Default model and notes |
|---|---|---|---|
Google Gemini |
|
API |
|
Anthropic Claude |
|
API |
|
OpenAI |
|
API |
|
Meta Muse Spark |
|
API |
|
Alibaba Qwen (Model Studio) |
|
API |
|
Google Gemma 4 |
|
local |
|
Meta Llama Vision |
|
local |
|
Meta Muse Glimmer |
|
local |
|
Alibaba Qwen VL |
|
local |
|
Any Hugging Face VLM |
|
local |
|
Meta SAM 3 |
|
local |
|
Each wrapper has list_known_models() for its curated catalog. Where the
provider supports it, list_available_models(api_key) asks the provider
which models your key can actually use.
Analyzing a collection#
AssetAnalyzer sends each asset’s images and
your prompt to the model and writes the answer into the asset’s attributes.
from rapidtools import AssetAnalyzer
from rapidtools.models import GenerationConfig, load
analyzer = AssetAnalyzer(
load('claude', api_key='sk-ant-...'),
prompt='prompts/damage.txt', # text or a path to a file
max_images_per_asset=2,
image_filter=lambda img: 'aerial' in img.id,
generation=GenerationConfig(json_mode=True, temperature=0.0),
)
buildings = analyzer(buildings)
The prompt can ask for free text or for JSON. If the answer parses as a JSON
object, each key becomes its own attribute; otherwise the whole text is
stored. Attribute names start with the provider’s prefix
(claude_damage_level; generic Hugging Face checkpoints use vlm_), or
with attribute_prefix if you set one.
Hosted models get max_workers requests in flight at once (five by
default). When a request fails, a RateLimitPolicy
pauses all the workers, doubling the pause if failures continue. Once the
pass is over, the analyzer goes back for the assets that failed, so a burst
of rate-limit errors does not leave gaps in the results. Hosted wrappers also
accept timeout= for providers that respond slowly.
Local models run one asset at a time or in batches of batch_size. The
wrapper picks the numeric precision for your hardware and frees GPU memory
between batches.
GenerationConfig holds the per-call options
(temperature, max_tokens, json_mode, system_instruction) and
translates them into each provider’s own parameters.
Output limits#
If you build a hosted model without max_tokens, it uses the default for
that model ID. That is 2,048 tokens for most models and 32,768 for Gemini 4,
whose thinking tokens count against the limit. A value you pass always takes
precedence. To set your own default for a model, call
set_model_defaults() before building it; a trailing
* matches a whole family. model_defaults()
shows what applies to a given ID.
from rapidtools.models import model_defaults, set_model_defaults
set_model_defaults('claude-opus-5-5', max_tokens=8192)
set_model_defaults('gpt-6.2-*', max_tokens=4096)
model_defaults('gemini-4-neon') # {'max_tokens': 32768}
The provider-specific analyzers such as GeminiAssetAnalyzer and
Gemma4AssetAnalyzer still work, but they are deprecated. Use
AssetAnalyzer(load(...)) instead.
Local model options#
Local wrappers accept device ('auto', 'cuda' or 'cpu'),
temperature and max_tokens. The Hugging Face, Qwen, Llama and Muse
Glimmer wrappers also accept load_in_4bit (off by default), which lets
larger checkpoints fit in memory. If you pass an argument a wrapper does not
take, load() tells you which ones it does. Gated
weights download automatically once you are logged in to the Hugging Face
Hub (see Installation).
model = load('qwen_vl', model_id='Qwen/Qwen3.5-9B', load_in_4bit=True, device='cuda')
Some open models, GLM-4.6V among them, write out their reasoning in a
<think> block before they answer. The wrappers return only the answer in
text and keep the full output in raw_response. The reasoning still
counts against max_tokens, which is 512 by default for the Hugging Face,
Qwen and Muse Glimmer wrappers (2,048 for Gemma 4 and Llama). If the model
runs out of tokens before it reaches the answer, the output is marked as a
failure with a message telling you to raise the limit.
Single images#
Outside a pipeline, call the model directly. You get back a
ModelOutput with text and, for segmentation
models, masks and bounding_boxes:
model = load('gemma4', model_id='google/gemma-4-E2B-it')
output = model.run_inference('scene.jpg', 'Describe the damage in this scene.')
print(output.text)