DEV Community

shashank ms
shashank ms

Posted on

LLM for Content Generation: A Step-by-Step Guide

Generating content with large language models has become a standard workflow for product teams, marketing engineers, and technical writers. Whether you are producing blog drafts, ad copy, or structured documentation, the challenge is rarely the prompt itself. It is the cost and latency that accumulate when you feed long style guides, reference material, and conversation history into each request. Token-based billing means every extra paragraph in your system prompt increases the price. Oxlo.ai uses request-based pricing instead. One flat cost per API call, regardless of how much context you include. For content pipelines that rely on extensive prompts or multi-turn refinement, this can change the economics entirely.

Select a Model That Matches Your Output Type

Not all content tasks need the same model. A short product description requires less reasoning capacity than a technical white paper or a long-form narrative. Oxlo.ai hosts more than 45 models across seven categories, all exposed through a single OpenAI-compatible endpoint.

For general copywriting and marketing content, Llama 3.3 70B and Qwen 3 32B handle multilingual fluency and instruction following well. If your pipeline generates code-heavy documentation or developer tutorials, DeepSeek V3.2 and Minimax M2.5 specialize in coding and agentic tool use. For deep reasoning tasks, such as turning raw research into structured long-form articles, DeepSeek R1 671B MoE or Kimi K2.6 provide advanced chain-of-thought capabilities. You can switch models by changing a single parameter in your request, so it is worth experimenting without rewriting your client code.

Configuring the Client

Oxlo.ai is fully compatible with the OpenAI SDK. Change the base URL and API key, and existing scripts work without modification.

from openai import OpenAI

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

Generating a First Draft

A single chat completion is enough for straightforward generation. The key is to be explicit about format, tone, and constraints inside the system prompt.

response = client.chat.completions.create(
    model="llama-3.3-70b",
    messages=[
        {
            "role": "system",
            "content": (
                "You are a technical copywriter. "
                "Write in a direct, precise tone. "
                "Avoid marketing fluff. "
                "Use short paragraphs and bullet points where appropriate."
            )
        },
        {
            "role": "user",
            "content": "Write a product description for an AI inference platform with flat per-request pricing."
        }
    ]
)

print(response.choices[0].message.content)

Because Oxlo.ai bills per request, expanding that system prompt with brand voice guidelines, keyword lists, or examples does not increase the cost of the call. On token-based platforms, those extra tokens add up across thousands of articles.

Enforcing Structure with JSON Mode

Content pipelines rarely stop at raw text. Editorial calendars, SEO metadata, and A/B test variants all need predictable fields. JSON mode lets you constrain the output to valid JSON that matches a provided schema.

import json

response = client.chat.completions.create(
    model="qwen-3-32b",
    response_format={"type": "json_object"},
    messages=[
        {
            "role": "system",
            "content": (
                "You generate blog post metadata. "
                "Respond only in JSON with keys: title, meta_description, keywords (list), and outline (list of strings)."
            )
        },
        {
            "role": "user",
            "content": "Topic: request-based pricing for LLM inference"
        }
    ]
)

metadata = json.loads(response.choices[0].message.content)
print(metadata)

This is useful when feeding downstream CMS tools or analytics dashboards. No regex parsing required.

Iterative Refinement with Multi-Turn Conversations

First drafts rarely ship. A practical content workflow treats the LLM as an editor: expand this section, rewrite for a different audience, or compress to a tweet thread. Each turn appends messages to the conversation context.

messages = [
    {"role": "system", "content": "You are a senior technical editor."},
    {"role": "user", "content": "Draft a 300-word launch announcement for our new vision model."},
]

# First draft
draft = client.chat.completions.create(model="kimi-k2.6", messages=messages)
messages.append({"role": "assistant", "content": draft.choices[0].message.content})

# Follow-up revision
messages.append({
    "role": "user",
    "content": "Make it more concise and add a quote from the CTO."
})

revision = client.chat.completions.create(model="kimi-k2.6", messages=messages)
print(revision.choices[0].message.content)

On token-based providers, every prior message in the context window is re-billed on each new turn. A five-turn editing

Top comments (0)