---
type: api
title: Create a model response
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/kibana/v8/operation/operation-chatcomplete
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/kibana/v8/operation/operation-chatcomplete
products:
  - Kibana
---

# Create a model response

- Server: `https://{kibana_url}`

## Paths

- `POST` `/api/security_ai_assistant/chat/complete`
- `POST` `/s/{space_id}/api/security_ai_assistant/chat/complete`

## Description

Refer to [Spaces](https://www.elastic.co/docs/deploy-manage/manage-spaces) for more information.

Create a model response for the given chat conversation.

## Authentication

- Api key: `Authorization: <value>`
  These APIs use key-based authentication. You must create an API key and use the encoded value in the request header. For example: `Authorization: ApiKey base64AccessApiKey`
- Basic: `Authorization: Basic <credentials>`

## Query string parameters

- `content_references_disabled` (boolean · default: false) — optional
  If true, the response will not include content references.

## Request body

`application/json`

- `connectorId` (string) — required
  Required connector identifier to route the request.
- `conversationId` (string · format: nonempty · min length: 1) — optional
  A string that does not contain only whitespace characters.
- `isStream` (boolean) — optional
  If true, the response will be streamed in chunks.
- `langSmithApiKey` (string) — optional
  API key for LangSmith integration.
- `langSmithProject` (string) — optional
  LangSmith project name for tracing.
- `messages` (object[]) — required
  List of chat messages exchanged so far.
  - `content` (string) — optional
    The textual content of the message.
  - `data` (object) — optional
    ECS-style metadata attached to the message.
  - `fields_to_anonymize` (string[]) — optional
    List of field names within the data object that should be anonymized.
  - `role` (enum) — required
    The role associated with the message in the chat.
    Values: `system`, `user`, `assistant`
- `model` (string) — optional
  Model ID or name to use for the response.
- `persist` (boolean) — required
  Whether to persist the chat and response to storage.
- `promptId` (string) — optional
  Prompt template identifier.
- `responseLanguage` (string) — optional
  ISO language code for the assistant's response.

## Responses

#### `200`

Indicates a successful model response call.

`application/octet-stream`

Type: `string · format: binary`

#### `400`

Generic Error

`application/json`

- `error` (string)
  Error type.
- `message` (string)
  Human-readable error message.
- `statusCode` (number)
  HTTP status code.
## Code examples

#### Console

```console
POST kbn:/api/security_ai_assistant/chat/complete
{
  "connectorId": "conn-001",
  "conversationId": "abc123",
  "isStream": true,
  "langSmithApiKey": "sk-abc123",
  "langSmithProject": "security_ai_project",
  "messages": [
    {
      "content": "How do I detect ransomware on my endpoints?",
      "data": {
        "device_id": "device-567"
      },
      "fields_to_anonymize": [
        "device.name",
        "file.path"
      ],
      "role": "user"
    }
  ],
  "model": "gpt-4",
  "persist": true,
  "promptId": "prompt_456",
  "responseLanguage": "en"
}
```

#### curl

```curl
curl -X POST "${KIBANA_URL}/api/security_ai_assistant/chat/complete" \
  -H "Authorization: ApiKey ${API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "connectorId": "conn-001",
    "conversationId": "abc123",
    "isStream": true,
    "langSmithApiKey": "sk-abc123",
    "langSmithProject": "security_ai_project",
    "messages": [
      {
        "content": "How do I detect ransomware on my endpoints?",
        "data": {
          "device_id": "device-567"
        },
        "fields_to_anonymize": [
          "device.name",
          "file.path"
        ],
        "role": "user"
      }
    ],
    "model": "gpt-4",
    "persist": true,
    "promptId": "prompt_456",
    "responseLanguage": "en"
  }'
```

