{
  "openapi": "3.1.0",
  "info": {
    "title": "AnySound API",
    "version": "1",
    "description": "Identify a short sound. Send a 5 to 30 second recording, poll the job, read a ranked result with its measured evidence. Authenticate with an API key (Authorization: Bearer KEY or X-API-Key). One analysis is billed only when it is delivered as matched or partial_match, after it succeeds."
  },
  "servers": [
    {
      "url": "/"
    }
  ],
  "security": [
    {
      "bearer": []
    },
    {
      "apiKey": []
    }
  ],
  "paths": {
    "/api/v1/jobs": {
      "post": {
        "summary": "Start an analysis",
        "operationId": "createJob",
        "tags": [
          "Jobs"
        ],
        "description": "Multipart upload of one recording. Repeating a request with the same Idempotency-Key returns the same job and never a second charge.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "audio"
                ],
                "properties": {
                  "audio": {
                    "type": "string",
                    "format": "binary",
                    "description": "WAV, MP3, M4A, OGG, FLAC or WebM, 5 to 30 seconds."
                  },
                  "context": {
                    "type": "string",
                    "description": "JSON object: category, region, vehicle, moving, setting, note. Unverified hints."
                  },
                  "title": {
                    "type": "string"
                  },
                  "language": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Accepted"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "402": {
            "description": "Prepaid wallet is empty",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "No subscription to this tool",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "413": {
            "description": "File too large",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "415": {
            "description": "Unsupported audio type",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Recording unusable; includes kind and duration_s",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Hourly limit reached",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/jobs/{id}": {
      "get": {
        "summary": "Read a job",
        "operationId": "getJob",
        "tags": [
          "Jobs"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The job",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "No such job",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Cancel or delete a job",
        "operationId": "deleteJob",
        "tags": [
          "Jobs"
        ],
        "description": "A queued job is cancelled. A finished job's result, history and shares are deleted (a charged job keeps a billing record with no content). A running job returns 409.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "No such job",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "The job is running",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      },
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      }
    },
    "schemas": {
      "Accepted": {
        "type": "object",
        "required": [
          "id",
          "status"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running"
            ]
          },
          "poll": {
            "type": "string"
          }
        }
      },
      "Job": {
        "type": "object",
        "required": [
          "id",
          "status"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "succeeded",
              "failed"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "billed": {
            "type": "boolean"
          },
          "result": {
            "$ref": "#/components/schemas/Result"
          },
          "result_expired": {
            "type": "boolean"
          },
          "error": {
            "$ref": "#/components/schemas/JobError"
          }
        }
      },
      "JobError": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string"
          },
          "detail": {
            "type": "string"
          },
          "retry_advice": {
            "type": "string"
          }
        }
      },
      "Result": {
        "type": "object",
        "description": "The delivered result. Confidence is evidence support from 0 to 10, never a probability.",
        "required": [
          "status",
          "candidates"
        ],
        "properties": {
          "schema_version": {
            "type": "string"
          },
          "duration_s": {
            "type": "number"
          },
          "status": {
            "type": "string",
            "enum": [
              "matched",
              "partial_match",
              "unknown",
              "poor_quality"
            ]
          },
          "quality": {
            "type": "object"
          },
          "candidates": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "$ref": "#/components/schemas/Candidate"
            }
          },
          "events": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "next_step": {
            "type": "string"
          },
          "heard_audio": {
            "type": "boolean"
          },
          "checks": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "versions": {
            "type": "object"
          },
          "context": {
            "type": "object"
          },
          "disclaimer": {
            "type": "string"
          }
        }
      },
      "Candidate": {
        "type": "object",
        "properties": {
          "rank": {
            "type": "integer"
          },
          "event_id": {
            "type": "string"
          },
          "taxonomy_id": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "category": {
            "type": "string"
          },
          "granularity": {
            "type": "string"
          },
          "confidence": {
            "type": "number",
            "minimum": 0,
            "maximum": 10
          },
          "support": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "evidence": {
            "type": "string"
          },
          "uncertainty": {
            "type": "string"
          },
          "cues": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "alternative": {
            "type": "boolean"
          },
          "reference": {
            "type": [
              "object",
              "null"
            ]
          },
          "caution": {
            "type": "string"
          }
        }
      },
      "Problem": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "instance": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "kind": {
            "type": "string"
          },
          "duration_s": {
            "type": "number"
          },
          "top_up_url": {
            "type": "string"
          },
          "subscribe_url": {
            "type": "string"
          }
        }
      }
    }
  }
}