Get model input and output schemas via the API

Every model on Replicate describes its inputs and outputs with OpenAPI Schema Objects in the openapi_schema property. This is a structured JSON object that includes the name, description, type, and allowed values for each input or output parameter.

Today we’ve improved our API reference documentation to clarify how to get a model’s input and output schema.

See the updated docs at https://replicate.com/docs/reference/http#models.versions.get

Here’s an example of how to get the input schema for Stable Diffusion using cURL:

curl -s \
  -H "Authorization: Token $REPLICATE_API_TOKEN" \
  -H 'Content-Type: application/json' \
  "https://api.replicate.com/v1/models/stability-ai/stable-diffusion/versions/db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf" | jq ".openapi_schema.components.schemas.Input.properties"

Using this command, we can see all the inputs to Stable Diffusion, including their types, description, min and max values, etc:

{
  "seed": {
    "type": "integer",
    "title": "Seed",
    "x-order": 7,
    "description": "Random seed. Leave blank to randomize the seed"
  },
  "prompt": {
    "type": "string",
    "title": "Prompt",
    "default": "a vision of paradise. unreal engine",
    "x-order": 0,
    "description": "Input prompt"
  },
  "scheduler": {
    "allOf": [
      {
        "$ref": "#/components/schemas/scheduler"
      }
    ],
    "default": "DPMSolverMultistep",
    "x-order": 6,
    "description": "Choose a scheduler."
  },
  "num_outputs": {
    "type": "integer",
    "title": "Num Outputs",
    "default": 1,
    "maximum": 4,
    "minimum": 1,
    "x-order": 3,
    "description": "Number of images to output."
  },
  "guidance_scale": {
    "type": "number",
    "title": "Guidance Scale",
    "default": 7.5,
    "maximum": 20,
    "minimum": 1,
    "x-order": 5,
    "description": "Scale for classifier-free guidance"
  },
  "negative_prompt": {
    "type": "string",
    "title": "Negative Prompt",
    "x-order": 2,
    "description": "Specify things to not see in the output"
  },
  "image_dimensions": {
    "allOf": [
      {
        "$ref": "#/components/schemas/image_dimensions"
      }
    ],
    "default": "768x768",
    "x-order": 1,
    "description": "pixel dimensions of output image"
  },
  "num_inference_steps": {
    "type": "integer",
    "title": "Num Inference Steps",
    "default": 50,
    "maximum": 500,
    "minimum": 1,
    "x-order": 4,
    "description": "Number of denoising steps"
  }
}

And here’s a command to the get the output schema:

curl -s \
  -H "Authorization: Token $REPLICATE_API_TOKEN" \
  -H 'Content-Type: application/json' \
  "https://api.replicate.com/v1/models/stability-ai/stable-diffusion/versions/db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf" | jq ".openapi_schema.components.schemas.Output"

From this command, we can see that Stable Diffusion output format is a list of URL strings:

{
  "type": "array",
  "items": {
    "type": "string",
    "format": "uri"
  },
  "title": "Output"
}