Skip to content

Examples

In this page we provide different examples using our API. The examples are provided in different programming languages:

  • Python
  • NodeJS
  • PHP
  • Go
  • Bash (using cURL)

What we need

The first thing is having the URL were you can send the images:

https://autoderm.firstderm.com/v1/query

The other thing you need is having an API key. In order to get one you can contact us, get a test key or send us and email.

To continue with the examples, we will say our API key is:

Pk566ZkEQRLr9vNwo2Gkr1uL6pr-4VjZUkvdJHAdFsA

Warning

Keep your API keys safe. Do not put your keys inside any file that is public or even in version control (if there's a risk of accidentally making the repository public). You can set the key as an environment variable and read it when your app starts. A good starting point is following the 12 factor app rules.

Even though it is not necessay, you should take into account the other two parameters we use:

  • language
  • model

The language parameter is a two-letter ISO 639-1 code which selects the language of the returned content. The default is "en" (english).

The model parameter is the version of the model you want to use. The documentation of available models is in the models section.

You can see all the available parameters in our testing page.

Query the API

We will use:

import requests
import os

API_URL = "https://autoderm.firstderm.com/v1/query"

# set sensitive data as environment varibles
API_KEY = os.getenv("API_KEY")

# open the test image and read the bytes
with open("skin.jpg", "rb") as f:
    image_contents = f.read()

# send the query
response = requests.post(
    API_URL,
    headers={"Api-Key": API_KEY},
    files={"file": image_contents},
    params={"language": "en", "model": "autoderm_v2_0"},
)

# get the JSON data returned
data = response.json()

print(data)

# get only the predictions
predictions = data["predictions"]

print(predictions)

# This script works as it is shown here:
# I order to run the script:
# API_KEY=Pk566ZkEQRLr9vNwo2Gkr1uL6pr-4VjZUkvdJHAdFsA python3 python_requests.py
const FormData = require('form-data');
const axios = require('axios');
const fs = require('fs');

const apiUrl = "https://autoderm.firstderm.com/v1/query"

// set the API key as an environment variable
const apiKey = process.env.API_KEY

const formData = new FormData();
const imageContents = fs.createReadStream('./skin.jpg')
formData.append('file', imageContents);
const formHeaders = formData.getHeaders()

const res = axios({
    method: "POST", url: apiUrl, data: formData,
    // You need to use `getHeaders()` in Node.js because Axios doesn't
    // automatically set the multipart form boundary in Node.
    headers: {
        // ...requestHeaders
        ...formHeaders,
        "Api-Key": apiKey
    },
}).then(function (response) {
    // handle success
    // print the full response data
    console.log(response);

    // print only the results
    console.log(response.data);
})
    .catch(function (response) {
        // handle error
        console.log(response);
    });;


// This script works as it is shown here:
// I order to run the script:
// API_KEY=Pk566ZkEQRLr9vNwo2Gkr1uL6pr-4VjZUkvdJHAdFsA node node_request.js
curl -X POST "https://autoderm.firstderm.com/v1/query?model=autoderm_v2_0&language=en" -H  "accept: application/json" -H  "Api-Key: Pk566ZkEQRLr9vNwo2Gkr1uL6pr-4VjZUkvdJHAdFsA" -H  "Content-Type: multipart/form-data" -F "file=@skin.jpg;type=image/jpeg"
import httpx
import asyncio
import os

API_URL = "https://autoderm.firstderm.com/v1/query"

# set sensitive data as environment varibles
API_KEY = os.getenv("API_KEY")

# create an async client and set the timeout a bit higher than the default
client = httpx.AsyncClient(timeout=10)


async def main():

    # send the query
    response = await client.post(
        API_URL,
        headers={"Api-Key": API_KEY},
        # We are opening the image here too.
        files={"file": ("image.jpg", open("skin.jpg", "rb"), "multipart/form-data")},
        params={"language": "en", "model": "autoderm_v2_0"},
    )

    # get the JSON data returned
    data = response.json()

    print(data)

    # get only the predictions
    predictions = data["predictions"]

    print(predictions)

    await client.aclose()


if __name__ == "__main__":
    asyncio.run(main())

# This script works as it is shown here:
# I order to run the script:
# API_KEY=Pk566ZkEQRLr9vNwo2Gkr1uL6pr-4VjZUkvdJHAdFsA python3 python_httpx.py