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

# List Threads

> Get a list of threads within your project.

Before using the Threads API, make sure you have set up the REST API integration.

Threads are a fundamental component of the Langtail API, designed to manage and maintain the state of conversations with AI assistants. Here's how the Threads API works:

1. Creation: A thread can be created either as a new conversation or by referencing an existing thread ID.

2. Message Storage: Threads store all messages exchanged during a conversation, including both user inputs and assistant responses.

3. Conversation Continuity: By using thread IDs, you can maintain context across multiple interactions, allowing for coherent, ongoing dialogues.

## Pagination

This endpoint supports pagination in the same way as the OpenAI API. Specifically, it follows the pagination mechanism described in the [OpenAI API documentation for listing Assistants](https://platform.openai.com/docs/api-reference/assistants/listAssistants).

Here's how it works:

1. The `limit` parameter allows you to specify the maximum number of threads to return in a single request. The default and maximum value is 100.

2. The `after` parameter is used as a cursor for pagination. It should be set to any thread ID from which you want to retrieve the next set of results.

3. To fetch the next page of results, make a new request with the `after` parameter set to the ID of the last thread in the current response.

4. The response includes a `has_more` parameter, which indicates whether there are more results available.

This pagination approach allows you to efficiently retrieve and process large numbers of threads in manageable chunks.


## OpenAPI

````yaml GET /v2/threads
openapi: 3.0.0
info:
  version: 1.0.0
  title: Langtail prompt endpoint
servers: []
security: []
paths:
  /v2/threads:
    get:
      description: Get a list of threads within your project.
      parameters:
        - schema:
            type: string
            example: <LANGTAIL_API_KEY>
          required: true
          description: Your Langtail API Key
          name: X-API-Key
          in: header
        - schema:
            type: number
            nullable: true
          name: limit
          in: query
          description: The maximum number of threads to return. Default is 100.
        - schema:
            type: string
            nullable: true
          name: after
          in: query
          description: >-
            A cursor for use in pagination. 'after' is a thread ID that defines
            your place in the list. For instance, if you make a list request and
            receive 100 threads, ending with thread 'xyz', your subsequent call
            can include after='xyz' in order to fetch the next page of the list.
            Pagination works the same as in the OpenAI API
            https://platform.openai.com/docs/api-reference/assistants/listAssistants.
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  object:
                    type: string
                    enum:
                      - list
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          description: The unique identifier for the thread.
                        createdAt:
                          type: integer
                          description: >-
                            The Unix timestamp (in seconds) of when the thread
                            was created.
                        projectId:
                          type: string
                          description: The ID of the project this thread belongs to.
                        createLog:
                          type: object
                          description: >-
                            A log created by the first message that creates the
                            thread.
                          nullable: true
                          properties:
                            id:
                              type: string
                              description: The unique identifier for the log.
                            url:
                              type: string
                              description: The URL of the request.
                            stream:
                              type: boolean
                              description: Indicates if the request was streamed.
                            metadata:
                              type: string
                              description: Additional metadata associated with the log.
                            promptId:
                              type: string
                              description: The ID of the prompt used.
                            threadId:
                              type: string
                              nullable: true
                              description: The ID of the associated thread, if any.
                            assistant:
                              type: boolean
                              description: Indicates if an assistant was used.
                            projectId:
                              type: string
                              description: The ID of the project.
                            requestIP:
                              type: string
                              description: The IP address of the request.
                            startedAt:
                              type: string
                              format: date-time
                              description: The timestamp when the request started.
                            variables:
                              type: string
                              description: Variables used in the request.
                            parameters:
                              type: string
                              description: Parameters used in the request.
                            promptSlug:
                              type: string
                              description: The slug of the prompt used.
                            doNotRecord:
                              type: boolean
                              description: Indicates if the request should not be recorded.
                            environment:
                              type: string
                              description: The environment in which the request was made.
                            openAIKeyId:
                              type: string
                              description: The ID of the OpenAI key used.
                            projectSlug:
                              type: string
                              description: The slug of the project.
                            requestData:
                              type: string
                              description: Data associated with the request.
                            deploymentId:
                              type: string
                              description: The ID of the deployment.
                            organizationId:
                              type: string
                              description: The ID of the organization.
                            projectAPIKeyId:
                              type: string
                              description: The ID of the project API key.
                            organizationSlug:
                              type: string
                              description: The slug of the organization.
                            deploymentVersion:
                              type: string
                              nullable: true
                              description: The version of the deployment, if applicable.
                            promptHistoryHash:
                              type: string
                              description: A hash of the prompt history.
                            openAIOrganization:
                              type: string
                              nullable: true
                              description: The OpenAI organization, if applicable.
                        metadata:
                          type: object
                          description: >-
                            A set of key-value pairs that can be attached to the
                            thread. This can be used to store additional
                            information about the thread to facilitate filtering
                            or organization.
                          example:
                            user_id: user_123
                            conversation_topic: product_inquiry
                            priority: high
                          nullable: true
                  first_id:
                    type: string
                    description: >-
                      The ID of the first thread in the list, or null if the
                      list is empty.
                    nullable: true
                  last_id:
                    type: string
                    description: >-
                      The ID of the last thread in the list, or null if the list
                      is empty.
                    nullable: true
                  has_more:
                    type: boolean
                    description: Whether there are more threads available after this batch.
                required:
                  - object
                  - data
                  - has_more
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    enum:
                      - Unauthorized
                  message:
                    type: string
                    example: Invalid API key
                required:
                  - error
                  - message
      servers:
        - url: https://api.langtail.com

````