We are building a multi-style draft generator that turns a one-sentence brief into technical documentation, marketing copy, and tutorial prose. It helps teams that ship content daily without maintaining separate pipelines for every format.
What you'll need
- An Oxlo.ai API key from https://portal.oxlo.ai
- Python 3.10 or newer
- The OpenAI SDK:
pip install openai
Step 1: Set up the Oxlo.ai client
I import the OpenAI SDK and instantiate the client with the Oxlo.ai endpoint. Because the platform is fully OpenAI API compatible, this is a drop-in replacement and 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")
Step 2: Write the system prompt
The system prompt is the only configuration layer. It forces the model to return JSON with three distinct voices so we get predictable, parseable output on every run.
SYSTEM_PROMPT = """You are a multi-style natural language generator.
Given a topic, write three versions of content about it.
Return ONLY a JSON object with exactly these keys:
- "technical": a precise, documentation-style paragraph
- "marketing": a punchy, one-sentence product tagline followed by a 2-sentence pitch
- "tutorial": a single concrete step a reader can follow, written in second person
Rules:
- Do not include markdown code fences around the JSON.
- Keep each value under 120 words.
- Be specific, not generic."""
Step 3: Build the generation function
I wrap the API call in a small function. I use llama-3.3-70b here because it handles mixed instructions and JSON structuring reliably on Oxlo.ai.
import json
def generate_drafts(topic: str, model: str = "llama-3.3-70b"):
response = client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": f"Topic: {topic}"},
],
temperature=0.7,
)
raw = response.choices[0].message.content
return json.loads(raw)
Step 4: Add streaming for real-time previews
For CLI tools or interactive demos, blocking on the full response is fine, but I also want a streaming version so I can watch long outputs arrive token by token. Oxlo.ai supports streaming on all chat models with no cold starts.
def stream_draft(topic: str, model: str = "llama-3.3-70b"):
stream = client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": f"Topic: {topic}"},
],
temperature=0.7,
stream=True,
)
for chunk in stream:
delta = chunk.choices[0].delta.content
if delta:
print(delta, end="", flush=True)
print()
Step 5: Batch test briefs
Now I batch a few real topics through the non-streaming function and print the formatted results. This is where flat per-request pricing matters. If these briefs expand into long-context rewrites, the cost stays predictable on Oxlo.ai rather than scaling with token count.
if __name__ == "__main__":
topics = [
"Implementing request-based pricing for AI inference",
"Debugging race conditions in async Python",
"Deploying a Qwen 3 32B model for multilingual support",
]
for t in topics:
print(f"\n=== Topic: {t} ===")
try:
result = generate_drafts(t)
for style, text in result.items():
print(f"\n{style.upper()}:")
print(text)
except Exception as e:
print("Error:", e)
Run it
Save the script as draft_generator.py, replace YOUR_OXLO_API_KEY, and run:
python draft_generator.py
Example output for the first topic looks like this:
=== Topic: Implementing request-based pricing for AI inference ===
TECHNICAL:
Request-based pricing is an inference billing model that charges a flat fee per API call rather than metering input and output tokens separately. This approach simplifies cost forecasting for workloads with variable context lengths, such as agentic loops or long-document summarization.
MARKETING:
Stop letting token meters eat your budget.
With request-based pricing, you pay one flat fee per API call no matter how large the prompt grows. That means predictable costs for agentic workflows and long-context applications.
TUTORIAL:
Open your Oxlo.ai dashboard, copy your API key, and set it as the api_key argument when initializing the OpenAI client in your Python script.
Wrap-up and next steps
This generator works as a standalone script or a FastAPI microservice. Two concrete upgrades worth shipping next:
- Swap in
qwen-3-32borkimi-k2.6when you need multilingual or vision-capable drafts, ordeepseek-v3.2for coding-focused tutorials. Because Oxlo.ai offers 45+ models on a single endpoint, switching is a one-line change. - Wire the script into a GitHub Action that auto-generates release notes. Since Oxlo.ai pricing is per request, running it on every commit stays cheap even when the diffs are large. See https://oxlo.ai/pricing for plan details.
Top comments (0)