A synchronous endpoint is preferred for users who have real-time needs, low latency requirements, and are submitting continuous / cyclical requests.

Submit your request using only one of the three keys below:

  • Use media to stream a file through the post request.
  • Use url to send us a url where we can download the file.
  • Use text_data to submit raw text.

The synchronous endpoint keeps the HTTP request open until results have finished processing and then sends the results directly in the response message.

Appropriate for Model-Only projects.

Form Data
file

Use this key to send a binary file through a post request.

string

Use this key to send your file using a publicly accessible url to a hosted media file.

string

Use text_data to submit raw text for text moderation projects.

HEADERS
string
required

Project API Token from hive customer dashboard. Prepend with 'token'


EXAMPLES

# submit a task with media with url(for nsfw, audio, speech, demographics ...)
curl --request POST \
  --url https://api.thehive.ai/api/v2/task/sync \
  --header 'accept: application/json' \
  --header 'authorization: token <API_KEY>' \
  --form 'url=http://hive-public.s3.amazonaws.com/demo_request/gun1.jpg'

# submit a task with media with local media file(for nsfw, audio, speech, demographics ...)
 curl --request POST \
     --url https://api.thehive.ai/api/v2/task/sync \
     --header 'Authorization: Token <token>' \
     --form 'media=@"<absolute/path/to/file>"'
 
#submit a task with text (text moderation, large language model, translation, ...)
	curl --request POST \
     --url https://api.thehive.ai/api/v2/task/sync \
     --header 'Authorization: Token <token>' \
     --form 'text_data="Hi there, this is a test task"'
     
#submit a task to a large language model with optional chat history for context
  curl --request POST \
    --url https://api.thehive.ai/api/v2/task/sync \
    --header 'Authorization: Token <token>' \
    --form 'text_data="Hi there, this is a test task"' \
    --form 'options="{\"max_tokens\":125, \"temperature\": 0.80, \"top_p\": 0.95, \"system_prompt\": \"You are a helpful, respectful. \"}"' 
#submit a task with specified language ( supported in speech/text moderation, transcription only)
# see docs for supported language
	curl --request POST \
     --url https://api.thehive.ai/api/v2/task/sync \
     --header 'Authorization: Token <token>' \
     --form 'text_data="Hi there, this is a test task"'' \
     --form 'options="{\"input_language\":\"es\"}"'
var request = require("request");

var options = {
  method: 'POST',
  url: 'https://api.thehive.ai/api/v2/task/sync',
  headers: {
    accept: 'application/json',
    authorization: 'token <API_KEY>'
  },
  form: {url:"http://hive-public.s3.amazonaws.com/demo_request/gun1.jpg"}
};  

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
# -------------------------- #
# Vision API request with public or signed url to hosted image.

import requests

headers = {
    'Authorization': 'Token YOUR_API_KEY',
}

data = {
  'url': 'my_domain/my_file.jpg',
  'metadata': '{"my_UUID": "3c78fc82-f797-11ea-adc1-0242ac120002"}'
}

response = requests.post('https://api.thehive.ai/api/v2/task/sync',
                          headers=headers, 
                          data=data)

response_string = response.text 
response_dict = response.json()

# -------------------------- #
# Vision API request for local media files.

import requests

headers = { 
    'Authorization': 'Token YOUR_API_KEY',
}

files = {'image': open('my_path/my_image.jpg', 'rb')}

data = {
  'metadata': '{"my_UUID": "3c78fc82-f797-11ea-adc1-0242ac120002"}'
}

response = requests.post('https://api.thehive.ai/api/v2/task/sync', 
                         headers=headers, 
                         files=files,
                         data = data)

response_string = response.text 
response_dict = response.json()

# -------------------------- #
# Text API requests

import requests

headers = {
    'Authorization': 'Token YOUR_API_KEY',
}

data = {
  'text_data': 'My input string goes here.',
  'metadata': '{"my_UUID": "3c78fc82-f797-11ea-adc1-0242ac120002"}'
}

response = requests.post('https://api.thehive.ai/api/v2/task/sync',
                          headers=headers, 
                          data=data)

response_string = response.text 
response_dict = response.json()

