NAV undefined
bash python java ruby


PEAT API is organized around REST. We only support JSON as the all returned responses, including errors, although our API libraries convert responses to appropriate language-specific objects.

We have language bindings in Shell, Python, Java, and many more in nearly future. You can view code examples in the dark area to the right, and you can switch the programming language of the examples with the tabs in the top right.


# With shell, you can just pass the correct header with each request
curl "api_endpoint_here"
  -H "Api-Key: <API_KEY>"

Before you can request to the API, make sure you have Api-Key for the authentication. Please contact to get your Api-Key. Your Api-Key carry many sensitive privileges, so make sure to keep it secure. Do not share your Api-Key in publicly accessible place, such as Github.

Authentication can be done by adding a header field on your request.

Allowed Headers

# You can write header key as title case with dash
curl "api_endpoint_here"
  -H "Gps-Accuracy: <GPS_ACCURACY>"

# you also can write header key as lower case with underscore
curl "api_endpoint_here"
  -H "gps_accuracy: <GPS_ACCURACY>"
Key Headers                            | Data Types
-----------------------                | ----------
latitude                               | float
longitude                              | float
Gps-Accuracy / gps_accuracy            | float
eppo                                   | string
User-Id / user_id                      | string
User-Name / user_name                  | string
crop                                   | string
variety                                | string
timestamp                              | string

Headers can be title style with dash for space or lowercase with underscore for space, example: Header for specifying User ID can be written as User-Id or user_id

Rate Limit

You will have rate limit request each month. Please contact to get more information about this.

Note that if you reach rate limit, the API responds with a HTTP 429 response code.

Response you'll get when you reach rate limit

  "message": "You have reached your maximum amount of requests this month"


The API responds a successful requests with HTTP status code 200 or 300 range.

Example response you'll get when everything is fine

    "big_enough": true,
    "code": 200,
    "image_analysis": [{
            "eppo": "COCHMI",
            "name": "Brown Spot of Rice",
            "peat_id": 100064,
            "rank": 1,
            "scientific_name": "Cochliobolus miyabeanus",
            "similarity": 87
    "recognized": "True",
    "recognized_bool": true
Response Meaning
200 OK -- Everything worked as expected
400 Bad Request -- The request was not acceptable
401 Unauthorized -- No valid Api-Key provided
429 Too Many Requests -- Rate limit request was reached
500 Internal Server Error -- Something wrong with our server (These are rare)


Analyze Image

Return image analysis

Example request

curl -H "Api-Key: <YOUR_API_KEY>" -F "picture=@../data/Wheat_Leaf_Rust_100059/PEAT_20160609_122425_85d9410f-5452-42da-b471-2d80a4e9d94e.jpg" ""
import os
import requests
from pprint import pprint as pp

IP = ''
VERSION = 'v1'
ROUTE = 'image_analysis'
URL = 'https://%s/%s/%s' % (IP, VERSION, ROUTE)

# Header of our requst. Replace <YOUR_API_KEY> with your api key.
HEADER = {'Api-Key': '<YOUR_API_KEY>'}

def single_processing():

    # make a dict with the picture
    image = os.path.join('..', 'data', 'tomato_nutrient', 'iron1.png')
    files = {"picture": open(image, 'rb')}

    # post both files to our API
    result =, files=files, headers=HEADER, timeout=200000)

    if result.status_code == 401:
        print('Authentication failed')
    elif result.status_code == 500:
        print('Internal server error...')
    elif result.status_code == 200:
        # load response that comes in JSON format and print the result
        json_data = result.json()

if __name__ == '__main__':
require 'net/http'
require 'uri'
require 'json'
require 'mime/types'

IP = ""
VERSION = "v1"
ROUTE = "image_analysis"
URL = "http://#{IP}/#{VERSION}/#{ROUTE}"

#Replace <YOUR_API_KEY> with your api key


FILE = "../data/tomato_nutrient/healthy_640x480.png"

def send_request
    uri = URI(URL)
    http =, uri.port)

    req =, initheader = {"Content-Type" => "multipart/form-data; boundary=#{BOUNDARY}", "Api-Key" => API_KEY})

    post_body = []

    # Add the file Data
    post_body << "--#{BOUNDARY}\r\n"
    post_body << "Content-Disposition: form-data; name=\"picture\"; filename=\"#{File.basename(FILE)}\"\r\n"
    post_body << "Content-Type: #{MIME::Types.type_for(FILE)}\r\n\r\n"
    post_body <<
    post_body << "\r\n--#{BOUNDARY}--\r\n"
    req.body = post_body.join

    print req.body

    res = http.request(req)
    puts "response #{res.body}"
rescue => e
    puts "failed #{e}"

package com.peat.examples;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

public class ImageAPIMinimal {
    private static final String API_KEY = "YOUR API KEY";
    private static final String LINE_FEED = "\r\n";

    public static void main(String[] args) throws Exception {

        String charset =;

        // Your image file to upload
        File uploadFile = new File("../../../data/tomato_nutrient/iron1.jpg");
        String requestURL = "";

        // Creates a unique boundary based on time stamp
        String boundary = String.valueOf(System.currentTimeMillis());

        // Setup http connection
        URL url = new URL(requestURL);
        HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
        httpConn.setDoOutput(true); // POST method
        httpConn.setRequestProperty("User-Agent", "API Java example");
        httpConn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
        httpConn.setRequestProperty("Api-Key", API_KEY);

        // Setup OutputStream and PrintWriter
        OutputStream outputStream = httpConn.getOutputStream();
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(outputStream, charset), true);

        // Add image file to POST request
        String fieldName = "picture";
        String fileName = uploadFile.getName();
        writer.append("--" + boundary).append(LINE_FEED);
        writer.append("Content-Disposition: form-data; name=\"" + fieldName + "\"; filename=\"" + fileName + "\"").append(LINE_FEED);

        FileInputStream inputStream = new FileInputStream(uploadFile);
        byte[] buffer = new byte[4096];
        int bytesRead;
        while ((bytesRead = != -1) {
            outputStream.write(buffer, 0, bytesRead);


        // Send POST request and get response
        List<String> response = new ArrayList<>();
        writer.append("--" + boundary + "--").append(LINE_FEED);

        // Check server status message
        int status = httpConn.getResponseCode();
        if (status == HttpURLConnection.HTTP_OK) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
            String line;
            while ((line = reader.readLine()) != null) {
        } else {
            throw new IOException("Server returned non-OK status: " + status);

        // Read response
        for (String line : response) {


The code returns JSON structured like this:

    "big_enough": true,
    "code": 200,
    "image_analysis": [{
            "eppo": "COCHMI",
            "name": "Brown Spot of Rice",
            "peat_id": 100064,
            "rank": 1,
            "scientific_name": "Cochliobolus miyabeanus",
            "similarity": 87
            "eppo": "PYRIOR",
            "name": "Blast of Rice",
            "peat_id": 100058,
            "rank": 3,
            "scientific_name": "Magnaporthe oryzae",
            "similarity": 7
    "objects_net": [{
            "name": "eft",
            "rank": 1,
            "similarity": 32
            "name": "rule",
            "rank": 2,
            "similarity": 8
    "pic_id": "79937583-d368-45b9-87c1-010b55df0f5c",
    "plant_net": [{
        "name": "RICE",
        "rank": 1,
        "similarity": 94
    "recognized": "True",
    "recognized_bool": true

HTTP Request


Query Parameters

Parameter Description
picture A binary file of picture you want to analyze