We will build a command-line draft generator that turns a topic and audience into a ready-to-edit blog post using an LLM. It is a practical first project for anyone integrating generative text into a product or workflow. We will run it against Oxlo.ai so cost stays flat per request even when we pass long style guides or examples.
What you'll need
- Python 3.10 or newer
- The OpenAI SDK:
pip install openai - An Oxlo.ai API key from https://portal.oxlo.ai
Step 1: Initialize the client
Create a file named draft_generator.py and set up the Oxlo.ai client. Oxlo.ai exposes an OpenAI-compatible endpoint, so the standard SDK works with just a base URL change.
from openai import OpenAI
client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")
# We will use Llama 3.3 70B as the default workhorse.
MODEL = "llama-3.3-70b"
Step 2: Define the system prompt
The system prompt constrains the model to act as a drafting assistant and sets formatting rules. Keeping it in a constant makes it easy to tweak without touching logic.
SYSTEM_PROMPT = """You are a drafting assistant. Given a topic and a target audience, write a concise, informative first draft suitable for a technical blog. Use short paragraphs. Do not include meta-commentary or bullet points. Output only the draft text."""
Step 3: Build the generation function
We will accept a topic and audience, package them into a user message, and call the chat completions endpoint. I return the generated text so the caller can do what it wants with it.
def generate_draft(topic: str, audience: str) -> str:
user_message = f"Topic: {topic}\nAudience: {audience}"
response = client.chat.completions.create(
model=MODEL,
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": user_message},
],
temperature=0.7,
max_tokens=1024,
)
return response.choices[0].message.content
Step 4: Add streaming
Waiting for the full draft can feel slow. Oxlo.ai supports streaming, so we can print tokens as they arrive. We switch the function to a generator and set stream=True.
def generate_draft_stream(topic: str, audience: str):
user_message = f"Topic: {topic}\nAudience: {audience}"
stream = client.chat.completions.create(
model=MODEL,
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": user_message},
],
temperature=0.7,
max_tokens=1024,
stream=True,
)
for chunk in stream:
token = chunk.choices[0].delta.content
if token:
print(token, end="", flush=True)
print()
Step 5: Wrap it in a CLI
Add an input loop so we can run multiple prompts without restarting the script. This is the final script.
if __name__ == "__main__":
print("Draft Generator (Oxlo.ai)")
print("Enter 'quit' to exit.\n")
while True:
topic = input("Topic: ").strip()
if topic.lower() == "quit":
break
audience = input("Audience: ").strip()
if audience.lower() == "quit":
break
print("\n--- Draft ---\n")
generate_draft_stream(topic, audience)
print("\n-------------\n")
Run it
Save the complete script and run it from your terminal.
$ python draft_generator.py
Draft Generator (Oxlo.ai)
Enter 'quit' to exit.
Topic: request-based pricing for LLM APIs
Audience: backend engineers
--- Draft ---
Request-based pricing changes how teams think about inference costs. Instead of counting tokens, you pay one flat fee per API call. This matters most when your prompts grow. Long system prompts, few-shot examples, and agentic context all inflate token counts, but with a per-request model the cost stays predictable.
For backend engineers, this simplifies budgeting. You can send detailed instructions or large code contexts without watching the meter spin. Oxlo.ai offers this flat-rate structure across its full catalog, including Llama 3.3 70B and DeepSeek V3.2. If you are building agents or RAG pipelines that stuff context windows, the savings add up quickly.
-------------
Wrap-up
Swap the model string to deepseek-v3.2 or qwen-3-32b if you need stronger reasoning or multilingual output. If you want to turn this into a service, move the logic into a FastAPI endpoint and add Pydantic validation for the topic and audience fields. You can view Oxlo.ai pricing at https://oxlo.ai/pricing to pick the right plan for your expected volume.
Top comments (0)