> ## Documentation Index
> Fetch the complete documentation index at: https://chainlit-5-wd-prompt.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Thread

## Using the `with` statement

You can create a thread and execute code within it using the `with` statement:

```python
with client.thread() as thread:
    # do something
```

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

```python

previous_thread_id = "UUID"

with client.thread(thread_id=previous_thread_id) as thread:
    # do something
```

## Thread API

<Card title="Thread API" icon="circle-nodes" href="/python-client/api-reference/thread">
  Manipulate threads directly using the API.
</Card>
