---
title: Purchases API (buying services)
description: Plans, pre-invoice, purchase requests and owner approval — nothing is bought without your click
sidebar:
  order: 6
  badge:
    text: Alpha
    variant: success
---

With this API (and the matching MCP tools) an AI tool can recommend a plan for your project, price it, and create a **purchase request**.

:::caution[The core rule]
**No order or payment happens without the account owner clicking on Hostino's approval page (`auth.hostino.ai/purchase`).** The approval permission (`orders:approve`) is only issued to Hostino's own web page; no other tool or app receives it, even if it asks.
:::

## Purchase flow

1. **`GET /v1/plans`**: purchasable plans and the price of each billing cycle.
2. **`POST /v1/orders/quote`**: exact pre-invoice, no side effects.
3. **`POST /v1/purchases`**: creates a purchase **request**; the response contains `approval_url`. Nothing is ordered yet.
4. The **account owner** opens `approval_url`, signs in, sees the server-computed pre-invoice and clicks Approve or Reject.
5. **`GET /v1/purchases/:id`**: track status until the service is active.

## Two payment methods

| `pay_with` | After approval | Scopes needed to create the request |
|---|---|---|
| `invoice` | The order and an **unpaid invoice** are created; you pay it in the panel and the service is set up automatically after payment. Credit is not touched. | `orders:write` |
| `credit` | The order is created and paid **from account credit**; the service is set up automatically. If credit is insufficient, the request is refused. | `orders:write` + `billing:pay` |

## Plans

```http
GET https://api.hostino.ai/v1/plans?category=nodejs_hosting&location=IR
```

| Item | Value |
|---|---|
| Scope | `orders:read` |
| `category` | `linux_hosting`, `smart_hosting`, `wordpress_hosting`, `nodejs_hosting`, `email_hosting`, `vip_hosting` |
| `location` | `IR` (Iran) or `EU` (Europe) |

Each plan has `pid`, `name`, `category`, `good_for`, `location`, `requires_domain` and per-cycle prices (`cycles`: `price`, `setup_fee` and Toman equivalents). Prices **exclude tax**.

## Pre-invoice

```bash
curl -s -X POST https://api.hostino.ai/v1/orders/quote -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" -d '{"pid":45,"billing_cycle":"monthly","domain":"example.com"}'
```

```json
{
  "pid": 45, "plan": "Node-Eco-IR", "billing_cycle": "monthly", "domain": "example.com", "currency": "IRR",
  "price": 1990000, "setup_fee": 0, "subtotal": 1990000, "estimated_tax": 199000, "estimated_total": 2189000,
  "estimated_total_toman": 218900, "credit_balance": 1960672, "can_pay_with_credit": false,
  "tax_note": "Estimated VAT 10%; the invoice shows the exact amount."
}
```

- Hosting plans need a `domain` (the domain the site will run on; registering a domain is separate).
- Tax is an estimate; the invoice shows the exact amount.

## Purchase request

```bash
curl -s -X POST https://api.hostino.ai/v1/purchases -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"pid":45,"billing_cycle":"monthly","domain":"example.com","pay_with":"invoice","idempotency_key":"my-key-1"}'
```

```json
{
  "id": "WuhjYldOOAUGOPTq2wnXsg",
  "status": "pending_approval",
  "approval_url": "https://auth.hostino.ai/purchase?id=WuhjYldOOAUGOPTq2wnXsg",
  "expires_at": "2026-10-21T12:00:00.000Z",
  "next_step": "The account owner must open approval_url and approve. Nothing is ordered until then."
}
```

- A request is valid for **15 minutes**.
- The same `idempotency_key` never creates a duplicate; an identical open request is reused.

## Request status

```http
GET https://api.hostino.ai/v1/purchases/{id}
```

| `status` | Meaning |
|---|---|
| `pending_approval` | Waiting for the owner to approve at `approval_url` |
| `processing` | Approved; placing the order |
| `awaiting_payment` | Order and invoice created; pay at `payment_url` (panel) |
| `completed` | Paid; the service is being set up (`service.ready` turns `true` once active) |
| `rejected` | The owner rejected it; no order was placed |
| `expired` | The approval window passed |
| `failed` | Not placed (e.g. `price_changed`, `order_failed`); nothing was charged |

## Free subdomain

For plans that need a domain, you can pass just `subdomain` (e.g. `myshop`) instead of `domain` to create the service on `myshop.hostino.cloud`.

- **Check availability:** `GET /v1/subdomains/check?name=myshop` (scope `orders:read`) → `{"subdomain":"myshop","domain":"myshop.hostino.cloud","available":true}`. Names are 3–32 characters: lowercase letters, digits and hyphens.
- `POST /v1/orders/quote` and `POST /v1/purchases` with `subdomain` run the same check (`subdomain_taken`, `409`).
- **Automatic DNS:** once the service is active, the subdomain's DNS record is pointed at the hosting server. `GET /v1/purchases/:id` reports it in `subdomain_dns` (`created`, `waiting_for_service`, or `pending (…)`).

## In-chat confirmation

Besides `approval_url`, a client the account owner granted `orders:confirm` can confirm a purchase with a **phrase the user typed themselves**:

