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

# Chat

{% tabs %}
{% tab title="NodeJS (TS)" %}

```typescript
import PropulsionAI from 'propulsionai';
import {
  ModelChatResponse,
  ModelChatParams
} from 'propulsionai/resources/models';

const p8n = new PropulsionAI({
  bearerToken: process.env['PROPULSIONAI_BEARER_TOKEN'] as string,
});

async function main() {
  try {
    let deployment_tag: string = '<deployment_tag>';
    let params: ModelChatParams = {
      messages: [
        {
          role: 'system',
          content: "You are an amazing poet.",
        },
        {
          role: 'user',
          content: "Can you write a poem about Tesla, the innovator?",
        },
      ],
      model: 'auto',
      stream: false,
      wait: true,
    };
    let response: ModelChatResponse;
    try{
      response = await p8n.models.ep(deployment_tag, params);
    }catch(e){
      console.log('Error:', e);
      return;
    }
    console.log("Task ID:", response.task_id);
    if(response.choices) {
      response.choices.forEach((choice) => {
        console.log(`${choice.message?.role}: ${choice.message?.content}`);
      });
    }
  } catch (error) {
    console.error('Error during model call:', error);
  }
}

main();

```

{% endtab %}

{% tab title="NodeJS (JS)" %}

```javascript
import PropulsionAI from 'propulsionai';

const p8n = new PropulsionAI({
  bearerToken: process.env['PROPULSIONAI_BEARER_TOKEN'],
});

async function main() {
  try {
    let deployment_tag = '<deployment_tag>';
    let params = {
      messages: [
        {
          role: 'system',
          content: "You are an amazing poet.",
        },
        {
          role: 'user',
          content: "Can you write a poem about Tesla, the innovator?",
        },
      ],
      model: 'auto',
      stream: false,
      wait: true,
    };
    let response;
    try{
      response = await p8n.models.ep(deployment_tag, params);
    }catch(e){
      console.log('Error:', e);
      return;
    }
    console.log("Task ID:", response.task_id);
    if(response.choices) {
      response.choices.forEach((choice) => {
        console.log(`${choice.message?.role}: ${choice.message?.content}`);
      });
    }
  } catch (error) {
    console.error('Error during model call:', error);
  }
}

main();
```

{% endtab %}

{% tab title="Python" %}

```python
import os
from propulsionai import AsyncPropulsionAI
from propulsionai.models import ModelChatResponse

# Initialize AsyncPropulsionAI with bearer token from environment variables
p8n = AsyncPropulsionAI(
    bearer_token=os.environ.get("PROPULSIONAI_BEARER_TOKEN"),
)

async def main() -> None:
    try:
        response: ModelChatResponse = await p8n.models.ep(
            '<deployment_tag>',
            messages=[
                {
                    "role": "system",
                    "content": "You are an amazing poet.",
                },
                {
                    "role": 'user',
                    "content": "Can you write a poem about Tesla, the innovator?",
                },
            ],
            model="auto",
            stream=False,
            wait=True,
        )
        print(response.id)
        print(response.content)
    except Exception as e:
        print(f"Error during model call: {e}")

if __name__ == "__main__":
    import asyncio
    asyncio.run(main())

```

{% endtab %}

{% tab title="cURL" %}

```bash
# Inference Call
curl -X "POST" "https://api.propulsionhq.com/api/v1/chat/<deployment_tag>?wait=true" \
     -H 'Authorization: Bearer <PROPULSIONAI_BEARER_TOKEN>' \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d $'{
  "messages": [
    {
      "role": "system",
      "content": "You are an amazing poet."
    },
    {
      "role": "user",
      "content": "Can you write a poem about Tesla, the innovator?"
    }
  ],
  "model": "auto",
}'
```

{% endtab %}
{% endtabs %}
