Skip to content

Steps and recipes

A job can run up to 5 steps. Each step converts what the step before made, and the job’s output is the last step’s: a Word file to PDF, then that PDF to Markdown, in one job.

POST /v1/jobs
{
"input": {
"upload_id": "up_01JBXA3Q6M2T8V4W9Y5Z7B1C3D"
},
"steps": [
{
"op": "convert",
"conversion": "word-to-pdf"
},
{
"op": "convert",
"conversion": "pdf-to-markdown"
}
]
}
  • One after another. A step starts when the one before it has finished. Name each by its conversion, or by the format to make (to); a later step’s from is what the step before makes.
  • Joining and splitting. Only the first step may join files (merge-pdf, with inputs), and only the last may make several files (split-pdf, a PDF’s pages as images).
  • Credits. The job costs every step’s credits, held when it starts and charged only if every step succeeds. A step priced per page or minute is counted on its own input when it starts, as one job of that conversion would be. If a step fails, the job ends with that step’s error and nothing is charged.
  • Files between steps. Each step but the last writes a file the next one reads. It’s deleted as soon as the next step has converted, and the job’s deletion receipt lists it with the role intermediate.
  • The job’s view. steps lists every step with its status, credits and engine; the job’s engine names them all.

A recipe is steps you save, with a name for the output, and run on any file later. Recipes come with Pro and the API plans; test keys have them on any plan. An organization keeps up to 100.

recipe.sh
#!/usr/bin/env bash
# Needs curl and jq.
set -euo pipefail
API=https://api.formatjet.com/v1
AUTH="Authorization: Bearer $FORMATJET_API_KEY"
# 1. Save a recipe: print a web page to PDF, then read that PDF as Markdown.
recipe=$(curl -sS --fail-with-body "$API/recipes" -H "$AUTH" -H "Content-Type: application/json" \
-d '{"name": "Web page to text", "output_name": "{name}-text",
"steps": [{"op": "convert", "conversion": "html-to-pdf"}, {"op": "convert", "to": "md"}]}')
recipe_id=$(jq -r .id <<< "$recipe")
# 2. Run it on a file: here sent as base64, as small files may be.
job=$(jq -n --arg recipe "$recipe_id" --rawfile page report.html \
'{input: {base64: ($page | @base64), filename: "report.html"}, recipe: $recipe}' |
curl -sS --fail-with-body "$API/jobs" -H "$AUTH" -H "Content-Type: application/json" -d @-)
id=$(jq -r .id <<< "$job")
# 3. Wait for every step to end.
status=$(jq -r .status <<< "$job")
until [[ $status == completed || $status == failed || $status == canceled ]]; do
sleep 1
job=$(curl -sS --fail-with-body "$API/jobs/$id" -H "$AUTH")
status=$(jq -r .status <<< "$job")
done
[[ $status == completed ]] || { jq .error <<< "$job"; exit 1; }
# 4. Download the last step's output, named by the recipe: report-text.md.
output=$(jq '.outputs[0]' <<< "$job")
curl -sS --fail-with-body "$(jq -r .url <<< "$output")" -o "$(jq -r .filename <<< "$output")"
# The recipe stays for later jobs; this removes it.
curl -sS --fail-with-body -X DELETE "$API/recipes/$recipe_id" -H "$AUTH"
  • Save one with POST /v1/recipes: a name, its steps as a job takes them, and an output_name. The first step names its conversion, or to with from, so every later step’s input is known. The steps are checked as a job’s would be.
  • Name the output with text and {'{name}'}, the input’s name without its extension: {'{name}'}-small makes report-small.pdf. Without an output_name, the output takes the input’s name; a job’s output.filename beats both.
  • Run one with recipe instead of steps on POST /v1/jobs, ?recipe= instead of conversion on POST /v1/convert, the SDKs’ recipe option, or the MCP server’s create_job. Its steps are checked again for each file, so a step that can’t take the file is refused before anything runs.
  • Change or delete one with PATCH and DELETE /v1/recipes/{'{id}'}. Jobs already running keep the steps they started with.
  • No passwords. A recipe can’t keep a password, such as Unlock PDF’s. Send that conversion in a job’s own steps.