When a Cog Docker image is run, it serves an HTTP API for making predictions. For more information, take a look at the documentation for deploying models.
The OpenAPI specification of the API, which is derived from the input and output types specified in your model's Predictor object.
Make a single prediction. The request body should be a JSON object with the following fields:
input
: a JSON object with the same keys as the arguments to thepredict()
function. AnyFile
orPath
inputs are passed as URLs.output_file_prefix
: A base URL to upload output files to.
The response is a JSON object with the following fields:
status
: Eithersucceeded
orfailed
.output
: The return value of thepredict()
function.error
: Ifstatus
isfailed
, the error message.
For example:
POST /predictions
{
"input": {
"image": "https://example.com/image.jpg",
"text": "Hello world!"
}
}
Responds with:
{
"status": "succeeded",
"output": "data:image/png;base64,..."
}
Or, with curl:
curl -X POST -H "Content-Type: application/json" -d '{"input": {"image": "https://example.com/image.jpg", "text": "Hello world!"}}' http://localhost:5000/predictions