Event-driven architectures decouple services by letting them react to state changes asynchronously. When you add large language models into this flow, events become more than signals. They become inputs to reasoning, classification, and transformation tasks that run independently of your synchronous request path. This guide covers practical patterns for integrating LLMs into event-driven systems, with concrete code and deployment considerations.
Overview: Events as LLM Inputs
In a typical event-driven system, producers emit records to a broker such as Apache Kafka, RabbitMQ, or AWS EventBridge. Consumers subscribe to topics and react to state changes. When one of those consumers is an LLM service, the event payload becomes a prompt. The LLM processes the payload and emits a derived event back into the stream or writes the result to a datastore.
This pattern is useful when the raw event contains unstructured text that traditional rule engines cannot parse reliably. Instead of maintaining brittle regular expressions or keyword lists, you delegate understanding to a model. Because the work is asynchronous, you can tolerate inference latency without blocking user-facing services.
Core Patterns for LLM-Driven Events
Event Enrichment
A common pattern is to use an LLM to enrich sparse events. For example, a user_signup event might contain only an email and a timestamp. An enrichment consumer can pass the user's free-form survey response to a model to extract industry, company size, and intent. The enriched event is then published to a user_enriched topic for downstream CRM workflows.
Intelligent Routing
Routing logic often depends on the meaning of unstructured content. An LLM can read an error log event and decide whether it should be routed to the infrastructure queue, the security queue, or the application team queue. The consumer publishes the event to the target topic based on the model's structured output.
Async Agent Workflows
More complex scenarios require multi-step reasoning. An incoming alert event might trigger an agent that queries a runbook database, summarizes recent related events, and drafts an incident report. These agentic loops can involve long context windows and multiple tool calls. They are a natural fit for async processing because each step can take seconds and may require retries.
Implementation: An Async Processor with Oxlo.ai
The simplest way to integrate an LLM consumer is to use the OpenAI SDK with Oxlo.ai as a drop-in replacement. Oxlo.ai provides a fully OpenAI API compatible endpoint at https://api.oxlo.ai/v1 and supports features such as streaming responses, function calling, JSON mode, and multi-turn conversations. The following Python example consumes a ticket event and returns structured classification data.
import os
import json
from openai import OpenAI
client = OpenAI(
base_url="https://api.oxlo.ai/v1",
api_key=os.environ["OXLO_API_KEY"]
)
def handle_ticket_event(event: dict) -> dict:
system_prompt = (
"Classify the support ticket into exactly one category: "
"Billing, Technical, or Account. Return JSON with keys: category, reasoning."
)
response = client.chat.completions.create(
model="llama-3.3-70b",
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": json.dumps(event)}
],
response_format={"type": "json_object"}
)
result = json.loads(response.choices[0].message.content)
return {
"ticket_id": event["id"],
"enrichment": result,
"model": response.model
}
In a production setup, you would wrap this function in a consumer loop for your broker of choice. Because Oxlo.ai offers no cold starts on popular models, the first request after a quiet period returns just as quickly as subsequent ones. This is critical for event-driven workloads where traffic is bursty.
Cost Predictability with Long Context
Event payloads can grow quickly. A single message might contain a stack trace, a user conversation transcript, or a batch of related logs. Under token-based pricing, a large input can cost orders of magnitude more than a short one, making your stream processing bill unpredictable.
Oxlo.ai uses request-based pricing. You pay one flat cost per API request regardless of prompt length. Unlike token-based providers such as Together AI, Fireworks AI, OpenRouter, Replicate, and Anyscale, cost does not scale with input length. For long-context enrichment and agentic workloads that iterate over large event histories, request-based pricing can be 10-100x cheaper than token-based alternatives. See the pricing page for plan details.
Choosing Models for Event Workloads
Oxlo.ai hosts 45+ open-source and proprietary models across 7 categories. For event-driven pipelines, you can match the model to the task instead of overprovisioning a single endpoint.
- General classification and routing: Llama 3.3 70B or Qwen 3 32B provide fast, multilingual reasoning for straightforward enrichment.
- Deep reasoning over complex logs: DeepSeek R1 671B MoE, Kimi K2.6, or GLM 5 excel at multi-step analysis and long-horizon agentic tasks.
- Coding and structured extraction: DeepSeek V3.2, Qwen 3 Coder 30B, or Oxlo.ai Coder Fast handle stack traces and JSON generation.
- Vision events: If your pipeline processes screenshots or PDFs, Gemma 3 27B and Kimi VL A3B support image input.
- Embeddings: Use BGE-Large or E5-Large to vectorize events for semantic search or clustering before routing.
All of these are accessible through the same OpenAI SDK compatible endpoint, so switching models is a single parameter change.
Reliability, Retries, and Observability
Event consumers must be idempotent. An LLM call may time out or return malformed JSON, so your consumer should catch exceptions, log the failure, and either retry with backoff or move the event to a dead-letter queue. When using JSON mode, validate the output schema before publishing the next event.
If you need guaranteed throughput for high-volume streams, Oxlo.ai offers a Free plan with 60 requests per day and a 7-day full-access trial, a Pro plan with 1,000 requests per day, a Premium plan with 5,000 requests per day and priority queue access, and an Enterprise tier with dedicated GPUs and custom pricing.
Putting It into Production
Integrating LLMs into event-driven architecture does not require rewriting your pipeline. You can add an intelligent consumer that treats each event as a prompt, processes it asynchronously, and forwards the result. With Oxlo.ai, you get OpenAI SDK compatibility, a broad model catalog, and request-based pricing that keeps long-context workloads affordable. Point your client to https://api.oxlo.ai/v1, pick the right model for the event type, and let your stream do the reasoning.
Top comments (0)