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

# Thread

<a id="literalai.observability.thread" />

<a id="literalai.observability.thread.Thread" />

## Thread

```python theme={null}
class Thread(Utils)
```

## Using the `with` statement

If you prefer to have more flexibility in logging Threads, you can use the `with` statement. You can create a thread and execute code within it using the `with` statement:

<CodeGroup>
  ```python theme={null}
  with literalai_client.thread() as thread:
      # do something
  ```
</CodeGroup>

You can also continue a thread by passing the thread id to the `thread` method:

<CodeGroup>
  ```python theme={null}

  previous_thread_id = "UUID"

  with literalai_client.thread(thread_id=previous_thread_id) as thread:
      # do something
  ```
</CodeGroup>

## Using the Literal AI API client

You can also create Threads using the `literalai_client.api.create_thread()` method.

<CodeGroup>
  ```python theme={null}
  thread = literalai_client.api.create_thread(
      participant_id="<PARTICIPANT_UUID>",
      environment="production",
      tags=["tag1", "tag2"],
      metadata={"key": "value"},
  )
  ```
</CodeGroup>

## Using Chainlit

If you built your LLM application with Chainlit, you don't need to specify Threads in your code. Chainlit logs Threads for you by default.
