API

Recommendation Generation

Recommendation generation used by the recommendation endpoint

Recommendation generation happens inside GET /api/recommend, which handles auth, cache reuse, regeneration, My List context, validation, and fallback behavior in one place.

How It Works

  1. Authenticates the user via a Supabase JWT token
  2. Fetches the user's watched movies from user_watched_movies
  3. Fetches the user's My List IDs from user_my_list
  4. Builds a compact taste profile from watched movies plus My List context
  5. Calls the platform AI client with JSON-schema-constrained output
  6. Resolves recommendation names back to TMDB IDs through Supabase search first, then TMDB fallback when needed
  7. Filters out watched movies, duplicates, unresolved titles, and excess My List matches
  8. Requests replacement picks when backend validation blocks too many candidates
  9. Returns valid TMDB IDs and caches them in Supabase

Provider Strategy

The AI client uses OpenAI-compatible chat completions.

Provider order comes from server/utils/recommendations/ai-client.ts:

  1. Google AI Studio models from NUXT_GOOGLE_MODELS
  2. OpenRouter models from NUXT_OPENROUTER_MODELS

If both providers are configured, Google is tried first. The server walks every configured model in order until one succeeds.

Default models in nuxt.config.ts are:

  1. gemini-flash-lite-latest
  2. gemini-2.5-flash-lite
  3. gemini-2.0-flash-lite
  4. google/gemini-2.5-flash-lite through OpenRouter

Rate Limiting

Recommendation generation is limited to 20 requests per day per authenticated user.

The following headers are included on generation requests:

HeaderDescription
X-RateLimit-LimitMaximum requests allowed per day
X-RateLimit-RemainingRequests remaining in the current window
X-RateLimit-ResetUnix timestamp (ms) when the window resets

Failure Behavior

When regeneration fails and an older cached set exists, /api/recommend can return:

  • regenerationError
  • staleRecommendations

If no provider is configured, or every configured provider/model attempt fails, the route returns an AI-provider error message and a regenerationError flag. If cached recommendations are available, it also returns a staleRecommendations flag to indicate that the returned recommendations may be outdated.

See Also

Copyright © 2026