Guaranteed 15% off your current AI inference bill for team spending up to $20000 / month.

Book a call →
Back to Blogs
Engineering

Implementing LLM in Production: A Comprehensive Guide

We are building a production support ticket triage agent that classifies incoming messages by urgency, extracts order IDs, and drafts a first response. It...

Implementing LLM in Production: A Comprehensive Guide

We are building a production support ticket triage agent that classifies incoming messages by urgency, extracts order IDs, and drafts a first response. It helps small support teams cut first-response time without hiring additional staff. I will walk through the exact code I shipped for an internal tool last quarter, using Oxlo.ai as the inference backend because its flat per-request pricing keeps costs predictable even when customers paste long error logs.

What you'll need

Before we start, make sure you have the following ready.

  • Python 3.10 or newer installed locally
  • The OpenAI SDK: pip install openai
  • An Oxlo.ai API key from https://portal.oxlo.ai

I store my key in an environment variable named OXLO_API_KEY. Oxlo.ai is fully OpenAI SDK compatible, so the only difference from a standard setup is the base URL. If you are migrating an existing project, you can keep the rest of your code unchanged.

Step 1: Configure the Oxlo.ai client

I start by initializing the client. The OpenAI SDK accepts a custom base_url, which lets me point directly at Oxlo.ai's API. I pull the key from the environment rather than hardcoding it, which is a non-negotiable habit for production services.

import os
from openai import OpenAI

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

Step 2: Define the system prompt

I keep the system prompt in a top-level constant so product managers can edit it without reading Python. The prompt forces strict JSON output with four fields: urgency, category, order_id, and draft_reply. Keeping this separate also makes A/B testing prompt variants trivial, because I can swap the string without touching the request logic.

SYSTEM_PROMPT = """
You are a support triage agent. Analyze the user's message and return a single JSON object with these exact keys:
- urgency: one of "low", "medium", "high", or "critical"
- category: one of "billing", "technical", "shipping", or "general"
- order_id: extract any order ID in the format ORD-XXXXX, or null if none
- draft_reply: a polite, concise first response in the same language as the user's message

Rules:
1. Return only valid JSON. No markdown, no explanation.
2. If the user is angry or mentions fraud, set urgency to "critical".
3. Keep draft_reply under 150 words.
"""

Step 3: Build the triage function

Next I write the core function. I call Llama 3.3 70B through Oxlo.ai and parse the JSON response. I keep temperature low because triage is fundamentally a deterministic classification task. Oxlo.ai serves this model with no cold starts, so the first request of the day returns in the same time as any other. That matters for a support pipeline where morning ticket spikes are common.

import json

def triage_ticket(ticket_text: str) -> dict:
    response = client.chat.completions.create(
        model="llama-3.3-70b",
        messages=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": ticket_text},
        ],
        temperature=0.1,
    )

    raw = response.choices[0].message.content
    return json.loads(raw)

Step 4: Add a local test harness

Before deploying, I want to run a few tickets through the script locally. I add a small CLI loop that reads a line of input and prints formatted JSON. This is the fastest way to catch prompt drift or edge cases without writing unit tests against the live API.

if __name__ == "__main__":
    print("Support Triage Agent. Paste a ticket and press Enter.")
    print("Send an empty line to quit.")
    while True:
        try:
            user_input = input("> ")
        except EOFError:
            break
        if not user_input.strip():
            break

        result = triage_ticket(user_input)
        print(json.dumps(result, indent=2, ensure_ascii=False))
        print("-" * 40)

Step 5: Guard against bad JSON

Production code cannot assume the model always returns perfect JSON. I wrap the parser in a try/except block and fall back to a safe default that forces human review. In practice, Oxlo.ai's JSON mode on Llama 3.3 70B rarely malforms output, but this guard prevents a 500 error from ever reaching the end user.

def safe_triage(ticket_text: str) -> dict:
    try:
        return triage_ticket(ticket_text)
    except Exception:
        return {
            "urgency": "high",
            "category": "general",
            "order_id": None,
            "draft_reply": "We have received your message and a human agent will review it shortly.",
            "error": True,
        }

Run it

I saved the full script as triage.py and ran it against a sample ticket to verify end-to-end behavior. Here is the exact input and output.

Terminal:

python triage.py

Input:

My order ORD-98234 never arrived and your tracking page is broken. I was charged twice. This is unacceptable.

Output:

{
  "urgency": "critical",
  "category": "shipping",
  "order_id": "ORD-98234",
  "draft_reply": "I sincerely apologize for the inconvenience. I have located your order ORD-98234 and escalated the double charge and missing shipment to our billing and logistics teams. You will receive an update within 2 hours."
}

The model correctly flagged urgency as critical due to the double charge and broken tracking, extracted the order ID, and kept the reply under the word limit. Because Oxlo.ai uses request-based pricing, this long ticket costs the same flat per-request rate as a one-word query. That makes monthly forecasting simple even when ticket volumes grow or users paste screenshots and stack traces that would inflate a token-based bill. You can see current plans at https://oxlo.ai/pricing.

Wrap-up

This agent is already useful, but two concrete next steps make it production-grade. First, add a confidence gate: if the model returns "critical", immediately open a PagerDuty incident and skip the auto-reply. Second, replace the CLI with a FastAPI endpoint so your helpdesk software can POST tickets to it in real time. Oxlo.ai's flat per-request pricing means your cost stays predictable even when users paste logs or lengthy conversation histories that blow up context length, which is where token-based bills usually spiral. If you want to experiment with stronger reasoning for ambiguous tickets, swap the model ID to deepseek-v3.2 or kimi-k2.6 without changing any other code.

Ready to build with Oxlo.ai?

Get started building high-performance AI inference applications today.

Get started
Ox Assistant
Online
OxBot
OxBot

Hi there! Try our cost calculator to see what you'd save with Oxlo.ai.