---
type: api
title: Perform decision inference on the service
description: Answer a set of named questions about an input, such as whether a customer is complaining, which team should handle a request, or how angry a customer is.
url: https://www.elastic.co/elastic/docs-builder/docs/4268/api/doc/elasticsearch-serverless/operation/operation-inference-decision
resource: https://www.elastic.co/elastic/docs-builder/docs/4268/api/doc/elasticsearch-serverless/operation/operation-inference-decision
products:
  - Elasticsearch Serverless
---

# Perform decision inference on the service

Authentication: required

Availability: Experimental

## Paths

- `POST` `/_inference/decision/{inference_id}`

#### Path parameters

- `inference_id` (string) — required
  The unique identifier for the inference endpoint.

## Description

Answer a set of named questions about an input, such as whether a customer is complaining, which team should handle a request, or how angry a customer is.
The questions are defined in the task settings of the inference endpoint, and can be replaced for a single request through `task_settings`.

> info
> Only the `elastic` service currently supports the `decision` task.

## Required privileges

- Cluster privileges: `monitor_inference`

## Query string parameters

- `timeout` (string · default: 30s) — optional
  The amount of time to wait for the inference request to complete.

## Request body

`application/json`

- `input` (union oneOf) — required
  The input to answer the questions about.
It can be specified as a string, or as an object.
The object form additionally allows specifying images.

string example:
```
"input": "I was charged twice for my order and nobody answers my emails."
```
object example:
```
"input": {
  "type": "image",
  "format": "base64",
  "value": "data:image/jpeg;base64,..."
}
```
  - **string**
  - **EmbeddingContentObjectItem**
    An object containing the input data for a single item for the model to embed.
    - `type` (enum) — required
      The type of input to embed. Not all models support all input types.
The `audio`, `video`, and `pdf` types are available in Elasticsearch 9.5.0 and later.
      Values: `text`, `image`, `audio`, `video`, `pdf`
    - `format` (enum) — optional
      The format of the input. For the `text` type this must be `text`. For all other types, this must be `base64` or `url`.
If not specified, this will default to `text` for the `text` type and `base64` for all other types.
The `url` format is available in Elasticsearch 9.6.0 and later.
Not all services and models support all formats.
      Values: `text`, `base64`, `url`
    - `value` (string) — required
      The value of the input to embed. For the `base64` format, this must be a base64-encoded data URI, i.e. "data:content/type;base64,...".
For the `url` format, this must be a URL that points to the content, i.e. "https://example.com/image.jpg".
- `task_settings` (object) — optional
  Task settings for the individual inference request.
These settings override the task settings specified when creating the inference endpoint.
  - `questions` (map string to oneOf) — optional
    The questions to answer, keyed by question name. The answers in the response use the same names.
The questions replace the ones of the inference endpoint as a whole. At least one question is required.

## Response

`application/json`

- `decision` (object)
  - `answers` (map string to oneOf)
    The answers, keyed by the name of the question they answer.
## Code examples

#### Console

```console
POST _inference/decision/my-decision-endpoint
{
  "input": "I was charged twice for my order and nobody answers my emails.",
  "task_settings": {
    "questions": {
      "is_complaint": {
        "type": "predicate",
        "instructions": "Is the customer complaining?"
      },
      "team": {
        "type": "choice",
        "instructions": "Which team should handle this?",
        "choices": {
          "billing": "Charges, refunds, invoices",
          "shipping": "Deliveries and returns",
          "other": null
        }
      },
      "anger": {
        "type": "score",
        "instructions": "How angry is the customer?",
        "levels": ["calm", "annoyed", { "label": "furious", "description": "Threatens to leave" }]
      }
    }
  }
}
```

#### JavaScript

```javascript
const response = await client.inference.decision({
  inference_id: "my-decision-endpoint",
  input: "I was charged twice for my order and nobody answers my emails.",
  task_settings: {
    questions: {
      is_complaint: {
        type: "predicate",
        instructions: "Is the customer complaining?",
      },
      team: {
        type: "choice",
        instructions: "Which team should handle this?",
        choices: {
          billing: "Charges, refunds, invoices",
          shipping: "Deliveries and returns",
          other: null,
        },
      },
      anger: {
        type: "score",
        instructions: "How angry is the customer?",
        levels: [
          "calm",
          "annoyed",
          {
            label: "furious",
            description: "Threatens to leave",
          },
        ],
      },
    },
  },
});
```

