{
  "openapi": "3.1.0",
  "info": {
    "title": "FetchLayer Reddit API — Utility",
    "version": "1.0.0",
    "description": "Helper endpoints for URL resolution and inspection."
  },
  "servers": [
    {
      "url": "https://api.fetchlayer.dev/reddit"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "components": {
    "schemas": {
      "Error": {
        "type": "object",
        "description": "Every error, on every route. Branch on code and retryable rather than on the text; on a 5xx the text is generic. MCP tool errors carry the same fields in structuredContent, and as a JSON text block.",
        "properties": {
          "error": {
            "type": "string",
            "description": "What went wrong, in words. For a 400, what to change."
          },
          "status": {
            "type": "integer",
            "description": "The HTTP status, repeated in the body."
          },
          "code": {
            "type": "string",
            "description": "The kind of error, stable: invalid_input, unauthorized, insufficient_credits, forbidden, not_found, expired, quota_exceeded, cancelled, time_limit, temporarily_unavailable, posts_unavailable, store_unreachable, upstream_error, internal_error, tool_error. A platform may add its own; more may be added. Treat a code you do not recognise by its retryable flag."
          },
          "retryable": {
            "type": "boolean",
            "description": "Whether asking again can succeed."
          },
          "requestId": {
            "type": "string",
            "description": "This request’s id, also sent as the X-Request-Id header. Quote it when reporting a problem."
          },
          "missing": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "With invalid_input when the request's parameters are refused before the request runs: the parameters that were missing. Always present on those errors, empty when nothing was missing."
          }
        },
        "required": [
          "error",
          "code",
          "retryable",
          "requestId"
        ]
      }
    },
    "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": {
    "/resolve-url-type": {
      "post": {
        "operationId": "resolve-url-type",
        "tags": [
          "Utility"
        ],
        "summary": "Identify what a Reddit URL points to",
        "description": "Resolve a Reddit URL into the backend target and normalized input needed to call the matching endpoint.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string",
                    "description": "Full Reddit URL."
                  }
                },
                "additionalProperties": false,
                "required": [
                  "url"
                ]
              },
              "examples": {
                "default": {
                  "value": {
                    "url": "https://www.reddit.com/r/programming/comments/173viwj/meta_the_future_of_rprogramming/"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "inputUrl": {
                      "type": "string",
                      "description": "URL supplied by the caller."
                    },
                    "normalizedUrl": {
                      "type": "string",
                      "description": "Normalized absolute Reddit URL."
                    },
                    "target": {
                      "type": "string",
                      "description": "Resolved backend target, such as post or comment_permalink."
                    },
                    "targetInput": {
                      "type": "object",
                      "additionalProperties": true,
                      "description": "Input object to send to the resolved endpoint."
                    },
                    "subreddit": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Resolved subreddit name."
                    },
                    "username": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Resolved username."
                    },
                    "postId": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Resolved post ID."
                    },
                    "commentId": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Resolved comment ID."
                    },
                    "query": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Resolved search query."
                    },
                    "sort": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Resolved sort value."
                    },
                    "time": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Resolved time filter."
                    }
                  },
                  "additionalProperties": true
                },
                "examples": {
                  "default": {
                    "value": {
                      "inputUrl": "https://www.reddit.com/r/programming/comments/173viwj/meta_the_future_of_rprogramming/",
                      "normalizedUrl": "https://www.reddit.com/r/programming/comments/173viwj/meta_the_future_of_rprogramming/",
                      "target": "post",
                      "targetInput": {
                        "url": "https://www.reddit.com/r/programming/comments/173viwj/meta_the_future_of_rprogramming/"
                      },
                      "subreddit": "programming",
                      "postId": "173viwj",
                      "commentId": null,
                      "username": null,
                      "query": null,
                      "sort": null,
                      "time": null
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "invalid_input: the request needs fixing; error names the field.",
            "headers": {
              "X-Request-Id": {
                "description": "The request id, equal to requestId in the body.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: the API key is missing or not valid.",
            "headers": {
              "X-Request-Id": {
                "description": "The request id, equal to requestId in the body.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "insufficient_credits: no credits, trial or monthly allowance left.",
            "headers": {
              "X-Request-Id": {
                "description": "The request id, equal to requestId in the body.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "forbidden: this key or account is not allowed this request.",
            "headers": {
              "X-Request-Id": {
                "description": "The request id, equal to requestId in the body.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "quota_exceeded: a request-rate limit was reached.",
            "headers": {
              "X-Request-Id": {
                "description": "The request id, equal to requestId in the body.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "temporarily_unavailable, time_limit or (on a store route) store_unreachable: ask again (with time_limit, allow more time). Retryable.",
            "headers": {
              "X-Request-Id": {
                "description": "The request id, equal to requestId in the body.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ]
      }
    }
  }
}