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

# Create an invoice

POST https://api.mitu.ai/v1/invoices
Content-Type: application/json

Create an invoice.

Reference: https://docs.mitu.ai/api-reference/invoices/create-invoice

## Authentication

- `x-api-key` header (required) — Account API key used to authenticate server-side requests. Use the credentials issued for the same environment as the API base URL.

## Servers

- `https://api.mitu.ai` (Production, default)
- `https://sandbox-api.mitu.ai` (Sandbox)

## Request

### Headers

- `Idempotency-Key` (string, optional) — Unique key used to safely retry the same state-changing request.

### Body (application/json)

This endpoint expects a CreateInvoice.

- `lineItems` (list of InvoiceLineItem, required)
- `currency` (string, required)
- `recipientId` (string, optional) — A saved recipient to address the invoice to.
- `recipient` (InvoiceRecipientInput, optional) — Someone to bill. If a saved recipient has the same email address or phone number, the invoice goes to them. Otherwise a new recipient is saved.
- `invoiceNumber` (string, optional)
- `description` (string, optional)
- `taxAmount` (double, optional, default: 0)
- `discountAmount` (double, optional, default: 0)
- `dueAt` (datetime, optional)

## Response

### 201

Invoice created successfully.

- `message` (string, required)
- `data` (Invoice, required) — Response fields are snake_case; request fields are camelCase.

## Errors

### 400 Bad Request Error

Send either `recipientId` or `recipient`, and a total after tax and discount above zero.

- `message` (string, required) — Human-readable description of the error.

### 401 Unauthorized Error

Authentication failed because the API key is missing or invalid.

- `message` (string, required) — Human-readable description of the error.

### 403 Forbidden Error

The authenticated account is not allowed to perform this action.

- `message` (string, required) — Human-readable description of the error.

### 404 Not Found Error

The requested resource could not be found.

- `message` (string, required) — Human-readable description of the error.

### 409 Conflict Error

This `Idempotency-Key` was already used with a different request.

- `message` (string, required) — Human-readable description of the error.

### 422 Unprocessable Entity Error

One or more request fields are invalid.

- `message` (string, required)
- `errors` (list of ValidationErrorDetail, required)

### 429 Too Many Requests Error

Too many requests were sent in a short period.

- `message` (string, required) — Human-readable description of the error.

### 500 Internal Server Error

An unexpected error occurred while processing the request.

- `message` (string, required) — Human-readable description of the error.

## Types

### InvoiceLineItem

- `name` (string, required)
- `quantity` (integer, required)
- `amount` (double, required)
- `description` (string, optional)

### InvoiceRecipientInput

Someone to bill. If a saved recipient has the same email address or phone number, the invoice goes to them. Otherwise a new recipient is saved.

- `name` (string, required)
- `email` (string, optional)
- `phone` (string, optional)
- `reference` (string, optional) — Your own tag for who the recipient belongs to. Matching by email or phone happens within it.

### Invoice

Response fields are snake_case; request fields are camelCase.

- `id` (string, optional)
- `invoice_number` (string, optional, nullable)
- `status` (enum, optional)
  - Allowed values: `draft`, `sent`, `viewed`, `settling`, `paid`, `overdue`, `cancelled`
- `recipient` (Recipient, optional, nullable) — Who the invoice is addressed to. Still returned after the recipient is deleted.
- `description` (string, optional, nullable)
- `line_items` (list of InvoiceLineItem, optional)
- `subtotal` (string, optional) — The sum of the line items.
- `tax_amount` (string, optional)
- `discount_amount` (string, optional)
- `amount` (string, optional) — The total the payer is asked for, `subtotal` plus `tax_amount` minus `discount_amount`.
- `currency` (string, optional)
- `url` (PayUrl, optional) — The two ways to pay one resource. `checkout` is the page a person opens; `agent` is the 402-protected route an AI agent calls. They are not interchangeable — an agent given the checkout URL receives HTML instead of a payment challenge.
- `due_at` (datetime, optional, nullable)
- `sent_at` (datetime, optional, nullable)
- `viewed_at` (datetime, optional, nullable)
- `paid_at` (datetime, optional, nullable)
- `created_at` (datetime, optional)

### ValidationErrorDetail

- `field` (string, required) — Field that failed validation.
- `message` (string, required) — Description of the validation problem.

### Recipient

- `id` (string, optional)
- `name` (string, optional)
- `email` (string, optional, nullable)
- `phone` (string, optional, nullable)
- `reference` (string, optional, nullable)
- `created_at` (datetime, optional)

### PayUrl

The two ways to pay one resource. `checkout` is the page a person opens; `agent` is the 402-protected route an AI agent calls. They are not interchangeable — an agent given the checkout URL receives HTML instead of a payment challenge.

- `checkout` (string, required) — The hosted checkout a person opens.
- `agent` (string, required) — The route an AI agent pays programmatically.

## Examples

**Request**

```json
{
  "lineItems": [
    {
      "name": "Integration support",
      "quantity": 10,
      "amount": 150,
      "description": "10 hours"
    }
  ],
  "currency": "USD",
  "recipient": {
    "name": "Ada Lovelace",
    "email": "ada@example.com"
  },
  "invoiceNumber": "INV-2026-0041",
  "description": "September retainer",
  "dueAt": "2026-09-30T23:59:59.000Z"
}
```

**Response**

