{
  "openapi": "3.1.0",
  "info": {
    "title": "Pretick Forecasting API",
    "version": "1.1.1",
    "description": "Numerical time-series forecasting. Five free forecasts by emailed trial key; $0.02 per successful bounded request thereafter. No model training on submitted data.",
    "contact": {
      "email": "es@textmei.com",
      "url": "https://pretick.ai/docs"
    }
  },
  "servers": [
    {
      "url": "https://pretick.ai"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/timeseries/forecast": {
      "post": {
        "operationId": "forecast",
        "summary": "Forecast the next numeric values",
        "description": "Synchronous forecasting; maximum payload 400,000 bytes. No idempotent retries: each successful call is billable. Busy/failed inference returns credit. Targets are jointly forecast; other history columns are past-only covariates.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "type": "object",
                    "additionalProperties": false,
                    "required": [
                      "data"
                    ],
                    "properties": {
                      "data": {
                        "description": "3-1,024 observations: delimited values, time/value pairs in two columns or two rows, or a numeric array. Slash dates are month/day[/year]; no-year dates start in the current year. Times must be regular. Alternating date/value lines are accepted. Weekday-only daily observations with weekend gaps and occasional skipped dates infer a weekday schedule; no gaps are filled. Future weekends are skipped, but holidays are not excluded.",
                        "oneOf": [
                          {
                            "type": "string",
                            "maxLength": 400000
                          },
                          {
                            "type": "array",
                            "minItems": 3,
                            "maxItems": 1024,
                            "items": {
                              "type": "number",
                              "minimum": -1000000000000,
                              "maximum": 1000000000000
                            }
                          }
                        ]
                      },
                      "horizon": {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 1024,
                        "description": "Optional: defaults to number of input observations."
                      },
                      "frequency": {
                        "type": "string",
                        "pattern": "^[1-9][0-9]*(s|min|h|d|w)$",
                        "maxLength": 24,
                        "example": "1d"
                      },
                      "model": {
                        "type": "string",
                        "enum": [
                          "pretick-default"
                        ],
                        "default": "pretick-default"
                      }
                    }
                  },
                  {
                    "type": "object",
                    "additionalProperties": false,
                    "required": [
                      "history",
                      "frequency",
                      "targets",
                      "horizon"
                    ],
                    "properties": {
                      "model": {
                        "type": "string",
                        "enum": [
                          "pretick-default"
                        ],
                        "default": "pretick-default"
                      },
                      "history": {
                        "type": "object",
                        "additionalProperties": false,
                        "required": [
                          "columns",
                          "values"
                        ],
                        "properties": {
                          "columns": {
                            "type": "array",
                            "minItems": 1,
                            "maxItems": 8,
                            "uniqueItems": true,
                            "items": {
                              "type": "string",
                              "minLength": 1,
                              "maxLength": 64
                            }
                          },
                          "values": {
                            "type": "array",
                            "minItems": 3,
                            "maxItems": 2048,
                            "description": "Oldest first, evenly spaced. Each row must match the column count.",
                            "items": {
                              "type": "array",
                              "minItems": 1,
                              "maxItems": 8,
                              "items": {
                                "type": "number",
                                "minimum": -1000000000000,
                                "maximum": 1000000000000
                              }
                            }
                          }
                        }
                      },
                      "frequency": {
                        "type": "string",
                        "pattern": "^[1-9][0-9]*(s|min|h|d|w)$",
                        "maxLength": 24,
                        "example": "1d"
                      },
                      "targets": {
                        "type": "array",
                        "minItems": 1,
                        "maxItems": 8,
                        "uniqueItems": true,
                        "items": {
                          "type": "string"
                        },
                        "description": "Names from history.columns; forecast jointly. Other columns are historical covariates."
                      },
                      "horizon": {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 1024
                      },
                      "quantiles": {
                        "type": "array",
                        "minItems": 1,
                        "maxItems": 9,
                        "uniqueItems": true,
                        "description": "Strictly increasing.",
                        "items": {
                          "type": "number",
                          "minimum": 0.1,
                          "maximum": 0.9
                        },
                        "default": [
                          0.1,
                          0.5,
                          0.9
                        ]
                      }
                    }
                  }
                ]
              },
              "examples": {
                "simple": {
                  "value": {
                    "data": "102, 108, 111, 104, 99, 106"
                  }
                },
                "timeAndValue": {
                  "value": {
                    "data": "key,value\n1,102\n2,108\n3,111"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "One forecast per target. Quantiles are estimates, not guaranteed coverage.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "predictions",
                    "prediction_columns",
                    "forecasts",
                    "model_version",
                    "request_id",
                    "cost_cents",
                    "balance_cents"
                  ],
                  "properties": {
                    "predictions": {
                      "description": "Best-guess median forecast. Flat array for one target; row matrix for multiple targets in prediction_columns order.",
                      "oneOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "number"
                          }
                        },
                        {
                          "type": "array",
                          "items": {
                            "type": "array",
                            "items": {
                              "type": "number"
                            }
                          }
                        }
                      ]
                    },
                    "times": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Present for time/value input. Continued time labels aligned with predictions."
                    },
                    "prediction_columns": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "model": {
                      "type": "string"
                    },
                    "model_version": {
                      "type": "string"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "frequency": {
                      "type": "string"
                    },
                    "horizon": {
                      "type": "integer"
                    },
                    "forecasts": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "target": {
                            "type": "string"
                          },
                          "median": {
                            "type": "array",
                            "items": {
                              "type": "number"
                            }
                          },
                          "quantiles": {
                            "type": "object",
                            "additionalProperties": {
                              "type": "array",
                              "items": {
                                "type": "number"
                              }
                            }
                          }
                        }
                      }
                    },
                    "usage": {
                      "type": "object",
                      "properties": {
                        "input_rows": {
                          "type": "integer"
                        },
                        "input_columns": {
                          "type": "integer"
                        },
                        "output_values": {
                          "type": "integer"
                        },
                        "inference_ms": {
                          "type": "integer"
                        }
                      }
                    },
                    "cost_cents": {
                      "type": "integer",
                      "const": 2
                    },
                    "balance_cents": {
                      "type": "integer"
                    },
                    "time_schedule": {
                      "type": "string",
                      "description": "Present when weekday scheduling was inferred. Explains weekend exclusion, no holiday calendar, and preserving observations without filling gaps."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Request or service error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "detail": {
                      "type": "string"
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "refunded": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Request or service error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "detail": {
                      "type": "string"
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "refunded": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "402": {
            "description": "Request or service error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "detail": {
                      "type": "string"
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "refunded": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "413": {
            "description": "Request or service error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "detail": {
                      "type": "string"
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "refunded": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Request or service error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "detail": {
                      "type": "string"
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "refunded": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/usage": {
      "get": {
        "operationId": "usage",
        "summary": "Balance and latest 100 accounting records",
        "responses": {
          "200": {
            "description": "Account usage",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "account": {
                      "type": "string"
                    },
                    "balance_cents": {
                      "type": "integer"
                    },
                    "recent_cost_cents": {
                      "type": "integer"
                    },
                    "recent": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "pending",
                              "succeeded",
                              "refunded"
                            ]
                          },
                          "cost_cents": {
                            "type": "integer"
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Request or service error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "detail": {
                      "type": "string"
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "refunded": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/trial": {
      "post": {
        "operationId": "requestTrial",
        "security": [],
        "summary": "Email a key with five free forecasts",
        "description": "One trial per eligible email, signup rate limits apply. The key is sent to the provided email, never in this response. Existing customers keep their original key.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "maxLength": 254
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Check email if eligible",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Request or service error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "detail": {
                      "type": "string"
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "refunded": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Request or service error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "detail": {
                      "type": "string"
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "refunded": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Request or service error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "detail": {
                      "type": "string"
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "refunded": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/stripe/checkout": {
      "post": {
        "operationId": "createCheckout",
        "security": [],
        "summary": "Create a prepaid credit checkout",
        "description": "A human must complete Stripe Checkout. Use the same email as the trial to top up that key. Never use real payment details in test flows.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "type": "object",
                    "required": [
                      "bundle"
                    ],
                    "properties": {
                      "bundle": {
                        "const": "start",
                        "type": "string"
                      }
                    }
                  },
                  {
                    "type": "object",
                    "required": [
                      "amount_cents"
                    ],
                    "properties": {
                      "amount_cents": {
                        "type": "integer",
                        "minimum": 1000,
                        "maximum": 500000
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Hosted checkout URL",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string",
                      "format": "uri"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Request or service error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "detail": {
                      "type": "string"
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "refunded": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Request or service error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "detail": {
                      "type": "string"
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "refunded": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "pretick_live_…"
      }
    }
  }
}
