Skip to content

Latest commit

 

History

History
41 lines (27 loc) · 1.41 KB

http.md

File metadata and controls

41 lines (27 loc) · 1.41 KB

HTTP API

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.

GET /openapi.json

The OpenAPI specification of the API, which is derived from the input and output types specified in your model's Predictor object.

POST /predictions

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 the predict() function. Any File or Path 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: Either succeeded or failed.
  • output: The return value of the predict() function.
  • error: If status is failed, 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