# Chat

## Create chat completion

## Create chat completion

<mark style="color:green;">`POST`</mark> `https://api.forefront.ai/v1/chat/completions`

Creates a model response for the given chat conversation.

#### Request Body

| Name                                       | Type    | Description |
| ------------------------------------------ | ------- | ----------- |
| model<mark style="color:red;">\*</mark>    | string  |             |
| messages<mark style="color:red;">\*</mark> | array   |             |
| max\_tokens                                | integer |             |
| temeperature                               | number  |             |
| stop                                       | array   |             |

{% tabs %}
{% tab title="200: OK Successfully returned the chat completion." %}

```typescript
{
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "Of course! I'm here to help."
      }
    }
  ],
  "usage": {
    "input_tokens": 28,
    "output_tokens": 10,
    "total_tokens": 38
  },
  "message": {
    "content": "Of course! I'm here to help."
  }
}
```

{% endtab %}
{% endtabs %}

### Example request

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

```python
from forefront import ForefrontClient

ff = ForefrontClient(api_key="YOUR_API_KEY")

completion = ff.chat.completions.create(
    messages=[
        {"role": "system", "content" "You are a gourmet chef"},
        {"role": "user", "content": "Write a recipe for an italian dinner"},
    ],
    model="MODEL_STRING", # replace with the name of the model 
    temperature=0,
    max_tokens=10,
)
```

{% endtab %}

{% tab title="Node.js" %}

```typescript
import Forefront from "forefront";

const client = new Forefront("YOUR_API_KEY");

const completion = await client.chat.completions.create({
  model: "MODEL_STRING",
  messages: [
    {
      role: "user",
      content: "Write a recipe for an italian dinner",
    },
  ],
  max_tokens: 256,
  stream: false,
});
```

{% endtab %}

{% tab title="cURL" %}

```
curl https://api.forefront.ai/v1/chat/completions \
--header 'content-type: application/json' \
--header 'authorization: Bearer $FOREFRONT_API_KEY' \
--data '{
    "model": "REPLACE_WITH_MODEL_STRING",
    "messages": [
       {
          "role": "user", 
          "content": "Write a recipe for an italian dinner"
       }
    ],
    "temperature": 0.1,
    "max_tokens": 128,
}'
```

{% endtab %}
{% endtabs %}
