> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.formantai.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.formantai.com/_mcp/server.

# Generate a decision

POST https://api.voice.formantai.com/v1/structured-response
Content-Type: application/json

Runs a managed prompt (selected by `prompt_type`) over your input variables and returns a JSON object shaped by the response schema.

Reference: https://docs.formantai.com/api-reference/formant-ai-voice-api/decision-generation/create-decision

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Servers

- `https://api.voice.formantai.com` (Global production, default)
- `https://api.in.voice.formantai.com` (India production)

## Request

### Body (application/json)

This endpoint expects a DecisionRequest.

- `prompt_type` (string, required) — Which managed prompt to run. Prompt types are enabled per workspace by FormantAI; a type that is not enabled returns `400`.
- `prompt_variables` (map from string to any, optional) — Values for the prompt's input variables, keyed by variable name. Not enforced: a missing variable still runs and is billed.
- `response_schema` (map from string to any, optional) — Optional JSON Schema for the answer. Omit it to get the prompt type's default shape.

## Response

### 200

The structured answer

- `data` (map from string to any, optional) — The answer, shaped by `response_schema` or the prompt type's default.

## Errors

### 400 Bad Request Error

Invalid request

- `error` (ErrorResponseError, optional)

### 401 Unauthorized Error

Invalid or missing API key

- `error` (ErrorResponseError, optional)

### 402 Payment Required Error

The workspace balance cannot cover the operation

- `error` (ErrorResponseError, optional)

### 413 Content Too Large Error

Request body exceeds the 32 MB upload limit

- `error` (ErrorResponseError, optional)

### 422 Unprocessable Entity Error

A form field is missing or cannot be parsed. Uses FastAPI's validation envelope, not the standard error envelope.

- `detail` (list of ValidationErrorResponseDetailItems, optional)

### 429 Too Many Requests Error

Rate limit exceeded

- `error` (ErrorResponseError, optional)

### 502 Bad Gateway Error

The prompt or the model failed to produce an answer (`upstream_error`). Not charged; safe to retry with backoff.

- `error` (ErrorResponseError, optional)

### 503 Service Unavailable Error

Decision generation is not configured on this deployment (`not_configured`). Not charged.

- `error` (ErrorResponseError, optional)

## Types

### ErrorResponseError

- `message` (string, optional)
- `type` (string, optional)

### ValidationErrorResponseDetailItems

- `type` (string, optional)
- `loc` (list of string, optional)
- `msg` (string, optional)

## Examples

**Request**

```json
{
  "prompt_type": "YOUR_PROMPT_TYPE",
  "prompt_variables": {
    "YOUR_VARIABLE": "the text you want a decision on"
  }
}
```

**Response**

```json
{
  "data": {
    "decision": true,
    "reason": "One short sentence explaining the verdict."
  }
}
```

**SDK Code**

```python Generate a decision
import requests

url = "https://api.voice.formantai.com/v1/structured-response"

payload = {
    "prompt_type": "YOUR_PROMPT_TYPE",
    "prompt_variables": { "YOUR_VARIABLE": "the text you want a decision on" }
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Generate a decision
const url = 'https://api.voice.formantai.com/v1/structured-response';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"prompt_type":"YOUR_PROMPT_TYPE","prompt_variables":{"YOUR_VARIABLE":"the text you want a decision on"}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Generate a decision
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.voice.formantai.com/v1/structured-response"

	payload := strings.NewReader("{\n  \"prompt_type\": \"YOUR_PROMPT_TYPE\",\n  \"prompt_variables\": {\n    \"YOUR_VARIABLE\": \"the text you want a decision on\"\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Generate a decision
require 'uri'
require 'net/http'

url = URI("https://api.voice.formantai.com/v1/structured-response")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"prompt_type\": \"YOUR_PROMPT_TYPE\",\n  \"prompt_variables\": {\n    \"YOUR_VARIABLE\": \"the text you want a decision on\"\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java Generate a decision
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.voice.formantai.com/v1/structured-response")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"prompt_type\": \"YOUR_PROMPT_TYPE\",\n  \"prompt_variables\": {\n    \"YOUR_VARIABLE\": \"the text you want a decision on\"\n  }\n}")
  .asString();
```

```php Generate a decision
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.voice.formantai.com/v1/structured-response', [
  'body' => '{
  "prompt_type": "YOUR_PROMPT_TYPE",
  "prompt_variables": {
    "YOUR_VARIABLE": "the text you want a decision on"
  }
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Generate a decision
using RestSharp;

var client = new RestClient("https://api.voice.formantai.com/v1/structured-response");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"prompt_type\": \"YOUR_PROMPT_TYPE\",\n  \"prompt_variables\": {\n    \"YOUR_VARIABLE\": \"the text you want a decision on\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Generate a decision
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "prompt_type": "YOUR_PROMPT_TYPE",
  "prompt_variables": ["YOUR_VARIABLE": "the text you want a decision on"]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.voice.formantai.com/v1/structured-response")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```