{
  "openapi": "3.1.0",
  "info": {
    "title": "Tended Agent Tools API",
    "version": "1.0.0",
    "summary": "Paid, agent-callable organic-gardening tools.",
    "description": "Curated, citable gardening answers and AI plant-photo check-ups for AI agents. Authenticate with an API key in the 'x-api-key' header; each call consumes one credit. A call with no key or no remaining credit returns HTTP 402 with how-to-pay details. Get a key: https://organicgardeningcollective.com/agents.html",
    "termsOfService": "https://organicgardeningcollective.com/api-terms.html",
    "contact": {
      "name": "Organic Gardening Collective",
      "email": "agents@organicgardeningcollective.com",
      "url": "https://organicgardeningcollective.com/agents.html"
    }
  },
  "servers": [
    {
      "url": "https://xyprjneejchdksjtdxko.supabase.co/functions/v1",
      "description": "Supabase Edge Functions"
    }
  ],
  "security": [
    {
      "apiKeyAuth": []
    }
  ],
  "paths": {
    "/garden-answer": {
      "post": {
        "operationId": "gardenAnswer",
        "summary": "Curated, citable organic-gardening answers to a question.",
        "description": "Returns human-written knowledge-base answers, each with a source_url for attribution. Price: $0.006 per call.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GardenAnswerRequest"
              },
              "example": {
                "question": "white powder on my squash leaves",
                "max_results": 2
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Curated answers.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GardenAnswerResponse"
                }
              }
            }
          },
          "400": {
            "description": "Missing or invalid 'question'."
          },
          "402": {
            "description": "No API key or no remaining credit.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentRequired"
                }
              }
            }
          }
        }
      }
    },
    "/agent-checkup": {
      "post": {
        "operationId": "plantCheckup",
        "summary": "AI vision health check-up for a single plant photo.",
        "description": "Send an image (https URL or base64) and optional context; get structured organic care advice. Price: $0.02 per call.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CheckupRequest"
              },
              "example": {
                "imageUrl": "https://example.com/leaf.jpg",
                "plantType": "tomato",
                "location": "USDA zone 6b, balcony"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Structured check-up.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CheckupResponse"
                }
              }
            }
          },
          "400": {
            "description": "No image provided."
          },
          "402": {
            "description": "No API key or no remaining credit.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentRequired"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "Your Tended agent API key. Get one at https://organicgardeningcollective.com/agents.html"
      }
    },
    "schemas": {
      "GardenAnswerRequest": {
        "type": "object",
        "required": [
          "question"
        ],
        "properties": {
          "question": {
            "type": "string",
            "maxLength": 400,
            "description": "The gardener's question, plain English."
          },
          "max_results": {
            "type": "integer",
            "minimum": 1,
            "maximum": 5,
            "default": 3
          }
        }
      },
      "GardenAnswerResponse": {
        "type": "object",
        "properties": {
          "question": {
            "type": "string"
          },
          "matched": {
            "type": "boolean"
          },
          "answers": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "topic": {
                  "type": "string"
                },
                "answer": {
                  "type": "string"
                },
                "status": {
                  "type": "string",
                  "enum": [
                    "ok",
                    "warn",
                    "bad",
                    "none"
                  ]
                },
                "source_url": {
                  "type": "string",
                  "format": "uri"
                },
                "confidence": {
                  "type": "number"
                }
              }
            }
          },
          "credits_remaining": {
            "type": [
              "integer",
              "null"
            ]
          },
          "license": {
            "type": "string"
          },
          "attribution": {
            "type": "string"
          },
          "disclaimer": {
            "type": "string"
          }
        }
      },
      "CheckupRequest": {
        "type": "object",
        "properties": {
          "imageUrl": {
            "type": "string",
            "format": "uri",
            "description": "https URL of the plant photo."
          },
          "imageBase64": {
            "type": "string",
            "description": "Base64 image data (alternative to imageUrl)."
          },
          "mediaType": {
            "type": "string",
            "default": "image/jpeg"
          },
          "plantName": {
            "type": "string"
          },
          "plantType": {
            "type": "string"
          },
          "location": {
            "type": "string"
          }
        },
        "oneOf": [
          {
            "required": [
              "imageUrl"
            ]
          },
          {
            "required": [
              "imageBase64"
            ]
          }
        ]
      },
      "CheckupResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "ok",
              "warn",
              "bad"
            ]
          },
          "summary": {
            "type": "string"
          },
          "tasks": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "credits_remaining": {
            "type": [
              "integer",
              "null"
            ]
          },
          "attribution": {
            "type": "string"
          },
          "disclaimer": {
            "type": "string"
          }
        }
      },
      "PaymentRequired": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "tool": {
            "type": "string"
          },
          "price": {
            "type": "string"
          },
          "get_access": {
            "type": "string",
            "format": "uri"
          },
          "catalog": {
            "type": "string",
            "format": "uri"
          },
          "contact": {
            "type": "string"
          }
        }
      }
    }
  }
}