# -------------------------- #
# submit a task with specified language (speech/text moderation, transcription only)
# see docs for supported language
import requests

headers = {
    'Authorization': 'Token YOUR_API_KEY',
}

files = {'image': open('my_path/my_image.jpg', 'rb')}

data = {
  'metadata': '{"my_UUID": "3c78fc82-f797-11ea-adc1-0242ac120002"}',
  'options': '{"input_language":"es"}'
}

response = requests.post('https://api.thehive.ai/api/v2/task/sync',
                          headers=headers, 
                         	files=files,
                          data=data)

response_string = response.text 
response_dict = response.json()

# -------------------------- #
/* -------------------------- */
/* Vision API request with public or signed url to hosted image. */

import java.io.*;
import okhttp3.*;
public class main {
 public static void main(String []args) throws IOException{
   OkHttpClient client = new OkHttpClient().newBuilder()
     .build();
   MediaType mediaType = MediaType.parse("text/plain");
   RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
     .addFormDataPart("url", "http://hive-public.s3.amazonaws.com/demo_request/gun1.jpg")
     .build();
   Request request = new Request.Builder()
     .url("https://api.thehive.ai/api/v2/task/sync")
     .method("POST", body)
     .addHeader("accept", "application/json")
     .addHeader("authorization", "token YOUR_API_KEY")
     .build();
   Response response = client.newCall(request).execute();
   System.out.println(response.body().string());
 }
}

/* -------------------------- */
/* Vision API request for local media files. */

import java.io.*;
import okhttp3.*;
public class main {
 public static void main(String []args) throws IOException{
   OkHttpClient client = new OkHttpClient().newBuilder()
     .build();
   MediaType mediaType = MediaType.parse("text/plain");
   File file= new File("YOUR_IMAGE_PATH/YOUR_IMAGE.jpg");
   String imageName="YOUR_IMAGE.jpg";
   RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
     .addFormDataPart("image", imageName, RequestBody.create(MEDIA_TYPE_PNG, file))
     .build();
   Request request = new Request.Builder()
     .url("https://api.thehive.ai/api/v2/task/sync")
     .method("POST", body)
     .addHeader("accept", "application/json")
     .addHeader("authorization", "token YOUR_API_KEY")
     .build();
   Response response = client.newCall(request).execute();
   System.out.println(response.body().string());
 }
}


/* -------------------------- */
/* Text API requests */

import java.io.*;
import okhttp3.*;
public class main {
 public static void main(String []args) throws IOException{
   OkHttpClient client = new OkHttpClient().newBuilder()
     .build();
   MediaType mediaType = MediaType.parse("text/plain");
   RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
     .addFormDataPart("text_data", "Test string.")
     .build();
   Request request = new Request.Builder()
     .url("https://api.thehive.ai/api/v2/task/sync")
     .method("POST", body)
     .addHeader("accept", "application/json")
     .addHeader("Authorization", "Token YOUR_API_KEY")
     .build();
   Response response = client.newCall(request).execute();
   System.out.println(response.body().string());
 }
}

RESULTS

{
  "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "code": 200,
  "project_id": 12345,
  "user_id": 1234,
  "created_on": "2020-05-25T19:55:02.312Z",
  "status": {
    "status": {
      "code": 0,
      "message": "SUCCESS"
    },
    "response": {
    "input": {
      "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
      "charge": 0,
	    "model": "string",
      "model_version": 0,
      "model_type": "string",
      "created_on": "string",
      "media": {
        "type": "string",
        "mimetype": "string",
        "duration": 0,
        "width": 0,
        "height": 0
      },
      "user_id": 0,
      "project_id": 0
    },
    "output": [
      {
        "time": 0,
        "classes": [
          {
            "class": "general_nsfw",
            "score": 0.9
          },
          {
            "class": "general_suggestive",
            "score": 0.05
          },
          {
            "class": "general_not_nsfw_not_suggestive",
            "score": 0.05
      	  }
      	  ]
        }
     ]
    }
  },
  "from_cache": false,
  "metadata": "string"
}
{
"return_code":400,
"message":"Invalid Auth Method. 'Token' authentication required."
}