LLM API for Prompts: Write and Refine Them in Code
This guide shows how to use a text API to write, expand and rewrite prompts for other tools, from one call to a batch of thousands.
Updated

Key points
- One chat call turns a rough idea into a finished prompt; the model ID is uncensored.
- JSON mode returns fields your script can store and search.
- A full key runs 8 requests at once and 300 per minute; retry 429 errors using Retry-After.
- The API writes text only; you paste the prompt into your video or image tool.
What an LLM API does for prompt work
An LLM API for prompts is good at the part of prompt work that wears people out: turning a three-word idea into a full description, writing ten variants of the same scene, or rewriting a prompt so it follows a house format. You send the rough idea and a set of rules, and you get finished prompt text back. Because the endpoint is OpenAI-compatible, the code is the same chat call you would write for any other model.
One boundary first. This service returns text only. It does not render video, images or audio. If your end goal is a clip from a text-to-video tool, the API writes the prompt, and you paste or pipe that prompt into whichever generator you use. That split is useful on its own, because prompt writing is the slow, repetitive step, and text tokens are cheap.
The model is an open-weight model tuned to answer without content refusals for lawful adult use, so a prompt-writing job about a dark thriller scene or a violent fantasy battle is not bounced back with a lecture. The one hard limit is that nothing involving minors in sexual content will be produced.
A first prompt-writer call in Python
Install the SDK with pip install openai and point it at the base URL. The model ID is uncensored, and the key goes in as a Bearer token, which the SDK handles for you.
from openai import OpenAI
client = OpenAI(
base_url="https://api.veo3apis.com/v1",
api_key="YOUR_API_KEY",
)
SYSTEM = (
"You write prompts for a text-to-video tool. "
"Given a rough idea, reply with one prompt of 60 to 90 words. "
"Name the subject, the camera movement, the lighting and the mood. "
"Reply with the prompt only, no preamble."
)
def expand(idea: str) -> str:
resp = client.chat.completions.create(
model="uncensored",
messages=[
{"role": "system", "content": SYSTEM},
{"role": "user", "content": idea},
],
temperature=0.8,
max_tokens=300,
)
return resp.choices[0].message.content.strip()
print(expand("a lighthouse during a storm, seen from a drone"))
Three details make this work better than a first attempt usually does. The system message defines length and the elements every prompt must name, so outputs stay comparable. Setting temperature around 0.8 gives variety between runs without drifting off the idea. And max_tokens is optional here, but a cap of 300 stops a chatty reply from costing more than it should. If you leave it out, the completion can use whatever is left of the 100,000-token window.
If you want ten takes on one idea, do not loop ten times with the same settings and hope. Either raise the temperature and pass a different seed per call, or ask for ten numbered prompts in one reply and split them in code. The second option is cheaper because the instructions are sent once.
Return structured prompts with JSON mode
Free text is fine for a human. Once a script consumes the output, you want fields. JSON mode makes the reply a valid JSON object, so you can read the prompt, the elements you want excluded and some tags without writing a fragile parser. Mention the word JSON and the keys you expect in the system message, and set response_format.
from openai import OpenAI
client = OpenAI(
base_url="https://api.veo3apis.com/v1",
api_key="YOUR_API_KEY",
)
import json
resp = client.chat.completions.create(
model="uncensored",
response_format={"type": "json_object"},
messages=[
{
"role": "system",
"content": (
"Return a JSON object with the keys prompt (string), "
"avoid (string) and tags (list of at most five short strings)."
),
},
{"role": "user", "content": "a night market in the rain, handheld camera"},
],
)
data = json.loads(resp.choices[0].message.content)
print(data["prompt"])
print(data["tags"])
Store the object, not just the text. A table with columns for the idea, the final prompt, the tags and the date lets you search your own history later, and it makes it easy to see which instructions produced the prompts you kept.
When the output must follow a format that JSON does not capture, such as a fixed order of labelled lines, say so with one concrete example inside the system message. Models copy examples more reliably than they follow abstract descriptions.
Stream the result for interactive tools
If a person is waiting on the result, for example in an internal prompt tool or a chat panel, stream the answer so the first words appear at once. Set stream: true; the reply arrives as server-sent events, and usage is reported at the end of the stream.
from openai import OpenAI
client = OpenAI(
base_url="https://api.veo3apis.com/v1",
api_key="YOUR_API_KEY",
)
stream = client.chat.completions.create(
model="uncensored",
messages=[
{"role": "system", "content": "Rewrite the user's prompt to be more specific about camera and light."},
{"role": "user", "content": "a man walking through a foggy forest"},
],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
print()
Remember that a streamed request holds its concurrency slot until the stream ends. A full key allows 8 requests at once, so eight users reading slow streams at the same moment will block a ninth. For a small internal tool that is plenty. For anything public, queue requests on your side.
Run a batch inside the rate limits
The prompt-writing jobs that save the most time are batches: 500 product shots, 200 scene ideas from a script, a whole spreadsheet of rough lines. A full key allows 8 concurrent requests and 300 requests per minute, and a trial key allows 2 and 60. A thread pool sized to the key is the simplest way to stay inside both numbers.
from openai import OpenAI
client = OpenAI(
base_url="https://api.veo3apis.com/v1",
api_key="YOUR_API_KEY",
)
import time
from concurrent.futures import ThreadPoolExecutor
from openai import RateLimitError
SYSTEM = "Turn the idea into one 60 to 90 word video prompt. Reply with the prompt only."
def expand(idea: str) -> str:
for attempt in range(4):
try:
resp = client.chat.completions.create(
model="uncensored",
messages=[
{"role": "system", "content": SYSTEM},
{"role": "user", "content": idea},
],
max_tokens=300,
)
return resp.choices[0].message.content.strip()
except RateLimitError as err:
wait = int(err.response.headers.get("Retry-After", "5"))
time.sleep(wait)
raise RuntimeError("gave up on: " + idea)
ideas = ["a paper boat in a gutter", "a train crossing a salt flat", "a chef plating dessert"]
with ThreadPoolExecutor(max_workers=8) as pool:
prompts = list(pool.map(expand, ideas))
for idea, prompt in zip(ideas, prompts):
print(idea, "->", prompt[:80])
A 429 can mean two things. The error code rate_limited means you went over requests per minute; concurrency means too many requests were running at once. Temporary overload also returns 429 with a Retry-After: 5 header. The loop above waits as long as the header says and tries again. Failed or refused requests are not charged, so a retry does not double the cost.
Write results to disk as you go, one line per finished prompt. A JSON-lines file works well: one object per line holding the idea, the prompt and the time, so a crashed run can skip what is already done when you start it again. A batch of a few thousand calls will eventually hit a bad network moment, and you do not want to start again from the top.
Put your style guide in the 100k context
Prompts get better when the model knows your rules. With a 100,000-token window, prompt plus completion, you can put a lot into the system message: a style guide, a list of banned phrases, twenty approved example prompts, and a glossary of how your team names camera moves.
Use that space on purpose, and keep one rule in mind: the model follows what is written, so write rules the way you would brief a new colleague. A short list of five excellent examples beats fifty mixed ones, because the model averages what it sees. Put the examples in the same format you want back. If a project has a recurring character, write the character sheet once, with hair, clothing and age (adult characters only) described in fixed wording, and tell the model to copy those words verbatim into every prompt. This is the cheapest consistency trick available: the same phrase appears in every prompt, so the generator downstream sees the same description each time.
Long instructions are resent with each call, so they are billed with each call. At $0.15 per million input tokens, a 3,000-token style guide costs $0.00045 per request in input alone. That is small, but across 10,000 requests it is $4.50, so trim the guide once it works. The pricing page has the full rates if you want to run your own numbers.
Common problems and how to fix them
A few mistakes show up again and again in prompt-writing pipelines.
- Preamble in the output. Replies that start with "Here is your prompt:" end up inside the generator. End the system message with "Reply with the prompt only" and strip the result.
- Prompts that are too long. More words do not always give better video or images. Set a word range in the instructions and check it in code.
- Same idea, same output. If you pass
seedwith a fixed value, runs repeat. Change the seed per item, or leave it out when you want variety. - Mixing roles. Keep rules in the system message and the idea in the user message. Putting both in one block makes the model treat your rules as content to rewrite.
- Drift across a long batch. Quality can slide when the same instructions run thousands of times. Spot-check items from the start, middle and end of the run, and keep the system message under version control so you can tell which wording made which batch.
- No review step. Read a sample of every batch before sending prompts to an expensive downstream tool. Ten minutes of reading saves a lot of wasted renders.
To start, create an account, claim the $0.50 trial credit on the API key page, and run the first script above. The trial is one claim per person, lasts 7 days and needs no card. The documentation lists every parameter that is passed through, including top_p, stop and the penalties.
More guides
Questions and answers
Can this API generate the video itself?
No. It generates text only. Use it to write the prompt, then give that prompt to the video tool of your choice.
How many prompts can I write per minute?
A full key allows 300 requests per minute and 8 at once. A trial key allows 60 per minute and 2 at once.
What happens if I send too many requests?
You get HTTP 429 with the code rate_limited or concurrency. Wait for the Retry-After value, then send the request again.
Are my prompts used for training?
No. Prompts are not used for training.
Your key is one form away
Create an account, copy the key, change the base URL. That is the whole setup.