# Buying a private modem line by HTTP

<!-- facts:begin product.mobile -->
**Private mobile proxies**: Not available yet. A dedicated 4G/5G modem on a carrier SIM, yours alone for the period. A signed-in account asks for it with `POST /app/api/demand/device` and the kind `mobile`: the request is recorded, and nothing is ordered or charged.
<!-- facts:end product.mobile -->

To ask for a private modem that is not listed or not in stock, use `POST /app/api/private/requests` (step 9): it answers in every state and records the country and the count.

A private modem is a 4G or 5G modem on a carrier SIM that your account holds alone for the period it ordered. Each modem is one line of an order, with a login for HTTP and one for SOCKS5. This page holds every step; each request and answer shape is also in [/openapi.json](/openapi.json).

Every path below is on the base URL you were given. The commands use curl and jq. Each block runs on its own: it sets `umask 077`, so only you can read the files it writes, and sets `BASE` to https://coronium.ai unless you exported `BASE` with your base URL first. The blocks read the session cookie from `coronium.cookies`, which [the quickstart](/guides/agents.md) writes.

## Rules

- Send JSON with `Content-Type: application/json`. Every refusal is a JSON object with `code`, `cause` and `fix`. Read `fix` and send what it names. Each block below prints the refusal when the answer is one.
- An account has three secrets: `credential`, `accessCode` and the session cookie. The commands below write answers to files only you can read, and pass nothing secret on a command line. Never print a secret, and never put one in a prompt, a log or a chat message.
- The logins of a line are secrets too. Step 7 writes them to a file only you can read and prints only whether each line has an address.
- These routes take the session cookie only. A request that carries the credential as a Bearer header is refused with `session_required`.
- Money is decimal text in micro-USD. Ask your person before you confirm a quote, unless they gave you a budget for it.

## Steps

### 0. Read the switches

`GET /app/api/buy` needs no account. `private.configured` says whether private modems can be ordered, `charging` says whether anything can be paid, and `card`, `crypto` and `agent` each say whether that way to add funds is configured. While coronium.ai is in private preview this answers `403` with the code `private_preview`: tell your person.

```
umask 077
BASE=${BASE:-https://coronium.ai}
curl -sS "$BASE/app/api/buy" -o coronium-buy.json
jq 'if .code then . else {private, charging, card: .card.configured, crypto: .crypto.configured, agent: .agent.configured} end' coronium-buy.json
```

### 1. Sign in

Follow steps 1 and 2 of [the quickstart](/guides/agents.md). While `registration` is `closed`, sign in with your person's access code as it says.

### 2. Read the offers

`GET /app/api/private/offers` needs no account. Add `?period=day`, `?period=week` or `?period=month` to read one period. Each offer has `offerId`, `country`, `carrier`, `period`, `days`, `inStock` and `unitUsdMicros`, the price of one modem for the whole period. An offer is on request when its `inStock` is zero: ask for it with step 9. The service reads the stock every minute, and `readAt` says when. While `private.configured` is false this answers 503 `private_not_configured`.

```
umask 077
BASE=${BASE:-https://coronium.ai}
curl -sS "$BASE/app/api/private/offers" -o coronium-offers.json
jq -r 'if .code then .code + ": " + .fix else (.offers[] | [.offerId, .country, .carrier, .period, .inStock, .unitUsdMicros] | map(tostring) | join(" ")) end' coronium-offers.json
```

### 3. Ask for a quote

`POST /app/api/private/quotes` with an `offerId` and a `quantity` from one to ten, the most one order holds. It reads the stock, writes nothing and owes nothing. The answer holds `quoteId`, `inStock`, `onRequest` (what is beyond the stock now, recorded as demand once you confirm), `unitUsdMicros`, `usdMicros` (the most the order will debit) and `expiresAt`. A quote holds for 30 minutes. Ask for more than one order holds with step 9. While `private.configured` is false this answers 503 `private_not_configured`.

