{
  "openapi": "3.1.0",
  "info": {
    "title": "Ephemeris API",
    "version": "1.0.0",
    "description": "Authenticated model discovery, balances, forecast execution, safe retries, costs, and usage history. Authenticate with an API key, or pay with Bittensor gamma and sign each request with your hotkey (btauth/1, receiver = a publisher hotkey from /services.json): no account or API key needed."
  },
  "servers": [
    {
      "url": "{baseUrl}",
      "variables": {
        "baseUrl": {
          "default": "https://api.cascade.industries"
        }
      }
    }
  ],
  "security": [
    {
      "apiKey": []
    },
    {
      "btauth": []
    }
  ],
  "paths": {
    "/api/v1/models": {
      "get": {
        "operationId": "listModels",
        "summary": "List available models with prices and context limits",
        "responses": {
          "200": {
            "description": "Model catalog",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Model"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "503": {
            "$ref": "#/components/responses/ProviderUnavailable"
          }
        }
      }
    },
    "/api/v1/balance": {
      "get": {
        "operationId": "getBalance",
        "summary": "Get the credits available to spend now",
        "responses": {
          "200": {
            "description": "Current balance",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Balance"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/v1/forecast": {
      "post": {
        "operationId": "runForecast",
        "summary": "Run and bill a forecast",
        "description": "Use the same Idempotency-Key when retrying an identical request. A completed retry returns the stored response without running or charging for the forecast again.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A unique 8-128 character retry key. Keys are scoped to the authenticated user.",
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9._:-]+$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ForecastRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Forecast completed",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/RequestId"
              },
              "Idempotency-Replayed": {
                "$ref": "#/components/headers/IdempotencyReplayed"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ForecastResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "description": "Not enough balance: no work was done. API-key callers get InsufficientCredits; btauth/1 callers get InsufficientBalance (error insufficient_balance).",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/InsufficientCredits"
                    },
                    {
                      "$ref": "#/components/schemas/InsufficientBalance"
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "Idempotency key conflict or request still processing",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/RequestId"
              },
              "Retry-After": {
                "description": "Seconds before retrying an in-progress request",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/ProviderUnavailable"
          }
        }
      }
    },
    "/api/v1/usage": {
      "get": {
        "operationId": "listUsage",
        "summary": "List billed forecast request history",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            }
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Usage page",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UsagePage"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/v1/device/code": {
      "post": {
        "operationId": "startDeviceLogin",
        "summary": "Start a sign-in from a terminal or agent (OAuth 2.0 device flow, RFC 8628); no API key needed",
        "description": "Returns a short user_code and a link. Show both to the person: they open the link, sign in or sign up, check the page shows the same code, and approve. Then poll /api/v1/device/token with device_code. Each network may start 10 sign-ins per 10 minutes.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "client"
                ],
                "properties": {
                  "client": {
                    "type": "string",
                    "pattern": "^[a-z0-9][a-z0-9._-]{0,39}$",
                    "description": "Short lowercase name of the tool asking, e.g. my-agent"
                  },
                  "name": {
                    "type": "string",
                    "maxLength": 80,
                    "description": "What the approval page shows, and the new key's name, e.g. my-agent on laptop"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Sign-in started",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "device_code",
                    "user_code",
                    "verification_uri",
                    "verification_uri_complete",
                    "expires_in",
                    "interval"
                  ],
                  "properties": {
                    "device_code": {
                      "type": "string",
                      "description": "Secret: keep it in the tool, never show it"
                    },
                    "user_code": {
                      "type": "string",
                      "example": "WDJB-MJHT",
                      "description": "Show this to the person"
                    },
                    "verification_uri": {
                      "type": "string",
                      "format": "uri"
                    },
                    "verification_uri_complete": {
                      "type": "string",
                      "format": "uri",
                      "description": "verification_uri with the code filled in: open this"
                    },
                    "expires_in": {
                      "type": "integer",
                      "example": 600
                    },
                    "interval": {
                      "type": "integer",
                      "example": 5,
                      "description": "Seconds between polls"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid client name",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeviceError"
                }
              }
            }
          },
          "429": {
            "description": "Too many sign-ins from this network; see Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeviceError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/device/token": {
      "post": {
        "operationId": "pollDeviceLogin",
        "summary": "Poll a sign-in; returns a new API key, exactly once, after the person approves",
        "description": "Poll every `interval` seconds. authorization_pending: keep waiting. slow_down: wait 5 seconds longer each time from now on. access_denied or expired_token: stop. The key appears on the dashboard API keys page under the name given, where it can be revoked.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "device_code"
                ],
                "properties": {
                  "device_code": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Approved: the new API key",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "key"
                  ],
                  "properties": {
                    "key": {
                      "type": "string",
                      "example": "pc_live_..."
                    },
                    "token_type": {
                      "type": "string",
                      "enum": [
                        "api_key"
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Not (yet) approved: error is authorization_pending, slow_down, access_denied, expired_token, invalid_grant or invalid_request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeviceError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/gamma/balance": {
      "get": {
        "operationId": "getGammaBalance",
        "summary": "Spendable balance of a hotkey account, in USD",
        "security": [],
        "parameters": [
          {
            "name": "hotkey",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "ss58 hotkey"
          }
        ],
        "responses": {
          "200": {
            "description": "Balance; zeros for a hotkey with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GammaBalance"
                }
              }
            }
          },
          "400": {
            "description": "Not an ss58 address"
          }
        }
      }
    },
    "/api/v1/pricing": {
      "get": {
        "operationId": "getPricing",
        "summary": "Prices per model and mode, in USD and millicredits",
        "security": [],
        "description": "Per series slot per block of up to 64 forecast steps. History length is free.",
        "responses": {
          "200": {
            "description": "Price list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "pc_live_...",
        "description": "Ephemeris application API key"
      },
      "btauth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Bittensor-Signature",
        "description": "Bittensor signed request, wire format btauth/1 (https://www.bittensor.com/docs/guides/signed-requests). Send X-Bittensor-Version: 1, X-Bittensor-Hotkey: <your sr25519 hotkey ss58>, X-Bittensor-Receiver: <a publisher hotkey from /services.json>, X-Bittensor-Nonce: <unix time in nanoseconds>, X-Bittensor-Signature: 0x<sr25519 signature>. Do not send X-Bittensor-Crypto (sr25519 only). The signature covers these eight lines joined by \\n: btauth/1, sr25519, METHOD, path?query as sent, sha256(raw body) lowercase hex, nonce, hotkey, receiver. Nonces must be within 10 s in the past or 2 s in the future and are accepted once. Balance comes from gamma spent at our service hotkey (spend_gamma); a valid signature from a hotkey with no balance gets 402 insufficient_balance.",
        "x-btauth": {
          "version": "1",
          "schemes": [
            "sr25519"
          ],
          "max_age_seconds": 10,
          "allowed_skew_seconds": 2,
          "receivers": "/services.json publishers[].hotkey"
        }
      }
    },
    "headers": {
      "RequestId": {
        "description": "Stable forecast request identifier used by usage logs and safe retries",
        "schema": {
          "type": "string",
          "pattern": "^req_[a-f0-9]{32}$"
        }
      },
      "IdempotencyReplayed": {
        "description": "True when a completed response was returned from the idempotency store",
        "schema": {
          "type": "string",
          "enum": [
            "true",
            "false"
          ]
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Invalid request",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing, invalid, or revoked API key",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Rate or capacity limit exceeded",
        "headers": {
          "Retry-After": {
            "description": "Seconds before retrying",
            "schema": {
              "type": "integer"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "ProviderUnavailable": {
        "description": "Forecasting or pricing is temporarily unavailable",
        "headers": {
          "Retry-After": {
            "description": "Seconds before retrying",
            "schema": {
              "type": "integer"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          }
        }
      },
      "Balance": {
        "type": "object",
        "required": [
          "balance_mc",
          "active_holds_mc"
        ],
        "properties": {
          "balance_mc": {
            "type": "string",
            "pattern": "^-?[0-9]+$"
          },
          "active_holds_mc": {
            "type": "string",
            "pattern": "^[0-9]+$"
          }
        }
      },
      "Model": {
        "type": "object",
        "required": [
          "name",
          "price_per_kslot_mc",
          "billing_context_cap"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "price_per_kslot_mc": {
            "type": [
              "string",
              "null"
            ],
            "description": "Millicredits per target series-slot per 64 forecast steps. No history-length multiplier."
          },
          "billing_context_cap": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Legacy field, now null. History does not affect pricing; model input limits still apply."
          },
          "billing_horizon_steps": {
            "type": "integer",
            "enum": [
              64
            ],
            "description": "Number of forecast steps per billing block, rounded up."
          },
          "billing_unit": {
            "type": "string",
            "enum": [
              "millicredits_per_series_slot_per_horizon_block"
            ]
          }
        },
        "additionalProperties": true
      },
      "ForecastSeries": {
        "type": "object",
        "required": [
          "values"
        ],
        "properties": {
          "values": {
            "oneOf": [
              {
                "type": "array",
                "minItems": 1,
                "items": {
                  "type": "number"
                }
              },
              {
                "type": "array",
                "minItems": 1,
                "items": {
                  "type": "array",
                  "minItems": 1,
                  "items": {
                    "type": "number"
                  }
                }
              }
            ]
          },
          "freq": {
            "type": "string",
            "minLength": 1,
            "description": "Optional per-series frequency. Mixed-frequency batches are split into compatible upstream calls and reassembled in request order."
          },
          "covariates": {
            "$ref": "#/components/schemas/SeriesCovariates"
          }
        },
        "additionalProperties": true
      },
      "SeriesCovariates": {
        "type": "object",
        "required": [
          "past"
        ],
        "properties": {
          "past": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "number"
              }
            },
            "description": "Named historical channels aligned to the series context length."
          },
          "future": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "number"
              }
            },
            "description": "Optional known-future channels aligned to the requested horizon. Every future channel must also have past history."
          }
        },
        "additionalProperties": false
      },
      "ForecastRequest": {
        "type": "object",
        "required": [
          "mode",
          "series"
        ],
        "properties": {
          "mode": {
            "type": "string",
            "enum": [
              "explicit",
              "ensemble",
              "route"
            ]
          },
          "model": {
            "type": "string"
          },
          "series": {
            "type": "array",
            "minItems": 1,
            "maxItems": 64,
            "items": {
              "$ref": "#/components/schemas/ForecastSeries"
            }
          },
          "context_len": {
            "type": "integer",
            "minimum": 1,
            "maximum": 16384
          },
          "horizon": {
            "type": "integer",
            "minimum": 1,
            "maximum": 4096,
            "description": "Maximum 4096 steps. Slots x horizon x quantiles must not exceed 120000 output values; omitted or empty quantiles are budgeted as 21."
          },
          "quantiles": {
            "type": "array",
            "maxItems": 21,
            "items": {
              "type": "number",
              "exclusiveMinimum": 0,
              "exclusiveMaximum": 1
            }
          },
          "top_k": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 16,
            "description": "Optional ensemble-only limit on the number of models."
          },
          "combine": {
            "type": "string",
            "enum": [
              "mixture",
              "vincentize"
            ],
            "description": "Optional ensemble combination method."
          }
        },
        "additionalProperties": true
      },
      "ForecastResponse": {
        "type": "object",
        "required": [
          "meta"
        ],
        "properties": {
          "meta": {
            "type": "object",
            "required": [
              "gateway_request_id",
              "billing"
            ],
            "properties": {
              "gateway_request_id": {
                "type": "string"
              },
              "request_id": {
                "type": "string"
              },
              "models_used": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "upstream_request_ids": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "Model request IDs when a mixed-frequency request is split into compatible groups."
              },
              "upstream_calls": {
                "type": "integer",
                "minimum": 1
              },
              "billing": {
                "type": "object",
                "required": [
                  "settled_mc",
                  "balance_mc"
                ],
                "properties": {
                  "settled_mc": {
                    "type": "string"
                  },
                  "balance_mc": {
                    "type": "string"
                  }
                }
              }
            },
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      },
      "InsufficientCredits": {
        "type": "object",
        "required": [
          "error",
          "balance_mc",
          "required_mc",
          "topup_url"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "balance_mc": {
            "type": "string"
          },
          "required_mc": {
            "type": "string"
          },
          "topup_url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "UsageRow": {
        "type": "object",
        "required": [
          "requestId"
        ],
        "properties": {
          "requestId": {
            "type": "string"
          },
          "paracastRequestId": {
            "type": [
              "string",
              "null"
            ]
          },
          "estimatedMc": {
            "type": [
              "string",
              "null"
            ]
          },
          "settledMc": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": [
              "integer",
              "null"
            ]
          }
        },
        "additionalProperties": true
      },
      "UsagePage": {
        "type": "object",
        "required": [
          "data",
          "pagination"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/UsageRow"
            }
          },
          "limit": {
            "type": "integer"
          },
          "offset": {
            "type": "integer"
          },
          "pagination": {
            "type": "object",
            "required": [
              "limit",
              "offset",
              "returned",
              "has_more",
              "next_offset"
            ],
            "properties": {
              "limit": {
                "type": "integer"
              },
              "offset": {
                "type": "integer"
              },
              "returned": {
                "type": "integer"
              },
              "has_more": {
                "type": "boolean"
              },
              "next_offset": {
                "type": [
                  "integer",
                  "null"
                ]
              }
            }
          }
        }
      },
      "DeviceError": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "enum": [
              "authorization_pending",
              "slow_down",
              "access_denied",
              "expired_token",
              "invalid_grant",
              "invalid_request"
            ]
          },
          "error_description": {
            "type": "string"
          }
        }
      },
      "InsufficientBalance": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "enum": [
              "insufficient_balance"
            ]
          },
          "message": {
            "type": "string"
          },
          "balance_mc": {
            "type": "string"
          },
          "required_mc": {
            "type": "string"
          }
        }
      },
      "GammaBalance": {
        "type": "object",
        "required": [
          "hotkey",
          "credited_usd",
          "used_usd",
          "remaining_usd"
        ],
        "properties": {
          "hotkey": {
            "type": "string"
          },
          "credited_usd": {
            "type": "string",
            "description": "Everything credited, decimal USD"
          },
          "used_usd": {
            "type": "string"
          },
          "remaining_usd": {
            "type": "string",
            "description": "Total spendable balance, decimal USD"
          }
        }
      }
    }
  }
}
