{
  "openapi": "3.1.0",
  "info": {"title": "moneypot", "version": "0.1.0"},
  "servers": [{"url": "https://obskura.ai"}],
  "paths": {
    "/healthz": {
      "get": {
        "operationId": "healthz",
        "summary": "Liveness check",
        "responses": {
          "200": {
            "description": "The service is up.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {"ok": {"type": "boolean"}},
                  "required": ["ok"]
                }
              }
            }
          },
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/v1/accounts": {
      "post": {
        "operationId": "createAccount",
        "summary": "Create an account and an API key instantly",
        "description": "No email or phone verification and no challenge. The API key is shown once, in this response; only its hash is stored.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {"schema": {"$ref": "#/components/schemas/CreateInput"}},
            "application/x-www-form-urlencoded": {
              "schema": {"$ref": "#/components/schemas/CreateInput"}
            }
          }
        },
        "responses": {
          "201": {
            "description": "Account and key created.",
            "content": {
              "application/json": {"schema": {"$ref": "#/components/schemas/Created"}}
            }
          },
          "400": {"$ref": "#/components/responses/Problem"},
          "415": {"$ref": "#/components/responses/Problem"},
          "429": {
            "$ref": "#/components/responses/RateLimited",
            "description": "Over the per-minute limit for this traffic class, or over the signup burst guard: at most 10 new accounts per address per minute (detail \"too many new accounts from this address in the last minute\", Retry-After 60). There is no daily quota. Requests are never challenged; wait and retry."
          }
        }
      }
    },
    "/v1/me": {
      "get": {
        "operationId": "me",
        "summary": "Describe the calling API key",
        "security": [{"bearer": []}],
        "responses": {
          "200": {
            "description": "The key and account behind the bearer token.",
            "content": {
              "application/json": {"schema": {"$ref": "#/components/schemas/Me"}}
            }
          },
          "401": {"$ref": "#/components/responses/Problem"},
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/v1/billing/setup": {
      "post": {
        "operationId": "billingSetup",
        "summary": "Start a Stripe Checkout session to save a card",
        "description": "Open the returned URL in a browser to attach a card in Stripe test mode. Once the card is saved, keys on the account with a zero monthly cap get a cap of 1000 cents.",
        "security": [{"bearer": []}],
        "responses": {
          "200": {
            "description": "A Stripe Checkout URL in setup mode. The session expires 2 hours after it is created. A new request replaces an open session: the previous URL is expired and a fresh one is returned.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {"url": {"type": "string", "format": "uri"}},
                  "required": ["url"]
                }
              }
            }
          },
          "401": {"$ref": "#/components/responses/Problem"},
          "429": {
            "$ref": "#/components/responses/RateLimited",
            "description": "Over the per-minute limit for this traffic class, or refused by a card setup rule, checked in this sequence: at most five sessions per account per rolling 24 hours (detail \"too many card setup sessions for this account in the last 24 hours\", Retry-After 3600); a pause for an address whose sessions from the last 24 hours carry 5 or more card failures reported by Stripe (detail \"card setup is paused for this address\", Retry-After 3600)."
          },
          "503": {"$ref": "#/components/responses/Problem"}
        }
      }
    },
    "/v1/macro/regions": {
      "get": {
        "operationId": "macroRegions",
        "summary": "List macro brief regions, live and proposed",
        "description": "Every region with its status, the latest brief date for live ones, the interest count and the page, brief and interest URLs. No key needed.",
        "responses": {
          "200": {
            "description": "The regions, the live Australian region first.",
            "content": {
              "application/json": {
                "schema": {"type": "array", "items": {"$ref": "#/components/schemas/MacroRegion"}}
              }
            }
          },
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/v1/macro/{region}/brief": {
      "get": {
        "operationId": "macroBrief",
        "summary": "The latest published brief for a region, or an archive edition",
        "description": "Without date: the latest brief. A keyless caller gets one per UTC day; after that send Authorization: Bearer mp_.... With date: an archive edition, key required, counted against the 1000 calls a month allowance. Accept: text/markdown returns the markdown; the default is JSON. A proposed region answers 402 with item_status proposed, the price it would carry and a register_interest URL. General information about economies and markets, not financial advice.",
        "security": [{}, {"bearer": []}],
        "parameters": [
          {"$ref": "#/components/parameters/Region"},
          {"name": "date", "in": "query", "description": "Archive edition, YYYY-MM-DD; requires a key.", "schema": {"type": "string", "format": "date"}}
        ],
        "responses": {
          "200": {
            "description": "The brief envelope, or its markdown with Accept: text/markdown.",
            "content": {
              "application/json": {"schema": {"$ref": "#/components/schemas/MacroBrief"}},
              "text/markdown": {"schema": {"type": "string"}}
            }
          },
          "400": {"$ref": "#/components/responses/Problem"},
          "401": {"$ref": "#/components/responses/Problem"},
          "402": {"$ref": "#/components/responses/Problem"},
          "404": {"$ref": "#/components/responses/Problem"},
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/v1/macro/{region}/calendar": {
      "get": {
        "operationId": "macroCalendar",
        "summary": "Scheduled releases and decisions for a region",
        "description": "Events from from to to inclusive; the default is the next 14 days and the range is at most 90 days. Key required; each call counts against the monthly allowance.",
        "security": [{"bearer": []}],
        "parameters": [
          {"$ref": "#/components/parameters/Region"},
          {"name": "from", "in": "query", "schema": {"type": "string", "format": "date"}},
          {"name": "to", "in": "query", "schema": {"type": "string", "format": "date"}}
        ],
        "responses": {
          "200": {
            "description": "Events, earliest first. A moved event carries previous_starts_at.",
            "content": {
              "application/json": {
                "schema": {"type": "array", "items": {"$ref": "#/components/schemas/MacroEvent"}}
              }
            }
          },
          "400": {"$ref": "#/components/responses/Problem"},
          "401": {"$ref": "#/components/responses/Problem"},
          "402": {"$ref": "#/components/responses/Problem"},
          "404": {"$ref": "#/components/responses/Problem"},
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/v1/macro/{region}/series": {
      "get": {
        "operationId": "macroRegionSeries",
        "summary": "The servable data series behind a region's brief",
        "description": "Each series with its licence, attribution and latest value. Cite-only series are left out. Key required; each call counts against the monthly allowance.",
        "security": [{"bearer": []}],
        "parameters": [{"$ref": "#/components/parameters/Region"}],
        "responses": {
          "200": {
            "description": "The series list.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "series": {"type": "array", "items": {"$ref": "#/components/schemas/MacroSeries"}}
                  }
                }
              }
            }
          },
          "401": {"$ref": "#/components/responses/Problem"},
          "402": {"$ref": "#/components/responses/Problem"},
          "404": {"$ref": "#/components/responses/Problem"},
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/v1/macro/series/{id}": {
      "get": {
        "operationId": "macroSeries",
        "summary": "Observations for one series",
        "description": "The newest vintage per date, at most the last 400 dates in the range, oldest first, with a per-row source URL and an attribution block. Series data is passed through under each source's own licence. Key required; each call counts against the monthly allowance.",
        "security": [{"bearer": []}],
        "parameters": [
          {"name": "id", "in": "path", "required": true, "schema": {"type": "string"}},
          {"name": "from", "in": "query", "schema": {"type": "string", "format": "date"}},
          {"name": "to", "in": "query", "schema": {"type": "string", "format": "date"}},
          {"name": "vintage", "in": "query", "schema": {"type": "string", "enum": ["latest"]}}
        ],
        "responses": {
          "200": {
            "description": "The series, its attribution and its observations.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "series": {"$ref": "#/components/schemas/MacroSeries"},
                    "attribution": {"type": "string"},
                    "observations": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "date": {"type": "string", "format": "date"},
                          "value": {"type": ["number", "null"]},
                          "vintage": {"type": "string"},
                          "source_url": {"type": "string"}
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {"$ref": "#/components/responses/Problem"},
          "401": {"$ref": "#/components/responses/Problem"},
          "402": {"$ref": "#/components/responses/Problem"},
          "404": {"$ref": "#/components/responses/Problem"},
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/v1/interest": {
      "post": {
        "operationId": "registerInterest",
        "summary": "Register interest in a proposed item",
        "description": "No key needed. Nothing is charged for anything unbuilt. Returns a receipt id.",
        "security": [{}, {"bearer": []}],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {"schema": {"$ref": "#/components/schemas/InterestInput"}},
            "application/x-www-form-urlencoded": {
              "schema": {"$ref": "#/components/schemas/InterestInput"}
            }
          }
        },
        "responses": {
          "201": {"$ref": "#/components/responses/InterestReceipt"},
          "400": {"$ref": "#/components/responses/Problem"},
          "401": {"$ref": "#/components/responses/Problem"},
          "402": {"$ref": "#/components/responses/Problem"},
          "404": {"$ref": "#/components/responses/Problem"},
          "413": {"$ref": "#/components/responses/Problem"},
          "415": {"$ref": "#/components/responses/Problem"},
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/v1/macro/{region}/interest": {
      "post": {
        "operationId": "registerRegionInterest",
        "summary": "Register interest in a region's macro brief",
        "description": "The item is macro/{region}; any item in the body is ignored. No key needed. Nothing is charged.",
        "security": [{}, {"bearer": []}],
        "parameters": [{"$ref": "#/components/parameters/Region"}],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {"schema": {"$ref": "#/components/schemas/InterestInput"}},
            "application/x-www-form-urlencoded": {
              "schema": {"$ref": "#/components/schemas/InterestInput"}
            }
          }
        },
        "responses": {
          "201": {"$ref": "#/components/responses/InterestReceipt"},
          "400": {"$ref": "#/components/responses/Problem"},
          "401": {"$ref": "#/components/responses/Problem"},
          "402": {"$ref": "#/components/responses/Problem"},
          "404": {"$ref": "#/components/responses/Problem"},
          "413": {"$ref": "#/components/responses/Problem"},
          "415": {"$ref": "#/components/responses/Problem"},
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {"type": "http", "scheme": "bearer", "description": "Authorization: Bearer mp_..."}
    },
    "parameters": {
      "Region": {
        "name": "region",
        "in": "path",
        "required": true,
        "description": "Region code from /v1/macro/regions, e.g. au.",
        "schema": {"type": "string"}
      }
    },
    "responses": {
      "InterestReceipt": {
        "description": "Interest recorded.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "required": ["receipt_id", "item", "status", "message"],
              "properties": {
                "receipt_id": {"type": "string"},
                "item": {"type": "string"},
                "status": {"type": "string", "enum": ["proposed", "live"]},
                "message": {"type": "string"}
              }
            }
          }
        }
      },
      "Problem": {
        "description": "An RFC 9457 problem.",
        "content": {
          "application/problem+json": {"schema": {"$ref": "#/components/schemas/Problem"}}
        }
      },
      "RateLimited": {
        "description": "Over the per-minute limit for this traffic class. Requests are never challenged; wait and retry.",
        "headers": {
          "Retry-After": {
            "description": "Seconds until the current window ends.",
            "schema": {"type": "integer", "minimum": 1}
          }
        },
        "content": {
          "application/problem+json": {"schema": {"$ref": "#/components/schemas/Problem"}}
        }
      }
    },
    "schemas": {
      "CreateInput": {
        "type": "object",
        "required": ["label"],
        "properties": {
          "label": {"type": "string", "minLength": 1, "maxLength": 64},
          "agent_framework": {"type": "string", "maxLength": 64},
          "owner_email": {"type": "string"},
          "is_bot": {"type": "boolean"},
          "accept_terms": {"type": "boolean", "description": "Required on the form; a JSON request accepts the terms by being made"}
        }
      },
      "Created": {
        "type": "object",
        "required": ["account_id", "api_key", "key_id", "benefits"],
        "properties": {
          "account_id": {"type": "integer"},
          "api_key": {"type": "string", "description": "mp_ prefix; shown once."},
          "key_id": {"type": "integer"},
          "benefits": {"type": "array", "items": {"type": "string"}},
          "terms_version": {"type": "string"},
          "terms_url": {"type": "string"},
          "privacy_url": {"type": "string"}
        }
      },
      "Me": {
        "type": "object",
        "properties": {
          "account_id": {"type": "integer"},
          "key_id": {"type": "integer"},
          "label": {"type": "string"},
          "agent_framework": {"type": "string"},
          "monthly_cap_cents": {"type": "integer"},
          "class": {"type": "string"}
        }
      },
      "Problem": {
        "type": "object",
        "properties": {
          "type": {"type": "string"},
          "title": {"type": "string"},
          "status": {"type": "integer"},
          "detail": {"type": "string"},
          "item_status": {"type": "string", "description": "On a 402 for a proposed item: proposed."},
          "price_per_call_usd": {"type": "number"},
          "sample": {"type": "string"},
          "register_interest": {"type": "string"},
          "item": {"type": "string"}
        }
      },
      "MacroRegion": {
        "type": "object",
        "properties": {
          "code": {"type": "string"},
          "name": {"type": "string"},
          "status": {"type": "string", "enum": ["live", "proposed"]},
          "timezone": {"type": "string"},
          "description": {"type": "string"},
          "latest_brief_date": {"type": ["string", "null"], "format": "date"},
          "interest_count": {"type": "integer"},
          "urls": {"type": "object", "additionalProperties": {"type": "string"}}
        }
      },
      "MacroBrief": {
        "type": "object",
        "properties": {
          "region": {"type": "string"},
          "brief_date": {"type": "string", "format": "date"},
          "covers_from": {"type": "string", "format": "date-time"},
          "covers_to": {"type": "string", "format": "date-time"},
          "status": {"type": "string"},
          "model": {"type": "string"},
          "published_at": {"type": ["string", "null"], "format": "date-time"},
          "summary": {"type": "string"},
          "sections": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {"type": "string"},
                "title": {"type": "string"},
                "body_md": {"type": "string"},
                "sources": {"type": "array", "items": {"$ref": "#/components/schemas/MacroSource"}}
              }
            }
          },
          "week_ahead": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "event_id": {"type": ["integer", "null"]},
                "starts_at": {"type": ["string", "null"], "format": "date-time"},
                "local_time": {"type": "string"},
                "title": {"type": "string"},
                "note": {"type": "string"}
              }
            }
          },
          "explainer": {
            "type": ["object", "null"],
            "properties": {"title": {"type": "string"}, "body_md": {"type": "string"}}
          },
          "series_snapshot": {"type": "array", "items": {"type": "object"}},
          "sources": {"type": "array", "items": {"$ref": "#/components/schemas/MacroSource"}},
          "disclaimer": {"type": "string"},
          "urls": {"type": "object", "additionalProperties": {"type": "string"}}
        }
      },
      "MacroSource": {
        "type": "object",
        "properties": {
          "title": {"type": "string"},
          "url": {"type": "string"},
          "reachable": {"type": "boolean"}
        }
      },
      "MacroEvent": {
        "type": "object",
        "properties": {
          "id": {"type": "integer"},
          "starts_at": {"type": "string", "format": "date-time"},
          "local_time": {"type": "string"},
          "title": {"type": "string"},
          "kind": {"type": "string"},
          "source": {"type": "string"},
          "source_url": {"type": "string"},
          "status": {"type": "string"},
          "previous_starts_at": {"type": ["string", "null"], "format": "date-time"}
        }
      },
      "MacroSeries": {
        "type": "object",
        "properties": {
          "id": {"type": "string"},
          "name": {"type": "string"},
          "unit": {"type": "string"},
          "frequency": {"type": "string"},
          "source": {"type": "string"},
          "source_url": {"type": "string"},
          "licence": {"type": "string"},
          "attribution": {"type": "string"},
          "latest": {
            "type": "object",
            "properties": {"date": {"type": "string"}, "value": {"type": "number"}}
          }
        }
      },
      "InterestInput": {
        "type": "object",
        "properties": {
          "item": {"type": "string", "maxLength": 64, "pattern": "^[a-z0-9-]+(/[a-z0-9-]+)*$", "description": "Required on /v1/interest; ignored on /v1/macro/{region}/interest."},
          "need": {"type": "string", "maxLength": 2000},
          "callback_url": {"type": "string", "format": "uri", "maxLength": 512, "description": "Absolute https URL."},
          "agent": {"type": "string", "maxLength": 128}
        }
      }
    }
  }
}
