Pictures from a preset
Turn a few words into a picture in your house style, with the style kept in a preset.
Amina runs the Instagram page of Dar Lahlou, a pastry shop in Tlemcen. She types three words, makrout for Ramadan. A text model, set up by the preset, writes them out as a full picture prompt in the shop's style, and a picture model draws the poster. The style lives in one place, and every app that calls the preset draws in it.
1. Save the house style
A preset keeps a request's settings under a name: here, the text model and a system prompt that holds the house style. The body is the one you would send to Chat, posted to POST /v1/presets/{slug}/chat/completions instead.
{
"model": "anthropic/claude-sonnet-4.5",
"messages": [
{
"role": "system",
"content": "You write picture prompts for Dar Lahlou, ..."
}
],
"temperature": 0.7,
"max_tokens": 300
}| The preset keeps | Here |
|---|---|
model | the text model that writes the prompt |
the first system message | the house style: the plate, the table, the light, the colours |
temperature | room to vary the scene from one poster to the next |
max_tokens | a ceiling on the prompt's length |
The slug here is poster-writer. Saving runs no model and costs nothing.
2. Ask it for a prompt
Name the preset as the model, @preset/poster-writer, and send the few words as the user's turn. The answer, in choices[0].message.content, is the full picture prompt. The sample saves the style, asks for a prompt, and writes it to prompt.txt for step 3.
import json
import os
import urllib.request
key = os.environ["OPENDUNES_API_KEY"]
base_url = "https://opendunes.com/v1"
model = "anthropic/claude-sonnet-4.5"
preset = "poster-writer"
style = (
"You write picture prompts for Dar Lahlou, a pastry shop in Tlemcen. "
"Turn the request into one prompt of at most 80 words: the pastry, "
"the plate, the table, the light, the colours. House style: seen from "
"above, a green and gold zellige table, soft morning light, no text "
"in the picture. Answer with the prompt alone."
)
words = "makrout for Ramadan"
def call(path, body):
request = urllib.request.Request(
base_url + path,
data=json.dumps(body).encode(),
headers={
"Authorization": "Bearer " + key,
"Content-Type": "application/json",
},
)
with urllib.request.urlopen(request) as response:
return json.load(response)
saved = call("/presets/" + preset + "/chat/completions", {
"model": model,
"messages": [{"role": "system", "content": style}],
"temperature": 0.7,
"max_tokens": 300,
})["data"]
print("version", saved["designated_version"]["version"])
answer = call("/chat/completions", {
"model": f"@preset/{preset}",
"messages": [{"role": "user", "content": words}],
})
prompt = answer["choices"][0]["message"]["content"]
with open("prompt.txt", "w") as out:
out.write(prompt)
print(prompt)
print(answer["usage"]["cost"])Run the save once. After it, any app sends @preset/poster-writer and the few words, and nothing else.
Don't write the house style into each app that makes pictures. Every change of season then means a deploy of each one.
Do keep the style in the preset, and the few words in the app. Save the preset again with the new style, and every app writes in it from its next request.
3. Draw the picture
Send the prompt to /v1/images with a picture model. The picture comes back in the answer, in base64: decode it and save the file, as the Pictures guide does. The sample reads prompt.txt, draws a 4:5 poster at 2K and writes it to poster.png or the type the model returned.
import base64
import json
import os
import urllib.request
API_KEY = os.environ["OPENDUNES_API_KEY"]
ADDRESS = "https://opendunes.com/v1/images"
MODEL = "google/gemini-3.1-flash-image"
PROMPT_FILE = "prompt.txt"
with open(PROMPT_FILE) as source:
prompt = source.read().strip()
request = urllib.request.Request(
ADDRESS,
data=json.dumps(
{
"model": MODEL,
"prompt": prompt,
"resolution": "2K",
"aspect_ratio": "4:5",
}
).encode(),
headers={
"Authorization": "Bearer " + API_KEY,
"Content-Type": "application/json",
},
)
with urllib.request.urlopen(request) as response:
answer = json.load(response)
picture = answer["data"][0]
extension = picture["media_type"].split("/")[1]
with open("poster." + extension, "wb") as out:
out.write(base64.b64decode(picture["b64_json"]))
print(answer["usage"]["cost"])| You send | Holds |
|---|---|
model | a picture model's ID, from its page in Models |
prompt | the prompt the preset wrote |
resolution | 2K, one of the sizes this model offers |
aspect_ratio | 4:5, a portrait frame, one of the shapes this model offers |
The model's page lists the sizes and the shapes it makes. A model ignores a field it does not offer.
What it cost
Two charges, in DADAThe Algerian dinar, the one currency the docs show.More on Balance and charges →, from your balanceBalanceWhat you can spend, in DA.More on Balance and charges →, each read in usage.cost of its own answer.
| Call | Charged on |
|---|---|
| saving the preset | nothing: it runs no model |
| asking it for a prompt | the text model's tokens, at the rates of the model the preset names |
| drawing the picture | the picture model's meter: each picture, or the tokens it reports, as its page in Models says |
A generation that fails, or answers with no picture, charges nothing. What to do on an error: Errors and retries.
Last modified on