Skip to content

Instantly share code, notes, and snippets.

@Nnonexistent
Last active July 19, 2023 14:41
Show Gist options
  • Save Nnonexistent/13c43217b62067b793a22dce11db1acb to your computer and use it in GitHub Desktop.
Save Nnonexistent/13c43217b62067b793a22dce11db1acb to your computer and use it in GitHub Desktop.
Usage of Neurolabs `/v1/detection-jobs/{detection_job_uuid}/urls` endpoint

How to use Neurolabs API

Setup

  1. Setup product catalog: https://docs.neurolabs.ai/docs/configuration/product-catalog

  2. Configure the Detection Job: https://docs.neurolabs.ai/docs/configuration/detection-jobs

  3. Obtain an API KEY: https://docs.neurolabs.ai/docs/apis/generate_api_key

Basic image processing

  1. Post a list of urls of images, that needs to be processed to the /v1/detection-jobs/{detection_job_uuid}/urls endpoint:

bash example:

curl -X 'POST' \
  "$BASE_API_URL/v1/detection-jobs/$DETECTION_JOB_UUID/urls" \
  -H 'accept: application/json' \
  -H "X-API-Key: $API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "urls": [
    "https://example.com/image1.jpg",
    "https://example.com/image2.jpg",
    "https://example.com/image3.jpg",
  ]
}'

python example:

import httpx

BASE_API_URL = ...
DETECTION_JOB_UUID = ...
API_KEY = ...

response = httpx.post(
    f"{BASE_API_URL}/v1/detection-jobs/{DETECTION_JOB_UUID}/urls",
    headers={"X-API-KEY": API_KEY},
    json={"urls": [
        "https://example.com/image1.jpg",
        "https://example.com/image2.jpg",
        "https://example.com/image3.jpg",
    ]}
)

detection_job_prediction_uuid = response.json()["uuid"]
  1. The response will contain uuid field. This is uuid of new detection job prediction

  2. Access the results of the processing via /v1/detection-jobs/{detection_job_uuid}/predictions/{detection_job_prediction_uuid} endpoint.

bash example:

curl "$BASE_API_URL/v1/detection-jobs/$DETECTION_JOB_UUID/predictions/$DETECTION_JOB_PREDICTION_UUID" \
  -H 'accept: application/json' \
  -H "X-API-Key: $API_KEY"

python example:

response = httpx.get(
    f"{BASE_API_URL}/v1/detection-jobs/{DETECTION_JOB_UUID}/predictions/{detection_job_prediction_uuid}",
    headers={"X-API-KEY": API_KEY},
)
results = response.json()["prediction"]

Using callback

  1. You can specify callback url at /v1/detection-jobs/{detection_job_uuid}/urls endpoint:

bash example:

curl -X 'POST' \
  "$BASE_API_URL/v1/detection-jobs/$DETECTION_JOB_UUID/urls" \
  -H 'accept: application/json' \
  -H "X-API-Key: $API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "urls": [
    "https://example.com/image1.jpg",
    "https://example.com/image2.jpg",
    "https://example.com/image3.jpg",
  ],
  "callback": "http://example.com/my-callback-endpoint"
}'

python example:

import httpx

BASE_API_URL = ...
DETECTION_JOB_UUID = ...
API_KEY = ...

response = httpx.post(
    f"{BASE_API_URL}/v1/detection-jobs/{DETECTION_JOB_UUID}/urls",
    headers={"X-API-KEY": API_KEY},
    json={
        "urls": [
            "https://example.com/image1.jpg",
            "https://example.com/image2.jpg",
            "https://example.com/image3.jpg",
        ], 
        "callback": "http://example.com/my-callback-endpoint",
    }
)
  1. The response will be the same, you still can track the progress via /v1/detection-jobs/{detection_job_uuid}/predictions/{detection_job_prediction_uuid} endpoint.

  2. But additionally, after the image processing will be finished, HTTP POST will be executed to the specified callback with a detection job prediction as a payload.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment