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

> AI-extract draft invoices from documents

- **Tag:** invoices
- **Operation ID:** `ai_create_invoice_payload_api_v1_invoices_ai_create_post`

## Description

Upload pasted text, PDFs, images, Excel files, or a CSV to extract draft invoice entities using AI. Returns draft invoices ready for user review before creation.

## Authentication

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

## Request body

Schema: `InvoiceAICreatePayloadRequest`

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

## Responses

### 201 — Successful Response

Schema: `InvoiceAICreatePayloadResponse`

- `items` (array · DraftInvoice · required) → `DraftInvoice` — List of draft invoice entities extracted by AI.
  - `customer_name` (string) — Customer/company name extracted by AI. Use to match or create a customer.
  - `amount` (integer) — Total invoice amount in cents extracted by AI.
  - `description` (string) — Invoice description or notes.
  - `invoice_number` (string) — Invoice number from the document.
  - `issue_date` (string) — Invoice issue date (YYYY-MM-DD) extracted by AI.
  - `due_date` (string) — Payment due date (YYYY-MM-DD) extracted by AI.
  - `notes` (string) — Additional notes or terms extracted by AI.
  - `customer_id` (string) — Matched customer UUID (if the customer was found in the system).
  - `currency` (string) — Currency code (USD, CAD, AUD, EUR, or GBP). Defaults to USD.
  - `line_items` (array · object) — Line items extracted by AI: [{description, quantity, unit_price_cents, total_cents}].
  - `s3_key` (string) — S3 key of the source document for this invoice.
  - `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 · InvoiceFileProcessingError) → `InvoiceFileProcessingError` — 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/invoices/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_invoice_s3_keys": [],
  "multi_invoice_s3_key": "string"
}'
```

### JavaScript

```javascript
const response = await fetch('https://api.ondayzero.com/api/v1/invoices/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_invoice_s3_keys": [],
  "multi_invoice_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_invoice_s3_keys": [],
  "multi_invoice_s3_key": "string"
}

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

## See also

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