```
umask 077
BASE=${BASE:-https://coronium.ai}
OFFER=of_put_the_offer_id_here
jq -n --arg offer "$OFFER" '{offerId: $offer, quantity: 2}' > coronium-ask.json
curl -sS -b coronium.cookies -H 'Content-Type: application/json' -d @- "$BASE/app/api/private/quotes" -o coronium-priced.json < coronium-ask.json
jq 'if .code then . else {quoteId, quantity, inStock, onRequest, unitUsdMicros, usdMicros, expiresAt} end' coronium-priced.json
```

### 4. Have funds

`GET /app/api/billing` answers `paid`, the paid balance. Only paid money buys a modem, never credit the operator granted. To add funds, follow step 7 of the quickstart with your person, for a card or crypto, or step 8 from your own wallet at `POST /v1/topup`. A top-up is refused with 503 `provider_not_configured` while the service has no key for that provider, and with 409 `topups_closed` while `charging` is false, and nothing settles; while `agent.configured` is false, `POST /v1/topup` offers nothing and charges nothing.

```
umask 077
BASE=${BASE:-https://coronium.ai}
curl -sS -b coronium.cookies "$BASE/app/api/billing" | jq 'if .code then . else {paid: .paid.usdMicros} end'
```

### 5. Confirm

`POST /app/api/private/orders` with the `quoteId` and `confirm` true. An order exists only when the account that was given a quote sends that quote back with `confirm` true. The quote is signed for your account alone, and the order debits at most its `usdMicros` from the paid balance, once. Ask your person before you confirm, unless they gave you a budget.

The order is sent to the modem supply once, and the answer comes within about a minute: `order` with its `orderId` and `state`, and `onRequest`. When nothing was in stock, `order` is null and nothing is charged. If the answer is a 5xx, or no answer came, send the same `quoteId` again: it reads the same order and charges nothing more. While `private.configured` is false this answers 503 `private_not_configured`; while `charging` is false it answers 409 `purchases_closed`; with too little paid balance it answers 402 `insufficient_balance` and `shortfallUsdMicros`, which step 4 adds.

```
umask 077
BASE=${BASE:-https://coronium.ai}
jq '{quoteId, confirm: true}' coronium-priced.json > coronium-confirm.json
curl -sS -b coronium.cookies -H 'Content-Type: application/json' -d @- "$BASE/app/api/private/orders" -o coronium-order.json < coronium-confirm.json
jq 'if .code then . else {order: (.order | if . then {orderId, state, quantity, usdMicros, failure} else null end), onRequest} end' coronium-order.json
```

### 6. Read the order

Read the order once a minute. `delivered` and `returned` are final. An open order keeps its debit and is charged nothing more; it becomes `delivered` when its lines arrive. If it is still open an hour after `createdAt`, stop reading: a person looks at it, and if its lines do not arrive the amount is returned to the balance. Tell your person, and name the `orderId`. Do not confirm the same quote again to hurry it: that reads the same order.

A `returned` order has its price back on the balance, and its `failure` is `on_request` when it was not in stock, otherwise `not_filled`. While `private.configured` is false the order still answers, with no lines. An `orderId` this account never made answers 404 `order_not_found`.

```
umask 077
BASE=${BASE:-https://coronium.ai}
ORDER=$(jq -r '.order.orderId' coronium-order.json)
curl -sS -b coronium.cookies "$BASE/app/api/private/orders/$ORDER" | jq 'if .code then . else {state, failure, delivered, createdAt, expiresAt, lines: [.lines[] | {lineId, expiresAt, online, capabilities}]} end'
```

### 7. Read the logins

`GET /app/api/private/orders/{orderId}/credentials` is answered with `Cache-Control: no-store`. Each line has `http` and `socks5`, each a host, a port, a username and a password. `hostPending` true means the line has no address to show: if it stays so, tell your person and name the `orderId`. Read the logins when you need them, and never pass them to a chat model. While `private.configured` is false this answers 503 `private_not_configured`.

