> For the complete documentation index, see [llms.txt](https://docs.forefront.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.forefront.ai/api-reference/completions.md).

# Completions

## Create 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  |             |
| prompt<mark style="color:red;">\*</mark> | string  |             |
| max\_tokens                              | integer |             |
| temeperature                             | number  |             |
| stop                                     | array   |             |

{% tabs %}
{% tab title="200: OK Successfully returned the 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(
    prompt="Write a recipe for an italian dinner",
    model="MODEL_STRING", # replace with model string
    temperature=0,
    max_tokens=10,
)
```

{% endtab %}

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

```typescript
import Forefront from "forefront";

const client = new Forefront("YOUR_API_KEY");

const completion: any = await client.chat.completions.create({
  model: "MODEL_STRING",
  prompt: "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",
    "prompt": "What is the meaning of 42?",
    "temperature": 0.1,
    "max_tokens": 128,
}'
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.forefront.ai/api-reference/completions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
