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

# Responses

> 通过 Responses API 带着记忆调用 OpenAI 模型

```
POST /openapi/memorylake/router/openai/v1/responses
```

OpenAI Responses。带上 `boundary_id` 时，会先把该 Boundary 中的相关记忆加入输入再调用模型。不带时，请求原样发给模型。

设置 `stream` 为 `true` 即可按 OpenAI 格式接收 server-sent events。下面未列出的参数会原样传给模型。

### 查询参数

<ParamField query="boundary_id" type="string">
  本次请求使用哪个 Boundary 的记忆。省略则不使用记忆，直接调用模型。
</ParamField>

### 请求头

<ParamField header="x-memorylake-api-key" type="string">
  使用自带的模型厂商密钥（BYOK）时，在这里放 MemoryLake API Key，模型厂商密钥则放在该厂商原生的鉴权头中。您的模型厂商密钥只会转发给模型厂商，不会被保存。
</ParamField>

<ParamField header="traceparent" type="string">
  W3C 链路上下文。带上后，请求会纳入您的链路，并在 `X-Trace-ID` 中返回同一个 trace id。
</ParamField>

### 请求体

<ParamField body="input" type="string | array" required>
  文本，或输入项数组
</ParamField>

<ParamField body="model" type="string" required>
  模型名称，与控制台「可用模型」中列出的一致
</ParamField>

<ParamField body="instructions" type="string">
  给模型的系统指令
</ParamField>

<ParamField body="max_output_tokens" type="integer">
  最多生成的 token 数，包含推理
</ParamField>

<ParamField body="stream" type="boolean" default="false">
  以 server-sent events 流式返回响应
</ParamField>

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

### 响应

<ResponseField name="created_at" type="integer">创建时间，Unix 秒级时间戳</ResponseField>
<ResponseField name="id" type="string">响应 ID</ResponseField>
<ResponseField name="model" type="string">作答的模型</ResponseField>
<ResponseField name="object" type="string">固定为 `response`</ResponseField>
<ResponseField name="output" type="array">输出项，例如消息和工具调用</ResponseField>
<ResponseField name="status" type="string">`completed`、`incomplete` 或 `failed`</ResponseField>

<ResponseField name="usage" type="object">
  本次用量

  <Expandable title="Usage 对象">
    <ResponseField name="input_tokens" type="integer">输入的 token 数</ResponseField>
    <ResponseField name="output_tokens" type="integer">生成的 token 数</ResponseField>
    <ResponseField name="total_tokens" type="integer">输入与输出之和</ResponseField>
  </Expandable>
</ResponseField>

<ResponseExample>
  ```json Success (200) theme={null}
  {
    "created_at": 1760000000,
    "id": "resp_abc123",
    "model": "gpt-4o-mini",
    "object": "response",
    "output": [
      {
        "content": [
          {
            "text": "You said your favourite city is Lisbon.",
            "type": "output_text"
          }
        ],
        "role": "assistant",
        "type": "message"
      }
    ],
    "status": "completed",
    "usage": {
      "input_tokens": 412,
      "output_tokens": 11,
      "total_tokens": 423
    }
  }
  ```
</ResponseExample>


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