Endpoint
/functions/v1/decodeTurn meal text, images, audio or known food items into molecular nutrition data.
2026-07-10 is the newest public version. Send it in mymolecules-api-version when submitting and polling. Without the header, Decode uses a legacy response format. An unsupported version returns HTTP 400 (unsupported_api_version).
For API-key setup and secure storage, see Authentication.
Choose an input mode
Both modes produce the same kind of result. Choose based on what your application already knows about the meal. Your API key must allow the selected mode; otherwise, Decode returns HTTP 403 (decode_input_mode_not_allowed).
| Mode | When to use it | What to send |
|---|---|---|
| Unstructured | Use when you have a meal description, image or recording and need Decode to identify the foods and quantities. | Send at least one of foodText, foodImage or foodVoice. Do not send items. |
| Structured | Use when your application already knows the food names and quantities and wants to skip food recognition. | Send 1–25 items with canonical_name, quantity and unit. Do not mix in unstructured food fields. |
Access and result tiers
Your API key determines which input modes and level of detail you can use:
| Tier | Included compounds |
|---|---|
| macros | Protein, total fat, carbohydrate, energy, total dietary fibre, water-soluble fibre, sodium chloride and water. |
| micros | Everything in macros, plus compounds such as calcium, iron, folate, vitamin B12, omega-3 fatty acids and caffeine.See all compounds 95
|
| molecular | Any compound for the selected food in our molecular database. |
Request fields
Common fields
| Field | Type | Description |
|---|---|---|
input_mode | string | Required in every request. Select structured or unstructured. Your API key must permit the selected mode. |
Unstructured input mode
| Field | Type | Description |
|---|---|---|
foodText | string | Required if you do not send foodImage or foodVoice; otherwise optional. Non-empty meal description, up to 1,500 characters. Also use it to describe what was left uneaten in words. You can combine text, images and audio. |
foodImage | string | string[] | Optional with foodText or foodVoice. One image or a list of one to three images of the same meal, including possible leftovers. Each accepts an HTTP(S) URL or base64 data URL, up to 10 MiB. Empty lists and invalid images are rejected. |
foodVoice | string | Required if you do not send foodText or foodImage; otherwise optional. Food recording as an HTTP(S) URL or inline base64 data URL, up to 15 MiB and 300 seconds. Supported inline MIME types: audio/mpeg, audio/mp3, audio/mp4, audio/x-m4a, audio/m4a, audio/wav, audio/x-wav, audio/webm and video/mp4. |
language | string | Optional, unstructured mode only. Use german or english for the returned food names and attributes. Without it, Decode follows the text or voice language; image-only input has no fixed default language. Structured requests must omit this field. |
- Send at most three images in foodImage and one audio input in foodVoice.
- Total media must not exceed 30 MiB; the JSON request body must not exceed 45 MiB.
- All images are interpreted together with text and voice. Multiple views or duplicate photos do not mean extra portions or automatically indicate leftovers. Remaining food is deducted only when there is sufficient evidence of its original portion; similar full plates do not imply zero consumption. Describe any remaining food in foodText or foodVoice. The retired foodImageRemaining and attachments fields are rejected.
- Media URLs must remain reachable when the background job downloads them. Use a signed URL for private files, with enough time before expiry. HTTPS alone does not grant access; local file paths are not supported.
- Every supplied image must be processed. An invalid or unreachable image fails the entire job, even when text or other valid images are present. The error identifies the affected image in details.field, for example foodImage[1], without exposing its URL.
Structured input mode
| Field | Type | Description |
|---|---|---|
items | object[] | Required in structured mode. One to 25 known food items. |
items[].canonical_name | string | Required for each item. Known food name, up to 160 characters. |
items[].quantity | number | Required for each item. Finite amount greater than zero. The normalized amount may not exceed 100,000 g. |
items[].unit | string | Required for each item. Unit for quantity: mg, g or kg. The response normalizes it to quantity_g. |
items[].brand | string | null | Optional. Brand when known. |
items[].attributes | string[] | Optional. Up to ten food attributes, each up to 80 characters. |
Result options
| Field | Type | Description |
|---|---|---|
compound_identifier_ids | (integer | string)[] | Optional. Restricts results to existing positive compound IDs within the key tier. IDs can be integers or numeric strings. An empty array does not filter. |
compound_identifier_names | string[] | Optional. Restricts results to exact, case-sensitive catalog names. Both filter arrays are combined and deduplicated; neither expands the key tier. |
include_compound_identifier_value | boolean | Optional. Set false to omit compound_identifier_value from every molecular row. Default: true. |
include_measurement_min_max | boolean | Optional. Set false to omit measurement bounds, their types and their references from every molecular row. Default: true. |
include_unquantified_measurements | boolean | Optional. Set false to omit rows whose measurement_value_type is trace or unquantified. Default: true. |
Request examples
Unstructured input mode
{
"input_mode": "unstructured",
"foodImage": [
"https://your-domain.example/meal.jpg",
"https://your-domain.example/leftovers.jpg"
],
"foodVoice": "https://your-domain.example/meal.m4a",
"foodText": "..."
}Structured input mode
{
"input_mode": "structured",
"items": [
{
"canonical_name": "greek yogurt",
"brand": null,
"attributes": [],
"quantity": 200,
"unit": "g"
}
],
"compound_identifier_ids": [
12057
],
"compound_identifier_names": [
"water"
],
"include_compound_identifier_value": false,
"include_measurement_min_max": false,
"include_unquantified_measurements": false
}Submit and poll a job
POST returns HTTP 202 with job_id and status_url, not the analysis. Poll that URL with the same API key until the status is completed or failed. Polling a found failed job still returns HTTP 200.
Accepted POST · HTTP 202
{
"data": {
"job_id": "8a93f4a0-2222-4a10-8c93-bca31ae9d48b",
"status": "queued",
"status_url": "<STATUS_URL_FROM_RESPONSE>"
},
"meta": {
"request_id": "req_...",
"api_version": "2026-07-10"
}
}Completed poll · HTTP 200
{
"data": {
"job_id": "8a93f4a0-2222-4a10-8c93-bca31ae9d48b",
"status": "completed",
"result": {
"type": "food_detected",
"items": [
{
"item_id": 1,
"canonical_name": "greek yogurt",
"brand": null,
"attributes": [],
"quantity_g": 200,
"status": "matched"
}
],
"molecular_analysis": [
{
"compound_identifier_id": 12057,
"compound_identifier_name": "protein",
"compound_identifier_value": "CHEBI_36080",
"measurement_value": 20000,
"measurement_value_min": 20000,
"measurement_value_max": 20000,
"measurement_value_type": "quantified",
"measurement_value_min_type": "quantified",
"measurement_value_max_type": "quantified",
"measurement_unit": "mg",
"provenance": "source",
"incomplete": false,
"references": [
{
"id": 42,
"citation": "Example food composition source"
}
],
"references_min": [
{
"id": 42,
"citation": "Example food composition source"
}
],
"references_max": [
{
"id": 42,
"citation": "Example food composition source"
}
]
}
]
},
"error": null
},
"meta": {
"request_id": "req_...",
"api_version": "2026-07-10"
}
}If only the state is needed, poll with include_result=false or result=none. Polling does not create another job.
Poll with cURL
Save the returned status_url as STATUS_URL. Use the same API key and version header.
curl "$STATUS_URL" \
-H "x-api-key: $MYMOLECULES_API_KEY" \
-H "mymolecules-api-version: 2026-07-10"- Add include_result=false or result=none to the polling URL when you only need job status; result is then null. Retrieve the complete result from the same URL without that option after completion.
- Complete molecular results can be large. Read the entire HTTP body before treating its JSON as complete, and allow sufficient download time. A connection that ends during the response is an incomplete retrieval: retry GET for the same job. Standard JSON clients remain compatible; no event-stream or line-by-line JSON parser is required.
- Clients that accept gzip can negotiate response compression with Accept-Encoding. Input image limits describe the request; they do not describe the size of the resulting molecular analysis.
- Wait a few seconds between polls and set your own maximum waiting time. queued and processing are not final states; data.error stays null while the job is running.
- If you reach your waiting limit, save job_id and check the same job later rather than submitting it again. No fixed processing time is guaranteed.
- Save results you need in your own system. Completed or failed jobs created more than 30 days ago are currently removed; this is not a guaranteed retention period.
Job response fields
| Field | Type | Description |
|---|---|---|
data.job_id | string | Job identifier in UUID format. Returned when submitting and polling; use it to identify this job. |
data.status | string | Job state: queued, processing, completed or failed. Stop polling at completed or failed. A found job returns HTTP 200 even when its status is failed. |
data.status_url | string | POST response only. URL for polling the job, included in the initial HTTP 202 response. |
data.result | object | null | GET response only. Result for a completed job, or null when unavailable or suppressed with result=none or include_result=false. |
data.error | object | null | GET response only. Failure details only when status is failed; null for queued, processing and completed jobs. Separate from the error envelope of a failed HTTP request. |
meta.request_id | string | Log this identifier when investigating a request. |
meta.api_version | string | Response contract version. Included when a supported mymolecules-api-version header is sent. |
Result fields
Fields inside data.result.
| Field | Type | Description |
|---|---|---|
type | string | food_detected contains normalized foods and meal-wide compound totals. no_food_detected means the job completed successfully without detecting food: items is empty and data.error is null. |
items | object[] | Normalized foods. Empty for no_food_detected. |
items[].item_id | integer | One-based position within this request, not a persistent food ID. |
items[].canonical_name | string | Food name identified in unstructured mode, using the selected or inferred language, or supplied in structured mode. |
items[].brand | string | null | Identified or supplied brand, or null when unknown. |
items[].attributes | string[] | Identified or supplied food descriptors. Empty when none are available. |
items[].quantity_g | number | Normalized quantity in grams. |
items[].status | string | matched when Decode matched the food to its database; unresolved otherwise. A match does not guarantee data for every requested compound. |
molecular_analysis | object[] | Present for food_detected. One row per compound for the whole meal, not one row per food item. A missing compound row does not mean its actual amount is zero. |
Compound measurement fields
Fields inside each entry of data.result.molecular_analysis.
| Field | Type | Description |
|---|---|---|
compound_identifier_id | integer | Identifier of the compound in the catalog. |
compound_identifier_name | string | The required human-readable name of the compound in the catalog. |
compound_identifier_value | string | External identifier value, such as a ChEBI identifier. Omitted when include_compound_identifier_value is false. |
measurement_value | number | null | Whole-meal quantity when a numeric value exists. Read together with measurement_value_type and measurement_unit. Do not treat trace, unquantified or a null numeric value as zero. |
measurement_value_min | number | null | Lower evidence bound or one-sided limit, not a confidence interval. Null when unavailable or the total is incomplete. Omitted when include_measurement_min_max is false. |
measurement_value_max | number | null | Upper evidence bound or one-sided limit, not a confidence interval. Null when unavailable or the total is incomplete. Omitted when include_measurement_min_max is false. |
measurement_value_type | string | null | quantified: a measured amount; calculated: a derived or combined amount; less_than or greater_than: below or above the given limit, not an exact amount; trace: detected in trace amounts; unquantified: present without a numeric amount. Null when no value type is available. |
measurement_value_min_type | string | null | How to interpret measurement_value_min, using the same types as measurement_value_type. Null when no lower bound is available. Omitted when include_measurement_min_max is false. |
measurement_value_max_type | string | null | How to interpret measurement_value_max, using the same types as measurement_value_type. Null when no upper bound is available. Omitted when include_measurement_min_max is false. |
measurement_unit | string | Unit for all measurement values; typically mg for mass compounds or kcal for energy. n.u. means there is no quantitative unit for trace or unquantified evidence. |
provenance | string | interpolation if any included evidence was interpolated; otherwise source. |
incomplete | boolean | True when the numeric total does not cover the whole meal: some food contributions are missing, unresolved or supported only by trace or unquantified evidence. The displayed number covers the quantifiable contributions only; missing contributions are not proof of actual zero. |
references | object[] | Evidence citations for measurement_value. Each entry contains id and citation. |
references_min | object[] | Evidence citations for measurement_value_min. Each entry contains id and citation. Omitted when include_measurement_min_max is false. |
references_max | object[] | Evidence citations for measurement_value_max. Each entry contains id and citation. Omitted when include_measurement_min_max is false. |
Handle errors
If a request fails, check error.code. Polling a found failed job still returns HTTP 200: check data.status and read data.error when it is failed.
Media size errors may also appear as job errors after a download.
Request errors
| Code | HTTP status | Description |
|---|---|---|
missing_api_key | 401 | Add your API key in the x-api-key header. |
invalid_api_key | 401 | The key is not valid. Check the value and whether the key is still active. |
scope_not_allowed | 403 | The key does not have access to Decode. Use a key with Decode access. |
decode_input_mode_not_allowed | 403 | The key does not permit this input mode. Use an allowed mode or request the corresponding permission. |
unsupported_api_version | 400 | The version header is not supported. Use a version listed in the version selector. |
method_not_allowed | 405 | Use POST to submit a job and GET to check its status. |
invalid_json | 400 | The request body is not valid JSON. Check its syntax before sending it again. |
idempotency_conflict | 409 | This Idempotency-Key was already used for a different request, or its job is no longer available. Retry an available original request unchanged, or use a new key for a new job. |
invalid_request | 400 | Check the request fields, their types and the selected input mode. This also covers missing fields, unsupported fields, conflicting modes and malformed compound filters. When supplied, details.field identifies the field to fix. |
unsupported_input_field | 400 | Remove foodImageRemaining and attachments. Send all meal and leftover photos together in foodImage. |
invalid_food_image | 400 | Use one non-empty image URL or data URL, or a list of one to three such strings. Empty lists, empty entries and other value types are rejected. |
validation_error | 422 | The input could not be validated. Read the error message, correct the input and submit it again. |
invalid_compound_identifier | 422 | A compound name or ID does not exist. Check the identifiers in your filters. |
compound_not_allowed_for_decode_scope | 403 | A requested compound is outside your result tier. Remove it or use a key with the required tier. |
structured_items_limit_exceeded | 400 | Send no more than 25 items in one structured request. |
food_name_too_long | 400 | Keep each structured food name within 160 characters. |
food_attributes_limit_exceeded | 400 | Send no more than 10 attributes per structured item. |
food_attribute_too_long | 400 | Keep each structured food attribute within 80 characters. |
invalid_food_quantity | 400 | Use a finite quantity greater than zero for each structured item. |
food_quantity_exceeded | 400 | Keep each structured item within 100,000 g after conversion to grams. |
food_text_too_long | 400 | Keep foodText within 1,500 characters. |
image_inputs_limit_exceeded | 400 | Send no more than three images in foodImage. |
audio_inputs_limit_exceeded | 400 | Send only one audio input in foodVoice. |
image_too_large | 413 | Reduce each image to 10 MiB or less. For media URLs, this can appear as a job error after the image is downloaded. |
audio_too_large | 413 | Reduce each audio file to 15 MiB or less. For media URLs, this can appear as a job error after the audio is downloaded. |
inline_media_total_exceeded | 400 | Keep the combined decoded size of inline media within 30 MiB. |
input_too_large | 413 | Reduce the complete request body to 45 MiB or less. |
job_not_found | 404 | Check job_id and use the same API key that submitted the job. Jobs belonging to another key, removed by cleanup or no longer accessible after a permission change are also returned as not found. |
rate_limited | 429 | You are sending requests too quickly. Wait before retrying, increase the delay between retries and follow Retry-After when supplied. |
backlog_high | 429 | Decode is temporarily at capacity. Wait before submitting again and follow Retry-After when supplied. |
quota_exceeded | 429 | Your monthly quota is exhausted. Wait for the quota to reset or arrange more capacity; repeated retries will not help. |
decode_scope_not_configured | 503 | Your result tier is not configured correctly. Contact support; changing the request will not fix it. |
service_unavailable | 503 | The service is temporarily unavailable. Follow the retry guidance below and Retry-After when supplied. |
upstream_error | 502 | The request could not be completed. Follow the retry guidance below; contact support if it persists. |
upstream_timeout | 504 | The request timed out. Follow the retry guidance below. |
WORKER_RESOURCE_LIMIT | 546 | HTTP 546 is returned by the hosting platform when the function exceeds its memory or CPU budget. It may not use the standard JSON error envelope. A failed GET does not mean the analysis job failed: check the same job with include_result=false, then retry its result with increasing delays. If it persists, contact support with the job ID, request ID and time; do not resubmit the analysis blindly. |
internal_error | 500 | An unexpected error occurred. Follow the retry guidance below. If it persists, contact support with the request ID. |
Job errors
| Code | HTTP status | Description |
|---|---|---|
image_too_large | 200 (failed job) | Reduce each image to 10 MiB or less. For media URLs, this can appear as a job error after the image is downloaded. |
audio_too_large | 200 (failed job) | Reduce each audio file to 15 MiB or less. For media URLs, this can appear as a job error after the audio is downloaded. |
media_total_exceeded | 200 (failed job) | Downloaded and inline media together exceed 30 MiB. Reduce their combined size and submit a new job. |
audio_duration_exceeded | 200 (failed job) | Audio exceeds five minutes. Shorten it and submit a new job. |
audio_duration_unavailable | 200 (failed job) | The audio duration cannot be read. Re-export the recording in a supported format and submit a new job. |
structure_failed | 200 (failed job) | The meal input could not be processed. Check the error message and media, then submit a new job. If the cause is temporary, wait before resubmitting. |
structure_invalid | 200 (failed job) | Meal recognition returned an unexpected result. Try a new job after a delay; contact support if it persists. |
structured_failed | 200 (failed job) | The structured foods could not be processed. Check the error message before submitting a new job. |
timeout | 200 (failed job) | Processing timed out. Submit a new job after a delay. |
foodImage_download_failed | 200 (failed job) | One supplied image could not be downloaded. Check the image identified by details.field and ensure its URL is accessible and has not expired. The whole job fails even if other input is valid. |
foodVoice_download_failed | 200 (failed job) | The audio could not be downloaded. Check that its URL is accessible and has not expired. |
job_failed | 200 (failed job) | The job failed without a more specific code. Read data.error.message and contact support with the job ID if needed. |
Retry safely
- GET: retry polling after a network error or temporary server failure, with increasing delays. Follow Retry-After when supplied.
- POST: send an optional Idempotency-Key to avoid duplicate jobs if the response is lost. Generate a unique key for each new request, save it with the request and reuse it only with the same API key, body and version when retrying. Use 1–128 printable ASCII characters without spaces.
- Repeating that request returns HTTP 202 with the existing job_id and status_url; it does not restart the job. Poll for its current status. Reusing the key for a different request returns HTTP 409 (idempotency_conflict). Use a new key when you intentionally create a new job, including after a failed job. If the original job has been removed, the old key returns HTTP 409 rather than creating another job.
- Without Idempotency-Key, another POST can create another job. x-request-id does not prevent duplicates. Do not retry blindly when it is unclear whether your request was accepted.
- Only status failed is a final job failure. Check data.error before deciding whether to correct the input and submit a new job.
See the Errors & rate limits guide for the shared error envelope.
Code examples
curl -X POST 'https://api.mymolecules.de/functions/v1/decode' \
-H "x-api-key: $MYMOLECULES_API_KEY" \
-H 'mymolecules-api-version: 2026-07-10' \
-H 'Content-Type: application/json' \
--data '{
"input_mode": "unstructured",
"foodText": "200 g Greek yogurt",
"compound_identifier_ids": [12057]
}'Use the examples on your server and set MYMOLECULES_API_KEY in its environment. Python requires the requests package (pip install requests). Set network timeouts in your application.
For generated types and every response schema, use the OpenAPI specification.



