DEV Community

shashank ms
shashank ms

Posted on

A Beginner's Guide to Using LLMs for Art Generation

We are building a Python tool that turns text descriptions into SVG artwork using an LLM. It is useful for developers and designers who need quick vector graphics or generative art without opening a design tool. We will run the entire pipeline against Oxlo.ai's OpenAI-compatible API, which keeps costs predictable with flat per-request pricing.

What you'll need

  • Python 3.10 or newer
  • An Oxlo.ai API key from https://portal.oxlo.ai
  • The OpenAI SDK. Install it with pip install openai

Step 1: Set up the Oxlo.ai client

Create a new file named svg_art_gen.py. Import the OpenAI SDK and point it at Oxlo.ai. I use Oxlo.ai here because the flat per-request pricing lets me iterate on long, detailed prompts without token costs scaling up. If you want to compare plans, see https://oxlo.ai/pricing.

from openai import OpenAI

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

Step 2: Write the art generator system prompt

Define a system prompt that instructs the model to return only raw SVG XML. This removes the need for complex parsing. I run this on Llama 3.3 70B, which follows formatting instructions reliably.

SYSTEM_PROMPT = """You are an expert SVG artist and frontend developer.
Given a user description, generate a complete, valid SVG file.
Rules:
- Output ONLY raw SVG XML. No markdown, no explanations, no code fences.
- Use a viewBox of "0 0 512 512".
- Use vibrant colors, gradients, and geometric shapes where appropriate.
- Ensure the SVG is self-contained and renders correctly in browsers."""

Step 3: Generate SVG from a description

Add a function that sends the user description to the model and extracts the SVG string. The call follows the standard Oxlo.ai chat completions pattern.

def generate_art(description):
    user_message = description

    response = client.chat.completions.create(
        model="llama-3.3-70b",
        messages=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": user_message},
        ],
    )

    svg_content = response.choices[0].message.content.strip()

    # Remove accidental markdown fences if the model includes them
    if svg_content.startswith("

```"):
        lines = svg_content.splitlines()
        if lines[0].startswith("```

"):
            lines = lines[1:]
        if lines and lines[-1].startswith("

```

"):
            lines = lines[:-1]
        svg_content = "\n".join(lines).strip()

    return svg_content

Step 4: Save and preview the artwork

Write the returned SVG to disk and print the absolute path. You can open the file in any browser or embed it in an HTML page.

import os

def save_art(svg_content, filename="output.svg"):
    filepath = os.path.abspath(filename)
    with open(filepath, "w", encoding="utf-8") as f:
        f.write(svg_content)
    print(f"Saved artwork to: {filepath}")
    return filepath

if __name__ == "__main__":
    description = input("Describe your artwork: ")
    svg = generate_art(description)
    save_art(svg)

Run it

Run the script from your terminal and enter a description. The model returns a complete SVG file that opens in any browser.

$ python svg_art_gen.py
Describe your artwork: A futuristic city skyline at sunset with neon reflections in the water

Saved artwork to: /home/user/projects/output.svg

Opening output.svg in a browser shows a 512x512 vector illustration of a neon city skyline. Because Oxlo.ai uses request-based pricing, the cost is the same whether my prompt is ten words or a detailed paragraph specifying color hex codes and layer ordering. If you prefer pixel-based generation, Oxlo.ai also hosts image models including Flux.1, Stable Diffusion 3.5, and Oxlo.ai Image Pro.

Next steps

1. Extend the script to batch-generate icons by reading descriptions from a JSON file and saving multiple SVGs in one run.

2. Swap the model to kimi-k2.6 or qwen-3-32b on Oxlo.ai to test which architecture produces more creative compositions for your specific style.

Top comments (0)