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.
{ "input": { "upload_id": "up_01JBXA3Q6M2T8V4W9Y5Z7B1C3D" }, "steps": [ { "op": "convert", "conversion": "word-to-pdf" }, { "op": "convert", "conversion": "pdf-to-markdown" } ]}How steps run
Section titled “How steps run”- 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’sfromis what the step before makes. - Joining and splitting. Only the first step may join files (
merge-pdf, withinputs), 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.
stepslists every step with its status, credits and engine; the job’senginenames them all.
Recipes
Section titled “Recipes”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.
#!/usr/bin/env bash# Needs curl and jq.set -euo pipefailAPI=https://api.formatjet.com/v1AUTH="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"import { readFile, writeFile } from 'node:fs/promises';import { FormatJet } from '@formatjet/sdk';
const formatjet = new FormatJet(); // reads FORMATJET_API_KEY
// Save a recipe: print a web page to PDF, then read that PDF as Markdown.const recipe = await formatjet.recipes.create({ name: 'Web page to text', steps: [ { op: 'convert', conversion: 'html-to-pdf' }, { op: 'convert', to: 'md' }, ], output_name: '{name}-text',});
// Run it on a file, wait for every step and download the last step's output.const result = await formatjet.uploadAndConvert( { data: await readFile('report.html'), filename: 'report.html' }, { recipe: recipe.id },);await writeFile(result.file.filename ?? 'report-text.md', result.file.data);console.log(`${result.jobId}: ${result.credits} credits, ${result.engine}`);
// The recipe stays for later jobs; this removes it.await formatjet.recipes.delete(recipe.id);from formatjet import FormatJet
formatjet = FormatJet() # reads FORMATJET_API_KEY
# Save a recipe: print a web page to PDF, then read that PDF as Markdown.recipe = formatjet.recipes.create( "Web page to text", [ {"op": "convert", "conversion": "html-to-pdf"}, {"op": "convert", "to": "md"}, ], output_name="{name}-text",)
# Run it on a file, wait for every step and download the last step's output.result = formatjet.upload_and_convert("report.html", recipe=recipe.id)result.file.save(result.file.filename or "report-text.md")print(f"{result.job_id}: {result.credits} credits, {result.engine}")
# The recipe stays for later jobs; this removes it.formatjet.recipes.delete(recipe.id)- Save one with
POST /v1/recipes: aname, itsstepsas a job takes them, and anoutput_name. The first step names its conversion, ortowithfrom, 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}'}-smallmakesreport-small.pdf. Without anoutput_name, the output takes the input’s name; a job’soutput.filenamebeats both. - Run one with
recipeinstead ofstepsonPOST /v1/jobs,?recipe=instead ofconversiononPOST /v1/convert, the SDKs’recipeoption, or the MCP server’screate_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
PATCHandDELETE /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.