{
  "openapi": "3.1.0",
  "info": {
    "title": "FetchLayer Reddit API — Search",
    "version": "1.0.0",
    "description": "Find content, communities, and users across Reddit."
  },
  "servers": [
    {
      "url": "https://api.fetchlayer.dev/reddit"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API Key",
        "description": "Send your FetchLayer key as Authorization: Bearer ss-your-key. No Reddit OAuth credentials are required."
      }
    }
  },
  "paths": {
    "/search": {
      "post": {
        "operationId": "search",
        "tags": [
          "Search"
        ],
        "summary": "Posts matching a keyword — globally or within a subreddit",
        "description": "Search Reddit posts by keyword. Optionally narrow to a specific subreddit. Results include title, score, comment count, author, and permalink.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "query": {
                    "type": "string",
                    "description": "Search keyword or phrase."
                  },
                  "subreddit": {
                    "type": "string",
                    "description": "Limit search to a specific subreddit."
                  },
                  "sort": {
                    "type": "string",
                    "description": "Sort order.",
                    "example": "relevance"
                  },
                  "limit": {
                    "type": "number",
                    "description": "Number of results (max 100).",
                    "example": "25"
                  },
                  "time": {
                    "type": "string",
                    "description": "Time filter: hour, day, week, month, year, all.",
                    "example": "all"
                  }
                },
                "additionalProperties": false,
                "required": [
                  "query"
                ]
              },
              "examples": {
                "default": {
                  "value": {
                    "query": "developer tools",
                    "subreddit": "webdev",
                    "sort": "top",
                    "limit": 10
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "results": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "title": {
                            "type": "string",
                            "description": "Post title."
                          },
                          "subreddit": {
                            "type": "string",
                            "description": "Subreddit name."
                          },
                          "author": {
                            "type": "string",
                            "description": "Reddit username."
                          },
                          "score": {
                            "type": "number",
                            "description": "Upvote score."
                          },
                          "numComments": {
                            "type": "number",
                            "description": "Comment count."
                          },
                          "url": {
                            "type": "string",
                            "description": "Permalink to the post."
                          },
                          "createdUtc": {
                            "type": "number",
                            "description": "Unix timestamp of creation."
                          }
                        },
                        "additionalProperties": false
                      }
                    }
                  },
                  "additionalProperties": false
                },
                "examples": {
                  "default": {
                    "value": {
                      "results": [
                        {
                          "title": "What tools do you swear by?",
                          "subreddit": "webdev",
                          "author": "devuser",
                          "score": 3241,
                          "numComments": 418,
                          "url": "https://reddit.com/r/webdev/comments/...",
                          "createdUtc": 1718000000
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing Bearer token"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ]
      }
    },
    "/search-comments": {
      "post": {
        "operationId": "search-comments",
        "tags": [
          "Search"
        ],
        "summary": "Comments matching a keyword — globally or within a subreddit",
        "description": "Search Reddit comments by keyword. Optionally narrow to a specific subreddit. Results include comment body, score, author, subreddit, and permalink.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "query": {
                    "type": "string",
                    "description": "Search keyword or phrase."
                  },
                  "subreddit": {
                    "type": "string",
                    "description": "Limit search to a specific subreddit."
                  },
                  "sort": {
                    "type": "string",
                    "description": "Sort order: relevance, new, comments, top.",
                    "example": "relevance"
                  },
                  "time": {
                    "type": "string",
                    "description": "Time filter: hour, day, week, month, year, all.",
                    "example": "all"
                  },
                  "limit": {
                    "type": "number",
                    "description": "Number of results (max 100).",
                    "example": "25"
                  },
                  "pages": {
                    "type": "number",
                    "description": "Number of pages to scrape.",
                    "example": "1"
                  }
                },
                "additionalProperties": false,
                "required": [
                  "query"
                ]
              },
              "examples": {
                "default": {
                  "value": {
                    "query": "mcp",
                    "sort": "top",
                    "time": "all",
                    "limit": 25
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "results": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "body": {
                            "type": "string",
                            "description": "Comment text."
                          },
                          "subreddit": {
                            "type": "string",
                            "description": "Subreddit name."
                          },
                          "author": {
                            "type": "string",
                            "description": "Reddit username."
                          },
                          "score": {
                            "type": "number",
                            "description": "Upvote score."
                          },
                          "permalink": {
                            "type": "string",
                            "description": "Permalink to the comment."
                          },
                          "createdUtc": {
                            "type": "number",
                            "description": "Unix timestamp of creation."
                          }
                        },
                        "additionalProperties": false
                      }
                    }
                  },
                  "additionalProperties": false
                },
                "examples": {
                  "default": {
                    "value": {
                      "results": [
                        {
                          "body": "MCP has been a game changer for my workflow.",
                          "subreddit": "programming",
                          "author": "devuser",
                          "score": 342,
                          "permalink": "/r/programming/comments/.../comment/...",
                          "createdUtc": 1718000000
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing Bearer token"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ]
      }
    },
    "/search-communities": {
      "post": {
        "operationId": "search-communities",
        "tags": [
          "Search"
        ],
        "summary": "Find subreddits by keyword",
        "description": "Search for subreddits matching a keyword. Returns community name, subscriber count, and description.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "query": {
                    "type": "string",
                    "description": "Search keyword."
                  },
                  "limit": {
                    "type": "number",
                    "description": "Max results.",
                    "example": "25"
                  }
                },
                "additionalProperties": false,
                "required": [
                  "query"
                ]
              },
              "examples": {
                "default": {
                  "value": {
                    "query": "programming",
                    "limit": 5
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "results": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string",
                            "description": "Subreddit name."
                          },
                          "title": {
                            "type": "string",
                            "description": "Subreddit display title."
                          },
                          "subscribers": {
                            "type": "number",
                            "description": "Subscriber count."
                          },
                          "description": {
                            "type": "string",
                            "description": "Short description."
                          }
                        },
                        "additionalProperties": false
                      }
                    }
                  },
                  "additionalProperties": false
                },
                "examples": {
                  "default": {
                    "value": {
                      "results": [
                        {
                          "name": "programming",
                          "title": "Programming",
                          "subscribers": 35000000,
                          "description": "Computer Programming"
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing Bearer token"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ]
      }
    },
    "/search-users": {
      "post": {
        "operationId": "search-users",
        "tags": [
          "Search"
        ],
        "summary": "Find Reddit users by name",
        "description": "Search for Reddit users by username. Useful for account lookup and verification.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "query": {
                    "type": "string",
                    "description": "Username to search for."
                  },
                  "limit": {
                    "type": "number",
                    "description": "Max results.",
                    "example": "10"
                  }
                },
                "additionalProperties": false,
                "required": [
                  "query"
                ]
              },
              "examples": {
                "default": {
                  "value": {
                    "query": "spez",
                    "limit": 5
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "results": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "username": {
                            "type": "string",
                            "description": "Username."
                          },
                          "totalKarma": {
                            "type": "number",
                            "description": "Combined karma."
                          },
                          "accountAgeDays": {
                            "type": "number",
                            "description": "Account age in days."
                          }
                        },
                        "additionalProperties": false
                      }
                    }
                  },
                  "additionalProperties": false
                },
                "examples": {
                  "default": {
                    "value": {
                      "results": [
                        {
                          "username": "spez",
                          "totalKarma": 1500000,
                          "accountAgeDays": 6200
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing Bearer token"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ]
      }
    }
  }
}