DEV Community

shashank ms
shashank ms

Posted on

Integrating LLM with Existing Applications

Most production software was not built to call a large language model. When engineering teams decide to add generative capabilities to an existing application, the real work is rarely the prompt itself. It is threading stateful context through legacy request handlers, managing token budgets that scale unpredictably with input size, and avoiding vendor lock-in that forces a full rewrite six months later. The goal should be to treat the LLM as an infrastructure layer, not a product rewrite.

Why Integration Is Harder Than an API Call

Adding an LLM to an existing codebase introduces three immediate problems. First, context management: your application already has databases, caches, and session stores, but LLMs require carefully curated conversation history or retrieved documents. Second, latency and reliability: synchronous blocking calls to a remote model can stall your API. Third, cost predictability: token-based meters mean a single long log file or extended agent loop can multiply your bill without warning.

A practical integration strategy addresses all three concerns before the first prompt is sent.

Use OpenAI SDK Compatibility as a Migration Bridge

If your application already uses the OpenAI SDK, Oxlo.ai functions as a drop-in replacement. Change the base URL and API key, and your existing chat completions, embeddings, and image generation calls route to Oxlo.ai's infrastructure without touching business logic.

import openai

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

response = client.chat.completions.create(
    model="llama-3.3-70b",
    messages=[{"role": "user", "content": "Refactor this SQL query for readability."}],
    temperature=0.2
)

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

The same pattern works in Node.js and cURL. Because Oxlo.ai supports streaming responses, function calling, JSON mode, and vision, most existing integrations need zero client-side changes beyond the initialization block.

Architectural Patterns That Minimize Refactoring

Rather than scattering LLM calls across controllers, introduce a gateway or adapter layer. This insulates your application from provider-specific quirks and lets you route traffic conditionally.

  • Gateway proxy: Intercept outgoing OpenAI-shaped requests in a middleware layer and rewrite the base URL to https://api.oxlo.ai/v1. This lets you A/B test models or failover across providers without changing service code.
  • Background workers: For long-context analysis or agentic loops, enqueue jobs in Celery, Bull, or RQ. Return a job ID to the client and stream results through a WebSocket when the worker completes.
  • Tool-use adapters: If your app exposes internal REST or SQL endpoints, define them as tools using Oxlo.ai's function calling schema. The model decides when to query your existing APIs, and your application logic stays unchanged.

Concrete Example: Structured Output in a Legacy Backend

Suppose you have a Python FastAPI service that processes support tickets. You want to extract sentiment, category, and priority without adding new dependencies beyond the OpenAI client you already import.

from openai import OpenAI
import json

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

def classify_ticket(ticket_text: str) -> dict:
    response = client.chat.completions.create(
        model="qwen3-32b",
        messages=[
            {
                "role": "system",
                "content": (
                    "Extract sentiment, category, and priority from the support ticket. "
                    "Return strictly valid JSON with keys: sentiment, category, priority."
                )
            },
            {"role": "user", "content": ticket_text}
        ],
        response_format={"type": "json_object"}
    )
    return json.loads(response.choices[0].message.content)

This function drops into your existing handler. Because Oxlo.ai supports JSON mode, you get deterministic structured output suitable for database writes without hand-writing parsers.

Cost Predictability for Long-Context and Agentic Work

Token-based pricing creates a nonlinear cost curve. A single request with a 128K context window can cost orders of magnitude more than a short query, which makes budgeting for log analysis, document review, or multi-step agents difficult.

Oxlo.ai uses flat per-request pricing. One API call costs the same regardless of whether you send a ten-word prompt or a ten-thousand-word document. For teams integrating LLMs into agentic workflows or long-context pipelines, this removes the need to truncate inputs aggressively or maintain separate token-counting middleware. You can see plan details at the Oxlo.ai pricing page.

Selecting Models That Fit Existing Workloads

Not every task requires the largest model. Oxlo.ai offers more than 45 models across seven categories, all accessible through the same endpoint. A practical integration usually splits traffic:

  • General reasoning and chat: Llama 3.3 70B or Qwen 3 32B.
  • Deep reasoning and complex coding: DeepSeek R1 671B or Kimi K2.6.
  • Fast classification or extraction: DeepSeek V4 Flash with its 1M context window.
  • Code-specific endpoints: Qwen 3 Coder 30B or Oxlo.ai Coder Fast.

Because there are no cold starts on popular models, routing logic in your gateway layer does not need to warm up instances or cache idle capacity.

Evaluating the Switch

If you are already running OpenAI SDK calls in production, the migration path to Oxlo.ai is a configuration change, not a refactor. Start with the Free tier to validate compatibility: it includes 60 requests per day across more than 16 models and a 7-day full-access trial. For production workloads, the Pro and Premium plans offer predictable daily request volumes, and the Enterprise tier provides dedicated GPUs with custom pricing.

The decisive factor is usually cost structure. When your existing application starts passing large contexts or running autonomous agents, token-based bills scale with every extra word. Flat per-request pricing keeps the integration financially predictable, which is exactly what legacy codebases need when adopting new infrastructure.

Top comments (0)