# POST /api/v1/bills/ai-create

> AI-extract draft bills from documents

- **Tag:** bills
- **Operation ID:** `ai_create_bill_payload_api_v1_bills_ai_create_post`

## Description

Upload pasted text, PDFs, images, Excel files, or a CSV to extract draft bill entities using AI. Returns draft bills in 'received' status format ready for user review before creation.

## Authentication

Bearer token in `Authorization` header.
Required header: `x-business-id: <business uuid>`.

## Request body

Schema: `BillAICreatePayloadRequest`

- `pasted_text` (string) — Raw text content to extract a bill from. Limit 1 bill per text input. Mutually exclusive with pasted_text_s3_key.
- `pasted_text_s3_key` (string) — S3 key of pasted text content. Limit 1 bill per text input. Mutually exclusive with pasted_text.
- `single_bill_s3_keys` (array · string) — S3 keys of individual bill documents (PDFs, images, Excel). Each file is processed independently.
- `multi_bill_s3_key` (string) — S3 key of a CSV file containing multiple bills.

## Responses

### 201 — Successful Response

Schema: `BillAICreatePayloadResponse`

- `items` (array · DraftBill · required) → `DraftBill` — List of draft bill entities extracted by AI.
  - `vendor_name` (string) — Vendor/company name extracted by AI. Use to match or create a vendor.
  - `amount` (integer) — Bill amount in cents extracted by AI.
  - `description` (string) — Description of what the bill is for.
  - `bill_number` (string) — Bill/invoice number from the vendor document.
  - `bill_date` (string) — Date of the bill (YYYY-MM-DD) extracted by AI.
  - `expense_category` (string) — Expense category suggested by AI (e.g., 'Office Supplies', 'Rent').
  - `vendor_id` (string) — Matched vendor UUID (if the vendor was found in the system).
  - `currency` (string) — Currency code (USD, CAD, AUD, EUR, or GBP). Defaults to USD.
  - `type` (string) — Bill type: 'recurring' or 'one_time'. Defaults to 'one_time'.
  - `received_on` (string) — Date bill was received (ISO 8601). Defaults to bill_date if available.
  - `due_on` (string) — Payment due date (ISO 8601). Maps from due_date.
  - `s3_key` (string) — S3 key of the source document for this bill.
  - `ledger_id` (string) — Matched expense ledger UUID (if matched from expense_category).
  - `journal_entry_date` (string) — Date for journal entry (ISO 8601). Defaults to received_on.
  - `confidence` (number) — AI confidence score for this extraction (0.0-1.0).
  - `source` (string) — Source type: 'pasted_text', 'single_file', or 'multi_file'.
  - `source_filename` (string) — Original filename or S3 key of the source document.
- `errors` (array · FileProcessingError) → `FileProcessingError` — List of per-file errors for files that could not be processed.
  - `s3_key` (string · required) — S3 key of the file that failed.
  - `filename` (string) — Original filename (if determinable from the S3 key).
  - `error` (string · required) — Human-readable error description.

### 400 — Bad Request - Invalid input

### 401 — Unauthorized - Authentication required

### 403 — Forbidden - Insufficient permissions

### 422 — Validation Error

Schema: `HTTPValidationError`

- `detail` (array · ValidationError) → `ValidationError`
  - `loc` (array · string | integer · required)
  - `msg` (string · required)
  - `type` (string · required)
  - `input` (object)
  - `ctx` (object)

## Code samples

### cURL

```bash
curl -X POST 'https://api.ondayzero.com/api/v1/bills/ai-create' \
  -H 'Authorization: Bearer dz_your_token' \
  -H 'x-business-id: YOUR_BUSINESS_ID' \
  -H 'Content-Type: application/json' \
  -d '{
  "pasted_text": "string",
  "pasted_text_s3_key": "string",
  "single_bill_s3_keys": [],
  "multi_bill_s3_key": "string"
}'
```

### JavaScript

```javascript
const response = await fetch('https://api.ondayzero.com/api/v1/bills/ai-create', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer dz_your_token',
    'x-business-id': 'YOUR_BUSINESS_ID',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
  "pasted_text": "string",
  "pasted_text_s3_key": "string",
  "single_bill_s3_keys": [],
  "multi_bill_s3_key": "string"
}),
});
const data = await response.json();
```

### Python

```python
import httpx

headers = {
    "Authorization": "Bearer dz_your_token",
    "x-business-id": "YOUR_BUSINESS_ID",
}

payload = {
  "pasted_text": "string",
  "pasted_text_s3_key": "string",
  "single_bill_s3_keys": [],
  "multi_bill_s3_key": "string"
}

response = httpx.post("https://api.ondayzero.com/api/v1/bills/ai-create", headers=headers, json=payload)
data = response.json()
```

## See also

- HTML version: https://www.ondayzero.com/docs/reference/bills/ai-create-bill-payload
- OpenAPI slice: https://www.ondayzero.com/docs/reference/bills/ai-create-bill-payload/openapi.json
- Other endpoints in **bills**: https://www.ondayzero.com/docs/reference/bills