1. The `POST /v1/purchases` response includes `confirm_in_chat.phrase` (Persian and English), e.g. `confirm purchase 108,900 toman code 4821`.
2. **`POST /v1/purchases/:id/confirm`** with `{"confirmation":"<typed text>"}` (scope `orders:confirm`) → order and an **unpaid invoice**, no charge.
3. If the credit covers it, the response includes `pay_with_credit_in_chat.phrase` with the **exact invoice amount**. **`POST /v1/purchases/:id/pay-with-credit`** in the same format (scope `orders:confirm` + `billing:pay`) pays the invoice from credit.
4. If the invoice amount changes in the meantime: `409 amount_changed` with a new phrase. After 5 wrong phrases: `429 too_many_attempts`. A wrong phrase: `400 confirmation_mismatch`.

Phrases accept Persian or English digits, with or without thousands separators, and expire with the request.

## Safeguards

- The price is re-checked right before ordering; if it changed, no order is placed (`price_changed`).
- Approving twice or concurrently never creates a second order.
- Ordering the same plan for the same domain within 24 hours is blocked (`duplicate_recent_order`).
- At most **3 orders per day** per account, and a per-order amount cap.
- Every step, including refused attempts, is written to the audit log.

## Errors

| Code | `error` | Cause |
|---|---|---|
| `400` | `domain_required` / `cycle_not_offered` / `pay_with_required` / `amount_over_limit` | Invalid input |
| `402` | `insufficient_credit` | Not enough credit for `pay_with: credit`; use `invoice` |
| `403` | `insufficient_scope` / `approval_requires_hostino_web` | Missing permission; approval only happens on Hostino's page |
| `404` | `unknown_plan` / `not_found` | Plan or request doesn't exist (or belongs to another account) |
| `409` | `price_changed` / `duplicate_recent_order` | Price changed or duplicate order |
| `410` | `request_expired` | Approval window passed; make a new request |
| `429` | `daily_limit_reached` | Daily order limit |

## Plan upgrades

Upgrade an existing hosting service to a higher plan, with the same rule as the panel: **the same product group** (same type and location), a plan priced higher for **the service's own billing cycle**, and **the billing cycle unchanged**. Email hosting and one-click apps are not upgraded this way. Full explanation: [Plan upgrades with AI](/en/ai-mcp/upgrades/).

| Endpoint | Scope | What it does |
|---|---|---|
| `GET /v1/services/:id/upgrades` | `services:read` | Allowed plans with the price per period (no side effects) |
| `POST /v1/services/:id/upgrade` | `orders:write` | `{"plan_id"}` → the exact prorated amount and a confirmation phrase; nothing changes yet |
| `POST /v1/upgrades/:id/confirm` | `orders:write` + `orders:confirm` | `{"confirmation"}` with what the account owner typed → upgrade order and an unpaid invoice |

```bash
curl -s https://api.hostino.ai/v1/services/150/upgrades -H "Authorization: Bearer $TOKEN"
```

```json
{
  "service_id": "150", "domain": "example.com", "billing_cycle": "monthly",
  "current": { "plan_id": "2", "name": "WP-Lite-IR", "group": "…", "price_toman": 335000, "next_due_date": "2026-12-01" },
  "upgrades": [ { "plan_id": "4", "name": "WP-Core-IR", "price_toman": 595000 }, { "plan_id": "1", "name": "WP-Plus-IR", "price_toman": 795000 }, { "plan_id": "14", "name": "WP-Max-IR", "price_toman": 995000 } ],
  "currency": "toman",
  "note": "Prices are per monthly period (VAT added on the invoice); the billing cycle stays monthly. …"
}
```

The answer to `POST /v1/services/:id/upgrade` contains `request_id`, `from`, `to`, `days_until_renewal`, `upgrade_charge_toman`, `estimated_total_toman` (with estimated VAT), `phrase` (Persian and English, e.g. `confirm upgrading example.com to WP-Core-IR 165,000 toman code 4821`) and `expires_at`.

- **The plan switches when the invoice is paid.** Pay it from credit with [`POST /v1/invoices/:id/credit-payment`](/en/api/billing/) or in the panel.
- The prorated amount is re-checked at confirmation; if it changed, the answer is `409 amount_changed` with a new request and phrase in `new_request`.
- `orders:confirm` is not allowed in API tokens, so **an upgrade cannot be confirmed with an API token** — only through OAuth, typed by the account owner.
- Errors: `not_upgradable_here` (`409`), `upgrade_not_allowed` (`400`), `service_not_active` (`409`), `confirmation_mismatch` (`400`), `request_expired` (`410`), `too_many_attempts` and `daily_limit_reached` (`429`), `amount_over_limit` (`400`).

## In MCP

The [`list_plans`, `check_subdomain`, `prepare_order`, `request_order`, `confirm_order`, `pay_with_credit` and `get_order_status`](/en/ai-mcp/remote-mcp/#buying-services) tools; for upgrades, [`service_upgrade_options`, `service_upgrade` and `service_upgrade_confirm`](/en/ai-mcp/upgrades/).
