{
  "openapi": "3.0.3",
  "info": {
    "title": "Nibb API",
    "version": "0.1.0",
    "description": "One personal journal shared by iOS, web, Siri, notifications and MCP. Single-owner deployment. Capture prose immediately; estimates are asynchronous with provenance and uncertainty. Remote MCP is POST /mcp with OAuth 2.1 or a personal bearer token."
  },
  "servers": [
    {
      "url": "http://localhost:4318",
      "description": "Local development; replace with hosted HTTPS URL"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/chat/messages": {
      "get": {
        "operationId": "get_v1_chat_messages",
        "summary": "Read meal entries, oldest first within the requested page",
        "tags": [
          "chat"
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 40
            }
          },
          {
            "name": "before",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "post": {
        "operationId": "post_v1_chat_messages",
        "summary": "Queue a message for the configured OpenRouter MCP client",
        "tags": [
          "chat"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "message": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 6000
                  },
                  "replyTo": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "purpose": {
                    "type": "string",
                    "enum": [
                      "saved_meal"
                    ]
                  },
                  "photo": {
                    "type": "object",
                    "properties": {
                      "mime": {
                        "type": "string",
                        "enum": [
                          "image/jpeg",
                          "image/png",
                          "image/webp"
                        ]
                      },
                      "base64": {
                        "type": "string",
                        "minLength": 8,
                        "maxLength": 1100000
                      }
                    },
                    "required": [
                      "mime",
                      "base64"
                    ],
                    "additionalProperties": false
                  },
                  "photos": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "mime": {
                          "type": "string",
                          "enum": [
                            "image/jpeg",
                            "image/png",
                            "image/webp"
                          ]
                        },
                        "base64": {
                          "type": "string",
                          "minLength": 8,
                          "maxLength": 1100000
                        }
                      },
                      "required": [
                        "mime",
                        "base64"
                      ],
                      "additionalProperties": false
                    },
                    "minItems": 1,
                    "maxItems": 5
                  },
                  "sentAt": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "targetMeal": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "expectedRevision": {
                        "type": "integer",
                        "exclusiveMinimum": true,
                        "minimum": 0
                      }
                    },
                    "required": [
                      "id",
                      "expectedRevision"
                    ],
                    "additionalProperties": false
                  }
                },
                "required": [
                  "message"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "Unique key for a logical capture. Reuse on retry; different input conflicts.",
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          }
        ],
        "responses": {
          "202": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/chat/messages/{id}": {
      "get": {
        "operationId": "get_v1_chat_messages__id_",
        "summary": "Read a message, reply, status and completed actions",
        "tags": [
          "chat"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "patch": {
        "operationId": "patch_v1_chat_messages__id_",
        "summary": "Dismiss or restore a finished entry notice; preserves logged meals",
        "tags": [
          "chat"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "dismissed": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "dismissed"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/chat/messages/{id}/photo": {
      "get": {
        "operationId": "get_v1_chat_messages__id__photo",
        "summary": "Read one original meal photo (authenticated, zero-based index)",
        "tags": [
          "chat"
        ],
        "parameters": [
          {
            "name": "index",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 4,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Original meal photo",
            "content": {
              "image/jpeg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/png": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/webp": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "Photo not found"
          }
        }
      }
    },
    "/v1/health/export": {
      "get": {
        "operationId": "get_v1_health_export",
        "summary": "Read meals and weight for Health sync; excludes demo data",
        "tags": [
          "health"
        ],
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "timezone": {
                      "type": "string"
                    },
                    "meals": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Meal"
                      }
                    },
                    "weights": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Weight"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "post": {
        "operationId": "post_v1_health_export",
        "summary": "Read a complete snapshot, including previously synced IDs outside the date range",
        "tags": [
          "health"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "from": {
                    "type": "string",
                    "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                  },
                  "to": {
                    "type": "string",
                    "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                  },
                  "mealIds": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "maxItems": 20000,
                    "default": []
                  },
                  "weightIds": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "maxItems": 20000,
                    "default": []
                  }
                },
                "required": [
                  "from",
                  "to"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "timezone": {
                      "type": "string"
                    },
                    "meals": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Meal"
                      }
                    },
                    "weights": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Weight"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/health/weights": {
      "post": {
        "operationId": "post_v1_health_weights",
        "summary": "Import Health weight additions and deletions; manual Nibb measurements take priority",
        "tags": [
          "health"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "samples": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "date": {
                          "type": "string",
                          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                        },
                        "kg": {
                          "type": "number",
                          "minimum": 10,
                          "maximum": 600
                        },
                        "measuredAt": {
                          "type": "string",
                          "format": "date-time"
                        }
                      },
                      "required": [
                        "id",
                        "date",
                        "kg",
                        "measuredAt"
                      ],
                      "additionalProperties": false
                    },
                    "maxItems": 500
                  },
                  "deletedIds": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "maxItems": 500
                  }
                },
                "required": [
                  "samples",
                  "deletedIds"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/health/activity": {
      "get": {
        "operationId": "get_v1_health_activity",
        "summary": "Read imported Health activity; unavailable readings are null",
        "tags": [
          "health"
        ],
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "source": {
                      "type": "string"
                    },
                    "days": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "date": {
                            "type": "string",
                            "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                          },
                          "steps": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 300000,
                            "nullable": true
                          },
                          "activeCalories": {
                            "type": "number",
                            "minimum": 0,
                            "maximum": 30000,
                            "nullable": true
                          },
                          "exerciseMinutes": {
                            "type": "number",
                            "minimum": 0,
                            "maximum": 1440,
                            "nullable": true
                          },
                          "workouts": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "id": {
                                  "type": "string",
                                  "format": "uuid"
                                },
                                "name": {
                                  "type": "string",
                                  "minLength": 1,
                                  "maxLength": 80
                                },
                                "start": {
                                  "type": "string",
                                  "format": "date-time"
                                },
                                "minutes": {
                                  "type": "number",
                                  "minimum": 0,
                                  "maximum": 1440
                                }
                              },
                              "required": [
                                "id",
                                "name",
                                "start",
                                "minutes"
                              ],
                              "additionalProperties": false
                            },
                            "maxItems": 100
                          },
                          "timezone": {
                            "type": "string"
                          },
                          "observedAt": {
                            "type": "string",
                            "format": "date-time"
                          }
                        },
                        "required": [
                          "date",
                          "steps",
                          "activeCalories",
                          "exerciseMinutes",
                          "workouts",
                          "timezone",
                          "observedAt"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "notes": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "post": {
        "operationId": "post_v1_health_activity",
        "summary": "Replace daily Health totals; repeat imports do not add calories or steps",
        "tags": [
          "health"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "timezone": {
                    "type": "string"
                  },
                  "observedAt": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "days": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "date": {
                          "type": "string",
                          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                        },
                        "steps": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 300000,
                          "nullable": true
                        },
                        "activeCalories": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 30000,
                          "nullable": true
                        },
                        "exerciseMinutes": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 1440,
                          "nullable": true
                        },
                        "workouts": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "string",
                                "format": "uuid"
                              },
                              "name": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 80
                              },
                              "start": {
                                "type": "string",
                                "format": "date-time"
                              },
                              "minutes": {
                                "type": "number",
                                "minimum": 0,
                                "maximum": 1440
                              }
                            },
                            "required": [
                              "id",
                              "name",
                              "start",
                              "minutes"
                            ],
                            "additionalProperties": false
                          },
                          "maxItems": 100
                        }
                      },
                      "required": [
                        "date",
                        "steps",
                        "activeCalories",
                        "exerciseMinutes",
                        "workouts"
                      ],
                      "additionalProperties": false
                    },
                    "maxItems": 31
                  }
                },
                "required": [
                  "timezone",
                  "observedAt",
                  "days"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/settings": {
      "get": {
        "operationId": "get_v1_settings",
        "summary": "Read goals and timezone",
        "tags": [
          "settings"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Settings"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "put": {
        "operationId": "put_v1_settings",
        "summary": "Replace preferences",
        "tags": [
          "settings"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Settings"
              }
            }
          }
        },
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Settings"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "patch": {
        "operationId": "patch_v1_settings",
        "summary": "Change requested settings with revision checking and history",
        "tags": [
          "settings"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "change": {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 80
                      },
                      "calorieGoal": {
                        "type": "integer",
                        "minimum": 500,
                        "maximum": 10000
                      },
                      "proteinGoal": {
                        "type": "number",
                        "minimum": 0,
                        "maximum": 1000
                      },
                      "carbsGoal": {
                        "type": "number",
                        "minimum": 0,
                        "maximum": 2000
                      },
                      "fatGoal": {
                        "type": "number",
                        "minimum": 0,
                        "maximum": 1000
                      },
                      "timezone": {
                        "type": "string"
                      },
                      "weightUnit": {
                        "type": "string",
                        "enum": [
                          "kg",
                          "lb"
                        ]
                      },
                      "onboardingCompleted": {
                        "type": "boolean"
                      },
                      "onboardingSkipped": {
                        "type": "boolean"
                      }
                    },
                    "additionalProperties": false
                  },
                  "expectedRevision": {
                    "type": "integer",
                    "exclusiveMinimum": true,
                    "minimum": 0
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1000
                  }
                },
                "required": [
                  "change",
                  "expectedRevision"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/sync": {
      "get": {
        "operationId": "get_v1_sync",
        "summary": "Read a compact journal/preferences change token",
        "tags": [
          "sync"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/settings/state": {
      "get": {
        "operationId": "get_v1_settings_state",
        "summary": "Read preferences with their current revision",
        "tags": [
          "settings"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/settings/history": {
      "get": {
        "operationId": "get_v1_settings_history",
        "summary": "Read past goals/preferences and applied recommendation evidence",
        "tags": [
          "settings"
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "beforeRevision",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/nutrition/research": {
      "get": {
        "operationId": "get_v1_nutrition_research",
        "summary": "Read public evidence, method version and limitations",
        "tags": [
          "nutrition"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/nutrition/recommendation": {
      "post": {
        "operationId": "post_v1_nutrition_recommendation",
        "summary": "Preview a starting nutrition plan without changing settings",
        "tags": [
          "nutrition"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "weightUnit": {
                    "type": "string",
                    "enum": [
                      "kg",
                      "lb"
                    ]
                  },
                  "gender": {
                    "type": "string",
                    "maxLength": 80,
                    "description": "Optional self-described gender; never substitutes for the equation coefficient."
                  },
                  "aspirations": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "age": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 120
                  },
                  "weightKg": {
                    "type": "number",
                    "minimum": 25,
                    "maximum": 350
                  },
                  "heightCm": {
                    "type": "number",
                    "minimum": 120,
                    "maximum": 230
                  },
                  "equationSex": {
                    "type": "string",
                    "enum": [
                      "male",
                      "female"
                    ],
                    "description": "Coefficient from the original resting-energy equation; ask, never infer from name. May be omitted with established maintenance calories."
                  },
                  "activityFactor": {
                    "type": "number",
                    "minimum": 1.2,
                    "maximum": 2.5,
                    "description": "Whole-day activity multiplier including exercise. NIDDK typical range 1.4 sedentary to 2.5 very active; this remains an estimate."
                  },
                  "knownMaintenanceKcal": {
                    "type": "number",
                    "minimum": 1200,
                    "maximum": 6000
                  },
                  "maintenanceEvidence": {
                    "type": "string",
                    "minLength": 5,
                    "maxLength": 1000,
                    "description": "How maintenance was established. Never infer it from partially logged intake."
                  },
                  "goal": {
                    "type": "string",
                    "enum": [
                      "maintain",
                      "lose_fat",
                      "gain_muscle"
                    ]
                  },
                  "training": {
                    "type": "string",
                    "enum": [
                      "none",
                      "endurance",
                      "resistance",
                      "mixed"
                    ]
                  },
                  "pregnantOrBreastfeeding": {
                    "type": "boolean"
                  },
                  "requiresClinicalDiet": {
                    "type": "boolean",
                    "description": "A condition or medication requiring individualized nutrition, e.g. kidney disease or glucose-lowering treatment."
                  },
                  "eatingDisorderHistory": {
                    "type": "boolean"
                  },
                  "pace": {
                    "type": "string",
                    "enum": [
                      "gentle",
                      "moderate"
                    ],
                    "default": "gentle"
                  },
                  "dietPreference": {
                    "type": "string",
                    "enum": [
                      "flexible",
                      "mediterranean",
                      "vegetarian",
                      "vegan"
                    ],
                    "default": "flexible"
                  },
                  "macroPreference": {
                    "type": "string",
                    "enum": [
                      "balanced",
                      "more_carbs",
                      "more_fat"
                    ],
                    "default": "balanced"
                  },
                  "proteinGPerKg": {
                    "type": "number",
                    "minimum": 1,
                    "maximum": 2
                  },
                  "targetWeightKg": {
                    "type": "number",
                    "minimum": 25,
                    "maximum": 350
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/nutrition/apply": {
      "post": {
        "operationId": "post_v1_nutrition_apply",
        "summary": "Apply a reviewed recommendation with revision checks and safe retries",
        "tags": [
          "nutrition"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "profile": {
                    "type": "object",
                    "properties": {
                      "weightUnit": {
                        "type": "string",
                        "enum": [
                          "kg",
                          "lb"
                        ]
                      },
                      "gender": {
                        "type": "string",
                        "maxLength": 80,
                        "description": "Optional self-described gender; never substitutes for the equation coefficient."
                      },
                      "aspirations": {
                        "type": "string",
                        "maxLength": 1000
                      },
                      "age": {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 120
                      },
                      "weightKg": {
                        "type": "number",
                        "minimum": 25,
                        "maximum": 350
                      },
                      "heightCm": {
                        "type": "number",
                        "minimum": 120,
                        "maximum": 230
                      },
                      "equationSex": {
                        "type": "string",
                        "enum": [
                          "male",
                          "female"
                        ],
                        "description": "Coefficient from the original resting-energy equation; ask, never infer from name. May be omitted with established maintenance calories."
                      },
                      "activityFactor": {
                        "type": "number",
                        "minimum": 1.2,
                        "maximum": 2.5,
                        "description": "Whole-day activity multiplier including exercise. NIDDK typical range 1.4 sedentary to 2.5 very active; this remains an estimate."
                      },
                      "knownMaintenanceKcal": {
                        "type": "number",
                        "minimum": 1200,
                        "maximum": 6000
                      },
                      "maintenanceEvidence": {
                        "type": "string",
                        "minLength": 5,
                        "maxLength": 1000,
                        "description": "How maintenance was established. Never infer it from partially logged intake."
                      },
                      "goal": {
                        "type": "string",
                        "enum": [
                          "maintain",
                          "lose_fat",
                          "gain_muscle"
                        ]
                      },
                      "training": {
                        "type": "string",
                        "enum": [
                          "none",
                          "endurance",
                          "resistance",
                          "mixed"
                        ]
                      },
                      "pregnantOrBreastfeeding": {
                        "type": "boolean"
                      },
                      "requiresClinicalDiet": {
                        "type": "boolean",
                        "description": "A condition or medication requiring individualized nutrition, e.g. kidney disease or glucose-lowering treatment."
                      },
                      "eatingDisorderHistory": {
                        "type": "boolean"
                      },
                      "pace": {
                        "type": "string",
                        "enum": [
                          "gentle",
                          "moderate"
                        ],
                        "default": "gentle"
                      },
                      "dietPreference": {
                        "type": "string",
                        "enum": [
                          "flexible",
                          "mediterranean",
                          "vegetarian",
                          "vegan"
                        ],
                        "default": "flexible"
                      },
                      "macroPreference": {
                        "type": "string",
                        "enum": [
                          "balanced",
                          "more_carbs",
                          "more_fat"
                        ],
                        "default": "balanced"
                      },
                      "proteinGPerKg": {
                        "type": "number",
                        "minimum": 1,
                        "maximum": 2
                      },
                      "targetWeightKg": {
                        "type": "number",
                        "minimum": 25,
                        "maximum": 350
                      }
                    },
                    "additionalProperties": false
                  },
                  "proposalId": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  },
                  "expectedRevision": {
                    "type": "integer",
                    "exclusiveMinimum": true,
                    "minimum": 0
                  },
                  "idempotencyKey": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  }
                },
                "required": [
                  "profile",
                  "proposalId",
                  "expectedRevision",
                  "idempotencyKey"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/progress-report": {
      "get": {
        "operationId": "get_v1_progress_report",
        "summary": "Daily nutrition, recorded weight trends and logging coverage",
        "tags": [
          "progress-report"
        ],
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "includeDemo",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/journal-context": {
      "get": {
        "operationId": "get_v1_journal_context",
        "summary": "Current local date, preferences and client capabilities",
        "tags": [
          "journal-context"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/mcp-guide": {
      "get": {
        "operationId": "get_v1_mcp_guide",
        "summary": "Client instructions for history, research, substitutions and logging",
        "tags": [
          "mcp-guide"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/meals/search": {
      "get": {
        "operationId": "get_v1_meals_search",
        "summary": "Search meal ingredients/history; excludes demo rows by default",
        "tags": [
          "meals"
        ],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 10
            }
          },
          {
            "name": "includeDemo",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/meal-variants/preview": {
      "post": {
        "operationId": "post_v1_meal_variants_preview",
        "summary": "Calculate substitutions without writing",
        "tags": [
          "meal-variants"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "base": {
                    "anyOf": [
                      {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "enum": [
                              "meal"
                            ]
                          },
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "expectedRevision": {
                            "type": "integer",
                            "exclusiveMinimum": true,
                            "minimum": 0
                          }
                        },
                        "required": [
                          "kind",
                          "id",
                          "expectedRevision"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "enum": [
                              "saved"
                            ]
                          },
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          }
                        },
                        "required": [
                          "kind",
                          "id"
                        ],
                        "additionalProperties": false
                      }
                    ]
                  },
                  "title": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  },
                  "eatenAt": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "mealType": {
                    "type": "string",
                    "enum": [
                      "breakfast",
                      "lunch",
                      "dinner",
                      "snack"
                    ]
                  },
                  "description": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 6000
                  },
                  "removeItemIds": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "maxItems": 40,
                    "default": []
                  },
                  "replacements": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "itemId": {
                          "type": "string"
                        },
                        "ingredient": {
                          "anyOf": [
                            {
                              "type": "object",
                              "properties": {
                                "foodId": {
                                  "type": "string",
                                  "minLength": 1,
                                  "maxLength": 200
                                },
                                "grams": {
                                  "type": "number",
                                  "exclusiveMinimum": true,
                                  "minimum": 0,
                                  "maximum": 20000
                                }
                              },
                              "required": [
                                "foodId",
                                "grams"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "object",
                              "properties": {
                                "item": {
                                  "type": "object",
                                  "properties": {
                                    "calories": {
                                      "type": "number",
                                      "minimum": 0,
                                      "maximum": 10000
                                    },
                                    "protein": {
                                      "type": "number",
                                      "minimum": 0,
                                      "maximum": 10000
                                    },
                                    "carbs": {
                                      "type": "number",
                                      "minimum": 0,
                                      "maximum": 10000
                                    },
                                    "fat": {
                                      "type": "number",
                                      "minimum": 0,
                                      "maximum": 10000
                                    },
                                    "id": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 100
                                    },
                                    "name": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 200
                                    },
                                    "grams": {
                                      "type": "number",
                                      "exclusiveMinimum": true,
                                      "minimum": 0,
                                      "maximum": 20000,
                                      "nullable": true
                                    },
                                    "preparation": {
                                      "type": "string",
                                      "maxLength": 200
                                    },
                                    "emoji": {
                                      "type": "string",
                                      "maxLength": 16
                                    },
                                    "source": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 200
                                    },
                                    "sourceUrl": {
                                      "type": "string",
                                      "format": "uri"
                                    },
                                    "basis": {
                                      "type": "string",
                                      "enum": [
                                        "database",
                                        "estimate",
                                        "measured"
                                      ]
                                    },
                                    "calorieLow": {
                                      "type": "number",
                                      "minimum": 0,
                                      "maximum": 10000
                                    },
                                    "calorieHigh": {
                                      "type": "number",
                                      "minimum": 0,
                                      "maximum": 10000
                                    }
                                  },
                                  "required": [
                                    "calories",
                                    "protein",
                                    "carbs",
                                    "fat",
                                    "id",
                                    "name",
                                    "grams",
                                    "source",
                                    "basis",
                                    "calorieLow",
                                    "calorieHigh"
                                  ],
                                  "additionalProperties": false
                                }
                              },
                              "required": [
                                "item"
                              ],
                              "additionalProperties": false
                            }
                          ]
                        }
                      },
                      "required": [
                        "itemId",
                        "ingredient"
                      ],
                      "additionalProperties": false
                    },
                    "maxItems": 40,
                    "default": []
                  },
                  "portions": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "itemId": {
                          "type": "string"
                        },
                        "multiplier": {
                          "type": "number",
                          "exclusiveMinimum": true,
                          "minimum": 0,
                          "maximum": 10
                        }
                      },
                      "required": [
                        "itemId",
                        "multiplier"
                      ],
                      "additionalProperties": false
                    },
                    "maxItems": 40,
                    "default": []
                  },
                  "additions": {
                    "type": "array",
                    "items": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "foodId": {
                              "type": "string",
                              "minLength": 1,
                              "maxLength": 200
                            },
                            "grams": {
                              "type": "number",
                              "exclusiveMinimum": true,
                              "minimum": 0,
                              "maximum": 20000
                            }
                          },
                          "required": [
                            "foodId",
                            "grams"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "object",
                          "properties": {
                            "item": {
                              "type": "object",
                              "properties": {
                                "calories": {
                                  "type": "number",
                                  "minimum": 0,
                                  "maximum": 10000
                                },
                                "protein": {
                                  "type": "number",
                                  "minimum": 0,
                                  "maximum": 10000
                                },
                                "carbs": {
                                  "type": "number",
                                  "minimum": 0,
                                  "maximum": 10000
                                },
                                "fat": {
                                  "type": "number",
                                  "minimum": 0,
                                  "maximum": 10000
                                },
                                "id": {
                                  "type": "string",
                                  "minLength": 1,
                                  "maxLength": 100
                                },
                                "name": {
                                  "type": "string",
                                  "minLength": 1,
                                  "maxLength": 200
                                },
                                "grams": {
                                  "type": "number",
                                  "exclusiveMinimum": true,
                                  "minimum": 0,
                                  "maximum": 20000,
                                  "nullable": true
                                },
                                "preparation": {
                                  "type": "string",
                                  "maxLength": 200
                                },
                                "emoji": {
                                  "type": "string",
                                  "maxLength": 16
                                },
                                "source": {
                                  "type": "string",
                                  "minLength": 1,
                                  "maxLength": 200
                                },
                                "sourceUrl": {
                                  "type": "string",
                                  "format": "uri"
                                },
                                "basis": {
                                  "type": "string",
                                  "enum": [
                                    "database",
                                    "estimate",
                                    "measured"
                                  ]
                                },
                                "calorieLow": {
                                  "type": "number",
                                  "minimum": 0,
                                  "maximum": 10000
                                },
                                "calorieHigh": {
                                  "type": "number",
                                  "minimum": 0,
                                  "maximum": 10000
                                }
                              },
                              "required": [
                                "calories",
                                "protein",
                                "carbs",
                                "fat",
                                "id",
                                "name",
                                "grams",
                                "source",
                                "basis",
                                "calorieLow",
                                "calorieHigh"
                              ],
                              "additionalProperties": false
                            }
                          },
                          "required": [
                            "item"
                          ],
                          "additionalProperties": false
                        }
                      ]
                    },
                    "maxItems": 40,
                    "default": []
                  },
                  "assumptions": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "maxLength": 1000
                    },
                    "maxItems": 20,
                    "default": []
                  }
                },
                "required": [
                  "base",
                  "title",
                  "eatenAt",
                  "mealType",
                  "description"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/meal-variants": {
      "post": {
        "operationId": "post_v1_meal_variants",
        "summary": "Log a new variant, preserving the original",
        "tags": [
          "meal-variants"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "base": {
                    "anyOf": [
                      {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "enum": [
                              "meal"
                            ]
                          },
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "expectedRevision": {
                            "type": "integer",
                            "exclusiveMinimum": true,
                            "minimum": 0
                          }
                        },
                        "required": [
                          "kind",
                          "id",
                          "expectedRevision"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "enum": [
                              "saved"
                            ]
                          },
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          }
                        },
                        "required": [
                          "kind",
                          "id"
                        ],
                        "additionalProperties": false
                      }
                    ]
                  },
                  "title": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  },
                  "eatenAt": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "mealType": {
                    "type": "string",
                    "enum": [
                      "breakfast",
                      "lunch",
                      "dinner",
                      "snack"
                    ]
                  },
                  "description": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 6000
                  },
                  "removeItemIds": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "maxItems": 40,
                    "default": []
                  },
                  "replacements": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "itemId": {
                          "type": "string"
                        },
                        "ingredient": {
                          "anyOf": [
                            {
                              "type": "object",
                              "properties": {
                                "foodId": {
                                  "type": "string",
                                  "minLength": 1,
                                  "maxLength": 200
                                },
                                "grams": {
                                  "type": "number",
                                  "exclusiveMinimum": true,
                                  "minimum": 0,
                                  "maximum": 20000
                                }
                              },
                              "required": [
                                "foodId",
                                "grams"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "object",
                              "properties": {
                                "item": {
                                  "type": "object",
                                  "properties": {
                                    "calories": {
                                      "type": "number",
                                      "minimum": 0,
                                      "maximum": 10000
                                    },
                                    "protein": {
                                      "type": "number",
                                      "minimum": 0,
                                      "maximum": 10000
                                    },
                                    "carbs": {
                                      "type": "number",
                                      "minimum": 0,
                                      "maximum": 10000
                                    },
                                    "fat": {
                                      "type": "number",
                                      "minimum": 0,
                                      "maximum": 10000
                                    },
                                    "id": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 100
                                    },
                                    "name": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 200
                                    },
                                    "grams": {
                                      "type": "number",
                                      "exclusiveMinimum": true,
                                      "minimum": 0,
                                      "maximum": 20000,
                                      "nullable": true
                                    },
                                    "preparation": {
                                      "type": "string",
                                      "maxLength": 200
                                    },
                                    "emoji": {
                                      "type": "string",
                                      "maxLength": 16
                                    },
                                    "source": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 200
                                    },
                                    "sourceUrl": {
                                      "type": "string",
                                      "format": "uri"
                                    },
                                    "basis": {
                                      "type": "string",
                                      "enum": [
                                        "database",
                                        "estimate",
                                        "measured"
                                      ]
                                    },
                                    "calorieLow": {
                                      "type": "number",
                                      "minimum": 0,
                                      "maximum": 10000
                                    },
                                    "calorieHigh": {
                                      "type": "number",
                                      "minimum": 0,
                                      "maximum": 10000
                                    }
                                  },
                                  "required": [
                                    "calories",
                                    "protein",
                                    "carbs",
                                    "fat",
                                    "id",
                                    "name",
                                    "grams",
                                    "source",
                                    "basis",
                                    "calorieLow",
                                    "calorieHigh"
                                  ],
                                  "additionalProperties": false
                                }
                              },
                              "required": [
                                "item"
                              ],
                              "additionalProperties": false
                            }
                          ]
                        }
                      },
                      "required": [
                        "itemId",
                        "ingredient"
                      ],
                      "additionalProperties": false
                    },
                    "maxItems": 40,
                    "default": []
                  },
                  "portions": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "itemId": {
                          "type": "string"
                        },
                        "multiplier": {
                          "type": "number",
                          "exclusiveMinimum": true,
                          "minimum": 0,
                          "maximum": 10
                        }
                      },
                      "required": [
                        "itemId",
                        "multiplier"
                      ],
                      "additionalProperties": false
                    },
                    "maxItems": 40,
                    "default": []
                  },
                  "additions": {
                    "type": "array",
                    "items": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "foodId": {
                              "type": "string",
                              "minLength": 1,
                              "maxLength": 200
                            },
                            "grams": {
                              "type": "number",
                              "exclusiveMinimum": true,
                              "minimum": 0,
                              "maximum": 20000
                            }
                          },
                          "required": [
                            "foodId",
                            "grams"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "object",
                          "properties": {
                            "item": {
                              "type": "object",
                              "properties": {
                                "calories": {
                                  "type": "number",
                                  "minimum": 0,
                                  "maximum": 10000
                                },
                                "protein": {
                                  "type": "number",
                                  "minimum": 0,
                                  "maximum": 10000
                                },
                                "carbs": {
                                  "type": "number",
                                  "minimum": 0,
                                  "maximum": 10000
                                },
                                "fat": {
                                  "type": "number",
                                  "minimum": 0,
                                  "maximum": 10000
                                },
                                "id": {
                                  "type": "string",
                                  "minLength": 1,
                                  "maxLength": 100
                                },
                                "name": {
                                  "type": "string",
                                  "minLength": 1,
                                  "maxLength": 200
                                },
                                "grams": {
                                  "type": "number",
                                  "exclusiveMinimum": true,
                                  "minimum": 0,
                                  "maximum": 20000,
                                  "nullable": true
                                },
                                "preparation": {
                                  "type": "string",
                                  "maxLength": 200
                                },
                                "emoji": {
                                  "type": "string",
                                  "maxLength": 16
                                },
                                "source": {
                                  "type": "string",
                                  "minLength": 1,
                                  "maxLength": 200
                                },
                                "sourceUrl": {
                                  "type": "string",
                                  "format": "uri"
                                },
                                "basis": {
                                  "type": "string",
                                  "enum": [
                                    "database",
                                    "estimate",
                                    "measured"
                                  ]
                                },
                                "calorieLow": {
                                  "type": "number",
                                  "minimum": 0,
                                  "maximum": 10000
                                },
                                "calorieHigh": {
                                  "type": "number",
                                  "minimum": 0,
                                  "maximum": 10000
                                }
                              },
                              "required": [
                                "calories",
                                "protein",
                                "carbs",
                                "fat",
                                "id",
                                "name",
                                "grams",
                                "source",
                                "basis",
                                "calorieLow",
                                "calorieHigh"
                              ],
                              "additionalProperties": false
                            }
                          },
                          "required": [
                            "item"
                          ],
                          "additionalProperties": false
                        }
                      ]
                    },
                    "maxItems": 40,
                    "default": []
                  },
                  "assumptions": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "maxLength": 1000
                    },
                    "maxItems": 20,
                    "default": []
                  }
                },
                "required": [
                  "base",
                  "title",
                  "eatenAt",
                  "mealType",
                  "description"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "Unique key for a logical capture. Reuse on retry; different input conflicts.",
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Meal"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/captures/{id}/resolve-entries": {
      "post": {
        "operationId": "post_v1_captures__id__resolve_entries",
        "summary": "Resolve a description into separately timed meals atomically",
        "tags": [
          "captures"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "entries": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "title": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 200
                        },
                        "items": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "calories": {
                                "type": "number",
                                "minimum": 0,
                                "maximum": 10000
                              },
                              "protein": {
                                "type": "number",
                                "minimum": 0,
                                "maximum": 10000
                              },
                              "carbs": {
                                "type": "number",
                                "minimum": 0,
                                "maximum": 10000
                              },
                              "fat": {
                                "type": "number",
                                "minimum": 0,
                                "maximum": 10000
                              },
                              "id": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 100
                              },
                              "name": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 200
                              },
                              "grams": {
                                "type": "number",
                                "exclusiveMinimum": true,
                                "minimum": 0,
                                "maximum": 20000,
                                "nullable": true
                              },
                              "preparation": {
                                "type": "string",
                                "maxLength": 200
                              },
                              "emoji": {
                                "type": "string",
                                "maxLength": 16
                              },
                              "source": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 200
                              },
                              "sourceUrl": {
                                "type": "string",
                                "format": "uri"
                              },
                              "basis": {
                                "type": "string",
                                "enum": [
                                  "database",
                                  "estimate",
                                  "measured"
                                ]
                              },
                              "calorieLow": {
                                "type": "number",
                                "minimum": 0,
                                "maximum": 10000
                              },
                              "calorieHigh": {
                                "type": "number",
                                "minimum": 0,
                                "maximum": 10000
                              }
                            },
                            "required": [
                              "calories",
                              "protein",
                              "carbs",
                              "fat",
                              "id",
                              "name",
                              "grams",
                              "source",
                              "basis",
                              "calorieLow",
                              "calorieHigh"
                            ],
                            "additionalProperties": false
                          },
                          "minItems": 1,
                          "maxItems": 40
                        },
                        "confidence": {
                          "type": "string",
                          "enum": [
                            "high",
                            "medium",
                            "low",
                            "measured"
                          ]
                        },
                        "assumptions": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "maxLength": 1000
                          },
                          "maxItems": 30
                        },
                        "eatenAt": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "mealType": {
                          "type": "string",
                          "enum": [
                            "breakfast",
                            "lunch",
                            "dinner",
                            "snack"
                          ]
                        },
                        "description": {
                          "type": "string",
                          "maxLength": 6000,
                          "default": ""
                        }
                      },
                      "required": [
                        "title",
                        "items",
                        "confidence",
                        "assumptions",
                        "eatenAt",
                        "mealType"
                      ],
                      "additionalProperties": false
                    },
                    "minItems": 1,
                    "maxItems": 20
                  }
                },
                "required": [
                  "entries"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "captureId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "meals": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Meal"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/captures/{id}/resolve": {
      "post": {
        "operationId": "post_v1_captures__id__resolve",
        "summary": "Resolve pending prose with client-calculated nutrition atomically",
        "tags": [
          "captures"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  },
                  "items": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "calories": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        },
                        "protein": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        },
                        "carbs": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        },
                        "fat": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        },
                        "id": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 100
                        },
                        "name": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 200
                        },
                        "grams": {
                          "type": "number",
                          "exclusiveMinimum": true,
                          "minimum": 0,
                          "maximum": 20000,
                          "nullable": true
                        },
                        "preparation": {
                          "type": "string",
                          "maxLength": 200
                        },
                        "emoji": {
                          "type": "string",
                          "maxLength": 16
                        },
                        "source": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 200
                        },
                        "sourceUrl": {
                          "type": "string",
                          "format": "uri"
                        },
                        "basis": {
                          "type": "string",
                          "enum": [
                            "database",
                            "estimate",
                            "measured"
                          ]
                        },
                        "calorieLow": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        },
                        "calorieHigh": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        }
                      },
                      "required": [
                        "calories",
                        "protein",
                        "carbs",
                        "fat",
                        "id",
                        "name",
                        "grams",
                        "source",
                        "basis",
                        "calorieLow",
                        "calorieHigh"
                      ],
                      "additionalProperties": false
                    },
                    "minItems": 1,
                    "maxItems": 40
                  },
                  "confidence": {
                    "type": "string",
                    "enum": [
                      "high",
                      "medium",
                      "low",
                      "measured"
                    ]
                  },
                  "assumptions": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "maxLength": 1000
                    },
                    "maxItems": 30
                  },
                  "eatenAt": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "mealType": {
                    "type": "string",
                    "enum": [
                      "breakfast",
                      "lunch",
                      "dinner",
                      "snack"
                    ]
                  }
                },
                "required": [
                  "title",
                  "items",
                  "confidence",
                  "assumptions"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Meal"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/foods/portion": {
      "get": {
        "operationId": "get_v1_foods_portion",
        "summary": "Calculate a cached food portion from grams",
        "tags": [
          "foods"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "grams",
            "in": "query",
            "required": true,
            "schema": {
              "type": "number",
              "exclusiveMinimum": true,
              "minimum": 0,
              "maximum": 20000
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FoodItem"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/status": {
      "get": {
        "operationId": "get_v1_status",
        "summary": "Read AI configuration and MCP address",
        "tags": [
          "status"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/meals": {
      "get": {
        "operationId": "get_v1_meals",
        "summary": "List meals for a date; otherwise return recent meals up to limit (default 500)",
        "tags": [
          "meals"
        ],
        "parameters": [
          {
            "name": "date",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 500
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Meal"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "post": {
        "operationId": "post_v1_meals",
        "summary": "Log exact nutrition",
        "tags": [
          "meals"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "eatenAt": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "mealType": {
                    "type": "string",
                    "enum": [
                      "breakfast",
                      "lunch",
                      "dinner",
                      "snack"
                    ]
                  },
                  "source": {
                    "type": "string",
                    "enum": [
                      "app",
                      "web",
                      "api"
                    ],
                    "default": "api"
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 6000,
                    "default": ""
                  },
                  "title": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  },
                  "items": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "calories": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        },
                        "protein": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        },
                        "carbs": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        },
                        "fat": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        },
                        "id": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 100
                        },
                        "name": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 200
                        },
                        "grams": {
                          "type": "number",
                          "exclusiveMinimum": true,
                          "minimum": 0,
                          "maximum": 20000,
                          "nullable": true
                        },
                        "preparation": {
                          "type": "string",
                          "maxLength": 200
                        },
                        "emoji": {
                          "type": "string",
                          "maxLength": 16
                        },
                        "source": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 200
                        },
                        "sourceUrl": {
                          "type": "string",
                          "format": "uri"
                        },
                        "basis": {
                          "type": "string",
                          "enum": [
                            "database",
                            "estimate",
                            "measured"
                          ]
                        },
                        "calorieLow": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        },
                        "calorieHigh": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        }
                      },
                      "required": [
                        "calories",
                        "protein",
                        "carbs",
                        "fat",
                        "id",
                        "name",
                        "grams",
                        "source",
                        "basis",
                        "calorieLow",
                        "calorieHigh"
                      ],
                      "additionalProperties": false
                    },
                    "minItems": 1,
                    "maxItems": 40
                  },
                  "confidence": {
                    "type": "string",
                    "enum": [
                      "high",
                      "medium",
                      "low",
                      "measured"
                    ]
                  },
                  "assumptions": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "maxLength": 1000
                    },
                    "maxItems": 30
                  }
                },
                "required": [
                  "eatenAt",
                  "mealType",
                  "title",
                  "items",
                  "confidence",
                  "assumptions"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Recommended. Stable key for safe retries of this exact meal write.",
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Meal"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/meals/{id}": {
      "get": {
        "operationId": "get_v1_meals__id_",
        "summary": "Read meal with nutrition and provenance",
        "tags": [
          "meals"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Meal"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "patch": {
        "operationId": "patch_v1_meals__id_",
        "summary": "Correct a meal; expectedRevision prevents lost updates",
        "tags": [
          "meals"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "expectedRevision": {
                    "type": "integer",
                    "exclusiveMinimum": true,
                    "minimum": 0
                  },
                  "title": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  },
                  "items": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "calories": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        },
                        "protein": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        },
                        "carbs": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        },
                        "fat": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        },
                        "id": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 100
                        },
                        "name": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 200
                        },
                        "grams": {
                          "type": "number",
                          "exclusiveMinimum": true,
                          "minimum": 0,
                          "maximum": 20000,
                          "nullable": true
                        },
                        "preparation": {
                          "type": "string",
                          "maxLength": 200
                        },
                        "emoji": {
                          "type": "string",
                          "maxLength": 16
                        },
                        "source": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 200
                        },
                        "sourceUrl": {
                          "type": "string",
                          "format": "uri"
                        },
                        "basis": {
                          "type": "string",
                          "enum": [
                            "database",
                            "estimate",
                            "measured"
                          ]
                        },
                        "calorieLow": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        },
                        "calorieHigh": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        }
                      },
                      "required": [
                        "calories",
                        "protein",
                        "carbs",
                        "fat",
                        "id",
                        "name",
                        "grams",
                        "source",
                        "basis",
                        "calorieLow",
                        "calorieHigh"
                      ],
                      "additionalProperties": false
                    },
                    "minItems": 1,
                    "maxItems": 40
                  },
                  "mealType": {
                    "type": "string",
                    "enum": [
                      "breakfast",
                      "lunch",
                      "dinner",
                      "snack"
                    ]
                  },
                  "eatenAt": {
                    "type": "string",
                    "format": "date-time"
                  }
                },
                "required": [
                  "expectedRevision"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Meal"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "delete": {
        "operationId": "delete_v1_meals__id_",
        "summary": "Delete a meal and its revision history",
        "tags": [
          "meals"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "revision",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/v1/meals/{id}/history": {
      "get": {
        "operationId": "get_v1_meals__id__history",
        "summary": "Read previous revisions",
        "tags": [
          "meals"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/captures": {
      "post": {
        "operationId": "post_v1_captures",
        "summary": "Persist prose for background estimation",
        "tags": [
          "captures"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CaptureInput"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "Unique key for a logical capture. Reuse on retry; different input conflicts.",
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          }
        ],
        "responses": {
          "202": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Capture"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "get": {
        "operationId": "get_v1_captures",
        "summary": "List up to 50 unfinished captures",
        "tags": [
          "captures"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Capture"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/captures/{id}": {
      "get": {
        "operationId": "get_v1_captures__id_",
        "summary": "Read queued, processing, complete or needs_review status",
        "tags": [
          "captures"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Capture"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "delete": {
        "operationId": "delete_v1_captures__id_",
        "summary": "Discard queued or needs_review capture",
        "tags": [
          "captures"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Discarded"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/v1/captures/{id}/retry": {
      "post": {
        "operationId": "post_v1_captures__id__retry",
        "summary": "Revise and retry a needs_review capture",
        "tags": [
          "captures"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CaptureInput"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Capture"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/summary": {
      "get": {
        "operationId": "get_v1_summary",
        "summary": "Daily totals; unlogged days absent; maximum one year",
        "tags": [
          "summary"
        ],
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "from": {
                      "type": "string"
                    },
                    "to": {
                      "type": "string"
                    },
                    "goals": {
                      "$ref": "#/components/schemas/Settings"
                    },
                    "days": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "date": {
                            "type": "string",
                            "format": "date"
                          },
                          "calories": {
                            "type": "number"
                          },
                          "protein": {
                            "type": "number"
                          },
                          "carbs": {
                            "type": "number"
                          },
                          "fat": {
                            "type": "number"
                          },
                          "calorieLow": {
                            "type": "number"
                          },
                          "calorieHigh": {
                            "type": "number"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/saved-meals": {
      "get": {
        "operationId": "get_v1_saved_meals",
        "summary": "List reusable meals",
        "tags": [
          "saved-meals"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/SavedMeal"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "post": {
        "operationId": "post_v1_saved_meals",
        "summary": "Save a meal template",
        "tags": [
          "saved-meals"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  },
                  "items": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "calories": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        },
                        "protein": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        },
                        "carbs": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        },
                        "fat": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        },
                        "id": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 100
                        },
                        "name": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 200
                        },
                        "grams": {
                          "type": "number",
                          "exclusiveMinimum": true,
                          "minimum": 0,
                          "maximum": 20000,
                          "nullable": true
                        },
                        "preparation": {
                          "type": "string",
                          "maxLength": 200
                        },
                        "emoji": {
                          "type": "string",
                          "maxLength": 16
                        },
                        "source": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 200
                        },
                        "sourceUrl": {
                          "type": "string",
                          "format": "uri"
                        },
                        "basis": {
                          "type": "string",
                          "enum": [
                            "database",
                            "estimate",
                            "measured"
                          ]
                        },
                        "calorieLow": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        },
                        "calorieHigh": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10000
                        }
                      },
                      "required": [
                        "calories",
                        "protein",
                        "carbs",
                        "fat",
                        "id",
                        "name",
                        "grams",
                        "source",
                        "basis",
                        "calorieLow",
                        "calorieHigh"
                      ],
                      "additionalProperties": false
                    },
                    "minItems": 1,
                    "maxItems": 40
                  },
                  "mealType": {
                    "type": "string",
                    "enum": [
                      "breakfast",
                      "lunch",
                      "dinner",
                      "snack"
                    ]
                  },
                  "description": {
                    "type": "string",
                    "default": ""
                  }
                },
                "required": [
                  "name",
                  "items",
                  "mealType"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "parameters": [],
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SavedMeal"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/saved-meals/{id}/log": {
      "post": {
        "operationId": "post_v1_saved_meals__id__log",
        "summary": "Log a usual instantly, with optional portion multiplier",
        "tags": [
          "saved-meals"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "eatenAt": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "mealType": {
                    "type": "string",
                    "enum": [
                      "breakfast",
                      "lunch",
                      "dinner",
                      "snack"
                    ]
                  },
                  "multiplier": {
                    "type": "number",
                    "exclusiveMinimum": true,
                    "minimum": 0,
                    "maximum": 10,
                    "default": 1
                  }
                },
                "required": [
                  "eatenAt"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Recommended. Stable key for safe retries of this exact meal write.",
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Meal"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/saved-meals/{id}": {
      "put": {
        "operationId": "put_v1_saved_meals__id_",
        "summary": "Edit a saved meal template without changing logged meals",
        "tags": [
          "saved-meals"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "meal": {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 200
                      },
                      "items": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "calories": {
                              "type": "number",
                              "minimum": 0,
                              "maximum": 10000
                            },
                            "protein": {
                              "type": "number",
                              "minimum": 0,
                              "maximum": 10000
                            },
                            "carbs": {
                              "type": "number",
                              "minimum": 0,
                              "maximum": 10000
                            },
                            "fat": {
                              "type": "number",
                              "minimum": 0,
                              "maximum": 10000
                            },
                            "id": {
                              "type": "string",
                              "minLength": 1,
                              "maxLength": 100
                            },
                            "name": {
                              "type": "string",
                              "minLength": 1,
                              "maxLength": 200
                            },
                            "grams": {
                              "type": "number",
                              "exclusiveMinimum": true,
                              "minimum": 0,
                              "maximum": 20000,
                              "nullable": true
                            },
                            "preparation": {
                              "type": "string",
                              "maxLength": 200
                            },
                            "emoji": {
                              "type": "string",
                              "maxLength": 16
                            },
                            "source": {
                              "type": "string",
                              "minLength": 1,
                              "maxLength": 200
                            },
                            "sourceUrl": {
                              "type": "string",
                              "format": "uri"
                            },
                            "basis": {
                              "type": "string",
                              "enum": [
                                "database",
                                "estimate",
                                "measured"
                              ]
                            },
                            "calorieLow": {
                              "type": "number",
                              "minimum": 0,
                              "maximum": 10000
                            },
                            "calorieHigh": {
                              "type": "number",
                              "minimum": 0,
                              "maximum": 10000
                            }
                          },
                          "required": [
                            "calories",
                            "protein",
                            "carbs",
                            "fat",
                            "id",
                            "name",
                            "grams",
                            "source",
                            "basis",
                            "calorieLow",
                            "calorieHigh"
                          ],
                          "additionalProperties": false
                        },
                        "minItems": 1,
                        "maxItems": 40
                      },
                      "mealType": {
                        "type": "string",
                        "enum": [
                          "breakfast",
                          "lunch",
                          "dinner",
                          "snack"
                        ]
                      },
                      "description": {
                        "type": "string",
                        "maxLength": 6000,
                        "default": ""
                      }
                    },
                    "required": [
                      "name",
                      "items",
                      "mealType"
                    ],
                    "additionalProperties": false
                  },
                  "expectedVersion": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  }
                },
                "required": [
                  "meal",
                  "expectedVersion"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SavedMeal"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "delete": {
        "operationId": "delete_v1_saved_meals__id_",
        "summary": "Remove a saved template",
        "tags": [
          "saved-meals"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Removed"
          }
        }
      }
    },
    "/v1/weights": {
      "get": {
        "operationId": "get_v1_weights",
        "summary": "List weight check-ins",
        "tags": [
          "weights"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Weight"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "post": {
        "operationId": "post_v1_weights",
        "summary": "Create or replace a weight measurement for a date",
        "tags": [
          "weights"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "date": {
                    "type": "string",
                    "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                  },
                  "kg": {
                    "type": "number",
                    "minimum": 10,
                    "maximum": 600
                  },
                  "note": {
                    "type": "string",
                    "maxLength": 1000,
                    "default": ""
                  }
                },
                "required": [
                  "date",
                  "kg"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "parameters": [],
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Weight"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/weights/{id}": {
      "delete": {
        "operationId": "delete_v1_weights__id_",
        "summary": "Remove weight measurement",
        "tags": [
          "weights"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Removed"
          }
        }
      }
    },
    "/v1/photos": {
      "get": {
        "operationId": "get_v1_photos",
        "summary": "List private progress photo metadata",
        "tags": [
          "photos"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Photo"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "post": {
        "operationId": "post_v1_photos",
        "summary": "Store a private progress photo under 3 MB",
        "tags": [
          "photos"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "date": {
                    "type": "string",
                    "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                  },
                  "note": {
                    "type": "string",
                    "maxLength": 1000,
                    "default": ""
                  },
                  "mime": {
                    "type": "string",
                    "enum": [
                      "image/jpeg",
                      "image/png",
                      "image/webp"
                    ]
                  },
                  "base64": {
                    "type": "string",
                    "maxLength": 4000000
                  }
                },
                "required": [
                  "date",
                  "mime",
                  "base64"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "parameters": [],
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Photo"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/photos/{id}/image": {
      "get": {
        "operationId": "get_v1_photos__id__image",
        "summary": "Read photo bytes; bearer authentication required",
        "tags": [
          "photos"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Private image",
            "content": {
              "image/jpeg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/png": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/webp": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          }
        }
      }
    },
    "/v1/photos/{id}": {
      "delete": {
        "operationId": "delete_v1_photos__id_",
        "summary": "Delete progress photo",
        "tags": [
          "photos"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Removed"
          }
        }
      }
    },
    "/v1/foods/search": {
      "get": {
        "operationId": "get_v1_foods_search",
        "summary": "Search USDA and Open Food Facts with provider status",
        "tags": [
          "foods"
        ],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 2,
              "maxLength": 100
            }
          },
          {
            "name": "remote",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": true
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "query": {
                      "type": "string"
                    },
                    "foods": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Food"
                      }
                    },
                    "online": {
                      "type": "object",
                      "properties": {
                        "status": {
                          "type": "string",
                          "enum": [
                            "not_requested",
                            "ok",
                            "cached",
                            "cooldown",
                            "unavailable"
                          ]
                        },
                        "message": {
                          "type": "string"
                        },
                        "retryAfterSeconds": {
                          "type": "number"
                        },
                        "excluded": {
                          "type": "number"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/foods": {
      "get": {
        "operationId": "get_v1_foods",
        "summary": "Search local library, optionally import Open Food Facts results",
        "tags": [
          "foods"
        ],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 2,
              "maxLength": 100
            }
          },
          {
            "name": "remote",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Food"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/foods/barcode/{code}": {
      "get": {
        "operationId": "get_v1_foods_barcode__code_",
        "summary": "Look up 8–14 digit barcode; caches Open Food Facts nutrition",
        "tags": [
          "foods"
        ],
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Food"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/connections": {
      "get": {
        "operationId": "get_v1_connections",
        "summary": "List OAuth client connections",
        "tags": [
          "connections"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/connections/{id}": {
      "delete": {
        "operationId": "delete_v1_connections__id_",
        "summary": "Immediately revoke all tokens for a client",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Revoked"
          }
        }
      }
    },
    "/v1/export": {
      "get": {
        "operationId": "get_v1_export",
        "summary": "Export complete journal JSON; image bytes are separate",
        "tags": [
          "export"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/demo": {
      "delete": {
        "operationId": "delete_v1_demo",
        "summary": "Remove only explicitly tagged example data",
        "tags": [
          "demo"
        ],
        "parameters": [],
        "responses": {
          "204": {
            "description": "Sample data removed"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Personal API token or OAuth access token"
      }
    },
    "responses": {
      "InvalidInput": {
        "description": "Invalid input",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing or invalid bearer token",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "Conflict": {
        "description": "Revision or idempotency conflict",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "RateLimited": {
        "description": "Rate limit exceeded",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "Settings": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "calorieGoal": {
            "type": "integer",
            "minimum": 500,
            "maximum": 10000
          },
          "proteinGoal": {
            "type": "number",
            "minimum": 0,
            "maximum": 1000
          },
          "carbsGoal": {
            "type": "number",
            "minimum": 0,
            "maximum": 2000
          },
          "fatGoal": {
            "type": "number",
            "minimum": 0,
            "maximum": 1000
          },
          "timezone": {
            "type": "string"
          },
          "weightUnit": {
            "type": "string",
            "enum": [
              "kg",
              "lb"
            ]
          },
          "onboardingCompleted": {
            "type": "boolean"
          },
          "onboardingSkipped": {
            "type": "boolean"
          }
        },
        "required": [
          "name",
          "calorieGoal",
          "proteinGoal",
          "carbsGoal",
          "fatGoal",
          "timezone",
          "weightUnit"
        ],
        "additionalProperties": false
      },
      "FoodItem": {
        "type": "object",
        "properties": {
          "calories": {
            "type": "number",
            "minimum": 0,
            "maximum": 10000
          },
          "protein": {
            "type": "number",
            "minimum": 0,
            "maximum": 10000
          },
          "carbs": {
            "type": "number",
            "minimum": 0,
            "maximum": 10000
          },
          "fat": {
            "type": "number",
            "minimum": 0,
            "maximum": 10000
          },
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "grams": {
            "type": "number",
            "exclusiveMinimum": true,
            "minimum": 0,
            "maximum": 20000,
            "nullable": true
          },
          "preparation": {
            "type": "string",
            "maxLength": 200
          },
          "emoji": {
            "type": "string",
            "maxLength": 16
          },
          "source": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "sourceUrl": {
            "type": "string",
            "format": "uri"
          },
          "basis": {
            "type": "string",
            "enum": [
              "database",
              "estimate",
              "measured"
            ]
          },
          "calorieLow": {
            "type": "number",
            "minimum": 0,
            "maximum": 10000
          },
          "calorieHigh": {
            "type": "number",
            "minimum": 0,
            "maximum": 10000
          }
        },
        "required": [
          "calories",
          "protein",
          "carbs",
          "fat",
          "id",
          "name",
          "grams",
          "source",
          "basis",
          "calorieLow",
          "calorieHigh"
        ],
        "additionalProperties": false
      },
      "Meal": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "calories": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 10000
                },
                "protein": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 10000
                },
                "carbs": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 10000
                },
                "fat": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 10000
                },
                "id": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100
                },
                "name": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 200
                },
                "grams": {
                  "type": "number",
                  "exclusiveMinimum": true,
                  "minimum": 0,
                  "maximum": 20000,
                  "nullable": true
                },
                "preparation": {
                  "type": "string",
                  "maxLength": 200
                },
                "emoji": {
                  "type": "string",
                  "maxLength": 16
                },
                "source": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 200
                },
                "sourceUrl": {
                  "type": "string",
                  "format": "uri"
                },
                "basis": {
                  "type": "string",
                  "enum": [
                    "database",
                    "estimate",
                    "measured"
                  ]
                },
                "calorieLow": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 10000
                },
                "calorieHigh": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 10000
                }
              },
              "required": [
                "calories",
                "protein",
                "carbs",
                "fat",
                "id",
                "name",
                "grams",
                "source",
                "basis",
                "calorieLow",
                "calorieHigh"
              ],
              "additionalProperties": false
            },
            "minItems": 1,
            "maxItems": 40
          },
          "confidence": {
            "type": "string",
            "enum": [
              "high",
              "medium",
              "low",
              "measured"
            ]
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string",
              "maxLength": 1000
            },
            "maxItems": 30
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "eatenAt": {
            "type": "string",
            "format": "date-time"
          },
          "description": {
            "type": "string"
          },
          "mealType": {
            "type": "string",
            "enum": [
              "breakfast",
              "lunch",
              "dinner",
              "snack"
            ]
          },
          "source": {
            "type": "string"
          },
          "revision": {
            "type": "integer"
          },
          "calories": {
            "type": "number"
          },
          "protein": {
            "type": "number"
          },
          "carbs": {
            "type": "number"
          },
          "fat": {
            "type": "number"
          },
          "calorieLow": {
            "type": "number"
          },
          "calorieHigh": {
            "type": "number"
          }
        },
        "required": [
          "title",
          "items",
          "confidence",
          "assumptions",
          "id",
          "eatenAt",
          "description",
          "mealType",
          "source",
          "revision",
          "calories",
          "protein",
          "carbs",
          "fat",
          "calorieLow",
          "calorieHigh"
        ],
        "additionalProperties": false
      },
      "CaptureInput": {
        "type": "object",
        "properties": {
          "description": {
            "type": "string",
            "minLength": 2,
            "maxLength": 6000
          },
          "eatenAt": {
            "type": "string",
            "format": "date-time"
          },
          "mealType": {
            "type": "string",
            "enum": [
              "breakfast",
              "lunch",
              "dinner",
              "snack"
            ]
          },
          "source": {
            "type": "string",
            "enum": [
              "app",
              "web",
              "siri",
              "notification",
              "mcp",
              "api",
              "widget"
            ],
            "default": "api"
          },
          "savedMealId": {
            "type": "string",
            "format": "uuid"
          },
          "correctionOf": {
            "type": "string",
            "format": "uuid"
          },
          "expectedRevision": {
            "type": "integer",
            "exclusiveMinimum": true,
            "minimum": 0
          }
        },
        "required": [
          "description",
          "eatenAt"
        ],
        "additionalProperties": false
      },
      "Capture": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "processing",
              "complete",
              "needs_review"
            ]
          },
          "input": {
            "allOf": [
              {
                "$ref": "#/components/schemas/CaptureInput"
              },
              {
                "type": "object",
                "properties": {
                  "mealTypeInferred": {
                    "type": "boolean"
                  },
                  "timingInferred": {
                    "type": "boolean"
                  },
                  "mentionedMealTypes": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "breakfast",
                        "lunch",
                        "dinner",
                        "snack"
                      ]
                    }
                  }
                }
              }
            ]
          },
          "mealIds": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            }
          },
          "mealId": {
            "type": "string",
            "nullable": true
          },
          "error": {
            "type": "string",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "SavedMeal": {
        "type": "object",
        "properties": {
          "version": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$",
            "description": "Content version for safe template updates."
          },
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FoodItem"
            }
          },
          "meal_type": {
            "type": "string",
            "enum": [
              "breakfast",
              "lunch",
              "dinner",
              "snack"
            ]
          },
          "description": {
            "type": "string"
          }
        }
      },
      "Weight": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "date": {
            "type": "string",
            "format": "date"
          },
          "kg": {
            "type": "number"
          },
          "note": {
            "type": "string"
          },
          "revision": {
            "type": "integer"
          },
          "healthSampleId": {
            "type": "string",
            "format": "uuid",
            "nullable": true
          },
          "measuredAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "Photo": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "date": {
            "type": "string",
            "format": "date"
          },
          "note": {
            "type": "string"
          }
        }
      },
      "Food": {
        "type": "object",
        "description": "Nutrition per 100 grams; serving weights come from the named source.",
        "properties": {
          "emoji": {
            "type": "string"
          },
          "categories": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "servings": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "label": {
                  "type": "string"
                },
                "grams": {
                  "type": "number"
                }
              }
            }
          },
          "dataset": {
            "type": "string"
          },
          "publishedAt": {
            "type": "string"
          },
          "preparation": {
            "type": "string"
          },
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "brand": {
            "type": "string",
            "nullable": true
          },
          "nutrients": {
            "type": "object",
            "properties": {
              "calories": {
                "type": "number"
              },
              "protein": {
                "type": "number"
              },
              "carbs": {
                "type": "number"
              },
              "fat": {
                "type": "number"
              }
            }
          },
          "source": {
            "type": "string"
          },
          "source_url": {
            "type": "string",
            "format": "uri"
          }
        }
      }
    }
  }
}