If an application lets operators swap Ollama models, a model name is not a dependable way to decide whether the next request can include an image. Ask the model details endpoint first. A successful response with no vision capability can drive a text-only interface. A failed request or a response without usable capability metadata is a different state and should be shown as unknown.

Test the request and routing decision offline

Use a supported Node.js release with the built-in Response class, such as Node.js 24 LTS. Save this as capabilities.mjs. The transport is a function supplied by the caller. Here it checks the request and returns a synthetic response, without opening a socket or requiring Ollama to be installed.

import assert from 'node:assert/strict';

async function vision(model, transport) {
  const res = await transport('http://127.0.0.1:11434/api/show', {
    method: 'POST',
    headers: {'content-type': 'application/json'},
    body: JSON.stringify({model})
  });
  if (!res.ok) throw new Error(`show failed: HTTP ${res.status}`);
  const payload = await res.json();
  const caps = payload?.capabilities;
  if (!Array.isArray(caps) || [...caps].some(c => typeof c !== 'string')) {
    throw new Error('missing or invalid capabilities');
  }
  return caps.includes('vision');
}

function fixture(body, status = 200) {
  return async (url, options) => {
    assert.equal(new URL(url).pathname, '/api/show');
    assert.equal(options.method, 'POST');
    assert.equal(options.headers['content-type'], 'application/json');
    assert.deepEqual(JSON.parse(options.body), {model: 'fixture:latest'});
    return new Response(JSON.stringify(body), {status});
  };
}

const model = 'fixture:latest';
const yes = await vision(model, fixture({capabilities: ['completion', 'vision']}));
const no = await vision(model, fixture({capabilities: ['completion']}));
assert.equal(yes, true);
assert.equal(no, false);
await assert.rejects(vision(model, fixture({})), /invalid capabilities/);
await assert.rejects(vision(model, fixture({error: 'missing'}, 404)), /HTTP 404/);
console.log(`image route: ${yes}; text-only route: ${!no}`);

Run node capabilities.mjs. Expected output:

image route: true; text-only route: true

Keep detection separate from inference

The two printed values come from different responses. This check looks for the exact capability name and tolerates unfamiliar string entries, so additional model features do not break the adapter. A malformed response raises an error instead of silently dropping image input. A future live integration can pass a Fetch wrapper with an explicit timeout as its transport and use the configured model tag rather than the invented fixture name.

If the live check reports HTTP 404, inspect the route and confirm the exact model identifier on that server. If the response succeeds but omits the capabilities array, inspect the installed server version and shape rather than guessing from the model name. Refresh a cached decision when the selected model changes or a tag is replaced. A positive decision only gates routing. It does not prove that a particular image is valid, that the model can load, or that inference will succeed.

Primary references and related tutorials: Ollama model details endpoint · Ollama response types · Ollama capability names · Node.js Response · Java Samples Node.js tutorials.