> ## Documentation Index
> Fetch the complete documentation index at: https://docs.memorylake.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat Completions

> Call OpenAI-compatible chat models with your memory attached

```
POST /openapi/memorylake/router/openai/v1/chat/completions
```

OpenAI Chat Completions. With `boundary_id`, memories from that Boundary are added to the conversation before the model is called. Without it, the request goes to the model as is.

Set `stream` to `true` to receive server-sent events in the OpenAI format. Parameters not listed below are passed to the model unchanged.

### Query Parameters

<ParamField query="boundary_id" type="string">
  The Boundary whose memory this request uses. Omit it to call the model without memory.
</ParamField>

### Headers

<ParamField header="x-memorylake-api-key" type="string">
  Your MemoryLake API key, when you call the model with your own provider key. The provider key then goes in the provider's usual key header. Your provider key is forwarded to the provider and never stored.
</ParamField>

<ParamField header="traceparent" type="string">
  W3C trace context. When present, the request joins your trace and the same trace id comes back in `X-Trace-ID`.
</ParamField>

### Request Body

<ParamField body="messages" type="array" required>
  The conversation so far

  <Expandable title="Chat Message object">
    <ParamField body="messages[].content" type="string | array" required>Message text, or an array of content parts</ParamField>
    <ParamField body="messages[].role" type="string" required>Who wrote the message. One of: `system`, `developer`, `user`, `assistant`, `tool`.</ParamField>
  </Expandable>
</ParamField>

<ParamField body="model" type="string" required>
  Model name, as listed under Available Models in the console
</ParamField>

<ParamField body="max_completion_tokens" type="integer">
  Maximum tokens to generate, reasoning included. Use this instead of `max_tokens` for the gpt-5 and o-series models.
</ParamField>

<ParamField body="max_tokens" type="integer">
  Maximum tokens to generate
</ParamField>

<ParamField body="stream" type="boolean" default="false">
  Stream the reply as server-sent events
</ParamField>

<ParamField body="temperature" type="number">
  Sampling temperature
</ParamField>

<ParamField body="tools" type="array">
  Tools the model may call, in the OpenAI format
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST 'https://app.memorylake.ai/openapi/memorylake/router/openai/v1/chat/completions?boundary_id=bnd-xxxxxx' \
    -H 'Authorization: Bearer sk_xxxxxx' \
    -H 'Content-Type: application/json' \
    -d '{
      "messages": [
        {
          "content": "What did I say my favourite city was?",
          "role": "user"
        }
      ],
      "model": "gpt-4o-mini"
    }'
  ```
</RequestExample>

### Response

<ResponseField name="choices" type="array">
  The generated replies

  <Expandable title="Choice object">
    <ResponseField name="finish_reason" type="string">Why the model stopped, such as `stop` or `length`</ResponseField>
    <ResponseField name="index" type="integer">Position in the list</ResponseField>

    <ResponseField name="message" type="object">
      The reply

      <Expandable title="Message object">
        <ResponseField name="content" type="string">Reply text</ResponseField>
        <ResponseField name="role" type="string">Always `assistant`</ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="created" type="integer">Creation time, Unix seconds</ResponseField>
<ResponseField name="id" type="string">Completion id</ResponseField>
<ResponseField name="model" type="string">Model that answered</ResponseField>
<ResponseField name="object" type="string">Always `chat.completion`</ResponseField>

<ResponseField name="usage" type="object">
  Tokens used

  <Expandable title="Chat Usage object">
    <ResponseField name="completion_tokens" type="integer">Tokens in the reply</ResponseField>
    <ResponseField name="prompt_tokens" type="integer">Tokens in the prompt</ResponseField>
    <ResponseField name="total_tokens" type="integer">Prompt and reply together</ResponseField>
  </Expandable>
</ResponseField>

<ResponseExample>
  ```json Success (200) theme={null}
  {
    "choices": [
      {
        "finish_reason": "stop",
        "index": 0,
        "message": {
          "content": "You said your favourite city is Lisbon.",
          "role": "assistant"
        }
      }
    ],
    "created": 1760000000,
    "id": "chatcmpl-abc123",
    "model": "gpt-4o-mini",
    "object": "chat.completion",
    "usage": {
      "completion_tokens": 11,
      "prompt_tokens": 412,
      "total_tokens": 423
    }
  }
  ```
</ResponseExample>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.