Interested in joining a scientific study?Learn more

Core API

Draft API

Available

Draft takes an existing recipe or meal idea and creates controlled substitutions or edits while respecting preferences, restrictions and sensory goals.

Endpoint

POST/functions/v1/draft

Inputs

  • input_mode: structured or unstructured
  • For unstructured mode, a non-empty request_text
  • For structured mode, recipe_title, ingredients and steps
  • Optional edit_instructions, preferences, restrictions and compound filters

Returns

  • 202 queued response with job_id and status_url
  • Completed result with recipe diffs, substitutions and warnings
  • Validation issues when the source recipe or constraints are incomplete

Request details

  • Structured mode is the default when input_mode is omitted.
  • Unstructured mode can include overrides such as ingredients, steps, diet, condition, avoided_foods and edit_instructions.
  • steps and cooking_steps are accepted aliases; avoided_foods is the canonical public field.

Response details

  • Poll GET /functions/v1/draft?job_id=... until status is completed or failed.
  • Completed results normalize the generated draft before returning it.
  • The meta object includes attempts and job timestamps when available.

Operational notes

  • Requires x-api-key with the edge:draft scope.
  • POST usage is counted and X-Usage-Count is returned.
  • Condition-based edits may require gender for rule validation.

Examples

Request JSON

{
  "input_mode": "unstructured",
  "request_text": "Make this tomato pasta higher protein and lactose-free.",
  "recipe_title": "Tomato pasta",
  "ingredients": ["pasta", "tomato sauce", "parmesan"],
  "steps": ["Cook pasta", "Warm sauce", "Serve with parmesan"],
  "language": "en"
}

Response JSON

{
  "job_id": "f13e52...",
  "status": "queued",
  "status_url": "https://tirqjzahcinadeulfylj.supabase.co/functions/v1/draft?job_id=f13e52..."
}

Code examples

curl -X POST 'https://tirqjzahcinadeulfylj.supabase.co/functions/v1/draft' \
  -H 'x-api-key: $MYMOLECULES_API_KEY' \
  -H 'Content-Type: application/json' \
  --data '{  "input_mode": "unstructured",  "request_text": "Make this tomato pasta higher protein and lactose-free.",  "recipe_title": "Tomato pasta",  "ingredients": ["pasta", "tomato sauce", "parmesan"],  "steps": ["Cook pasta", "Warm sauce", "Serve with parmesan"],  "language": "en"}'