#### Python

```python
resp = client.inference.decision(
    inference_id="my-decision-endpoint",
    input="I was charged twice for my order and nobody answers my emails.",
    task_settings={
        "questions": {
            "is_complaint": {
                "type": "predicate",
                "instructions": "Is the customer complaining?"
            },
            "team": {
                "type": "choice",
                "instructions": "Which team should handle this?",
                "choices": {
                    "billing": "Charges, refunds, invoices",
                    "shipping": "Deliveries and returns",
                    "other": None
                }
            },
            "anger": {
                "type": "score",
                "instructions": "How angry is the customer?",
                "levels": [
                    "calm",
                    "annoyed",
                    {
                        "label": "furious",
                        "description": "Threatens to leave"
                    }
                ]
            }
        }
    },
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_inference/decision/my-decision-endpoint" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input": "I was charged twice for my order and nobody answers my emails.",
    "task_settings": {
      "questions": {
        "is_complaint": {
          "type": "predicate",
          "instructions": "Is the customer complaining?"
        },
        "team": {
          "type": "choice",
          "instructions": "Which team should handle this?",
          "choices": {
            "billing": "Charges, refunds, invoices",
            "shipping": "Deliveries and returns",
            "other": null
          }
        },
        "anger": {
          "type": "score",
          "instructions": "How angry is the customer?",
          "levels": [
            "calm",
            "annoyed",
            {
              "label": "furious",
              "description": "Threatens to leave"
            }
          ]
        }
      }
    }
  }'
```

#### PHP

```php
$resp = $client->inference()->decision([
    "inference_id" => "my-decision-endpoint",
    "body" => [
        "input" => "I was charged twice for my order and nobody answers my emails.",
        "task_settings" => [
            "questions" => [
                "is_complaint" => [
                    "type" => "predicate",
                    "instructions" => "Is the customer complaining?",
                ],
                "team" => [
                    "type" => "choice",
                    "instructions" => "Which team should handle this?",
                    "choices" => [
                        "billing" => "Charges, refunds, invoices",
                        "shipping" => "Deliveries and returns",
                        "other" => null,
                    ],
                ],
                "anger" => [
                    "type" => "score",
                    "instructions" => "How angry is the customer?",
                    "levels" => array(
                        "calm",
                        "annoyed",
                        [
                            "label" => "furious",
                            "description" => "Threatens to leave",
                        ],
                    ),
                ],
            ],
        ],
    ],
]);
```

#### Ruby

```ruby
response = client.inference.decision(
  inference_id: "my-decision-endpoint",
  body: {
    "input": "I was charged twice for my order and nobody answers my emails.",
    "task_settings": {
      "questions": {
        "is_complaint": {
          "type": "predicate",
          "instructions": "Is the customer complaining?"
        },
        "team": {
          "type": "choice",
          "instructions": "Which team should handle this?",
          "choices": {
            "billing": "Charges, refunds, invoices",
            "shipping": "Deliveries and returns",
            "other": nil
          }
        },
        "anger": {
          "type": "score",
          "instructions": "How angry is the customer?",
          "levels": [
            "calm",
            "annoyed",
            {
              "label": "furious",
              "description": "Threatens to leave"
            }
          ]
        }
      }
    }
  }
)
```

## Response examples

#### Decision task

`application/json`

A response from `POST _inference/decision/my-decision-endpoint`, with an answer for each question.

```json
{
  "decision": {
    "answers": {
      "is_complaint": {
        "type": "predicate",
        "probability": 0.94
      },
      "team": {
        "type": "choice",
        "choice": "billing",
        "probabilities": [
          { "value": "billing", "probability": 0.91 },
          { "value": "shipping", "probability": 0.04 },
          { "value": "other", "probability": 0.05 }
        ],
        "confidence": 0.89
      },
      "anger": {
        "type": "score",
        "score": 1.4,
        "probabilities": [
          { "value": 0, "label": "calm", "probability": 0.1 },
          { "value": 1, "label": "annoyed", "probability": 0.4 },
          { "value": 2, "label": "furious", "probability": 0.5 }
        ],
        "confidence": 0.62
      }
    }
  }
}
```

