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

# Extract structured data

POST https://api.milliseconds.ai/v1/decision-machine-1/extract
Content-Type: application/json

Fills a JSON Schema from the text. Supports strings, numbers, booleans, enums, string arrays and nested objects. Arrays of objects are accepted and returned empty. Missing values are null. On an `image` the vision model fills the schema itself, arrays of objects included; the schema may ask for at most 5 fields (`image_schema_too_large`), because a generative pass over a photo is for a handful of values, not a page.

Send `text` for one result, `texts` for a batch wrapped as `{ results: [...] }`, or `image` (one image, at most 5 MB decoded, optionally with `text`; never with `texts`). The response carries `x-input-chars` (input characters) and `x-input-tokens` (input tokens billed for this call) headers. Each item of `texts` (and each of `statements` or `questions`) counts as one request against the requests-per-minute limit.

Reference: https://docs.milliseconds.ai/api/decision-machine-1/extract

## Authentication

- `Authorization` header (bearer token, required) — A milliseconds API key, test\_sk-\{namespace}-\{entropy} or prod\_sk-\{namespace}-\{entropy}. Every /v1 route requires it.

## Request

### Body (application/json)

This endpoint expects an ExtractRequest.

- `schema` (map from string to any, required) — JSON Schema of the object to extract. Strings, numbers, booleans, enums, arrays of strings and nested objects. Arrays of objects are accepted and returned empty.
- `text` (string, optional) — The text to decide about.
- `texts` (list of string, optional) — Batch form: one result per text.
- `image` (string, optional) — One image: a `data:image/(jpeg|png|webp);base64,` URL, or bare base64 of a JPEG, PNG or WebP. 5 MB decoded at most. URLs are never fetched. May travel with `text` (extra context), never with `texts`.
- `detail` (enum, optional) — Image resolution: `low` 512 px, `medium` 768 px (default), `high` 1024 px longest edge. Higher sees more and bills more.
  - Allowed values: `low`, `medium`, `high`

## Response

### 200

Result, or \{ results } for a batch

- `decision-machine-1_extract_Response_200`
  - ExtractResult: ExtractResult
  - DecisionMachine1ExtractResponse2001

## Errors

### 400 Bad Request Error

Invalid request

- `error` (ErrorError, required)

### 502 Bad Gateway Error

Inference failed twice

- `error` (ErrorError, required)

## Types

### ExtractResult

- `data` (map from string to any, required)

### DecisionMachine1ExtractResponse2001

- `results` (list of ExtractResult, required)

### ErrorError

- `code` (string, required)
- `message` (string, required)

## Examples

**Request**

```json
{
  "schema": {
    "properties": {
      "customer": {
        "description": "Company being billed",
        "type": "string"
      },
      "invoice_number": {
        "description": "The invoice identifier",
        "type": "string"
      },
      "net_terms_days": {
        "description": "Payment terms in days",
        "type": "integer"
      },
      "total_due": {
        "type": "number"
      }
    },
    "type": "object"
  },
  "text": "INVOICE #4471\nBilled to: Acme Corp\nInvoice date: 3 September 2026\nTotal due: $2,676.00\nPayment terms: Net 30"
}
```

**Response**

```json
{
  "data": {
    "customer": "Acme Corp",
    "invoice_number": "4471",
    "net_terms_days": 30,
    "total_due": 2676
  }
}
```

**SDK Code**

```python decision-machine-1_extract_example
import requests

url = "https://api.milliseconds.ai/v1/decision-machine-1/extract"

payload = {
    "schema": {
        "properties": {
            "customer": {
                "description": "Company being billed",
                "type": "string"
            },
            "invoice_number": {
                "description": "The invoice identifier",
                "type": "string"
            },
            "net_terms_days": {
                "description": "Payment terms in days",
                "type": "integer"
            },
            "total_due": { "type": "number" }
        },
        "type": "object"
    },
    "text": "INVOICE #4471
Billed to: Acme Corp
Invoice date: 3 September 2026
Total due: $2,676.00
Payment terms: Net 30"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript decision-machine-1_extract_example
const url = 'https://api.milliseconds.ai/v1/decision-machine-1/extract';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"schema":{"properties":{"customer":{"description":"Company being billed","type":"string"},"invoice_number":{"description":"The invoice identifier","type":"string"},"net_terms_days":{"description":"Payment terms in days","type":"integer"},"total_due":{"type":"number"}},"type":"object"},"text":"INVOICE #4471\nBilled to: Acme Corp\nInvoice date: 3 September 2026\nTotal due: $2,676.00\nPayment terms: Net 30"}'
};

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

```go decision-machine-1_extract_example
package main

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

