{
  "openapi": "3.1.0",
  "info": {
    "title": "CreationLoop run reporting",
    "version": "1",
    "description": "An agent reports each job with four calls: describe, start, gate and end. Send describe one time before the first job. For each job, make a new random run ID and send it on every call of that job. Send the calls of one run one at a time, in order. Wait up to 30 seconds for an answer. With no answer, or a 429 or a 503, send the exact same body again, at most 4 tries in all. Never send a call again after any other 4xx. Reporting never stops or changes the job: if a report still fails, go on with the work. The key is sent only in the Authorization header. Never put it in a prompt, a chat, a repository, a log or an address. The whole method is at https://creationloop.ai/connect.md."
  },
  "servers": [
    {
      "url": "https://events.creationloop.ai"
    }
  ],
  "security": [
    {
      "reportingKey": []
    }
  ],
  "paths": {
    "/v1/runs/describe": {
      "post": {
        "operationId": "report_describe",
        "summary": "Read the gates the owner chose",
        "description": "Send this before the first job. It answers the gate version, the phase, and the gates the owner chose, each with its ID, its name and whether it is required. It records nothing.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {},
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The gate version, the phase and the gates.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Described"
                }
              }
            }
          },
          "400": {
            "description": "A field is wrong, and the answer names it. Fix it. Do not send the same body again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            }
          },
          "401": {
            "description": "The key is missing or not known: key_required or key_not_recognized. Stop reporting and ask the owner.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            }
          },
          "403": {
            "description": "The key cannot report here: key_not_active or key_out_of_scope, or the workspace of the owner cannot report now. Stop reporting and tell the owner.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            }
          },
          "409": {
            "description": "The call does not fit the run: run_exists, gate_conflict, run_ended or run_not_started. On run_not_started, send the start and then this call again. On the others, make a new run ID for a new job.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            }
          },
          "413": {
            "description": "The body is too large. Send a fingerprint in place of text.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            }
          },
          "429": {
            "description": "Too many calls. Wait, then send the same body again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "The seconds to wait before the same body is sent again.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "503": {
            "description": "Busy. Wait, then send the same body again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "The seconds to wait before the same body is sent again.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    },
    "/v1/runs/start": {
      "post": {
        "operationId": "report_run_start",
        "summary": "Report that a run started",
        "description": "Send this one time when a job starts, before the work. Send the fingerprint of the input, or the input text: one of inputSha256 or inputText is required. Sending it again with the same body records nothing new.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "runId": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9._:-]{1,128}$",
                    "description": "The run ID you made for this job. Make a new random one for every job and never use it for another job. Send the same one on every call and every resend of the job."
                  },
                  "inputSha256": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$",
                    "description": "The SHA-256 fingerprint of the input, as 64 lower case hex characters. Send it only if a tool computed it. Never guess one."
                  },
                  "inputText": {
                    "type": "string",
                    "description": "The exact input, as text. Use this when you cannot compute SHA-256 yourself. CreationLoop makes the fingerprint on arrival and does not store the text."
                  },
                  "agentVersion": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9._:-]{1,128}$",
                    "description": "The version of the agent, if it has one."
                  }
                },
                "required": [
                  "runId"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Recorded.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Recorded"
                }
              }
            }
          },
          "200": {
            "description": "The same body was recorded before. The answer is the first answer again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Recorded"
                }
              }
            }
          },
          "400": {
            "description": "A field is wrong, and the answer names it. Fix it. Do not send the same body again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            }
          },
          "401": {
            "description": "The key is missing or not known: key_required or key_not_recognized. Stop reporting and ask the owner.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            }
          },
          "403": {
            "description": "The key cannot report here: key_not_active or key_out_of_scope, or the workspace of the owner cannot report now. Stop reporting and tell the owner.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            }
          },
          "409": {
            "description": "The call does not fit the run: run_exists, gate_conflict, run_ended or run_not_started. On run_not_started, send the start and then this call again. On the others, make a new run ID for a new job.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            }
          },
          "413": {
            "description": "The body is too large. Send a fingerprint in place of text.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            }
          },
          "429": {
            "description": "Too many calls. Wait, then send the same body again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "The seconds to wait before the same body is sent again.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "503": {
            "description": "Busy. Wait, then send the same body again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "The seconds to wait before the same body is sent again.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    },
    "/v1/runs/gate": {
      "post": {
        "operationId": "report_gate",
        "summary": "Report that a gate was reached",
        "description": "Send this when the job really reaches one of the gates the owner chose. You can add the fingerprint, or the text, of what the job made at this gate. Each gate is reported one time in a run. Sending it again with the same body records nothing new.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "runId": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9._:-]{1,128}$",
                    "description": "The run ID you made for this job. Make a new random one for every job and never use it for another job. Send the same one on every call and every resend of the job."
                  },
                  "gateId": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9._:-]{1,128}$",
                    "description": "The ID of the gate the job reached, as describe lists it."
                  },
                  "artifactSha256": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$",
                    "description": "The SHA-256 fingerprint of what the job made at this gate, as 64 lower case hex characters. Send it only if a tool computed it. Never guess one."
                  },
                  "artifactText": {
                    "type": "string",
                    "description": "The exact result at this gate, as text. Use this when you cannot compute SHA-256 yourself. CreationLoop makes the fingerprint on arrival and does not store the text."
                  }
                },
                "required": [
                  "runId",
                  "gateId"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Recorded.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Recorded"
                }
              }
            }
          },
          "200": {
            "description": "The same body was recorded before. The answer is the first answer again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Recorded"
                }
              }
            }
          },
          "400": {
            "description": "A field is wrong, and the answer names it. Fix it. Do not send the same body again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            }
          },
          "401": {
            "description": "The key is missing or not known: key_required or key_not_recognized. Stop reporting and ask the owner.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            }
          },
          "403": {
            "description": "The key cannot report here: key_not_active or key_out_of_scope, or the workspace of the owner cannot report now. Stop reporting and tell the owner.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            }
          },
          "409": {
            "description": "The call does not fit the run: run_exists, gate_conflict, run_ended or run_not_started. On run_not_started, send the start and then this call again. On the others, make a new run ID for a new job.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            }
          },
          "413": {
            "description": "The body is too large. Send a fingerprint in place of text.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            }
          },
          "429": {
            "description": "Too many calls. Wait, then send the same body again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "The seconds to wait before the same body is sent again.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "503": {
            "description": "Busy. Wait, then send the same body again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "The seconds to wait before the same body is sent again.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    },
    "/v1/runs/end": {
      "post": {
        "operationId": "report_run_end",
        "summary": "Report that a run ended",
        "description": "Send this one time when the job is done or has failed. For a delivered run, send the fingerprint of the final output, or the output text, or outputNotFingerprinted true when you cannot do either. Nothing can be reported for the run after this.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "runId": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9._:-]{1,128}$",
                    "description": "The run ID you made for this job. Make a new random one for every job and never use it for another job. Send the same one on every call and every resend of the job."
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "delivered",
                      "failed"
                    ],
                    "description": "delivered when the job made its output, failed when it did not."
                  },
                  "outputSha256": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$",
                    "description": "The SHA-256 fingerprint of the final output, as 64 lower case hex characters. Send it only if a tool computed it. Never guess one."
                  },
                  "outputText": {
                    "type": "string",
                    "description": "The exact final output, as text. Use this when you cannot compute SHA-256 yourself. CreationLoop makes the fingerprint on arrival and does not store the text."
                  },
                  "outputNotFingerprinted": {
                    "type": "boolean",
                    "enum": [
                      true
                    ],
                    "description": "Send true when no fingerprint and no text of the output can be sent, for example for a video. The receipt then says that no file is tied to the run."
                  },
                  "knownCostCents": {
                    "type": "integer",
                    "minimum": 0,
                    "description": "What the run cost in cents, if you know it."
                  }
                },
                "required": [
                  "runId",
                  "status"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Recorded.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Recorded"
                }
              }
            }
          },
          "200": {
            "description": "The same body was recorded before. The answer is the first answer again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Recorded"
                }
              }
            }
          },
          "400": {
            "description": "A field is wrong, and the answer names it. Fix it. Do not send the same body again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            }
          },
          "401": {
            "description": "The key is missing or not known: key_required or key_not_recognized. Stop reporting and ask the owner.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            }
          },
          "403": {
            "description": "The key cannot report here: key_not_active or key_out_of_scope, or the workspace of the owner cannot report now. Stop reporting and tell the owner.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            }
          },
          "409": {
            "description": "The call does not fit the run: run_exists, gate_conflict, run_ended or run_not_started. On run_not_started, send the start and then this call again. On the others, make a new run ID for a new job.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            }
          },
          "413": {
            "description": "The body is too large. Send a fingerprint in place of text.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            }
          },
          "429": {
            "description": "Too many calls. Wait, then send the same body again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "The seconds to wait before the same body is sent again.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "503": {
            "description": "Busy. Wait, then send the same body again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refusal"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "The seconds to wait before the same body is sent again.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "reportingKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "The reporting key the owner made at https://creationloop.ai/connect/setup. It starts with clk_. Keep it in a secret setting."
      }
    },
    "schemas": {
      "Described": {
        "type": "object",
        "required": [
          "gateVersion",
          "phase",
          "gates"
        ],
        "properties": {
          "loopName": {
            "type": [
              "string",
              "null"
            ],
            "description": "The name the owner gave this work."
          },
          "gateVersion": {
            "type": "integer",
            "description": "The number of the saved gate version this key reports for."
          },
          "phase": {
            "type": "string",
            "enum": [
              "test",
              "live"
            ]
          },
          "gates": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "name",
                "required"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "description": "Send this as gateId when the job reaches the gate."
                },
                "name": {
                  "type": "string"
                },
                "required": {
                  "type": "boolean",
                  "description": "Whether a run must report this gate to be complete."
                }
              }
            }
          },
          "next": {
            "type": "string",
            "description": "One plain sentence that says which call can come next."
          }
        }
      },
      "Recorded": {
        "type": "object",
        "required": [
          "runId",
          "receiptId",
          "messageId",
          "recordedAt"
        ],
        "properties": {
          "runId": {
            "type": "string"
          },
          "receiptId": {
            "type": "string"
          },
          "messageId": {
            "type": "string"
          },
          "recordedAt": {
            "type": "string",
            "format": "date-time"
          },
          "next": {
            "type": "string",
            "description": "One plain sentence that says which call can come next."
          }
        }
      },
      "Refusal": {
        "type": "object",
        "required": [
          "code"
        ],
        "properties": {
          "code": {
            "type": "string",
            "description": "Why the call was refused, for example key_not_active, run_not_started or run_ended."
          },
          "field": {
            "type": "string",
            "description": "The field that is wrong, when one field is wrong."
          }
        }
      }
    }
  }
}
