Low-Cost Vision Integration for Text Models: A Routing Architecture and Implementation Guide

    This article explains how to add vision capabilities to text-only models through a routing layer that decides when an image actually needs visual understanding. It covers a five-layer architecture, vision-need detection, structured visual output, cost control, common pitfalls, and practical deployment advice for keeping marginal costs low.

    1. Background: Vision as a Capability Upgrade

    Before multimodal capabilities became widely available, most text models could only accept plain text input. Real business inputs, however, often mix in screenshots, scanned documents, UI captures, photos of tables, and flowcharts. Asking users to manually convert images to text before asking a question creates a broken experience. Calling a high-end multimodal service for every image is also too expensive to sustain.

    A pragmatic approach has emerged in the industry: insert a “routing and conversion” layer between the text model and the vision model. It does not change how users interact. Instead, it decides in the background whether a request needs to “look at an image.” If it does, the image is handed to a vision-capable model, and the conclusion is returned as text to the main model for further reasoning. The value is straightforward: use expensive capabilities on demand rather than keeping them on at all times.

    2. Overall Architecture: Five Layers

    A practical vision routing solution typically contains five layers:

    1. Unified input layer: accepts text, images, files, and other modalities, and converts them into a unified internal message structure.
    2. Task decision layer: determines whether the current turn truly needs visual understanding, avoiding unnecessary calls.
    3. Routing and adaptation layer: assembles the image and prompt into a request the vision model can consume.
    4. Result injection layer: structures the visual conclusion and injects it into the main model’s context.
    5. Cost and observability layer: tracks call volume, latency, and failure rate, and applies caching and fallback.

    An illustrative internal message structure (structure only, not a specific API):

    1. {
    2. "session_id": "s-1024",
    3. "turn": 3,
    4. "parts": [
    5. {"type": "text", "value": "What is causing the error in this image?"},
    6. {"type": "image", "value": "ref://blob/9f2c", "mime": "image/png"}
    7. ],
    8. "meta": {"need_vision": null, "budget": "low"}
    9. }

    3. Key Design 1: Deciding Whether Vision Is Needed

    Use a two-stage strategy: rules first, model as fallback.

    • Rule layer: set need_vision=true directly when an image attachment is present, when the user explicitly mentions “this image / screenshot / UI,” or when a previous turn already included an image.
    • Fallback layer: when rules are uncertain, use a lightweight text model to make a very short judgment that outputs a boolean value and a confidence score.

    Write the decision into meta and carry it through the session so the same image is not re-analyzed in later turns. In practice, maintain a mapping of “image fingerprint to recognition result,” where the fingerprint is a content hash. On a hit, reuse the result.

    4. Key Design 2: Assembling the Vision Request and Structuring Output

    The most common failure in the vision step is not “can it understand the image” but “can the output be consumed by a program.” The prompt should therefore strongly constrain the output to a fixed structure, for example:

    1. {
    2. "scene": "desktop_ui",
    3. "objects": ["energy orb", "waveform", "chat panel"],
    4. "texts": ["SYSTEM ONLINE"],
    5. "errors": [],
    6. "confidence": 0.86
    7. }

    Three points matter when assembling the request. First, control image resolution and cropping; oversized images significantly raise processing cost. Second, make the task description decidable, for example “extract only the error text and line numbers.” Third, set a timeout and a retry limit; when the vision step fails, fall back to “not recognized” rather than blocking the entire session.

    5. Key Design 3: Cost Control and Performance Trade-offs

    There are four levers for cost control:

    • On-demand calls: the decision layer determines whether a call is necessary.
    • Result caching: cache structured conclusions keyed by image fingerprint, with a validity period.
    • Tiered models: route simple OCR-style tasks to a low-cost path and complex reasoning to a high-capability path.
    • Batching and merging: combine multiple images in the same session into a single request to reduce round trips.

    It is worth emphasizing that reasoning-oriented models are more robust on complex tasks but show more noticeable first-token latency and lag. Lightweight models respond quickly but may fall short on complex reasoning. A reasonable approach is to route by task complexity rather than relying on a single model for everything.

    6. Common Pitfalls

    1. Treating “can see images” as “can reason.” The visual conclusion is only evidence; the final judgment should still be made by the main model in the context of the conversation.
    2. Ignoring the context injection format. If injected text is mixed with the user’s original question, the main model can confuse evidence with instructions. Wrap it with explicit markers such as <vision_result>.
    3. Launching without observability. Without call volume and failure rate tracking, costs can spiral out of control as traffic grows.
    4. Over-pursuing descriptive UI summaries. For UI images, structured fields are more valuable for engineering than elaborate descriptions.

    7. Implementation Advice

    If you use Baidu AI Cloud capabilities, a general combination works: object storage for images, a message queue for peak shaving, a container platform to host the routing service, and logging plus monitoring and alerting for observability. Keep the principles of “seamless integration, pay as you go, and fallback-capable,” and any text model can gain usable vision capabilities at extremely low marginal cost.