LLM API Workflow in Python: Step-by-Step Setup
Point the OpenAI SDK at a new base URL, use the model ID uncensored, and add retries, parallel runs and tool calls one layer at a time.
Updated

Key points
- Install openai, set base_url to https://api.veo3apis.com/v1 and use the model uncensored.
- Handle 429 by waiting for Retry-After; failed requests are not charged.
- Size your thread pool to the key: 8 workers for a full key, 2 for the trial key.
- Read X-Balance-USD from the response headers to track spend per run.
The short version
To build an llm api workflow python script, install the official OpenAI SDK, set the base URL to https://api.veo3apis.com/v1, use your key as the API key and call the model uncensored. Nothing else changes. The service is OpenAI-compatible, so every pattern you already know from the SDK works: plain chat calls, streaming, JSON mode and tool calling.
This article builds one small workflow in layers. You start with a single call, then add configuration from environment variables, a retry wrapper, a parallel runner, a tool call and balance tracking. Each layer is short, and you can stop at any one that covers your needs.
The model is one open-weight model run by an independent provider. It is not the official API of any big vendor and it is not a router, so there is only one model ID to remember. It handles text only. There is no image, audio or video generation, no embeddings and no fine-tuning.
Install the SDK and make the first call
You need Python 3.9 or newer. Install the SDK:
pip install openai
Create a key from the API key page after signing up with Google or with an email and password. The page also has a one-click claim for $0.50 of trial credit, valid for 7 days, one per person, no card required. Then run the smallest possible call:
from openai import OpenAI
client = OpenAI(
base_url="https://api.veo3apis.com/v1",
api_key="YOUR_API_KEY",
)
resp = client.chat.completions.create(
model="uncensored",
messages=[
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "List three uses for a hosted text API."},
],
)
print(resp.choices[0].message.content)
print(resp.usage)
If this prints text and a usage object, authentication, routing and the model ID are all correct. The SDK sends your key as Authorization: Bearer, and the request goes to POST /v1/chat/completions. You can check which model IDs your key sees with client.models.list(), which calls GET /v1/models.
A raw curl version is useful when you debug from a server without Python:
curl https://api.veo3apis.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "uncensored", "messages": [{"role": "user", "content": "Say hello."}]}'
Keep configuration in one client
Hard-coding a key in a script is the quickest way to leak it into a repository. Read both values from the environment, and make the client in one place so every step of the workflow shares it.
import os
from openai import OpenAI
client = OpenAI(
base_url=os.environ.get("LLM_BASE_URL", "https://api.veo3apis.com/v1"),
api_key=os.environ["LLM_API_KEY"],
max_retries=0,
timeout=120,
)
MODEL = "uncensored"
def ask(system: str, user: str, **kwargs) -> str:
resp = client.chat.completions.create(
model=MODEL,
messages=[
{"role": "system", "content": system},
{"role": "user", "content": user},
],
**kwargs,
)
return resp.choices[0].message.content
Two choices here are deliberate. max_retries=0 turns off the SDK's built-in retries so the retry logic in the next section is the only one, which makes behavior easier to reason about. The 120-second timeout leaves room for long completions; the context window is 100,000 tokens for prompt plus completion, and a big answer takes time to stream out. Sampling parameters such as temperature, top_p, stop, seed and the penalties pass through **kwargs as usual.
Retry the right errors
Every real workflow hits rate limits sooner or later. A full key allows 300 requests per minute and 8 at once. A trial key allows 60 per minute and 2 at once. Exceed either and the API returns HTTP 429. The error code tells you which limit you hit: rate_limited for requests per minute, concurrency for too many at once. During temporary overload the API also sends 429 with a Retry-After: 5 header.
All three cases have the same cure: wait, then try again. This wrapper honors the header and backs off when it is absent.
from openai import OpenAI
client = OpenAI(
base_url="https://api.veo3apis.com/v1",
api_key="YOUR_API_KEY",
)
import time
from openai import RateLimitError, APIConnectionError, APIStatusError
def call_with_retry(messages, tries=5, **kwargs):
delay = 2
for attempt in range(tries):
try:
return client.chat.completions.create(
model="uncensored", messages=messages, **kwargs
)
except RateLimitError as err:
wait = err.response.headers.get("Retry-After")
time.sleep(int(wait) if wait else delay)
delay = min(delay * 2, 30)
except APIConnectionError:
time.sleep(delay)
delay = min(delay * 2, 30)
except APIStatusError as err:
if err.status_code < 500:
raise
time.sleep(delay)
delay = min(delay * 2, 30)
raise RuntimeError("request failed after retries")
Only retry errors that can change. A 400 means your request is malformed, and sending it again will fail the same way, so the wrapper re-raises any client error other than 429. Failed or refused requests are not charged, so retrying costs nothing extra.
Run many inputs in parallel
For a loop over many inputs, a thread pool is enough. The SDK client is safe to share across threads. Size the pool to your key: 8 workers for a full key, 2 for the trial key.
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
def summarize(text: str) -> str:
for _ in range(5):
try:
resp = client.chat.completions.create(
model="uncensored",
messages=[
{"role": "system", "content": "Summarize the text in two sentences."},
{"role": "user", "content": text},
],
max_tokens=150,
)
return resp.choices[0].message.content.strip()
except RateLimitError as err:
time.sleep(int(err.response.headers.get("Retry-After", "5")))
return ""
documents = ["First long text...", "Second long text...", "Third long text..."]
with ThreadPoolExecutor(max_workers=8) as pool:
summaries = list(pool.map(summarize, documents))
for s in summaries:
print(s)
Pool size is not the same as request rate. Eight workers each finishing a call in half a second would make 960 requests a minute, well over 300. If your calls are fast, add a small sleep or a token-bucket limiter so you stay under the per-minute cap. If your calls are slow, concurrency is the limit you will meet first. Streamed requests hold their slot until the stream finishes.
Structured output and tool calls
Two features turn a chat call into a workflow step that other code can rely on. JSON mode guarantees parseable output. Tool calling lets the model ask your code to do something and then use the answer.
JSON mode
Set response_format to a JSON object and describe the keys in the prompt.
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": "Reply with JSON: {\"title\": string, \"tags\": [string]}"},
{"role": "user", "content": "A short post about nightly backups."},
],
)
post = json.loads(resp.choices[0].message.content)
print(post["title"], post["tags"])
Tool calling
Declare tools with tools, optionally force a choice with tool_choice, run the function yourself and send the result back as a message with role: "tool".
from openai import OpenAI
client = OpenAI(
base_url="https://api.veo3apis.com/v1",
api_key="YOUR_API_KEY",
)
import json
tools = [{
"type": "function",
"function": {
"name": "word_count",
"description": "Count the words in a piece of text.",
"parameters": {
"type": "object",
"properties": {"text": {"type": "string"}},
"required": ["text"],
},
},
}]
messages = [{"role": "user", "content": "How many words are in 'the quick brown fox'?"}]
first = client.chat.completions.create(model="uncensored", messages=messages, tools=tools)
msg = first.choices[0].message
if msg.tool_calls:
messages.append(msg)
for call in msg.tool_calls:
args = json.loads(call.function.arguments)
result = {"words": len(args["text"].split())}
messages.append({
"role": "tool",
"tool_call_id": call.id,
"content": json.dumps(result),
})
final = client.chat.completions.create(model="uncensored", messages=messages, tools=tools)
print(final.choices[0].message.content)
else:
print(msg.content)
Always check that tool_calls is present before reading it. The model may answer directly, and your code should handle both outcomes.
Chain steps into a pipeline
Real workflows rarely stop at one call. A common shape is draft, review, rewrite: the first call produces something, the second criticizes it against a checklist, and the third applies the criticism. Each step is a separate request with its own system message, which keeps the instructions short and the failures easy to locate.
from openai import OpenAI
client = OpenAI(
base_url="https://api.veo3apis.com/v1",
api_key="YOUR_API_KEY",
)
def step(system: str, user: str, temperature: float = 0.7) -> str:
resp = client.chat.completions.create(
model="uncensored",
messages=[
{"role": "system", "content": system},
{"role": "user", "content": user},
],
temperature=temperature,
max_tokens=800,
)
return resp.choices[0].message.content.strip()
topic = "a changelog entry for a new export feature"
draft = step("Write the requested text in under 120 words.", topic)
review = step(
"List at most three concrete problems with this text: vague wording, missing detail, wrong tone.",
draft,
temperature=0.2,
)
final = step(
"Rewrite the text so it fixes every listed problem. Reply with the text only.",
"TEXT:\n" + draft + "\n\nPROBLEMS:\n" + review,
)
print(final)
Notice the lower temperature on the review step. Critique should be consistent from run to run, while drafting benefits from some variety. If you run the pipeline over many inputs, put the whole three-step function inside the thread-pool worker from the previous section, so each worker owns one item from start to finish and the 8-request ceiling is respected.
Keep intermediate results. When the final text is wrong, the draft and the review tell you which step failed, and you can fix one system message instead of rewriting the whole pipeline. Writing each step to a JSON-lines file with the input, the three outputs and the request IDs makes this easy, and it gives you a resume point if the process stops halfway.
Track balance and request IDs
Each response carries headers that are worth logging: X-Request-Id identifies the call if you contact support, X-Balance-USD shows what is left of your credit, and the two X-RateLimit-Limit headers report the request and concurrency limits for your key. The SDK hides headers by default; use the raw-response wrapper to read them.
from openai import OpenAI
client = OpenAI(
base_url="https://api.veo3apis.com/v1",
api_key="YOUR_API_KEY",
)
raw = client.chat.completions.with_raw_response.create(
model="uncensored",
messages=[{"role": "user", "content": "Reply with the single word ready."}],
max_tokens=10,
)
print("request id:", raw.headers.get("X-Request-Id"))
print("balance usd:", raw.headers.get("X-Balance-USD"))
print("req limit:", raw.headers.get("X-RateLimit-Limit-Requests"))
print("concurrency limit:", raw.headers.get("X-RateLimit-Limit-Concurrency"))
resp = raw.parse()
print(resp.choices[0].message.content)
Pricing is $0.15 per million input tokens and $0.50 per million output tokens, so a call with 1,000 input and 500 output tokens costs $0.00015 + $0.00025 = $0.0004. A workflow that runs 5,000 such calls spends $2.00. Print the balance at the start and end of a run, and you will know what each batch costs without any extra tooling. For rates and top-up bonuses, see the pricing page; for every supported parameter, read the API documentation.
One more habit worth adopting: keep prompts out of your logs unless you need them. Prompts sent to this API are not used for training, but your own log files are your responsibility.
Troubleshooting a new setup
Most first-run problems come from a short list of causes.
- The call hangs or errors on connect. Check the base URL. It must end in
/v1, and the SDK appends/chat/completionsitself. A doubled path is the usual mistake. - An authentication error. The key is missing, truncated or has a stray space or newline from a copy and paste. Print its length, not the key itself, and compare it with what the key page shows.
- Model not found. The model ID is
uncensored, in lower case. Call the models endpoint to see exactly what your key can use. - Constant 429 on a small script. You may be on the trial key, which allows 2 concurrent requests and 60 per minute. Drop the pool to 2 workers, or top up to get a full key.
- Cut-off answers. A low
max_tokensends the reply early. Raise it, or remove it and let the completion use the rest of the window. - Request too large. The body limit is 8 MB, and the token window is 100,000 tokens for prompt and completion together. Split large inputs into pieces and process them as separate calls.
When something looks wrong on the service side, send the value from X-Request-Id to the contact on the site. A request ID lets the operator find your exact call, which is far more useful than a description of what you saw.
More guides
Questions and answers
Do I need a special SDK?
No. The official OpenAI Python SDK works once you set the base URL and your key.
Which model ID do I use?
Use uncensored. You can list available IDs with GET /v1/models.
How many requests can run in parallel?
A full key allows 8 concurrent requests and 300 per minute. A trial key allows 2 and 60.
Does streaming work in the Python SDK?
Yes. Pass stream=True and iterate over the chunks. Usage is reported at the end of the stream.
Your key is one form away
Create an account, copy the key, change the base URL. That is the whole setup.