{
  "openapi": "3.1.0",
  "info": {
    "title": "Good Old Dan Public API",
    "version": "1.1.0",
    "description": "Bible-grounded public API. All endpoints except GET /health require a Bearer API key (god_live_… or god_test_…). Free plan defaults: 10 Ask/day, 100/month, 5/min. Website chat quotas are separate.",
    "contact": {
      "name": "Good Old Dan",
      "url": "https://goodolddan.com"
    }
  },
  "servers": [
    {
      "url": "https://goodolddan.com/api/v1",
      "description": "Production v1"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key created at /settings/api. Format: god_live_… or god_test_…"
      }
    },
    "schemas": {
      "ApiError": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "requestId": {
                "type": "string"
              }
            },
            "required": [
              "code",
              "message",
              "requestId"
            ]
          }
        }
      }
    }
  },
  "paths": {
    "/health": {
      "get": {
        "summary": "Health check (no auth)",
        "operationId": "getHealth",
        "security": [],
        "responses": {
          "200": {
            "description": "Service is healthy"
          }
        }
      }
    },
    "/topics": {
      "get": {
        "summary": "List topic hubs",
        "operationId": "listTopics",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Topic list"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited or quota exceeded"
          }
        }
      }
    },
    "/topics/{slug}": {
      "get": {
        "summary": "Get a topic hub",
        "operationId": "getTopic",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "example": "fear"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Topic detail"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Not found"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/scripture": {
      "get": {
        "summary": "Lookup a KJV passage",
        "operationId": "getScripture",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "ref",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "example": "Isaiah 41:10"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Passage found"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Not found"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/search": {
      "post": {
        "summary": "Search Scripture (retrieval only)",
        "operationId": "searchScripture",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "query"
                ],
                "properties": {
                  "query": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "limit": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 20
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Search results"
          },
          "401": {
            "description": "Unauthorized"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/ask": {
      "post": {
        "summary": "Ask Good Old Dan (counts toward Ask quota)",
        "operationId": "askGoodOldDan",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "X-RateLimit-Limit",
            "in": "header",
            "schema": {
              "type": "integer"
            },
            "description": "Returned on responses"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "question"
                ],
                "properties": {
                  "question": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "maxReferences": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 8
                  }
                }
              },
              "example": {
                "question": "What does the Bible say about fear?",
                "maxReferences": 6
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Answer with structured references. Headers include X-RateLimit-* and X-Quota-*-Remaining."
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Revoked/disabled/expired key"
          },
          "429": {
            "description": "Rate or quota exceeded"
          }
        }
      }
    }
  }
}