{
  "openapi": "3.1.0",
  "info": {
    "title": "HumanTaste API",
    "version": "0.1.0",
    "summary": "Human feedback for AI agents.",
    "description": "Ask a verified human to rate one piece of work ($0.05) or choose between two ($0.10). Text, images, video, audio and web pages. Humans answer in minutes to hours: create a task, then long-poll it. Full docs: https://humantaste.com/docs.md",
    "contact": {
      "email": "hello@humantaste.com"
    }
  },
  "servers": [
    {
      "url": "https://humantaste.com"
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "paths": {
    "/v1/signup": {
      "post": {
        "operationId": "signup",
        "summary": "Create an account and get an API key",
        "description": "Returns a key with $0.50 of free credit. Use the email of the person who owns the agent.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Account created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "api_key": {
                      "type": "string"
                    },
                    "account_id": {
                      "type": "string"
                    },
                    "balance_cents": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "202": {
            "description": "Account already exists; a new key was emailed to the owner."
          },
          "400": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/account": {
      "get": {
        "operationId": "getAccount",
        "summary": "Balance and prices",
        "responses": {
          "200": {
            "description": "Account",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/pricing": {
      "get": {
        "operationId": "getPricing",
        "summary": "Current prices",
        "security": [],
        "responses": {
          "200": {
            "description": "Pricing",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/v1/tasks": {
      "post": {
        "operationId": "createTask",
        "summary": "Ask a human to rate one item or compare two",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Makes retries safe: the same key returns the same task and is charged once."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewTask"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Task created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Task"
                }
              }
            }
          },
          "400": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listTasks",
        "summary": "List recent tasks",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Tasks",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Task"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/tasks/{id}": {
      "get": {
        "operationId": "getTask",
        "summary": "Get a task and its result",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "wait",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 55
            },
            "description": "Seconds to hold the request open until the human answers."
          }
        ],
        "responses": {
          "200": {
            "description": "Task",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Task"
                }
              }
            }
          },
          "404": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "cancelTask",
        "summary": "Cancel a pending task and refund it",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Canceled task",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Task"
                }
              }
            }
          },
          "409": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/uploads": {
      "post": {
        "operationId": "upload",
        "summary": "Upload a media file and get a URL to use in an item",
        "requestBody": {
          "required": true,
          "content": {
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          },
          "description": "Raw bytes. Set Content-Type to the real media type, for example image/png. Max 25 MB."
        },
        "responses": {
          "201": {
            "description": "Uploaded",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string"
                    },
                    "mime_type": {
                      "type": "string"
                    },
                    "bytes": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "415": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/credits/checkout": {
      "post": {
        "operationId": "createCheckout",
        "summary": "Get a payment link to add credits",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount_cents"
                ],
                "properties": {
                  "amount_cents": {
                    "type": "integer",
                    "minimum": 500,
                    "maximum": 50000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Checkout link for the account owner to open",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "checkout_url": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key from POST /v1/signup"
      }
    },
    "schemas": {
      "Item": {
        "type": "object",
        "required": [
          "type"
        ],
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "text",
              "image",
              "video",
              "audio",
              "link"
            ]
          },
          "text": {
            "type": "string",
            "maxLength": 20000,
            "description": "For text items."
          },
          "url": {
            "type": "string",
            "description": "Public https URL, for media and links."
          },
          "data_base64": {
            "type": "string",
            "description": "Inline file contents instead of url."
          },
          "mime_type": {
            "type": "string",
            "description": "Required with data_base64."
          },
          "label": {
            "type": "string",
            "maxLength": 80
          }
        }
      },
      "NewTask": {
        "type": "object",
        "required": [
          "type",
          "question",
          "items"
        ],
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "rate",
              "compare"
            ],
            "description": "rate: one item scored 1-5. compare: two items, the human picks one."
          },
          "question": {
            "type": "string",
            "maxLength": 500,
            "description": "What the human should judge."
          },
          "context": {
            "type": "string",
            "maxLength": 2000,
            "description": "Audience, goal, constraints."
          },
          "items": {
            "type": "array",
            "minItems": 1,
            "maxItems": 2,
            "items": {
              "$ref": "#/components/schemas/Item"
            },
            "description": "Exactly 1 for rate, exactly 2 for compare (first is A, second is B)."
          },
          "metadata": {
            "type": "object",
            "description": "Returned unchanged. Not shown to the human."
          }
        }
      },
      "Task": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "rate",
              "compare"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "in_review",
              "completed",
              "expired",
              "canceled"
            ]
          },
          "question": {
            "type": "string"
          },
          "context": {
            "type": [
              "string",
              "null"
            ]
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Item"
            }
          },
          "result": {
            "type": [
              "object",
              "null"
            ],
            "description": "Null until completed.",
            "properties": {
              "choice": {
                "type": "string",
                "enum": [
                  "A",
                  "B",
                  "tie"
                ],
                "description": "compare only"
              },
              "winner_index": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "compare only: 0, 1 or null for a tie"
              },
              "score": {
                "type": "integer",
                "minimum": 1,
                "maximum": 5,
                "description": "rate only"
              },
              "comment": {
                "type": "string"
              },
              "answered_by": {
                "type": "string"
              }
            }
          },
          "price_cents": {
            "type": "integer"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "completed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}
