---
type: api
title: Create a model response
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/v9/operation/operation-chatcomplete
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/v9/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`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/kibana/v9/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/kibana/v9/authentication#basicauth)

## 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.

## Query String Parameters

- `content_references_disabled` (boolean · default: false)
  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 · min: 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`

#### `400`

Bad Request response.

`application/json`

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

#### curl

```curl
curl \
 --request POST 'http://localhost:5601/api/security_ai_assistant/chat/complete' \
 --header "Authorization: $API_KEY" \
 --header "Content-Type: application/json" \
 --data '{"connectorId":"conn-001","persist":true,"messages":[{"role":"user","content":"What are common phishing techniques?"}]}'
```

## Request Examples

#### Chat complete

```json
{
  "connectorId": "conn-001",
  "conversationId": "abc123",
  "isStream": true,
  "langSmithApiKey": "\u003CLANGSMITH_API_KEY\u003E",
  "langSmithProject": "security_ai_project",
  "messages": [
    {
      "content": "What are some common phishing techniques?",
      "data": {
        "user_id": "user_789"
      },
      "fields_to_anonymize": [
        "user.name",
        "source.ip"
      ],
      "role": "user"
    }
  ],
  "model": "gpt-4",
  "persist": true,
  "promptId": "prompt_456",
  "responseLanguage": "en"
}
```

## Response Examples

#### Chat complete response200

```json
(streaming binary response)
```

#### Chat complete response400

```json
{
  "error": "Bad Request",
  "message": "Invalid request payload.",
  "statusCode": 400
}
```

