---
title: "Run resolve_custom_item_to_food pipeline (internal testing)"
method: POST
path: "/internal/grounding/resolve_custom_item"
tags: ["internal"]
---

# Run resolve_custom_item_to_food pipeline (internal testing)

`POST /internal/grounding/resolve_custom_item`

Requires elevated permissions. Exercises search grounding + Food Engine + reconcile LLM, with optional persist and apply_to_meal. Provide either meal_photo_queue_id (full QueueLabelContext) or patient_id. Use imdr_row_index with meal_photo_queue_id to load a real MPQ_IM_LBL_MATCH_V2 row; otherwise send synthetic food/brand/grounding_mode fields.

## Request body

- GroundingTestResolveCustomItemRequest
  - `apply_to_meal` boolean — When true, apply reconciled UPN to meal_item or meal_item_custom_addon.
  - `brand` string, nullable
  - `composite_food_id` string, nullable
  - `food` string, nullable — Required for synthetic mode (when imdr_row_index is omitted).
  - `grounding_mode` 'cpg' | 'restaurant' | 'whole_food', nullable — Required for synthetic mode (when imdr_row_index is omitted).
  - `imdr_row_index` integer, nullable — 0-based index into MPQ_IM_LBL_MATCH_V2 result; requires meal_photo_queue_id.
  - `is_composite_food` boolean
  - `meal_item_custom_addon_id` integer, nullable — Optional custom addon row override when apply_to_meal is true.
  - `meal_item_id` integer, nullable — Optional meal row override when apply_to_meal is true.
  - `meal_photo_queue_id` integer, nullable — When set, builds QueueLabelContext from this MPQ. Required when imdr_row_index is set.
  - `patient_id` integer, nullable — Required when meal_photo_queue_id is omitted; patient used for OpenAI context.
  - `persist` boolean — When true, persist v3 grounding_request + outcome.
  - `preparation_method` string, nullable — Stored on the synthetic raw (e.g. cpg, restaurant); defaults to grounding_mode.

## Response `200`

successful operation (resolved false if no usable UPN)

- GroundingTestResolveCustomItemResponse
  - `applied` boolean, required
  - `dedup_skipped_sg` boolean, required
  - `food_engine_candidates` object[], nullable
  - `food_engine_ran` boolean, required
  - `food_engine_selected` object, nullable
  - `food_engine_sources` string, nullable
  - `grounding_mode` 'cpg' | 'restaurant' | 'whole_food', required
  - `grounding_request_id` integer, nullable
  - `grounding_request_outcome_id` integer, nullable
  - `input_summary` object, nullable
  - `meal_item_custom_addon_id` integer, nullable
  - `meal_item_id` integer, nullable
  - `message` string, nullable
  - `reconciliation` object, nullable
  - `resolved` boolean, required
  - `search_grounding_result` object, nullable
  - `user_provided_nutrition` object, nullable
  - `winner` 'search_grounding' | 'food_engine' | 'combined', nullable

## Other responses

- `400` — invalid request
- `403` — not authorized
- `404` — patient, meal photo queue, or IMDR not found

---

[API](https://skmtc.dev/rxfoodapp/apis/inneranalytics-mnt-server.md) · [All operations](https://skmtc.dev/rxfoodapp/apis/inneranalytics-mnt-server/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/rxfoodapp/inneranalytics-mnt-server/revisions/0703cbbbefe8/schema)
