{"openapi":"3.1.0","info":{"title":"FarmRisk AI Backend API","description":"Production-grade agrometeorological advisory and village resolution system.","version":"1.0.0"},"paths":{"/":{"get":{"tags":["Health"],"summary":"Root","description":"Root landing page showing backend health, live docs links, and API catalog.","operationId":"root__get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}}},"head":{"tags":["Health"],"summary":"Root","description":"Root landing page showing backend health, live docs links, and API catalog.","operationId":"root__head","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}}}},"/health":{"get":{"tags":["Health"],"summary":"Health Check","description":"Simple API health check endpoint.","operationId":"health_check_health_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}}},"head":{"tags":["Health"],"summary":"Health Check","description":"Simple API health check endpoint.","operationId":"health_check_health_head","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}}}},"/api/location/search":{"get":{"tags":["Location"],"summary":"Search Locations","description":"Search for villages and towns in India via Nominatim.\nReturns details (village, district, state, latitude, longitude)","operationId":"search_locations_api_location_search_get","parameters":[{"name":"q","in":"query","required":true,"schema":{"type":"string","minLength":2,"description":"Search term for village/city/town","title":"Q"},"description":"Search term for village/city/town"}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/LocationDetail"},"title":"Response Search Locations Api Location Search Get"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/advisory":{"post":{"tags":["Advisory"],"summary":"Generate Crop Advisory","description":"Generate agrometeorological advisory from the full frontend data payload.","operationId":"generate_crop_advisory_api_advisory_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AIAdvisoryRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","title":"Response Generate Crop Advisory Api Advisory Post"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/advisory/weather-summary":{"post":{"tags":["Advisory"],"summary":"Generate Weather Summary","description":"Generate a simple 1-2 sentence weather summary using the primary/fallback LLM providers.","operationId":"generate_weather_summary_api_advisory_weather_summary_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AIAdvisoryRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","title":"Response Generate Weather Summary Api Advisory Weather Summary Post"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/advisory/pest-card":{"post":{"tags":["Advisory"],"summary":"Generate Pest Disease Card","description":"Build the crop-specific \"Pest & Disease\" card.\n\nFlow:\n  1. Build the deterministic AdvisoryContext (crop name/stage/season).\n  2. RAG-retrieve ICAR chunks filtered by the selected crop.\n  3. Compute the deterministic pest score + band (score_pest / pest_band).\n  4. LLM phrases summary / potential pests / actions grounded ONLY in the\n     retrieved chunks; the band can never be overridden by the model.\n  5. General crop (\"general\") skips RAG and keeps the crop-agnostic card.","operationId":"generate_pest_disease_card_api_advisory_pest_card_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AIAdvisoryRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","title":"Response Generate Pest Disease Card Api Advisory Pest Card Post"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/advisory/what-to-do":{"post":{"tags":["Advisory"],"summary":"Generate What To Do","description":"Build the \"What To Do Today\" card — an aggregation/display layer over the\nEXISTING recommendation systems (NOT a new engine).\n\nFlow:\n  1. Deterministic irrigation decision + insight (one calculation).\n  2. Weather to-dos (rain/temp/wind engine) — deterministic phrasing.\n  3. Crop-specific Pest & Disease card (shared cache with /pest-card).\n  4. Deterministic selection: best pest action + best irrigation\n     recommendation, weather to-dos as fallback, at most TWO items.\n  5. Translate the selected items' title/hint into the request language.\n\nThe card does NOT wait for the AI Overview: the advisory LLM never runs here.","operationId":"generate_what_to_do_api_advisory_what_to_do_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AIAdvisoryRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","title":"Response Generate What To Do Api Advisory What To Do Post"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/advisory/pre-sowing":{"post":{"tags":["Pre-Sowing Advisory"],"summary":"Generate Presowing Advisory","description":"Generate all 7 pre-sowing advisory sections in one call.\n\nReturns a JSON object where each section value is a Markdown string\nthat can be passed directly to your frontend Markdown parser/renderer.\n\n**Fallback behavior**: If no state-specific knowledge exists in the vector DB,\nautomatically falls back to All-India ICAR data without any error.","operationId":"generate_presowing_advisory_api_advisory_pre_sowing_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PresowingRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PresowingResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}},"components":{"schemas":{"AIAdvisoryRequest":{"properties":{"location":{"$ref":"#/components/schemas/LocationInput"},"cropId":{"type":"string","minLength":1,"title":"Cropid"},"calendarData":{"$ref":"#/components/schemas/CalendarDataInput"},"weatherData":{"$ref":"#/components/schemas/WeatherDataInput"},"forecastData":{"anyOf":[{"$ref":"#/components/schemas/ForecastDataInput"},{"type":"null"}]},"language":{"type":"string","minLength":1,"title":"Language"}},"type":"object","required":["location","cropId","calendarData","weatherData","language"],"title":"AIAdvisoryRequest"},"CalendarDataInput":{"properties":{"success":{"type":"boolean","title":"Success"},"state":{"type":"string","title":"State"},"district":{"type":"string","title":"District"},"districtCode":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Districtcode"},"calendar":{"items":{"$ref":"#/components/schemas/CalendarEventInput"},"type":"array","title":"Calendar","default":[]}},"type":"object","required":["success","state","district"],"title":"CalendarDataInput"},"CalendarEventInput":{"properties":{"crop":{"type":"string","title":"Crop"},"season":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Season","default":"General"},"sowingPeriod":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Sowingperiod","default":""},"harvestingPeriod":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Harvestingperiod","default":""},"sowFromMon":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Sowfrommon"},"sowToMon":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Sowtomon"},"harvFromMon":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Harvfrommon"},"harvToMon":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Harvtomon"}},"type":"object","required":["crop"],"title":"CalendarEventInput"},"CurrentWeatherInput":{"properties":{"time":{"type":"string","title":"Time"},"temperature_2m":{"type":"number","title":"Temperature 2M"},"relative_humidity_2m":{"type":"number","title":"Relative Humidity 2M"},"apparent_temperature":{"type":"number","title":"Apparent Temperature"},"weather_code":{"type":"integer","title":"Weather Code"},"pressure_msl":{"type":"number","title":"Pressure Msl"},"surface_pressure":{"type":"number","title":"Surface Pressure"},"wind_speed_10m":{"type":"number","title":"Wind Speed 10M"},"wind_direction_10m":{"type":"number","title":"Wind Direction 10M"},"wind_gusts_10m":{"type":"number","title":"Wind Gusts 10M"},"precipitation":{"type":"number","title":"Precipitation"},"cloud_cover":{"type":"number","title":"Cloud Cover"},"icon":{"type":"string","title":"Icon"},"condition":{"additionalProperties":{"type":"string"},"type":"object","title":"Condition"}},"type":"object","required":["time","temperature_2m","relative_humidity_2m","apparent_temperature","weather_code","pressure_msl","surface_pressure","wind_speed_10m","wind_direction_10m","wind_gusts_10m","precipitation","cloud_cover","icon","condition"],"title":"CurrentWeatherInput"},"DailyForecastCorrectionInput":{"properties":{"date":{"type":"string","title":"Date"},"tmax_raw":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"Tmax Raw","default":0.0},"tmax_corrected":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"Tmax Corrected","default":0.0},"tmin_raw":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"Tmin Raw","default":0.0},"tmin_corrected":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"Tmin Corrected","default":0.0},"pcp_raw":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"Pcp Raw","default":0.0},"pcp_corrected":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"Pcp Corrected","default":0.0}},"type":"object","required":["date"],"title":"DailyForecastCorrectionInput"},"DailyWeatherInput":{"properties":{"time":{"items":{"type":"string"},"type":"array","title":"Time"},"temperature_2m_max":{"items":{"type":"number"},"type":"array","title":"Temperature 2M Max"},"temperature_2m_min":{"items":{"type":"number"},"type":"array","title":"Temperature 2M Min"},"precipitation_sum":{"items":{"type":"number"},"type":"array","title":"Precipitation Sum"}},"type":"object","required":["time","temperature_2m_max","temperature_2m_min","precipitation_sum"],"title":"DailyWeatherInput"},"ForecastBlockInput":{"properties":{"success":{"type":"boolean","title":"Success"},"location":{"anyOf":[{"$ref":"#/components/schemas/ForecastLocationInput"},{"type":"null"}]},"grids_used":{"items":{"$ref":"#/components/schemas/GridUsedInput"},"type":"array","title":"Grids Used","default":[]},"forecast_source":{"type":"string","title":"Forecast Source","default":""},"forecast":{"items":{"$ref":"#/components/schemas/DailyForecastCorrectionInput"},"type":"array","title":"Forecast","default":[]},"runtime_seconds":{"type":"number","title":"Runtime Seconds","default":0.0},"error":{"anyOf":[{"additionalProperties":true,"type":"object"},{"type":"null"}],"title":"Error"}},"type":"object","required":["success"],"title":"ForecastBlockInput"},"ForecastDataInput":{"properties":{"requested_lat":{"type":"number","title":"Requested Lat"},"requested_lon":{"type":"number","title":"Requested Lon"},"village_id":{"type":"integer","title":"Village Id"},"forecast":{"anyOf":[{"$ref":"#/components/schemas/ForecastBlockInput"},{"type":"null"}]},"soil_moisture":{"anyOf":[{"$ref":"#/components/schemas/SoilMoistureBlockInput"},{"type":"null"}]},"cache_hit":{"type":"boolean","title":"Cache Hit","default":false},"total_runtime_seconds":{"type":"number","title":"Total Runtime Seconds","default":0.0},"cache_key":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Cache Key"}},"type":"object","required":["requested_lat","requested_lon","village_id"],"title":"ForecastDataInput"},"ForecastLocationInput":{"properties":{"lat":{"type":"number","title":"Lat"},"lon":{"type":"number","title":"Lon"},"elevation_m":{"type":"number","title":"Elevation M"}},"type":"object","required":["lat","lon","elevation_m"],"title":"ForecastLocationInput"},"GridUsedInput":{"properties":{"lat":{"type":"number","title":"Lat"},"lon":{"type":"number","title":"Lon"},"distance_deg":{"type":"number","title":"Distance Deg"},"cached":{"type":"boolean","title":"Cached"}},"type":"object","required":["lat","lon","distance_deg","cached"],"title":"GridUsedInput"},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"HourlyWeatherInput":{"properties":{"time":{"items":{"type":"string"},"type":"array","title":"Time"},"temperature_2m":{"items":{"type":"number"},"type":"array","title":"Temperature 2M"},"precipitation_probability":{"items":{"type":"number"},"type":"array","title":"Precipitation Probability"},"precipitation":{"anyOf":[{"items":{"type":"number"},"type":"array"},{"type":"null"}],"title":"Precipitation"},"wind_speed_10m":{"items":{"type":"number"},"type":"array","title":"Wind Speed 10M"},"wind_gusts_10m":{"anyOf":[{"items":{"type":"number"},"type":"array"},{"type":"null"}],"title":"Wind Gusts 10M"},"weather_code":{"items":{"type":"integer"},"type":"array","title":"Weather Code"},"icon":{"items":{"type":"string"},"type":"array","title":"Icon"}},"type":"object","required":["time","temperature_2m","precipitation_probability","wind_speed_10m","weather_code","icon"],"title":"HourlyWeatherInput"},"LightningInput":{"properties":{"score":{"type":"number","title":"Score"},"category":{"type":"string","title":"Category"}},"type":"object","required":["score","category"],"title":"LightningInput"},"LocationDetail":{"properties":{"village":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Village"},"district":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"District"},"state":{"type":"string","title":"State"},"latitude":{"type":"number","title":"Latitude"},"longitude":{"type":"number","title":"Longitude"}},"type":"object","required":["state","latitude","longitude"],"title":"LocationDetail"},"LocationInput":{"properties":{"lat":{"type":"number","title":"Lat"},"lng":{"type":"number","title":"Lng"},"name":{"type":"string","title":"Name"},"displayName":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Displayname","default":""}},"type":"object","required":["lat","lng","name"],"title":"LocationInput"},"PresowingRequest":{"properties":{"crop":{"type":"string","maxLength":60,"minLength":2,"title":"Crop","description":"Crop name — must match one of the canonical crops in config/crops.json","examples":["Cotton","Wheat","Rice"]},"state":{"type":"string","maxLength":60,"minLength":2,"title":"State","description":"Indian state name — must match config/states.json","examples":["Gujarat","Punjab","Tamil Nadu"]},"soil_type":{"type":"string","enum":["black cotton soil","sandy loam","clay","loam","laterite","alluvial","red soil","saline","alkaline"],"title":"Soil Type","description":"Soil classification — adjusts fertilizer splits, irrigation counts, and field prep","examples":["black cotton soil"]},"season":{"type":"string","enum":["Kharif","Rabi","Zaid"],"title":"Season","description":"Crop season","default":"Kharif"},"irrigation_type":{"type":"string","enum":["flood","drip","sprinkler","rainfed"],"title":"Irrigation Type","description":"Primary irrigation method — adjusts fertilizer scheduling and water amounts","default":"flood"},"language":{"type":"string","title":"Language","description":"Target language code (e.g. 'en', 'hi', 'gu', 'pa', 'ta', 'te', 'mr') or language name ('English', 'Hindi', 'Gujarati', etc.)","default":"en","examples":["en","gu","hi","pa"]}},"type":"object","required":["crop","state","soil_type"],"title":"PresowingRequest","description":"Input for the Pre-Sowing Advisory endpoint.\n\ncrop           : Canonical crop name (must match config/crops.json, case-insensitive)\nstate          : Indian state name (must match config/states.json, case-insensitive)\nsoil_type      : Soil classification — drives fertilizer, irrigation, and field prep advice\nseason         : Kharif | Rabi | Zaid (defaults to Kharif if not provided)\nirrigation_type: flood | drip | sprinkler | rainfed (defaults to flood)\nlanguage       : Target language code ('en', 'hi', 'gu', 'pa', 'ta', 'te', 'mr') or name ('English', 'Hindi', 'Gujarati', etc.)"},"PresowingResponse":{"properties":{"crop":{"type":"string","title":"Crop"},"state":{"type":"string","title":"State"},"season":{"type":"string","title":"Season"},"soil_type":{"type":"string","title":"Soil Type"},"irrigation_type":{"type":"string","title":"Irrigation Type"},"language":{"type":"string","title":"Language"},"generated_at":{"type":"string","title":"Generated At"},"rag_sources_used":{"type":"integer","title":"Rag Sources Used"},"runtime_seconds":{"type":"number","title":"Runtime Seconds"},"sections":{"additionalProperties":{"type":"string"},"type":"object","title":"Sections","description":"7 Markdown strings keyed by section name, ready for frontend rendering"}},"type":"object","required":["crop","state","season","soil_type","irrigation_type","language","generated_at","rag_sources_used","runtime_seconds","sections"],"title":"PresowingResponse"},"SoilMoistureBlockInput":{"properties":{"success":{"type":"boolean","title":"Success"},"location":{"anyOf":[{"$ref":"#/components/schemas/SoilMoistureLocationInput"},{"type":"null"}]},"cold_start":{"type":"boolean","title":"Cold Start","default":false},"days_computed":{"type":"integer","title":"Days Computed","default":0},"checkpoint_last_date":{"type":"string","title":"Checkpoint Last Date","default":""},"soil_moisture":{"items":{"$ref":"#/components/schemas/SoilMoistureRecordInput"},"type":"array","title":"Soil Moisture","default":[]},"runtime_seconds":{"type":"number","title":"Runtime Seconds","default":0.0},"error":{"anyOf":[{"additionalProperties":true,"type":"object"},{"type":"null"}],"title":"Error"}},"type":"object","required":["success"],"title":"SoilMoistureBlockInput"},"SoilMoistureLocationInput":{"properties":{"lat":{"type":"number","title":"Lat"},"lon":{"type":"number","title":"Lon"}},"type":"object","required":["lat","lon"],"title":"SoilMoistureLocationInput"},"SoilMoistureRecordInput":{"properties":{"date":{"type":"string","title":"Date"},"P_obs":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"P Obs","default":0.0},"Tmean":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"Tmean","default":0.0},"PE":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"Pe","default":0.0},"P_eff":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"P Eff","default":0.0},"snowpack":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"Snowpack","default":0.0},"w":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"W","default":0.0},"E":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"E","default":0.0},"R":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"R","default":0.0},"G":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"G","default":0.0},"w_frac":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"W Frac","default":0.0},"sm_percentile":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"Sm Percentile","default":50.0},"is_forecast":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Is Forecast","default":0}},"type":"object","required":["date"],"title":"SoilMoistureRecordInput"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"},"input":{"title":"Input"},"ctx":{"type":"object","title":"Context"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"},"WeatherDataInput":{"properties":{"latitude":{"type":"number","title":"Latitude"},"longitude":{"type":"number","title":"Longitude"},"elevation":{"type":"number","title":"Elevation"},"timezone":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Timezone"},"timezoneAbbreviation":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Timezoneabbreviation"},"utcOffsetSeconds":{"type":"integer","title":"Utcoffsetseconds"},"current":{"$ref":"#/components/schemas/CurrentWeatherInput"},"hourly":{"$ref":"#/components/schemas/HourlyWeatherInput"},"daily":{"$ref":"#/components/schemas/DailyWeatherInput"},"lightning":{"anyOf":[{"$ref":"#/components/schemas/LightningInput"},{"type":"null"}]}},"type":"object","required":["latitude","longitude","elevation","utcOffsetSeconds","current","hourly","daily"],"title":"WeatherDataInput"}}}}