# Doubao Image MCP — API reference

Base URL: `https://tu.xfeixie.com`. All JSON. Generation takes 20–60 s.

## Authentication

- No key: free trial, 3 images per device (client IP). Then `FREE_TRIAL_USED`.
- With key: `Authorization: Bearer tu_...` (also `X-Api-Key` header or `?key=` query). Get a key at `/app` (email sign-in, 3 more free images).
- An invalid key is an error (`INVALID_KEY`), never silently downgraded to the trial.

## Envelope

Success `{ "ok": true, "data": ... }`. Failure `{ "ok": false, "code": "...", "msg": "..." }` with the real HTTP status. `msg` is a readable instruction (Chinese unless `Accept-Language` is not Chinese). Web console endpoints return `msg = code` and the frontend translates.

## Generate — `POST /api/v1/images`

Body:

| field | type | default | notes |
|---|---|---|---|
| prompt | string | required | 1–2000 chars, Chinese or English |
| aspect_ratio | `1:1` `4:3` `3:4` `16:9` `9:16` `3:2` `2:3` `21:9` | `1:1` | |
| quality | `standard` \| `hd` | `standard` | standard ≈2.5 MP, hd ≈4 MP |
| reference_images | string[] | none | ≤4, public http(s) URL or `data:image/...;base64,...` (body ≤24 MB) |

Returns `GenerateResult`: `{ id, url, page, prompt, width, height, quality, costFen, paidBy, createdAt, freeLeft, balanceFen }`. `url` is the permanent image file, `page` a share page (noindex). `paidBy`: `free_trial` | `free_account` | `balance`. `balanceFen` is `null` without a key.

Price (CNY fen, same as Volcengine `doubao-seedream-5-0-pro`): standard 30, hd 60, each reference image after the first +2. Account free images are used before balance. Failed or blocked generations are refunded.

## Other endpoints

- `GET /api/v1/account` → `{ signedIn, freeLeft, balanceFen }`
- `GET /api/v1/pricing` → prices and signup URL
- `POST /v1/images/generations` — OpenAI-compatible. Body `{ prompt, size?: "WxH", quality?: "standard"|"hd", image?: string|string[] }` (size maps to the nearest supported aspect). Returns `{ created, data: [{ url, revised_prompt }] }`; errors `{ error: { message, type, code } }`.
- `POST /mcp` — Streamable HTTP MCP (stateless, POST only). Tools: `generate_image(prompt, aspect_ratio?, quality?, reference_images?)`, `get_account()`. Works without a key (trial).
- `GET /i/<id>.jpeg|png` image file; `GET /i/<id>` share page.

## Web console (cookie session `tu_sid`)

- `GET /api/config` → `PublicConfigView`
- `POST /api/auth/email/start` `{ email, lang }` → `{ sent }`; `POST /api/auth/email/verify` `{ email, code }` → `MeView` + cookie; `POST /api/auth/logout`
- `GET /api/me` → `MeView`; `POST /api/me/rotate-key`; `GET /api/me/images?limit=` → `ImageView[]`; `POST /api/me/generate` (same body as `/api/v1/images`)
- `POST /api/pay/order` `{ pack, idempotencyKey }` → `OrderView` (WeChat: QR to `https://ai.xfeixie.com/api/wallet/tu-entry?order=<rid>`; PayPal: `paypalApproveUrl`); `GET /api/cashier/order-status?rid=` → `{ rid, status }`
- Packs: `cny10` `cny30` `cny100` (WeChat Pay), `usd2` `usd5` `usd15` (PayPal, credited at USD 1 = CNY 7)
- `GET /api/wallet/recharge-entry`, `POST /api/payment/wechat-notify`, `GET /api/wallet/paypal-return` — payment pages and callbacks

## Error codes

| code | HTTP | meaning |
|---|---|---|
| BAD_PROMPT / BAD_ASPECT / BAD_QUALITY / BAD_REFERENCE / BAD_PARAM | 400 | invalid input |
| CONTENT_REJECTED | 400 | blocked by Volcengine safety filter, not charged |
| INVALID_KEY | 401 | unknown API key |
| FREE_TRIAL_USED | 401 | 3 trial images used on this device — sign up for a key |
| FREE_TRIAL_BUSY | 401 | daily trial pool exhausted — sign up for a key |
| AUTH_REQUIRED | 401 | console session missing |
| INSUFFICIENT_BALANCE | 402 | top up at /app |
| NOT_FOUND | 404 | |
| TOO_MANY | 429 | rate limited (6 generations per minute per IP) |
| GENERATION_FAILED | 502 | upstream failure, not charged |
| INTERNAL | 500 | |
