> For the complete documentation index, see [llms.txt](https://docs.aibrary.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aibrary.dev/chat-and-multimodal-features/chat.md).

# Chat

{% tabs %}
{% tab title="Multimodal \[Text, Audio]" %}

```python
import base64
from aibrary import AiBrary

aibrary = AiBrary()

# Function to encode the image
def encode_file(path):
    with open(path, "rb") as file:
        return base64.b64encode(file.read()).decode("utf-8")

# Getting the base64 string
english_audio_base64 = encode_file("tests/assets/file.mp3")
return aibrary.chat.completions.create(
    model="GPT-4o-Audio-Preview-2024-12-17@openai",
    modalities=["text", "audio"],
    audio={"voice": "alloy", "format": "wav"},
    messages=[
        {"role": "system", "content": "translate to persian"},
        {
            "role": "user",
            "content": [
                {
                    "type": "input_audio",
                    "input_audio": {"data": english_audio_base64, "format": "mp3"},
                }
            ],
        },
    ],
)
```

{% endtab %}

{% tab title="Multimodal \[Text, Image]" %}

```python
from aibrary import AiBrary
aibrary = AiBrary()

# Function to encode the image
def encode_file(path):
    with open(path, "rb") as file:
        return base64.b64encode(file.read()).decode("utf-8")

# Getting the base64 string
base64_image = encode_file("tests/assets/test-image.jpg")

return aibrary.chat.completions.create(
    model="Claude-3-5-Haiku",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "What is in this image?",
                },
                {
                    "type": "image_url",
                    "image_url": {"url": f"data:image/jpeg;base64,{base64_image}"},
                },
            ],
        }
    ],
)
```

{% endtab %}

{% tab title="Chat \[Stream]" %}

```python
aibrary = AiBrary()
aibrary.chat.completions.create(
    model="Llama-3.1-Nemotron-70B-Instruct",
    messages=[
        {"role": "user", "content": "How are you today?"},
        {"role": "assistant", "content": "I'm doing great, thank you!"},
    ],
    stream=True,
)
```

{% endtab %}

{% tab title="Chat \[Non-Stream]" %}

```python
aibrary = AiBrary()
aibrary.chat.completions.create(
    model="Llama-3.1-Nemotron-70B-Instruct",
    messages=[
        {"role": "user", "content": "How are you today?"},
        {"role": "assistant", "content": "I'm doing great, thank you!"},
    ]
)
```

{% endtab %}
{% endtabs %}

{% openapi src="/files/Dw2lhls9PkqDudu910qL" path="/v0/chat/completions" method="post" %}
[openapi.json](https://2030775142-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fp4IwQOR0zSJQKAC7b7hY%2Fuploads%2F4Z0rHZNC7ipANhpX4HEf%2Fopenapi.json?alt=media\&token=525b1926-3989-474c-baed-7a15958ec382)
{% endopenapi %}