```json
{
  "message": "Invoice retrieved successfully",
  "data": {
    "id": "inv_4k2m9x7ptw3c",
    "invoice_number": "INV-2026-0041",
    "status": "draft",
    "recipient": {
      "id": "rcp_ds9hazr8jd3l",
      "name": "Ada Lovelace",
      "email": "ada@example.com",
      "phone": null,
      "created_at": "2026-09-09T10:12:04.512Z"
    },
    "description": "September retainer",
    "line_items": [
      {
        "name": "Integration support",
        "quantity": 10,
        "amount": 150,
        "description": "10 hours"
      }
    ],
    "subtotal": "1500.00",
    "tax_amount": "0.00",
    "discount_amount": "0.00",
    "amount": "1500.00",
    "currency": "USD",
    "url": {
      "checkout": "https://mitu.ai/invoice/inv_4k2m9x7ptw3c",
      "agent": "https://api.mitu.ai/invoice/inv_4k2m9x7ptw3c"
    },
    "due_at": "2026-09-30T23:59:59.000Z",
    "sent_at": null,
    "viewed_at": null,
    "paid_at": null,
    "created_at": "2026-09-09T10:12:04.881Z"
  }
}
```

**SDK Code**

```python
import requests

url = "https://api.mitu.ai/v1/invoices"

payload = {
    "lineItems": [
        {
            "name": "Integration support",
            "quantity": 10,
            "amount": 150,
            "description": "10 hours"
        }
    ],
    "currency": "USD",
    "recipient": {
        "name": "Ada Lovelace",
        "email": "ada@example.com"
    },
    "invoiceNumber": "INV-2026-0041",
    "description": "September retainer",
    "dueAt": "2026-09-30T23:59:59.000Z"
}
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://api.mitu.ai/v1/invoices';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"lineItems":[{"name":"Integration support","quantity":10,"amount":150,"description":"10 hours"}],"currency":"USD","recipient":{"name":"Ada Lovelace","email":"ada@example.com"},"invoiceNumber":"INV-2026-0041","description":"September retainer","dueAt":"2026-09-30T23:59:59.000Z"}'
};

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

```go
package main

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

func main() {

	url := "https://api.mitu.ai/v1/invoices"

	payload := strings.NewReader("{\n  \"lineItems\": [\n    {\n      \"name\": \"Integration support\",\n      \"quantity\": 10,\n      \"amount\": 150,\n      \"description\": \"10 hours\"\n    }\n  ],\n  \"currency\": \"USD\",\n  \"recipient\": {\n    \"name\": \"Ada Lovelace\",\n    \"email\": \"ada@example.com\"\n  },\n  \"invoiceNumber\": \"INV-2026-0041\",\n  \"description\": \"September retainer\",\n  \"dueAt\": \"2026-09-30T23:59:59.000Z\"\n}")

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

	req.Header.Add("x-api-key", "<apiKey>")
	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
require 'uri'
require 'net/http'

url = URI("https://api.mitu.ai/v1/invoices")

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

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"lineItems\": [\n    {\n      \"name\": \"Integration support\",\n      \"quantity\": 10,\n      \"amount\": 150,\n      \"description\": \"10 hours\"\n    }\n  ],\n  \"currency\": \"USD\",\n  \"recipient\": {\n    \"name\": \"Ada Lovelace\",\n    \"email\": \"ada@example.com\"\n  },\n  \"invoiceNumber\": \"INV-2026-0041\",\n  \"description\": \"September retainer\",\n  \"dueAt\": \"2026-09-30T23:59:59.000Z\"\n}"

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

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.mitu.ai/v1/invoices")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"lineItems\": [\n    {\n      \"name\": \"Integration support\",\n      \"quantity\": 10,\n      \"amount\": 150,\n      \"description\": \"10 hours\"\n    }\n  ],\n  \"currency\": \"USD\",\n  \"recipient\": {\n    \"name\": \"Ada Lovelace\",\n    \"email\": \"ada@example.com\"\n  },\n  \"invoiceNumber\": \"INV-2026-0041\",\n  \"description\": \"September retainer\",\n  \"dueAt\": \"2026-09-30T23:59:59.000Z\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.mitu.ai/v1/invoices', [
  'body' => '{
  "lineItems": [
    {
      "name": "Integration support",
      "quantity": 10,
      "amount": 150,
      "description": "10 hours"
    }
  ],
  "currency": "USD",
  "recipient": {
    "name": "Ada Lovelace",
    "email": "ada@example.com"
  },
  "invoiceNumber": "INV-2026-0041",
  "description": "September retainer",
  "dueAt": "2026-09-30T23:59:59.000Z"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.mitu.ai/v1/invoices");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"lineItems\": [\n    {\n      \"name\": \"Integration support\",\n      \"quantity\": 10,\n      \"amount\": 150,\n      \"description\": \"10 hours\"\n    }\n  ],\n  \"currency\": \"USD\",\n  \"recipient\": {\n    \"name\": \"Ada Lovelace\",\n    \"email\": \"ada@example.com\"\n  },\n  \"invoiceNumber\": \"INV-2026-0041\",\n  \"description\": \"September retainer\",\n  \"dueAt\": \"2026-09-30T23:59:59.000Z\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "lineItems": [
    [
      "name": "Integration support",
      "quantity": 10,
      "amount": 150,
      "description": "10 hours"
    ]
  ],
  "currency": "USD",
  "recipient": [
    "name": "Ada Lovelace",
    "email": "ada@example.com"
  ],
  "invoiceNumber": "INV-2026-0041",
  "description": "September retainer",
  "dueAt": "2026-09-30T23:59:59.000Z"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.mitu.ai/v1/invoices")! 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()
```