DEV Community

shashank ms
shashank ms

Posted on

Building Conversational AI Apps with LLMs

Conversational AI apps are moving beyond simple question-and-answer interfaces. Modern implementations rely on multi-turn state, tool use, and long context windows that accumulate history, system prompts, and retrieved documents. For developers, the infrastructure challenge is not just choosing a capable model, but managing state and cost as conversations grow. Oxlo.ai provides a developer-first inference platform with request-based pricing and full OpenAI SDK compatibility, making it a strong fit for production conversational workloads.

Architecture of a Conversational Stack

A production conversational app usually has three layers: the interaction layer, the state layer, and the model layer. The interaction layer handles streaming text, voice, or visual inputs. The state layer persists thread memory, session context, and user preferences across turns. The model layer executes inference, optionally calling external tools to fetch data or perform actions.

Unlike stateless completion APIs, conversational apps must maintain message history. Each turn appends user and assistant messages to a growing array. This pattern directly increases prompt size, which has significant cost implications on token-based billing. Oxlo.ai flips this model with flat per-request pricing, so the cost of a turn stays predictable even as context accumulates.

Model Selection for Dialogue and Agents

Oxlo.ai hosts more than 45 open-source and proprietary models across seven categories. For conversational use cases, the following are solid starting points:

  • Llama 3.3 70B: The general-purpose flagship. It balances instruction following, helpfulness, and latency for standard assistant interfaces.
  • Qwen 3 32B: Optimized for multilingual reasoning and agent workflows. Use this when your users interact in multiple languages or when the app delegates tasks to sub-agents.
  • DeepSeek R1 671B MoE: Built for deep reasoning and complex coding. Ideal when the conversation involves step-by-step problem solving or generating large code blocks.
  • Kimi K2.6: Offers advanced reasoning, agentic coding, vision, and a 131K context window. Choose this when the chat includes image inputs or long codebases.
  • DeepSeek V4 Flash: An efficient MoE model with a 1M context window and near state-of-the-art open-source reasoning. Use this for very long documents or extended session histories.
  • DeepSeek V3.2: Strong at coding and reasoning, and available on the Oxlo.ai free tier for prototyping.

If your app requires vision, audio, embeddings, or object detection, Oxlo.ai also provides Gemma 3 27B, Whisper variants, BGE-Large, and YOLOv11 under the same API and pricing structure.

Implementation: Streaming and Multi-Turn State

Because Oxlo.ai is fully compatible with the OpenAI SDK, you can point your existing client to Oxlo.ai and start building immediately. The snippet below shows a minimal streaming chat loop in Python. The messages array acts as conversational state, and each turn appends to it.

import openai

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

messages = [
    {"role": "system", "content": "You are a helpful assistant."}
]

def chat(user_input):
    messages.append({"role": "user", "content": user_input})

    stream = client.chat.completions.create(
        model="llama-3.3-70b",
        messages=messages,
        stream=True
    )

    reply = ""
    for chunk in stream:
        content = chunk.choices[0].delta.content
        if content:
            reply += content
            print(content, end="")

    messages.append({"role": "assistant", "content": reply})
    return reply

# Example usage
chat("Explain how request-based pricing helps long conversations.")

For agentic apps, you can extend this pattern with function calling. Oxlo.ai supports tools, JSON mode, and vision inputs through the same chat completions endpoint, so you can add weather lookups, database queries, or image analysis without changing client libraries.

The Pricing Impact of Long Conversations

Conversational history bloats the prompt. On token-based providers such as Together AI, Fireworks AI, OpenRouter, Replicate, or Anyscale, longer contexts mean higher costs per turn. A ten-turn conversation with retrieved documents can quickly become expensive because input tokens are billed for every message in the history window.

Oxlo.ai uses request-based pricing: one flat cost per API request regardless of prompt length. This makes it significantly cheaper for long-context and agentic workloads where conversations accumulate history, tool outputs, and external context. You can focus on building richer dialogue instead of trimming messages to save tokens. For exact plan details, see the Oxlo.ai pricing page.

Memory and Context Window Strategies

Even with predictable pricing, you should design memory carefully. Three common patterns work well on Oxlo.ai:

  1. Truncation with summarization: When the message history approaches the model limit, summarize early turns into a single system message and drop the raw history. This preserves intent while freeing space.
  2. Large-context models: Models like DeepSeek V4

Top comments (0)