<!-- generated: do not edit. source: content/docs/decisions/index.md -->

# Decisions

Decisions lets you ask typed questions about a piece of evidence and get each
answer back with its probabilities. You send the evidence once, then a list of
questions, and the response carries one answer per question in the same order.

| Question type | Answers with |
| --- | --- |
| `predicate` | The probability that a condition holds |
| `choice` | One of the values you supply, with a probability for each |
| `score` | A rating on a scale of levels you define, with a probability for each level |

Use Decisions when your code acts on the answer: routing a ticket, flagging a
call, grading a response against a rubric.

## Get an API key
Create a Sprag account and open [API keys](/app/api-keys) in the app to generate
one.

Copy the key immediately. The full value is shown once and is not recoverable
after you leave the page.

Export it as an environment variable, replacing the placeholder with your key:

```bash
export SPRAG_API_KEY=<your_sprag_api_key>
```

## Make a request
Send the evidence in `input` and the questions in `questions`.

```bash
curl https://api.sprag.ai/v1/decisions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $SPRAG_API_KEY" \
  -d '{
    "model": "spev",
    "input": "I was charged twice. Please refund the duplicate payment.",
    "questions": [
      {
        "name": "department",
        "type": "choice",
        "instructions": "Which team should handle this?",
        "choices": [{ "value": "billing" }, { "value": "technical" }]
      },
      {
        "name": "refund",
        "type": "predicate",
        "instructions": "Is the customer asking for a refund?"
      }
    ]
  }'
```

```python
import os
import requests

response = requests.post(
    "https://api.sprag.ai/v1/decisions",
    headers={"Authorization": f"Bearer {os.environ['SPRAG_API_KEY']}"},
    json={
        "model": "spev",
        "input": "I was charged twice. Please refund the duplicate payment.",
        "questions": [
            {
                "name": "department",
                "type": "choice",
                "instructions": "Which team should handle this?",
                "choices": [{"value": "billing"}, {"value": "technical"}],
            },
            {
                "name": "refund",
                "type": "predicate",
                "instructions": "Is the customer asking for a refund?",
            },
        ],
    },
)
response.raise_for_status()

for answer in response.json()["answers"]:
    print(answer)
```

```typescript
const response = await fetch("https://api.sprag.ai/v1/decisions", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    Authorization: `Bearer ${process.env.SPRAG_API_KEY}`,
  },
  body: JSON.stringify({
    model: "spev",
    input: "I was charged twice. Please refund the duplicate payment.",
    questions: [
      {
        name: "department",
        type: "choice",
        instructions: "Which team should handle this?",
        choices: [{ value: "billing" }, { value: "technical" }],
      },
      {
        name: "refund",
        type: "predicate",
        instructions: "Is the customer asking for a refund?",
      },
    ],
  }),
});

const { answers } = await response.json();
console.log(answers);
```

## Read the answers
Each answer carries its question's `type` and `name`, in question order.

```json
{
  "model": "spev",
  "answers": [
    {
      "type": "choice",
      "name": "department",
      "choice": "billing",
      "probabilities": [
        { "value": "billing", "probability": 0.981 },
        { "value": "technical", "probability": 0.019 }
      ],
      "confidence": 0.962
    },
    {
      "type": "predicate",
      "name": "refund",
      "probability": 0.9997
    }
  ],
  "usage": {
    "input_tokens": 221,
    "input_tokens_details": { "cached_tokens": 0 },
    "output_tokens": 0,
    "total_tokens": 221
  }
}
```

To act on a choice, read `choice`. To set your own threshold, read the
probabilities instead.

## Where to go next

**[API](/docs/decisions/api).** Look up the question types, the evidence
formats, and the errors.

**[Models](/docs/decisions/models).** See which models answer Decisions
requests and what evidence each one accepts.