```
umask 077
BASE=${BASE:-https://coronium.ai}
ORDER=$(jq -r '.order.orderId' coronium-order.json)
curl -sS -b coronium.cookies "$BASE/app/api/private/orders/$ORDER/credentials" -o coronium-logins.json
jq -r 'if .code then .code + ": " + .fix else (.lines[] | .lineId + " " + (if .hostPending then "no address to show" else "ready" end)) end' coronium-logins.json
```

### 8. Rotate or replace a line

`POST /app/api/private/orders/{orderId}/lines/{lineId}/rotate` or `/replace` with `confirm` true, on a line whose `capabilities.rotate` or `capabilities.replace` is true. Nothing is charged. A rotation may answer 429 `rotation_too_soon` with `retryAfterSeconds`: wait that long, then rotate again. `action_refused` changed nothing and charged nothing: the line may be offline, ended or busy, so read the order again. Rotations and replacements count toward the account's bound on writes: `rate_limited` says how long to wait. `pending` true means the action is still running: read the order again in a minute. A replaced line has a new `lineId` and new logins. While `private.configured` is false these answer 503 `private_not_configured`.

```
umask 077
BASE=${BASE:-https://coronium.ai}
ORDER=$(jq -r '.order.orderId' coronium-order.json)
LINE=ln_put_the_line_id_here
curl -sS -b coronium.cookies -H 'Content-Type: application/json' -d '{"confirm": true}' "$BASE/app/api/private/orders/$ORDER/lines/$LINE/rotate"
```

### 9. Ask for what is not listed, or not in stock

`POST /app/api/private/requests` with a two-letter `country`, a `quantity` of up to a thousand, and an optional one-line `note` with the carrier and the period. It needs no switch, so it answers in every state: `recorded` true and `onRequest`, the count recorded. Nothing is ordered or charged.

```
umask 077
BASE=${BASE:-https://coronium.ai}
curl -sS -b coronium.cookies -H 'Content-Type: application/json' -d '{"country": "de", "note": "Any carrier, for a month", "quantity": 20}' "$BASE/app/api/private/requests"
```

### 10. Read the bill

`GET /app/api/billing/statement` lists the month's `orders`, each with its `orderId`, and counts them in `purchases`.

```
umask 077
BASE=${BASE:-https://coronium.ai}
curl -sS -b coronium.cookies "$BASE/app/api/billing/statement" | jq 'if .code then . else {orders, purchases} end'
```

## Refusals

| Code | Status | What to do |
| --- | --- | --- |
| `private_not_configured` | 503 | Private modems cannot be ordered now. Ask for one with step 9, or read `GET /app/api/buy` later |
| `purchases_closed` | 409 | Nothing was charged. Confirm again once `GET /app/api/buy` answers `charging` true |
| `insufficient_balance` | 402 | Add at least `shortfallUsdMicros` with step 4, then ask for a new quote and confirm it |
| `invalid_quote` | 400 | This `quoteId` was not given to this account, or it was changed. Ask for a new quote |
| `quote_expired` | 409 | Nothing was charged. Ask for a new quote |
| `price_changed` | 409 | Nothing was charged. Show your person the new `unitUsdMicros`, then ask for a new quote |
| `offer_not_found` | 404 | Read the offers again and choose one |
| `confirmation_required` | 400 | Send `confirm` true, after your person agreed |
| `session_required` | 403 | Send the session cookie and no Bearer header |
| `order_not_found` | 404 | Use an `orderId` from `GET /app/api/private/orders` |
| `action_unsupported` | 409 | Use an action whose capability on that line is true |
| `action_refused` | 409 | Nothing changed. Read the order again |
| `rotation_too_soon` | 429 | Wait `retryAfterSeconds`, then rotate again |
| `action_failed` | 503 | Nothing was charged. Try again in a minute |
| `rate_limited` | 429 | Nothing was sent. Wait as `fix` says, then send it again |
