Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ricardomb-tech/surqo/llms.txt

Use this file to discover all available pages before exploring further.

The Surqo API is a FastAPI-powered REST backend deployed on Fly.io (Dallas — dfw) with min_machines_running = 1 and auto_stop_machines = false. There are no cold starts — every request hits a live machine. All endpoints live under the base path /api/v1/. Interactive Swagger UI (/docs) and ReDoc (/redoc) are available in local development only; both are disabled in production for security.

Base URLs

EnvironmentURL
Productionhttps://surqo-api.fly.dev
Local devhttp://localhost:8000
Swagger UIhttp://localhost:8000/docs (dev only)

HTTP Status Codes

Every response conforms to standard HTTP semantics. The table below covers all codes you will encounter across Surqo endpoints.
CodeMeaning
200OK — request succeeded, body contains data
201Created — resource successfully created
204No Content — successful DELETE, no response body
401JWT missing, expired, or invalid
402Plan quota exceeded (farms limit or AI analyses)
403Resource belongs to a different user
404Resource not found
422Pydantic validation error — check request body shape
429Rate limit exceeded (slowapi per-IP / per-user)
The 402 response is used for quota enforcement, not payment. When a free-tier user exhausts their 4 lifetime AI analyses or tries to create a second farm, the API returns 402 with a structured error body containing code, message, and contact_url.

Rate Limits

Rate limiting is handled by slowapi. Limits are enforced per authenticated user when a valid JWT is present (keyed on the sub claim), or per IP for unauthenticated requests. Exceeding a limit returns 429 Too Many Requests.
Endpoint groupLimit
POST /api/v1/farms/10 / minute
POST /api/v1/analysis/analyze10 / minute
POST /api/v1/analysis/chat20 / minute
POST /api/v1/sensors/reading120 / minute
POST /api/v1/devices/register30 / minute
GET /api/v1/users/me60 / minute

Endpoint Index

A complete reference of every route exposed by the API. All authenticated endpoints require Authorization: Bearer <jwt>.
MethodPathAuthDescription
GET/healthNoServer health check
POST/api/v1/sensors/readingYesIngest a sensor reading
GET/api/v1/sensors/timeseries/{farm_id}YesTime-series data (query: hours, metric)
GET/api/v1/sensors/latest/{device_id}YesLatest reading for a device
GET/api/v1/sensors/stats/{farm_id}YesAggregated 24 h statistics
WS/api/v1/sensors/ws/live/{farm_id}Yes (token param)Live sensor stream over WebSocket
POST/api/v1/farms/YesCreate a farm (free plan: max 1)
GET/api/v1/farms/YesList all farms for the authenticated user
GET/api/v1/farms/{id}YesGet a single farm
PATCH/api/v1/farms/{id}YesUpdate farm fields (all optional)
DELETE/api/v1/farms/{id}YesDelete farm and all associated data
GET/api/v1/farms/{id}/kpisYesAgronomic KPIs for the last 24 h
POST/api/v1/analysis/analyzeYesRun an AI analysis (free plan: 4 lifetime)
GET/api/v1/analysis/history/{farm_id}YesAnalysis history (latest 10)
GET/api/v1/analysis/{id}YesRetrieve a single analysis result
POST/api/v1/analysis/chatYesChat with the AI agronomist
GET/api/v1/alerts/activeYesActive alerts (query: farm_id)
GET/api/v1/alerts/historyYesAll alerts — active and resolved
PATCH/api/v1/alerts/{id}/resolveYesMark an alert as resolved
POST/api/v1/alerts/{id}/notifyYesRe-send alert email manually
GET/api/v1/kpis/farm/{id}YesDetailed KPIs (VPD, ETc, GDD, soil score)
GET/api/v1/kpis/farm/{id}/vpd-historyYesVPD readings over the last 48 h
GET/api/v1/kpis/farm/{id}/water-balanceYes7-day water balance (ETc vs rainfall)
GET/api/v1/kpis/farm/{id}/pest-riskYesPest risk score and pathogen list
POST/api/v1/devices/registerNoESP32 self-registration
POST/api/v1/devices/{device_mac}/readingNoESP32 HTTP fallback — publishes a reading by MAC when MQTT is unavailable
GET/api/v1/devices/YesList devices paired to the user’s farms
GET/api/v1/devices/discoverableYesUnpaired devices available to claim
POST/api/v1/devices/claimYesPair a device to a farm
PATCH/api/v1/devices/{id}YesRename a paired device
DELETE/api/v1/devices/{id}YesUnpair a device from its farm
GET/api/v1/users/meYesAuthenticated user’s profile
GET/api/v1/users/me/plan-limitsYesCurrent quota status and remaining allowances
PATCH/api/v1/users/{id}/planAdminChange a user’s plan (freepaid)

Health Check

Use the /health endpoint to verify the backend is reachable. In production it returns a minimal body to avoid exposing internal state.
curl https://surqo-api.fly.dev/health
{"status": "ok"}
In local development the health response is more verbose, including db, mqtt_active, and ws_connections fields — useful for confirming all subsystems started correctly.

Build docs developers (and LLMs) love