Analyzing social media manually does not scale. In this tutorial we will build a lightweight trend analyzer that ingests raw post text, extracts sentiment and topics per post, and rolls everything into a concise executive summary. The pipeline runs entirely on Oxlo.ai, and because the platform charges a flat rate per request instead of per token, you can batch large post dumps without watching costs climb.
What you'll need
- Python 3.10 or newer
- An Oxlo.ai API key from https://portal.oxlo.ai
- The OpenAI SDK:
pip install openai
Step 1: Set up the client and load sample data
I start with a hardcoded list of messy social posts so you can run the script without wrestling with Reddit or X API credentials. The Oxlo.ai client is a drop-in replacement for the standard OpenAI client. Just point the base URL at https://api.oxlo.ai/v1.
from openai import OpenAI
client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")
RAW_POSTS = [
"Just tried the new AI feature in my editor and WOW it actually wrote a whole function for me #coding #AI",
"Anyone else noticing their LLM API bills going through the roof this month? Token pricing is brutal for long threads.",
"My startup switched to flat pricing for inference and our burn dropped significantly. Highly recommend looking at request-based platforms.",
"Another day, another broken promise from the cloud provider. Downtime again during peak hours.",
"The new open source model from DeepSeek is impressive on coding benchmarks. Has anyone tested it on production workloads?",
"Social media sentiment analysis is basically impossible without an LLM now. The volume is just too high.",
"Why does every SaaS tool suddenly have an AI assistant? Half of them are just wrappers around GPT-4.",
"Finally got Whisper running locally for transcription. The accuracy is good but setup was painful.",
]
print(f"Loaded {len(RAW_POSTS)} posts.")
Step 2: Define the extraction prompt
The first stage turns unstructured text into structured JSON. I keep the system prompt strict: the model must return only a JSON object with no markdown and no explanation. This removes the need for fragile regex parsing later.
EXTRACTION_PROMPT = """You are a structured data extraction engine. Read the social media post below and output a single JSON object with no markdown, no explanation, and no surrounding text.
Required fields:
- sentiment: one of [positive, negative, neutral, mixed]
- topics: array of 1-3 short topic tags in lowercase
- entities: array of mentioned products, companies, or technologies in lowercase
- summary: one sentence summarizing the post's main point
Post:
"""
Step 3: Extract signals from each post
I loop over the raw posts and call llama-3.3-70b for each extraction. Because Oxlo.ai bills per request rather than per token, a two-hundred-word rant costs the same as a ten-word comment. That means I can send the full post every time without trimming to save money.
import json
def extract_post_signals(post_text: str):
response = client.chat.completions.create(
model="llama-3.3-70b",
messages=[
{"role": "system", "content": EXTRACTION_PROMPT},
{"role": "user", "content": post_text},
],
temperature=0.1,
max_tokens=256,
)
raw = response.choices[0].message.content.strip()
# Some models wrap JSON in backticks; strip them if present
if raw.startswith("
```"):
raw = raw.split("```
")[1]
if raw.startswith("json"):
raw = raw[4:]
return json.loads(raw.strip())
extracted = [extract_post_signals(p) for p in RAW_POSTS]
print(json.dumps(extracted, indent=2))
Step 4: Aggregate and generate the executive report
Once I have structured signals for every post, I flatten them into a bullet list and hand them to kimi-k2.6. The larger model reasons over the aggregate data and writes the final report. I keep temperature low so the output stays grounded in the provided evidence.
AGGREGATION_PROMPT = """You are a senior market analyst. Review the following structured social media signals and write a concise executive report with three sections: Key Trends, Sentiment Distribution, and Strategic Recommendations. Be specific, cite examples from the data, and avoid generic advice."""
def build_report(extracted_signals: list[dict]) -> str:
bullet_lines = []
for s in extracted_signals:
bullet_lines.append(
f"- Sentiment: {s['sentiment']} | Topics: {', '.join(s['topics'])} | "
f"Entities: {', '.join(s['entities'])} | Summary: {s['summary']}"
)
context = "\n".join(bullet_lines)
response = client.chat.completions.create(
model="kimi-k2.6",
messages=[
{"role": "system", "content": AGGREGATION_PROMPT},
{"role": "user", "content": context},
],
temperature=0.3,
max_tokens=1024,
)
return response.choices[0].message.content
report = build_report(extracted)
print(report)
Run it
Save the complete script as social_analyzer.py, drop in your API key from https://portal.oxlo.ai, and run python social_analyzer.py. The script prints the intermediate JSON first, then the final report. Typical output looks like this:
Key Trends:
1. Pricing frustration dominates the infrastructure conversation. Multiple posts mention token-based billing as a pain point, while flat pricing is praised as a cost saver.
2. Developer tooling is evolving fast. Users are excited about AI-assisted coding features but skeptical of shallow SaaS wrappers.
3. Open-source models are gaining credibility. DeepSeek and local Whisper setups appear as viable alternatives to hosted APIs.
Sentiment Distribution:
- Positive: 3 posts (AI coding features, flat pricing, open-source models)
- Negative: 2 posts (API bills, cloud downtime)
- Neutral/Mixed: 3 posts (observations on SaaS AI, sentiment analysis volume, setup pain)
Strategic Recommendations:
- If you sell inference, highlight request-based pricing loudly. The market is sensitive to unpredictable token bills.
- Differentiate AI features with depth. Users are tired of thin GPT wrappers.
- Invest in reliability and transparent benchmarking. Production trust matters more than demo scores.
Next steps
Replace RAW_POSTS with live data from the Reddit or X APIs. If you move to production, batch multiple extractions into a single Oxlo.ai request to cut latency, or switch to an async loop. For details on request-based pricing, see https://oxlo.ai/pricing.
Top comments (0)