> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stophy.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Reddit search API

> Call the Reddit search API to get title, text, author, subreddit, score and upvote percent, as JSON or markdown. 2 credits.

* **Endpoint:** `reddit.search`
* **Returns:** `data` has `results`.
* **Cost:** 2 credits. Failed calls cost nothing.
* **Paging:** Yes. Send the `cursor` from the response to get the next page. See [Paging](/advanced-guide#paging).

## Example

<CodeGroup>
  ```typescript TypeScript icon="https://mintcdn.com/sirathic/7E4w9-IC4ysabjfc/images/icons/typescript.svg?fit=max&auto=format&n=7E4w9-IC4ysabjfc&q=85&s=d8272a85e64145620f1fbbfcf7932986" theme={null}
  import { Stophy } from "stophy";

  const stophy = new Stophy({ apiKey: process.env.STOPHY_API_KEY });
  const result = await stophy.reddit.search({ query: "typescript" });
  console.log(result.data.results);
  ```

  ```python Python icon="python" theme={null}
  from stophy import Stophy

  stophy = Stophy()  # reads STOPHY_API_KEY
  result = stophy.reddit.search(query="typescript")
  print(result["data"]["results"])
  ```

  ```bash cURL icon="terminal" theme={null}
  curl -X POST https://api.stophy.dev/v1/reddit/search \
    -H "Authorization: Bearer $STOPHY_API_KEY" \
    -H "content-type: application/json" \
    -d '{"query":"typescript"}'
  ```

  ```bash CLI icon="square-terminal" theme={null}
  stophy reddit search typescript
  ```
</CodeGroup>


## OpenAPI

````yaml api-reference/openapi.json POST /v1/reddit/search
openapi: 3.1.0
info:
  title: Stophy API
  version: '1'
  description: >-
    Every endpoint is a POST that takes its input as a JSON object body. Unknown
    fields are rejected with 400.


    Send Accept: text/markdown to get markdown instead of JSON.


    Responses leave out empty values: null, empty strings, empty objects and
    empty nested lists are not sent.


    x-credits is what one call costs. When x-per-items is set, a call costs
    x-credits for every x-per-items items it returns, and at least x-credits.


    When a response has a cursor, send it back with the same input to get the
    next page.
servers:
  - url: https://api.stophy.dev
security:
  - apiKey: []
paths:
  /v1/reddit/search:
    post:
      summary: Search Reddit posts, comments, subreddits and users
      description: Costs 2 credits. Pages with cursor.
      operationId: redditSearch
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                query:
                  type: string
                  minLength: 1
                  maxLength: 512
                type:
                  default: posts
                  type: string
                  enum:
                    - posts
                    - subreddits
                    - users
                subreddit:
                  type: string
                sort:
                  default: relevance
                  type: string
                  enum:
                    - relevance
                    - hot
                    - top
                    - newest
                    - mostComments
                within:
                  default: all
                  type: string
                  enum:
                    - hour
                    - day
                    - week
                    - month
                    - year
                    - all
                includeNsfw:
                  default: false
                  type: boolean
                limit:
                  default: 25
                  type: integer
                  minimum: 1
                  maximum: 100
                cursor:
                  type: string
                  minLength: 1
                  maxLength: 8192
              required:
                - query
              additionalProperties: false
            example:
              query: typescript
      responses:
        '200':
          description: The data, and the credits this call used.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
            x-credits-used:
              $ref: '#/components/headers/CreditsUsed'
            X-RateLimit-Limit:
              $ref: '#/components/headers/RateLimitLimit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/RateLimitRemaining'
          content:
            application/json:
              schema:
                type: object
                required:
                  - success
                  - data
                  - creditsUsed
                  - requestId
                properties:
                  success:
                    const: true
                  data:
                    type: object
                    additionalProperties: false
                    properties:
                      results:
                        type: array
                        items:
                          oneOf:
                            - type: object
                              additionalProperties: false
                              properties:
                                type:
                                  type: string
                                  const: post
                                id:
                                  type: string
                                url:
                                  type: string
                                  format: uri
                                title:
                                  type: string
                                text:
                                  type: string
                                author:
                                  type: object
                                  additionalProperties: false
                                  properties:
                                    id:
                                      type: string
                                    username:
                                      type: string
                                    name:
                                      type: string
                                    url:
                                      type: string
                                      format: uri
                                    avatar:
                                      type: string
                                      format: uri
                                    isVerified:
                                      type: boolean
                                  required: []
                                subreddit:
                                  type: string
                                score:
                                  type: integer
                                  minimum: -9007199254740991
                                  maximum: 9007199254740991
                                upvotePercent:
                                  type: number
                                  minimum: 0
                                  maximum: 100
                                comments:
                                  type: integer
                                  minimum: -9007199254740991
                                  maximum: 9007199254740991
                                createdAt:
                                  type: string
                                  format: date-time
                                  pattern: >-
                                    ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z))$
                                flair:
                                  type: string
                                link:
                                  type: object
                                  additionalProperties: false
                                  properties:
                                    url:
                                      type: string
                                      format: uri
                                    title:
                                      type: string
                                    description:
                                      type: string
                                    image:
                                      type: string
                                      format: uri
                                  required:
                                    - url
                                thumbnail:
                                  type: string
                                  format: uri
                                isNsfw:
                                  type: boolean
                                isVideo:
                                  type: boolean
                                isPinned:
                                  type: boolean
                                images:
                                  type: array
                                  items:
                                    type: object
                                    additionalProperties: false
                                    properties:
                                      url:
                                        type: string
                                        format: uri
                                      caption:
                                        type: string
                                      alt:
                                        type: string
                                    required:
                                      - url
                                video:
                                  type: object
                                  additionalProperties: false
                                  properties:
                                    url:
                                      type: string
                                      format: uri
                                    hls:
                                      type: string
                                      format: uri
                                    durationSeconds:
                                      type: number
                                  required:
                                    - url
                                poll:
                                  type: object
                                  additionalProperties: false
                                  properties:
                                    options:
                                      type: array
                                      items:
                                        type: object
                                        additionalProperties: false
                                        properties:
                                          text:
                                            type: string
                                          votes:
                                            type: integer
                                            minimum: -9007199254740991
                                            maximum: 9007199254740991
                                        required: []
                                    totalVotes:
                                      type: integer
                                      minimum: -9007199254740991
                                      maximum: 9007199254740991
                                    endsAt:
                                      type: string
                                      format: date-time
                                      pattern: >-
                                        ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z))$
                                  required: []
                                repostOf:
                                  type: object
                                  additionalProperties: false
                                  properties:
                                    id:
                                      type: string
                                    url:
                                      type: string
                                      format: uri
                                    subreddit:
                                      type: string
                                    title:
                                      type: string
                                  required: []
                              required:
                                - type
                                - url
                                - score
                                - comments
                                - isNsfw
                                - isVideo
                                - isPinned
                            - type: object
                              additionalProperties: false
                              properties:
                                type:
                                  type: string
                                  const: subreddit
                                id:
                                  type: string
                                name:
                                  type: string
                                url:
                                  type: string
                                  format: uri
                                title:
                                  type: string
                                description:
                                  type: string
                                members:
                                  type: integer
                                  minimum: -9007199254740991
                                  maximum: 9007199254740991
                                createdAt:
                                  type: string
                                  format: date-time
                                  pattern: >-
                                    ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z))$
                                avatar:
                                  type: string
                                  format: uri
                                isNsfw:
                                  type: boolean
                                rules:
                                  type: array
                                  items:
                                    type: object
                                    additionalProperties: false
                                    properties:
                                      title:
                                        type: string
                                      description:
                                        type: string
                                    required: []
                              required:
                                - type
                                - url
                                - isNsfw
                            - type: object
                              additionalProperties: false
                              properties:
                                type:
                                  type: string
                                  const: user
                                id:
                                  type: string
                                username:
                                  type: string
                                url:
                                  type: string
                                  format: uri
                                postKarma:
                                  type: integer
                                  minimum: -9007199254740991
                                  maximum: 9007199254740991
                                commentKarma:
                                  type: integer
                                  minimum: -9007199254740991
                                  maximum: 9007199254740991
                                createdAt:
                                  type: string
                                  format: date-time
                                  pattern: >-
                                    ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z))$
                                avatar:
                                  type: string
                                  format: uri
                                isVerified:
                                  type: boolean
                              required:
                                - type
                                - url
                                - isVerified
                      cursor:
                        type: string
                    required:
                      - results
                  creditsUsed:
                    type: integer
                  requestId:
                    type: string
            text/markdown:
              schema:
                type: string
        4XX:
          $ref: '#/components/responses/Error'
        5XX:
          $ref: '#/components/responses/Error'
