Response Schema¶
Detailed breakdown of the diagnosis response structure.
DiagnosisResponse¶
The main response object returned by the /diagnoses/ endpoint.
{
"request_id": "string",
"image_analysis": "ImageAnalysis",
"crop_health": "enum",
"diagnoses": "array[DiagnosisDetail]",
"treatment": "Treatment | null",
"detections": "array[Detection] | null",
"additional_notes": "string | null",
"error": "string | null"
}
Fields¶
| Field | Type | Required | Description |
|---|---|---|---|
request_id |
string | Yes | UUID for request tracking |
image_analysis |
object | Yes | Image metadata (plant detection, quality) |
crop_health |
enum | Yes | Overall health status |
diagnoses |
array | Yes | List of possible diagnoses (1-3 hypotheses) |
treatment |
object | null | No | Treatment recommendations for primary diagnosis |
detections |
array | null | No | Bounding boxes (if include_bbox=true) |
additional_notes |
string | null | No | Extra observations |
error |
string | null | No | Error message if analysis failed |
ImageAnalysis¶
Metadata about the analyzed image.
Fields¶
| Field | Type | Description |
|---|---|---|
is_plant |
boolean | Whether image contains a plant |
quality_issue |
string | null | Quality problem description if any (blur, lighting, etc.) |
Enums¶
CropHealth¶
Overall health assessment of the plant.
| Value | Description |
|---|---|
healthy |
No disease or problems detected |
unhealthy |
One or more issues identified |
unknown |
Cannot determine (quality issue, not a plant, etc.) |
Urgency¶
Urgency level for each diagnosis.
| Value | Description |
|---|---|
low |
Monitor situation, no immediate action needed |
moderate |
Take action within days to prevent spread |
high |
Treat as soon as possible |
critical |
Immediate action required to save crop |
DiagnosisCategory¶
Category of the diagnosed problem.
| Value | Description |
|---|---|
fungal |
Fungal disease (mildew, rust, blight) |
bacterial |
Bacterial infection |
viral |
Viral disease |
nutrient_deficiency |
Nutrient deficiency (nitrogen, potassium, etc.) |
pest |
Insect or pest damage |
physiological |
Physiological disorder (sunscald, cold injury) |
environmental |
Environmental stress (drought, flooding) |
DiagnosisDetail¶
A single diagnosis hypothesis. Ordered by confidence (highest first).
{
"scientific_name": "Alternaria solani",
"eppo_code": "ALTESO",
"name": "Early Blight",
"category": "fungal",
"confidence": 0.87,
"urgency": "moderate",
"description": "Fungal disease characterized by dark, concentric rings...",
"affected_parts": ["leaves", "lower foliage"],
"reference_images": ["https://gd.eppo.int/..."]
}
Fields¶
| Field | Type | Description |
|---|---|---|
scientific_name |
string | null | Latin binomial name (e.g., "Alternaria solani") |
eppo_code |
string | null | EPPO code for the pathogen (e.g., "ALTESO") |
name |
string | Common name of disease/condition |
category |
enum | null | Problem category (fungal, bacterial, pest, etc.) |
confidence |
float | Confidence score (0.0 to 1.0) |
urgency |
enum | null | Urgency level for this specific diagnosis |
description |
string | Detailed explanation |
affected_parts |
array[string] | Plant parts affected |
reference_images |
array[string] | null | URLs to EPPO reference images |
EPPO Integration¶
When available, diagnoses include EPPO (European and Mediterranean Plant Protection Organization) data:
eppo_code: Standardized identifier for the pathogen/pestreference_images: High-quality reference photos from the EPPO Global Database
EPPO links follow the format: https://gd.eppo.int/taxon/{EPPO_CODE}
Confidence Interpretation¶
| Score | Interpretation |
|---|---|
| 0.8 - 1.0 | High confidence - likely diagnosis |
| 0.5 - 0.8 | Moderate confidence - probable diagnosis |
| 0.3 - 0.5 | Low confidence - possible diagnosis |
| < 0.3 | Very low - consider other causes |
Treatment¶
Treatment recommendations for the primary diagnosis.
{
"immediate_actions": ["Remove affected leaves", "..."],
"recommended_products": ["Copper fungicide", "..."],
"natural_alternatives": ["Neem oil", "..."],
"prevention": ["Crop rotation", "..."]
}
Fields¶
| Field | Type | Description |
|---|---|---|
immediate_actions |
array[string] | Steps to take now |
recommended_products |
array[string] | Commercial treatments |
natural_alternatives |
array[string] | Organic/natural options |
prevention |
array[string] | Future prevention measures |
Detection¶
Location of detected problem area (when include_bbox=true).
Fields¶
| Field | Type | Description |
|---|---|---|
name |
string | What was detected |
bbox |
array[float] | [x, y, width, height] normalized 0-1 |
confidence |
float | Detection confidence (0.0 to 1.0) |
Bounding Box Coordinates¶
Coordinates are normalized to the image dimensions (0.0 to 1.0):
┌─────────────────────────┐
│ (0,0) │
│ ┌───────┐ │
│ │ bbox │ │
│ │ │ │
│ └───────┘ │
│ (1,1) │
└─────────────────────────┘
bbox = [x, y, width, height]
= [0.15, 0.30, 0.25, 0.20]
To convert to pixels:
pixel_x = x * image_width
pixel_y = y * image_height
pixel_w = width * image_width
pixel_h = height * image_height
Example: Drawing Bounding Box¶
from PIL import Image, ImageDraw
# Load image
img = Image.open("plant.jpg")
draw = ImageDraw.Draw(img)
# Get bbox from response
bbox = response["detections"][0]["bbox"]
x, y, w, h = bbox
# Convert to pixel coordinates
img_w, img_h = img.size
left = x * img_w
top = y * img_h
right = (x + w) * img_w
bottom = (y + h) * img_h
# Draw rectangle
draw.rectangle([left, top, right, bottom], outline="red", width=3)
img.show()
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
// Get bbox from response
const [x, y, w, h] = response.detections[0].bbox;
// Convert to pixel coordinates
const pixelX = x * canvas.width;
const pixelY = y * canvas.height;
const pixelW = w * canvas.width;
const pixelH = h * canvas.height;
// Draw rectangle
ctx.strokeStyle = 'red';
ctx.lineWidth = 3;
ctx.strokeRect(pixelX, pixelY, pixelW, pixelH);
Full Response Example¶
{
"request_id": "550e8400-e29b-41d4-a716-446655440000",
"image_analysis": {
"is_plant": true,
"quality_issue": null
},
"crop_health": "unhealthy",
"diagnoses": [
{
"scientific_name": "Alternaria solani",
"eppo_code": "ALTESO",
"name": "Early Blight",
"category": "fungal",
"confidence": 0.87,
"urgency": "moderate",
"description": "Fungal disease characterized by dark, concentric rings forming a 'target' pattern on older leaves. The pathogen thrives in warm (24-29°C) and humid conditions. Spores spread through wind, rain splash, and infected plant debris.",
"affected_parts": ["leaves", "lower foliage", "stems"],
"reference_images": [
"https://gd.eppo.int/media/data/photos/ALTESO/ALTESO_001.jpg",
"https://gd.eppo.int/media/data/photos/ALTESO/ALTESO_002.jpg"
]
},
{
"scientific_name": "Septoria lycopersici",
"eppo_code": "SEPTLY",
"name": "Septoria Leaf Spot",
"category": "fungal",
"confidence": 0.32,
"urgency": "low",
"description": "Secondary possibility with small circular spots.",
"affected_parts": ["leaves"],
"reference_images": null
}
],
"treatment": {
"immediate_actions": [
"Remove and destroy all affected leaves - do not compost",
"Improve air circulation by pruning lower branches",
"Switch to drip irrigation to keep foliage dry",
"Apply mulch to prevent soil splash onto leaves"
],
"recommended_products": [
"Chlorothalonil (Daconil) - apply every 7-10 days",
"Copper hydroxide - organic option",
"Mancozeb - rotate with other fungicides"
],
"natural_alternatives": [
"Neem oil spray (2%) - weekly application",
"Baking soda solution (1 tbsp/gallon + few drops dish soap)",
"Compost tea foliar spray for plant immunity"
],
"prevention": [
"Practice 3-year crop rotation with non-solanaceous crops",
"Use certified disease-free seeds",
"Choose resistant varieties (Mountain Merit, Iron Lady)",
"Space plants 60-90cm apart for airflow",
"Water early morning so leaves dry quickly"
]
},
"detections": [
{
"name": "early_blight",
"bbox": [0.15, 0.30, 0.25, 0.20],
"confidence": 0.87
},
{
"name": "early_blight",
"bbox": [0.55, 0.45, 0.18, 0.15],
"confidence": 0.72
}
],
"additional_notes": "The infection appears to be in early to moderate stages. With prompt treatment, you should be able to prevent significant yield loss. Monitor new growth carefully over the next 2 weeks.",
"error": null
}