# openfood for agents

openfood (openfood.fun) is the AI-first food photo calorie and macro tracker of Open Group: snap a meal, check it, log it. The Agentic Era Has Arrived.

## Actions

| Action | Access | REST |
|---|---|---|
| `health` | public, no sign-in | `GET /api/health` |
| `revision` | public, no sign-in | `GET /api/revision` |
| `preview_agent_task` | scopes `diary:write` | `POST /api/v1/agent-tasks` |
| `confirm_agent_task` | scopes `diary:write` | `POST /api/v1/agent-tasks/:id/confirm` |
| `cancel_agent_task` | scopes `diary:write` | `POST /api/v1/agent-tasks/:id/cancel` |
| `get_agent_task` | scopes `diary:read` | `GET /api/v1/agent-tasks/:id` |
| `list_agent_tasks` | scopes `diary:read` | `GET /api/v1/agent-tasks` |
| `get_billing_status` | scopes `profile:read` | `GET /api/v1/billing` |
| `analyze_photo` | scopes `scans:write` | `POST /api/v1/scans` |
| `get_scan` | scopes `scans:write` | `GET /api/v1/scans/:id` |
| `log_scan` | scopes `scans:write`, `diary:write` | `POST /api/v1/scans/:id/log` |
| `quick_add_calories` | scopes `diary:write` | `POST /api/v1/capture/calories` |
| `save_label_food` | scopes `diary:write` | `POST /api/v1/foods` |
| `community_feed` | scopes `diary:read` | `GET /api/v1/community/feed` |
| `list_community_cooks` | scopes `diary:read` | `GET /api/v1/community/cooks` |
| `get_community_cook` | scopes `diary:read` | `GET /api/v1/community/cook` |
| `get_community_post` | scopes `diary:read` | `GET /api/v1/community/post` |
| `follow_community_cook` | scopes `diary:write` | `POST /api/v1/community/follow` |
| `comment_on_community_post` | scopes `diary:write` | `POST /api/v1/community/comments` |
| `list_community_chats` | scopes `diary:read` | `GET /api/v1/community/chats` |
| `get_community_chat` | scopes `diary:read` | `GET /api/v1/community/chat` |
| `send_community_message` | scopes `diary:write` | `POST /api/v1/community/chat` |
| `save_community_recipe` | scopes `diary:write` | `POST /api/v1/community/save-recipe` |
| `log_water` | scopes `diary:write` | `POST /api/v1/water` |
| `get_day` | scopes `diary:read` | `GET /api/v1/days/:date` |
| `search_foods` | public, no sign-in | `GET /api/v1/foods/search` |
| `get_food` | public, no sign-in | `GET /api/v1/foods/:id` |
| `lookup_barcode` | public, no sign-in | `GET /api/v1/foods/barcode/:code` |
| `get_targets` | scopes `diary:read`, `profile:read` | `GET /api/v1/goals` |
| `set_targets` | scopes `diary:write`, `profile:read` | `PUT /api/v1/goals` |
| `set_daily_macros` | scopes `diary:write`, `profile:read` | `PUT /api/v1/goals/day` |
| `get_weights` | scopes `diary:read` | `GET /api/v1/weights` |
| `log_weight` | scopes `diary:write` | `POST /api/v1/weights` |
| `get_checkin` | scopes `diary:read`, `profile:read` | `GET /api/v1/checkins` |
| `confirm_intake_day` | scopes `diary:write` | `PUT /api/v1/checkins/day` |
| `run_checkin` | scopes `diary:write`, `profile:read` | `POST /api/v1/checkins` |
| `decide_checkin` | scopes `diary:write`, `profile:read` | `POST /api/v1/checkins/decision` |
| `get_weekly_insight` | scopes `diary:read` | `GET /api/v1/insights/week` |
| `request_weekly_insight` | scopes `diary:write`, `diary:read` | `POST /api/v1/insights/week` |
| `get_week_review` | scopes `diary:read` | `GET /api/v1/insights/week-review` |
| `preview_recipe_import` | scopes `diary:write` | `POST /api/v1/library/recipes/import` |
| `search_library` | scopes `diary:read` | `GET /api/v1/library/search` |
| `save_meal_template` | scopes `diary:write` | `POST /api/v1/library/meals` |
| `plan_dinner` | scopes `diary:read` | `GET /api/v1/plan/dinner` |
| `shopping_list` | scopes `diary:read` | `GET /api/v1/plan/shopping-list` |
| `get_meal_plan` | scopes `diary:read` | `GET /api/v1/plan/week` |
| `suggest_meal_plan` | scopes `diary:read` | `GET /api/v1/plan/week/suggestions` |
| `fill_meal_plan` | scopes `diary:write` | `POST /api/v1/plan/week/fill` |
| `set_meal_plan_entry` | scopes `diary:write` | `PUT /api/v1/plan/week/entry` |
| `clear_meal_plan_entry` | scopes `diary:write` | `POST /api/v1/plan/week/clear` |
| `meal_plan_shopping_list` | scopes `diary:read` | `GET /api/v1/plan/week/shopping-list` |
| `get_plan_preferences` | scopes `diary:read` | `GET /api/v1/plan/preferences` |
| `set_plan_preferences` | scopes `diary:write` | `PUT /api/v1/plan/preferences` |
| `log_meal` | scopes `diary:write` | `POST /api/v1/meals` |
| `get_pantry` | scopes `diary:read` | `GET /api/v1/pantry` |
| `add_pantry_items` | scopes `diary:write` | `POST /api/v1/pantry/items` |
| `update_pantry_item` | scopes `diary:write` | `PUT /api/v1/pantry/item` |
| `remove_pantry_item` | scopes `diary:write` | `POST /api/v1/pantry/item/remove` |
| `pantry_use_up` | scopes `diary:read` | `GET /api/v1/pantry/use-up` |
| `preview_receipt_import` | scopes `diary:write` | `POST /api/v1/pantry/receipt/preview` |
| `estimate_text_meal` | scopes `scans:write` | `POST /api/v1/quick-log/estimate` |