func main() {

	url := "https://api.milliseconds.ai/v1/decision-machine-1/extract"

	payload := strings.NewReader("{\n  \"schema\": {\n    \"properties\": {\n      \"customer\": {\n        \"description\": \"Company being billed\",\n        \"type\": \"string\"\n      },\n      \"invoice_number\": {\n        \"description\": \"The invoice identifier\",\n        \"type\": \"string\"\n      },\n      \"net_terms_days\": {\n        \"description\": \"Payment terms in days\",\n        \"type\": \"integer\"\n      },\n      \"total_due\": {\n        \"type\": \"number\"\n      }\n    },\n    \"type\": \"object\"\n  },\n  \"text\": \"INVOICE #4471\\nBilled to: Acme Corp\\nInvoice date: 3 September 2026\\nTotal due: $2,676.00\\nPayment terms: Net 30\"\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 decision-machine-1_extract_example
require 'uri'
require 'net/http'

url = URI("https://api.milliseconds.ai/v1/decision-machine-1/extract")

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  \"schema\": {\n    \"properties\": {\n      \"customer\": {\n        \"description\": \"Company being billed\",\n        \"type\": \"string\"\n      },\n      \"invoice_number\": {\n        \"description\": \"The invoice identifier\",\n        \"type\": \"string\"\n      },\n      \"net_terms_days\": {\n        \"description\": \"Payment terms in days\",\n        \"type\": \"integer\"\n      },\n      \"total_due\": {\n        \"type\": \"number\"\n      }\n    },\n    \"type\": \"object\"\n  },\n  \"text\": \"INVOICE #4471\\nBilled to: Acme Corp\\nInvoice date: 3 September 2026\\nTotal due: $2,676.00\\nPayment terms: Net 30\"\n}"

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

```java decision-machine-1_extract_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.milliseconds.ai/v1/decision-machine-1/extract")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"schema\": {\n    \"properties\": {\n      \"customer\": {\n        \"description\": \"Company being billed\",\n        \"type\": \"string\"\n      },\n      \"invoice_number\": {\n        \"description\": \"The invoice identifier\",\n        \"type\": \"string\"\n      },\n      \"net_terms_days\": {\n        \"description\": \"Payment terms in days\",\n        \"type\": \"integer\"\n      },\n      \"total_due\": {\n        \"type\": \"number\"\n      }\n    },\n    \"type\": \"object\"\n  },\n  \"text\": \"INVOICE #4471\\nBilled to: Acme Corp\\nInvoice date: 3 September 2026\\nTotal due: $2,676.00\\nPayment terms: Net 30\"\n}")
  .asString();
```

```php decision-machine-1_extract_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.milliseconds.ai/v1/decision-machine-1/extract', [
  'body' => '{
  "schema": {
    "properties": {
      "customer": {
        "description": "Company being billed",
        "type": "string"
      },
      "invoice_number": {
        "description": "The invoice identifier",
        "type": "string"
      },
      "net_terms_days": {
        "description": "Payment terms in days",
        "type": "integer"
      },
      "total_due": {
        "type": "number"
      }
    },
    "type": "object"
  },
  "text": "INVOICE #4471\\nBilled to: Acme Corp\\nInvoice date: 3 September 2026\\nTotal due: $2,676.00\\nPayment terms: Net 30"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp decision-machine-1_extract_example
using RestSharp;

var client = new RestClient("https://api.milliseconds.ai/v1/decision-machine-1/extract");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"schema\": {\n    \"properties\": {\n      \"customer\": {\n        \"description\": \"Company being billed\",\n        \"type\": \"string\"\n      },\n      \"invoice_number\": {\n        \"description\": \"The invoice identifier\",\n        \"type\": \"string\"\n      },\n      \"net_terms_days\": {\n        \"description\": \"Payment terms in days\",\n        \"type\": \"integer\"\n      },\n      \"total_due\": {\n        \"type\": \"number\"\n      }\n    },\n    \"type\": \"object\"\n  },\n  \"text\": \"INVOICE #4471\\nBilled to: Acme Corp\\nInvoice date: 3 September 2026\\nTotal due: $2,676.00\\nPayment terms: Net 30\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift decision-machine-1_extract_example
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "schema": [
    "properties": [
      "customer": [
        "description": "Company being billed",
        "type": "string"
      ],
      "invoice_number": [
        "description": "The invoice identifier",
        "type": "string"
      ],
      "net_terms_days": [
        "description": "Payment terms in days",
        "type": "integer"
      ],
      "total_due": ["type": "number"]
    ],
    "type": "object"
  ],
  "text": "INVOICE #4471
Billed to: Acme Corp
Invoice date: 3 September 2026
Total due: $2,676.00
Payment terms: Net 30"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.milliseconds.ai/v1/decision-machine-1/extract")! 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()
```