POST
/
v1
/
chat
/
completions
curl --request POST \
  --url https://app.premai.io/v1/chat/completions \
  --header 'Authorization: <api-key>' \
  --header 'Content-Type: application/json' \
  --data '{
  "project_id": 123,
  "session_id": "<string>",
  "repositories": {
    "ids": [
      123
    ],
    "limit": 3,
    "similarity_threshold": 0.5
  },
  "messages": [
    {
      "role": "user",
      "content": "<string>",
      "template_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
      "params": {}
    }
  ],
  "model": "<string>",
  "system_prompt": "<string>",
  "max_tokens": 1,
  "stream": true,
  "temperature": 1,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "<string>",
        "description": "<string>",
        "parameters": {
          "type": "<string>",
          "properties": {},
          "required": [
            "<string>"
          ]
        }
      }
    }
  ]
}'
{
  "choices": [
    {
      "index": 123,
      "message": {
        "role": "user",
        "content": "<string>",
        "template_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
        "params": {}
      },
      "finish_reason": "<string>",
      "tool_calls": [
        {
          "id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
          "function": {
            "name": "<string>",
            "arguments": {}
          },
          "type": "<string>"
        }
      ]
    }
  ],
  "created": 123,
  "model": "<string>",
  "provider_name": "<string>",
  "provider_id": "<string>",
  "document_chunks": [
    {
      "repository_id": 123,
      "document_id": 123,
      "chunk_id": 123,
      "document_name": "<string>",
      "similarity_score": 123,
      "content": "<string>"
    }
  ],
  "usage": {
    "prompt_tokens": 123,
    "completion_tokens": 123,
    "total_tokens": 123
  },
  "trace_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}

Authorizations

Authorization
string
headerrequired

Body

project_id
integer
required

The ID of the project to use.

session_id
string

The ID of the session to use. It helps to track the chat history.

repositories
object

Options for Retrieval Augmented Generation (RAG). Will override launched model settings

messages
object[]
required

A list of messages comprising the conversation so far.

model
string

ID of the model to use. See the model endpoint compatibility table for details.

system_prompt
string

The system prompt to use.

max_tokens
integer | null

The maximum number of tokens to generate in the chat completion.

stream
boolean

If set, partial message deltas will be sent, like in ChatGPT.

temperature
number
default: 1

What sampling temperature to use, between 0 and 2.

tools
object[] | null

The tools to use in the completion.

Response

200 - application/json
choices
object[]
required

A list of chat completion choices. Can be more than one if n is greater than 1.

created
integer
required

The Unix timestamp (in seconds) of when the chat completion was created. Each chunk has the same timestamp.

model
string
required

The model to generate the completion.

provider_name
string
required

The name of the provider that generated the completion.

provider_id
string
required

The ID of the provider that generated the completion.

document_chunks
object[]

Chunks used to improve the completion

usage
object
required

The usage statistics for the completion.

trace_id
string
required

The trace ID of the completion.