DEV Community

shashank ms
shashank ms

Posted on

Building Media Tools with LLM: A Step-by-Step Guide

I built a small pipeline last month that turns raw podcast transcripts into publish-ready metadata and social clips. It saves about twenty minutes per episode. Here is how to build the same thing on Oxlo.ai, which fits this workflow well because long transcripts cost the same per request regardless of token count.

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
  • Pydantic: pip install pydantic

Step 1: Configure the Oxlo.ai client

I keep my API key in an environment variable, but a hardcoded string works for local testing. Instantiate the client and confirm the endpoint responds.

from openai import OpenAI
import os

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

response = client.chat.completions.create(
    model="llama-3.3-70b",
    messages=[{"role": "user", "content": "Hello"}],
    max_tokens=10
)
print(response.choices[0].message.content)

Step 2: Define the schema and system prompt

I enforce structure with Pydantic so downstream tools do not break when the model adds an unexpected field. The system prompt is strict about JSON-only output.

from pydantic import BaseModel, Field
from typing import List

class MediaMetadata(BaseModel):
    title: str = Field(description="SEO-friendly title, max 60 characters")
    summary: str = Field(description="Two-sentence summary of the content")
    tags: List[str] = Field(description="5 to 8 relevant keywords or hashtags")
    key_quotes: List[str] = Field(description="2 to 4 verbatim quotes suitable for graphics")
    sentiment: str = Field(description="Overall tone: positive, neutral, or negative")

SYSTEM_PROMPT = """You are a media production assistant. Analyze the user transcript and return valid JSON matching the MediaMetadata schema. Do not include markdown formatting or explanations outside the JSON object."""

Step 3: Build the core processor

The processor sends the full transcript in a single request. On Oxlo.ai, this is where the pricing model shines. A long transcript costs the same as a short prompt because you pay per request, not per token.

from openai import OpenAI

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

def extract_metadata(transcript: str) -> MediaMetadata:
    user_message = f"Analyze this transcript and produce metadata:\n\n{transcript}"
    
    response = client.chat.completions.create(
        model="llama-3.3-70b",
        messages=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": user_message},
        ],
        response_format={"type": "json_object"},
        temperature=0.2,
    )
    
    raw_json = response.choices[0].message.content
    return MediaMetadata.model_validate_json(raw_json)

Step 4: Generate platform clips

With the metadata in hand, a second call writes social copy tailored to each platform. I switch to qwen-3-32b here because it handles structured creative tasks cleanly, though llama-3.3-70b works too.

from openai import OpenAI
import json

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

def generate_clips(transcript: str, metadata: MediaMetadata) -> dict:
    prompt = f"""Title: {metadata.title}
Summary: {metadata.summary}
Transcript excerpt: {transcript[:2000]}

Write three social posts in JSON format:
- twitter_post: under 280 characters, include 2 tags
- linkedin_post: 3 to 4 sentences, professional tone
- tiktok_hook: first 3 seconds of voiceover, casual and punchy"""

    response = client.chat.completions.create(
        model="qwen-3-32b",
        messages=[
            {"role": "system", "content": "You are a social media editor. Return only JSON."},
            {"role": "user", "content": prompt},
        ],
        response_format={"type": "json_object"},
        temperature=0.7,
    )
    
    return json.loads(response.choices[0].message.content)

Run it

This sample transcript is roughly three hundred fifty tokens. Drop it into the pipeline and print the results.

from openai import OpenAI
import json

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

SAMPLE_TRANSCRIPT = """
Host: Welcome back. Today Dr. Sarah Chen joins us to talk about solid-state batteries.
Dr. Chen: Thanks. We are seeing lab prototypes hit 400 watt-hours per kilogram. That is roughly double today's lithium-ion density.
Host: When will this reach consumers?
Dr. Chen: If manufacturing scales, 2028. Without policy support, closer to 2032.
Host: What should listeners watch for?
Dr. Chen: Look for pilot factories in the U.S. and Germany. Those will be the bellwether.
"""

if __name__ == "__main__":
    meta = extract_metadata(SAMPLE_TRANSCRIPT)
    clips = generate_clips(SAMPLE_TRANSCRIPT, meta)
    
    print(json.dumps(meta.model_dump(), indent=2))
    print("\n--- Platform Clips ---\n")
    print(json.dumps(clips, indent=2))

Expected output:

{
  "title": "Dr. Sarah Chen on Solid-State Batteries and the 2028 Timeline",
  "summary": "Dr. Sarah Chen explains recent solid-state battery breakthroughs achieving 400 Wh/kg in lab conditions and discusses the path to commercialization by 2028.",
  "tags": ["solid-state batteries", "energy storage", "EVs", "clean tech", "battery density"],
  "key_quotes": [
    "We are seeing lab prototypes hit 400 watt-hours per kilogram.",
    "If manufacturing scales, 2028. Without policy support, closer to 2032."
  ],
  "sentiment": "positive"
}

--- Platform Clips ---

{
  "twitter_post": "Solid-state batteries just hit 400 Wh/kg in the lab. Dr. Sarah Chen says consumer devices could arrive by 2028. #BatteryTech #CleanEnergy",
  "linkedin_post": "Dr. Sarah Chen joined us to discuss a major milestone in energy storage. Lab prototypes of solid-state batteries are now achieving 400 watt-hours per kilogram, roughly double current lithium-ion density. Commercial timelines depend on scaling manufacturing and policy support.",
  "tiktok_hook": "Your phone battery is about to double in capacity. Here is why 2028 is the year to watch."
}

Next steps

To productionize this, wrap the two functions in a FastAPI endpoint so your ingest service can POST transcripts and receive structured JSON back. If you need to generate transcripts from audio, pipe the audio through Oxlo.ai's Whisper endpoint first, then feed the resulting text into the pipeline above. For plan details, see https://oxlo.ai/pricing.

Top comments (0)