> For the complete documentation index, see [llms.txt](https://pycai.gitbook.io/welcome/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pycai.gitbook.io/welcome/quick-start.md).

# Quick Start

Let's write a version of the code for chatting with a character

First of all, we need to import the library and write the startup code

{% tabs %}
{% tab title="Sync" %}

```python
from characterai import PyCAI

client = PyCAI('TOKEN')

# CODE
```

{% endtab %}

{% tab title="Async" %}

```python
import asyncio
from characterai import PyAsyncCAI

async def main():
    client = PyAsyncCAI('TOKEN')
    
    # CODE

asyncio.run(main())
```

{% endtab %}
{% endtabs %}

Now we have to take the necessary chat information to send the message

{% tabs %}
{% tab title="Sync" %}

```python
char = input('Enter CHAR: ')

chat = client.chat.get_chat(char)

participants = chat['participants']

if not participants[0]['is_human']:
    tgt = participants[0]['user']['username']
else:
    tgt = participants[1]['user']['username']
```

{% endtab %}

{% tab title="Async" %}

```python
char = input('Enter CHAR: ')

chat = await client.chat.get_chat(char)

participants = chat['participants']

if not participants[0]['is_human']:
    tgt = participants[0]['user']['username']
else:
    tgt = participants[1]['user']['username']
```

{% endtab %}
{% endtabs %}

And now let's make a cycle in which there will be a chat

{% tabs %}
{% tab title="Sync" %}

```python
while True:
    message = input('You: ')

    data = client.chat.send_message(
        chat['external_id'], tgt, message
    )

    name = data['src_char']['participant']['name']
    text = data['replies'][0]['text']

    print(f"{name}: {text}")
```

{% endtab %}

{% tab title="Async" %}

```python
while True:
    message = input('You: ')

    data = await client.chat.send_message(
        chat['external_id'], tgt, message
    )

    name = data['src_char']['participant']['name']
    text = data['replies'][0]['text']

    print(f"{name}: {text}")
```

{% endtab %}
{% endtabs %}

The full code is available in the "Examples" folder
