I built a small incident triage bot that reads raw application logs and returns structured diagnoses. It runs on Llama 3.3 70B through Oxlo.ai, and the flat per-request pricing means I do not worry about token count when I feed it multi-line stack traces.
What you'll need
Before starting, grab an Oxlo.ai API key from https://portal.oxlo.ai. You also need Python 3.10 or newer and the OpenAI SDK installed.
pip install openai
Step 1: Verify the connection
I always send a quick hello to confirm the endpoint and credentials are working. Oxlo.ai is fully OpenAI SDK compatible, so the only change is the base URL.
from openai import OpenAI
client = 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": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Say hello."},
],
)
print(response.choices[0].message.content)
Step 2: Write the system prompt
To get repeatable JSON, I lock the model into a strict schema in the system prompt. I also tell it to skip markdown fences so I do not have to strip them later.
SYSTEM_PROMPT = """You are an incident triage engineer. Analyze the provided logs and output a single JSON object with exactly these keys:
- severity: one of INFO, WARNING, CRITICAL
- root_cause: a one-sentence description
- remediation: a list of concrete steps
Do not wrap the output in markdown. Output raw JSON only."""
Step 3: Prepare the log payload
Raw logs are noisy. I strip trailing whitespace and wrap them in a short template so the model knows exactly what to analyze.
def build_payload(raw_logs: str) -> str:
cleaned = raw_logs.strip()
return f"Analyze these application logs and return raw JSON:\n\n{cleaned}"
Step 4: Call Llama 3.3 70B
Now I wire the pieces together. I use Llama 3.3 70B on Oxlo.ai because it follows instructions reliably and handles long stack traces without ballooning cost, since Oxlo.ai charges per request rather than per token.
from openai import OpenAI
import json
client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")
def triage_logs(raw_logs: str) -> dict:
user_message = build_payload(raw_logs)
response = client.chat.completions.create(
model="llama-3.3-70b",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": user_message},
],
)
content = response.choices[0].message.content.strip()
# Guard against occasional markdown fences
if content.startswith("
```"):
content = content.split("\n", 1)[1].rsplit("```
", 1)[0].strip()
return json.loads(content)
Step 5: Test with sample logs
I pass a realistic Django traceback with a database connection failure to see if the agent catches the root cause and severity correctly.
sample_logs = """
2024-05-21 14:03:12 ERROR django.request Internal Server Error: /api/v1/checkout
Traceback (most recent call last):
File "/app/venv/lib/python3.11/site-packages/django/db/backends/base/base.py", line 289, in ensure_connection
self.connect()
File "/app/venv/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/app/venv/lib/python3.11/site-packages/django/db/backends/postgresql/base.py", line 187, in connect
self.connection = self.get_new_connection(conn_params)
psycopg2.OperationalError: connection to server at "db.internal" (10.0.4.15), port 5432 failed: Connection refused
"""
result = triage_logs(sample_logs)
print(json.dumps(result, indent=2))
Run it
When I execute the script, the response comes back in about a second. Oxlo.ai serves Llama 3.3 70B with no cold starts, so the first request is just as fast as the tenth.
{
"severity": "CRITICAL",
"root_cause": "The application cannot connect to the PostgreSQL server at db.internal because the connection was refused.",
"remediation": [
"Verify that the PostgreSQL service is running on db.internal (10.0.4.15) port 5432.",
"Check network ACLs and security groups between the application host and the database.",
"Review recent deployment changes that might have altered connection pooling or credentials."
]
}
Wrap up
To make this production-grade, wire it into a log aggregation pipeline like Fluentd or Vector so each new error file triggers a triage request automatically. If you need deeper reasoning for complex distributed traces, swap the model string to deepseek-v3.2 or kimi-k2.6 on Oxlo.ai without changing any other code.
Top comments (0)