Skip to content

Suggestions

Suggestions propose a seven-option pool or meals for selected open slots, and Recipe drafts turn a new meal idea, or the member's own description of a dish, into an unsaved Recipe. Generation never writes an Entry, Idea, or Recipe. Adding a suggestion to the plan, saving it as an Idea, or saving a draft is an ordinary write through the Entry, Idea, or Recipe routes (D-144). The API builds context under the member's RLS client and makes the provider call directly through its registered adapter. Server-only execution leases enforce account credits for sessions, API keys and OAuth owners; providers receive no member credential (docs/ai.md).

Method and pathScopeBehavior
POST /api/v1/suggestionsreadPropose up to one meal for each of up to ten selected placements.
POST /api/v1/suggestions/poolreadReturn exactly seven distinct options for any day.
GET /api/v1/meal-spaces/{groupId}/ai-guidancereadRead shared guidance for the supplied membership.
PUT /api/v1/meal-spaces/{groupId}/ai-guidanceadminSave guidance with revision and membership checks.
POST /api/v1/suggestions/recipe-draftswriteGenerate an unsaved Recipe draft for a new meal idea or a description.

POST /api/v1/suggestions/pool takes only meal_space_id and an Idempotency-Key. It requires content-write permission and the acting user's Pro/trial allowance. A ready result contains status: "ready", generated_at, guidance_revision, and exactly seven distinct suggestions. Each card has a session-local id, title, kind, optional recipe_id, and reason, with no placement. Seven cards must survive validation or the whole batch returns failed with no charge. A pool works even when every upcoming meal is already planned. Its bounded context includes those plans, enabled Slots, History, Ideas, active Recipes, and saved guidance in that Meal Space.

Guidance reads take membership_id in the query. Writes take membership_id, expected_revision, allergies: string[], preferences: string, and an Idempotency-Key. Only owners and admins can write. Empty guidance starts at revision 0; a changed save increments it. An unchanged save keeps the revision. A stale revision returns 409 conflict. Repeating an uncertain save must send the same body and key. Limits are 20 distinct allergies, 80 Unicode characters each, 1,000 total, and 2,000 characters for preferences. Guidance is shared with space members and sent to AI only on a requested generation. Reading or saving guidance costs no AI action and works with AI disabled.

Every generation mode and Recipe draft uses saved guidance. Guidance or membership changing during generation returns 412 precondition_failed and spends nothing. Literal known ingredient conflicts are excluded, but this does not guarantee allergy or medical suitability. Clients recheck guidance before using a cached pool and discard pools after 24 hours or confirmed access loss.

POST /api/v1/suggestions takes meal_space_id, placements (1 to 10 {date, slot} pairs inside the next 14 planning days, on enabled Slots), and up to three preset priorities. The member needs permission to write the Meal Space: a viewer or a read-only space gets 403 or 409 before any AI action is spent. Results, in data.status:

  • ready: suggestions holds one card per placement the service could match well, and may hold fewer than requested. Each card has placement, title, kind (recipe, simple, or new_recipe_idea), recipe_id for a recipe card, and a short reason. A recipe card always carries the Recipe's saved title.
  • failed: reason is unusable (the model returned nothing that passed validation) or provider_unavailable. No AI action was spent; the same key may be retried.

If another member has filled a selected placement, the request returns 412 precondition_failed and spends nothing. Refresh the plan and choose again. Other invalid placements return 422 validation_error.

POST /api/v1/suggestions/recipe-drafts takes meal_space_id, a title (a new Recipe idea's, up to 200 characters), a prompt (the member's own description of the dish, up to 1,000 characters), or both, and optional priorities; a body with neither returns 422 validation_error (D-218). A given title is kept. Without one, the model names the dish, and only the claim words of a title that makes a diet, health, allergy or cost claim are removed ("Vegan Game Day Chili" becomes "Game Day Chili"); a title that is nothing but a claim, or a description of something that is not food, returns failed with unusable. Before any AI action it checks that the member may create a Recipe in that Meal Space and that Free Personal capacity allows one more. A draft result holds draft.content, draft.warnings (every Save-time content issue), and review with the label "AI-generated, review before cooking", the request's priorities as preferences to verify, and the allergy and medical verification sentence. The client keeps the draft for up to 24 hours and saves it with the ordinary Recipe create command, which rechecks permission and capacity.

All generation routes use the member's own Pro allowance: 25 actions across a trial, or 200 per UTC month. Without Pro the request returns 403 pro_required; with the allowance used up it returns 429 rate_limited. A usable suggestion set or draft spends one action; any failure spends none. An Idempotency-Key pays for one model call: repeating it while that call runs or after it succeeded returns 409 conflict, so start a new request with a new key (D-182).

Temporary attempt limits include a bounded integer Retry-After header; exhausted credits do not. 503 can indicate disabled AI, admission pressure, provider cooldown, or unavailable accounting. Never automatically regenerate after an uncertain response. Check usage; a new explicit action uses a new UUID and can spend another credit.