## Connect

1. Public reads (`search_foods`, `get_food`, `lookup_barcode`, `health`, `revision`) need no key.
2. For a person's diary, ask them to open https://app.openfood.fun/me/agents, create a key with only the scopes you need (`diary:read`, `diary:write`, `scans:write`, `profile:read`) and give it to you. It is shown once.
3. Send `Authorization: Bearer ofk_…` on REST calls, or on `POST https://openfood.fun/mcp` (JSON-RPC 2.0: `initialize`, `tools/list`, `tools/call`).
4. The key acts only for that person and only for the actions below. Key management, health-data consent, sign-in, export and deletion stay with the person. Revoked or expired keys get 401 at once.
5. Every call is recorded with its result and shown to the person in Me → Agents.

## Rules

- Errors always use one envelope: `{"error":{"code","message"}}`. Codes below.
- Writes need an `Idempotency-Key` header (8-128 characters); over MCP pass the optional `idempotency_key` argument. Same key + same body returns the stored response; same key + another body returns 409 `idempotency_conflict`.
- When AI is not connected the app says so (`not_configured`, `ai_paused`); it never invents an analysis.
- openfood estimates nutrition and is not medical advice.
- Contact: hi@openfood.fun

## Error codes

| code | HTTP |
|---|---|
| `validation_failed` | 422 |
| `bad_request` | 400 |
| `subscription_required` | 402 |
| `unauthenticated` | 401 |
| `forbidden` | 403 |
| `insufficient_scope` | 403 |
| `csrf_failed` | 403 |
| `not_found` | 404 |
| `method_not_allowed` | 405 |
| `idempotency_key_required` | 400 |
| `idempotency_conflict` | 409 |
| `idempotency_in_progress` | 409 |
| `conflict` | 409 |
| `account_required` | 409 |
| `payload_too_large` | 413 |
| `payload_rejected` | 422 |
| `rate_limited` | 429 |
| `quota_exceeded` | 429 |
| `provider_not_connected` | 503 |
| `ai_paused` | 503 |
| `unavailable` | 503 |
| `billing_unavailable` | 503 |
| `webhook_not_configured` | 503 |
| `internal` | 500 |

## Discovery

- https://openfood.fun/llms.txt · https://openfood.fun/llms-full.txt · https://openfood.fun/openapi.json · https://openfood.fun/api/docs · https://openfood.fun/mcp · https://openfood.fun/mcp-tools.json