components:
  headers:
    RequestId:
      description: The request id. Quote it when you report a problem.
      schema:
        type: string
    CreditsUsed:
      description: Credits this call used.
      schema:
        type: integer
    RateLimitLimit:
      description: Requests allowed in the current window.
      schema:
        type: integer
    RateLimitRemaining:
      description: Requests left in the current window.
      schema:
        type: integer
    RetryAfter:
      description: Seconds to wait before retrying.
      schema:
        type: integer
  responses:
    Error:
      description: The request failed. retryable says whether trying again can help.
      headers:
        X-Request-ID:
          $ref: '#/components/headers/RequestId'
        Retry-After:
          $ref: '#/components/headers/RetryAfter'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  schemas:
    Error:
      type: object
      required:
        - success
        - error
      properties:
        success:
          const: false
        error:
          type: object
          required:
            - code
            - message
            - retryable
            - requestId
          properties:
            code:
              type: string
              enum:
                - cliSessionCompleted
                - cliSessionExists
                - cliSessionNotFound
                - forbidden
                - insufficientCredits
                - internalError
                - invalidCliSession
                - invalidCliVerifier
                - invalidRequest
                - notFound
                - rateLimited
                - sourceChanged
                - sourceRefused
                - sourceTimeout
                - sourceUnavailable
                - tooManyInFlight
                - unauthorized
                - unsupportedMediaType
            message:
              type: string
            retryable:
              type: boolean
            retryAfterSeconds:
              type: integer
            requestId:
              type: string
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer

````