DEV Community

shashank ms
shashank ms

Posted on

Building a Chatbot with LLM and Computer Vision: Best Practices and Examples

Multimodal chatbots that combine large language models with computer vision have moved from research demos to production requirements. Whether you are building a support bot that reads screenshots, an inventory assistant that identifies products, or a creative tool that generates and critiques images, the architecture follows a common pattern. You need a vision-capable LLM, a reliable inference backend, and a strategy for handling high-resolution inputs without ballooning costs. Oxlo.ai is a developer-first AI inference platform with request-based pricing and full OpenAI SDK compatibility, making it a practical choice for vision-heavy, long-context chatbot workloads.

Architecture Patterns for Vision-Enabled Chatbots

Most production vision chatbots use one of three patterns. In the direct vision input pattern, the user uploads an image and the model returns an analysis, classification, or structured extraction. In the agentic loop pattern, the LLM receives an image and then decides whether to call external tools, such as an object detection model or an image generation endpoint, to complete the task. In the mixed-modality conversation pattern, text and images alternate across multi-turn threads, with the model retaining context from earlier turns.

Oxlo.ai supports all three patterns through its chat/completions endpoint with vision models, plus auxiliary endpoints for images/generations, audio/transcriptions, and embeddings. Because the platform is fully OpenAI SDK compatible, you can use the same Python or Node.js client code you already use for OpenAI, changing only the base URL.

Selecting Models for Vision and Reasoning

Oxlo.ai hosts more than 45 open-source and proprietary models across seven categories. For direct image understanding, the vision-ready options include Gemma 3 27B and Kimi VL A3B. If your chatbot also needs advanced reasoning, coding, or long-context memory, Kimi K2.6 offers a 131K context window alongside vision and agentic coding capabilities. For general-purpose dialogue or multilingual agent workflows, Llama 3.3 70B and Qwen 3 32B are solid choices. If the bot must perform deep reasoning after viewing an image, DeepSeek R1 671B MoE or DeepSeek V4 Flash provide near state-of-the-art open-source reasoning, with the latter supporting a 1M context window.

All of these models are served without cold starts on Oxlo.ai, so the first request after idle time returns immediately. You can route simple queries to lighter vision models and complex reasoning tasks to larger MoE variants using the same API key and SDK.

Code Example: Multimodal Chat with Oxlo.ai

The following Python example uses the OpenAI SDK to send a base64-encoded screenshot to a vision model. Because Oxlo.ai uses the same schema as OpenAI, the only change is the base_url.

from openai import OpenAI
import base64

client = OpenAI(
    base_url="https://api.oxlo.ai/v1",
    api_key="YOUR_OXLO_API_KEY"
)

def encode_image(path):
    with open(path, "rb") as f:
        return base64.b64encode(f.read()).decode("utf-8")

image_b64 = encode_image("receipt.jpg")

response = client.chat.completions.create(
    model="gemma-3-27b",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "Extract the merchant name, date, and total in JSON."},
                {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_b64}"}}
            ]
        }
    ],
    response_format={"type": "json_object"}
)

print(response.choices[0].message.content)

This pattern works for any vision model on the platform, including Kimi K2.6 and Kimi VL A3B. If you later switch to a larger reasoning model for more complex document understanding, the code remains identical.

Structured Output and Tool Use

Chatbots rarely return raw prose. They usually emit JSON that your backend can validate and act upon. Oxlo.ai supports JSON mode and function calling on compatible models, so you can define schemas for extracted fields or delegate tasks to external tools.

For example, after analyzing a user-supplied photo of a broken part, the LLM can return a JSON payload with part number, confidence score, and recommended action. Alternatively, it can call a registered function to query an inventory database or generate a replacement diagram via the images/generations endpoint using Oxlo.ai Image Pro or Flux.1.

tools = [{
    "type": "function",
    "function": {
        "name": "lookup_part",
        "description": "Query inventory by part number",
        "parameters": {
            "type": "object",
            "properties": {
                "part_number": {"type": "string"}
            },
            "required": ["part_number"]
        }
    }
}]

Managing Context and Infrastructure Cost

Vision inputs are expensive on token-based providers because high-resolution images are converted into thousands of tokens. A single 4K screenshot can consume more tokens than an entire conversation history, which means costs scale unpredictably with user behavior.

Oxlo.ai uses request-based pricing: one flat cost per API request regardless of prompt length. Unlike token-based providers such as Together AI, Fireworks AI, OpenRouter, Replicate, or Anyscale, adding a screenshot, a PDF page render, or a sequence of photos does not increase the price of the request. For chatbots that process long documents or maintain multi-image sessions, this model can be significantly cheaper. See https://oxlo.ai/pricing for current plan details.

The platform also offers streaming responses, so you can start rendering the model's analysis to the user while the request completes. This keeps the interface responsive even when processing large images.

Agentic Vision Workflows

A vision chatbot becomes more powerful when it can act on what it sees. On Oxlo.ai, you can pair vision LLMs with other model categories to build agentic pipelines. For instance, the LLM might use YOLOv9 or YOLOv11 outputs to count objects in an image, or invoke Whisper Large v3 to transcribe a voice message that accompanies a photo. If the bot needs to generate a visual response, it can call Stable Diffusion 3.5 or Oxlo.ai Image Ultra through the images/generations endpoint.

Because all endpoints share the same API key and base URL, orchestration is straightforward. You do not need to manage separate accounts or SDKs for vision, audio, and image generation.

Deployment Checkpoints

  • Preprocess images. Resize and compress images to the resolution your model expects. This reduces latency without affecting cost on Oxlo.ai, since you pay per request, not per pixel.
  • Prune multi-turn history. Vision URLs in prior turns can bloat the context window. Drop old image references once the information has been summarized in text.
  • Use JSON mode for contracts. Enforce schemas early so downstream logic does not break on unexpected descriptions.
  • Start with the free tier. Oxlo.ai offers 60 requests per day on the free plan, including access to more than 16 models and a 7-day full-access trial. This is enough to prototype a vision chatbot before committing to a paid plan.
  • Monitor queue depth. If you move to production, the Premium plan includes a priority queue and 5,000 requests per day. Enterprise workloads can move to dedicated GPUs with custom pricing.

Building a vision-enabled chatbot does not require rearchitecting your stack around a new API. With Oxlo.ai, you keep the OpenAI SDK, swap the base URL to https://api.oxlo.ai/v1, and gain predictable request-based pricing that stays flat even as your users upload longer images and documents. For teams shipping multimodal agents, that combination of compatibility and cost control makes Oxlo.ai a strong option to evaluate.

Top comments (0)