What Is an API Pipeline? A Practical LLM Example
An API pipeline is a chain of automated steps where each step calls an API and passes its result to the next one. Here is how the idea works in practice, with a small text-generation example you can copy.

Key points
- A pipeline is an ordered set of API calls with data handed from one stage to the next.
- Each stage needs a clear input, a checked output and a plan for failure.
- A text LLM stage works best when it returns structured JSON that the next stage can parse.
- Rate limits and retries matter more than prompt wording once you run hundreds of jobs.
The short answer
So, what is an api pipeline? It is a sequence of steps that run one after another without a person pushing each button. Step one calls an API and gets data back. Step two takes that data, maybe cleans it, and calls a different API. Step three stores or publishes the result. The word "pipeline" comes from the picture of water going through connected pipes: what leaves one section enters the next.
A single API call is a question and an answer. A pipeline is a small production line built from several of those calls, plus the glue code between them. The glue handles things the APIs do not: reshaping data, checking it, retrying when something fails, and deciding what to do next.
You do not need a special framework to build one. A Python script that calls three endpoints in order is already a pipeline. Frameworks and schedulers only become useful when the number of jobs, the number of stages or the number of people involved grows.
The parts every pipeline has
Whatever tools you use, the same five parts show up. Naming them helps when something breaks, because you can ask which part failed instead of "why is the whole thing broken".
| Part | What it does | Typical example |
|---|---|---|
| Source | Supplies the raw input | A spreadsheet of ideas, a database row, a webhook |
| Stages | Each calls one API or runs one transformation | An LLM writes a script, a TTS service reads it |
| Handoff format | The shape of data between stages | JSON with fixed field names |
| Control logic | Retries, limits, branching, ordering | Wait on a 429, skip a bad record |
| Sink | Where the final result lands | A folder, a CMS, a queue for human review |
The handoff format is the part beginners skip and regret. If stage one returns free-form prose and stage two expects a list of five items, you will spend your evenings writing regular expressions. Agree on a structure early and make every stage honor it.
An example: from an idea to a shot list
Take a team that produces short videos. The video model itself lives in another tool, and this site does not generate video, audio or images. What a text LLM can do is the planning work in front of it. A pipeline for that might look like this:
- Source: a list of one-line ideas, one per row.
- Stage 1: a call to the chat completions endpoint turns each idea into a shot list, returned as JSON.
- Stage 2: your own code checks that every shot has a description and a duration, and that the total length fits the target.
- Stage 3: a second LLM call rewrites each description into the exact prompt style your video tool prefers.
- Sink: the prompts are saved to a file or queue, and a person or another service sends them to the video tool.
Stages 1 and 3 are text work, which is what an OpenAI-compatible API handles. Stage 2 is plain code and costs nothing. The video step sits outside the part you are building here. Splitting the work this way keeps each stage small enough to test alone.
If your pipeline touches audio too, the same logic applies to lyric and brief writing, as described on the music pipelines page. The text stage is the same kind of call; only the downstream tool changes.
A minimal version in Python
The code below is stage 1 of that example. It asks for JSON, parses it and refuses to pass along data that is missing fields. Set SORA2APIS_KEY to your key first. The base URL and the model ID uncensored are the only values specific to this service; the rest is standard OpenAI SDK usage.
import json
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.sora2apis.com/v1",
api_key=os.environ["SORA2APIS_KEY"],
)
SYSTEM = (
'Return a JSON object: {"shots": [{"order": 1, '
'"description": "...", "duration_s": 4}]}. '
"Between 3 and 6 shots. No text outside the JSON."
)
REQUIRED = {"order", "description", "duration_s"}
def write_shots(idea: str) -> list:
resp = client.chat.completions.create(
model="uncensored",
response_format={"type": "json_object"},
temperature=0.7,
messages=[
{"role": "system", "content": SYSTEM},
{"role": "user", "content": idea},
],
)
data = json.loads(resp.choices[0].message.content)
shots = data["shots"]
for shot in shots:
missing = REQUIRED - set(shot.keys())
if missing:
raise ValueError("shot missing fields: " + ", ".join(sorted(missing)))
return shots
if __name__ == "__main__":
for shot in write_shots("A lighthouse keeper finds a message in a bottle"):
print(shot["order"], shot["duration_s"], shot["description"])
The check at the end is what turns a script into a pipeline stage. Without it, a malformed answer travels down the line and fails somewhere harder to debug. With it, the failure happens at the stage that caused it, with a message that names the problem.
Where pipelines break
Most failures are not about the model. They come from the plumbing, and they are predictable.
Rate limits and concurrency
If you run jobs in parallel, you will hit limits. A full key on this service allows 8 concurrent requests and 300 requests per minute; a trial key allows 2 and 60. When you go over, the API answers HTTP 429 with the error code rate_limited (too many per minute) or concurrency (too many at once). On temporary overload it also returns 429 with a Retry-After: 5 header. Your pipeline should read that header and wait, not hammer the endpoint again.
Bad handoffs
JSON mode (response_format set to json_object) makes the model return valid JSON, but it cannot guarantee your field names. Validate every output before the next stage sees it. Keep the schema in the system prompt short and give one example.
Lost context when a job fails halfway
Imagine 500 ideas and a crash at number 312. If you saved nothing, you start over and pay again. Write each finished record to disk or a database as soon as it passes validation, and on restart skip anything already done.
No trace of what happened
Each response carries an X-Request-Id header. Log it next to your own job ID. When a result looks wrong, that ID is what you quote to support, and you can find the exact call in your own logs. The X-Balance-USD header also tells you how much credit is left, which is handy for stopping a batch before it runs dry.
What a stage costs
A pipeline multiplies small costs, so it is worth doing the arithmetic before a big run. Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens, from prepaid credit.
Say stage 1 sends about 800 tokens in (instructions plus the idea) and gets about 600 tokens back (the JSON shot list). For 500 ideas:
- Input: 500 x 800 = 400,000 tokens, which is 0.4M x $0.15 = $0.06.
- Output: 500 x 600 = 300,000 tokens, which is 0.3M x $0.50 = $0.15.
- Total for the stage: $0.21.
If stage 3 adds a second call of similar size, double it to $0.42. Failed or refused requests are not charged, so a retry after an error does not add to the bill. The pricing page lists the top-up tiers and bonuses.
Questions to settle before you build
Most pipeline trouble starts with decisions nobody wrote down. Spend ten minutes answering these on paper and the code gets shorter.
- What is one unit of work? One idea, one document, one customer record. Every stage should accept that unit and return that unit, enriched. Mixing units (a stage that takes one record and a stage that takes a whole list) is how off-by-one bugs get in.
- Who looks at the output? If a person reviews results before anything is published, you can tolerate a looser stage. If the sink is another automated system, the validation has to be stricter.
- What happens to a bad record? You can stop the run, skip the record and log it, or park it in a "needs attention" file. For batches, skipping and logging is usually right, because one odd input should not hold up 499 good ones.
- How often will it run? Once a month by hand, on a schedule, or whenever a file appears in a folder. A scheduled run needs logs you can read the next morning; a one-off run can print to the screen.
Write the answers at the top of your script as a comment. Six months later, when someone asks why failed records go to a side file, the reason will be sitting right there.
Pipeline or single call?
Not every task deserves a pipeline. A rough test: if you will run the same sequence more than a handful of times, or if the output of one call feeds another call, build the pipeline. If you are exploring a prompt by hand, stay in a notebook or a chat client until the prompt stops changing.
Also ask whether two stages can be one. A model with a 100,000 token context window can often draft and polish in a single request, which means fewer places to fail. Split a stage when you need to inspect or validate something in between, or when the two steps need different settings, such as a high temperature for brainstorming and a low one for formatting.
When you are ready to try it, the quickstart shows the first request, and the API key page explains how to claim the $0.50 trial credit, which is enough to test a short run of the example above.
More guides
Questions and answers
Is an API pipeline the same as a workflow?
They overlap. A workflow is any ordered set of tasks, including manual ones. An API pipeline is the automated kind where each task is an API call or a code step, and data moves between them without a person.
Do I need a framework to build an API pipeline?
No. A script that calls endpoints in order and checks each result is a pipeline. Schedulers and workflow engines help once you have many jobs, many stages or several people maintaining it.
Where does a text LLM fit in a pipeline?
Usually in the stages that write or rewrite: scripts, prompts, descriptions, summaries, structured data from messy text. Ask for JSON so the next stage can parse the result.
Can this API generate the video or audio in my pipeline?
No. It is text only, with no image, audio or video generation. It handles the writing stages and hands text to whichever tool does the rendering.
How do I stop a pipeline from burning credit on a bug?
Test on a handful of records first, validate every output, cap the number of retries, and watch the X-Balance-USD response header during large runs.
Your key is one form away
Create an account, copy the key, change the base URL. That is the whole setup.
Get API key