# Quickstart

Make your first BunCho API request and read its result.

A coding agent can call the BunCho API with `curl` or the official OpenAI SDKs,
or connect to the BunCho MCP server. An application calls the HTTP API. This
page covers both.

> Use the endpoint names and fields in this page and in the OpenAPI file
> (https://bun-cho.work/developers/openapi.json). Do not guess endpoints from
> other OpenAI-compatible APIs: BunCho has no `/v1/images` or `/v1/embeddings`.

- Base URL: `https://bun-cho.work/studio/api/v1`
- Authentication: `Authorization: Bearer bk_live_...`
- Billing: DREAM, debited per call from the account that owns the key
- Human docs: https://bun-cho.work/en/developers (Japanese: https://bun-cho.work/developers)

## Try a price first (no key)

Before anything else, you can check what a call costs. This needs no key and
spends nothing (limited to 20 requests per minute per IP address):

```sh
curl --fail-with-body -sS https://bun-cho.work/studio/api/v1/estimate/public \
  -H "Content-Type: application/json" \
  -d '{"action": "novel", "length": 1000}'
```

It returns `dream` (typical), `max_dream`, the yen guide and
`recommended_pack`, the smallest DREAM pack that covers one call. Manga and
video prices depend on the script, so they need a key (`POST /estimate`, free).

## With the CLI

```sh
npx @ai_buncho/cli login            # sign in in the browser; no key to copy
npx @ai_buncho/cli cost manga --story story.md --format webtoon
npx @ai_buncho/cli manga create --story story.md --format webtoon --wait --max-dream 300
```

Skills for Claude Code and Codex: `npx skills add Industrial-Dream-inc/skills`.
The CLI calls the same HTTP API and spends from the same DREAM balance. It
adds an `Idempotency-Key` to every paid request and stops before starting when
the estimate is above `--max-dream`.

## With a coding agent

Follow these steps if you are a coding agent, or to set one up.

1. Ask the user for an API key. A person has to create it; you cannot. Give
   them these steps and wait:

   1. Open https://bun-cho.work/studio/developers and sign in. Signing up is
      free.
   2. Press **Create key** (日本語の画面では「鍵を作る」).
   3. Copy the key. It starts with `bk_live_` and is shown only once.
   4. In their own terminal, run `export BUNCHO_API_KEY="bk_live_..."`, or put
      `BUNCHO_API_KEY=bk_live_...` in the project's `.env` file.

   Do not ask the user to paste the key into the chat, and do not write the key
   into a command, a source file, or a commit. Read it from `BUNCHO_API_KEY`.

2. Check the key and the balance. This call is free:

   ```sh
   curl --fail-with-body -sS https://bun-cho.work/studio/api/v1/balance \
     -H "Authorization: Bearer $BUNCHO_API_KEY"
   ```

   `available_dream` is what the account can spend. If it is `0`, create a
   payment link with `POST /billing/checkout` (see [Paying for DREAM](#paying-for-dream))
   and give it to the user. A person pays with Stripe; you cannot. A new
   account's first key may come with 50 trial DREAM, which is enough for the
   first request below.

3. Make the first request. Follow [With the HTTP API](#with-the-http-api),
   step 3. It costs about 1 DREAM (about ¥0.71). Make it once. If it fails,
   read the error (see [Errors and retries](#errors-retries-and-limits)) before
   you try again.

4. Tell the user what came back: the generated text, `x_buncho.dream_charged`,
   and how to continue. Then pick the endpoint for what they want to make from
   [Choose an endpoint](#choose-an-endpoint).

5. Optional: connect the MCP server so the agent can make manga and videos as
   tools. See [MCP server](#mcp-server).

Before any call that costs more than a few DREAM, check the price and tell the
user: `POST /estimate` (free) for manga and video, `GET /audio/music` (free) for
songs. Do not start paid jobs in a
loop.

## With the HTTP API

The rest of this page makes the same request for applications that call the
API directly: create a key, check it, send one request, read the result.

### 1. Create an API key

Open https://bun-cho.work/studio/developers, sign in, press **Create key**, and
copy the secret when it appears. It cannot be shown again. One account can hold
up to 5 keys. Each key has its own limits, which you can lower on the same
page: requests per minute (default 30), concurrent requests (default 2) and
DREAM per day (default 3,000).

### 2. Configure the client

```sh
export BUNCHO_API_BASE="https://bun-cho.work/studio/api/v1"
export BUNCHO_API_KEY="bk_live_replace_with_your_key"
```

Confirm that the API is reachable without a key. The price table is public, so
this prints `200`:

```sh
curl --fail-with-body -sS -o /dev/null -w "%{http_code}\n" "$BUNCHO_API_BASE/pricing"
```

Then confirm the key (free):

```sh
curl --fail-with-body -sS "$BUNCHO_API_BASE/balance" \
  -H "Authorization: Bearer $BUNCHO_API_KEY"
```

It returns:

```json
{"object": "balance", "available_dream": 50, "approx_jpy": 36.5, "key": {"id": "key_...", "used_today_dream": 0, "limits": {"requests_per_minute": 30, "concurrency": 2, "daily_dream": 3000}}, "purchase_url": "https://bun-cho.work/studio/developers#buy"}
```

A `401` here means the key is missing, mistyped or revoked. It is not a network
problem. With `--fail-with-body`, curl prints `curl: (22) ... 401` before the
error body.

### 3. Send the first request

`POST /chat/completions` has the same shape as OpenAI Chat Completions. The
default model is `buncho-creative` (BunCho's own model for fiction). This asks
for a short opening scene and caps the output so the cost stays near 1 DREAM.

```sh
curl --fail-with-body -sS "$BUNCHO_API_BASE/chat/completions" \
  -H "Authorization: Bearer $BUNCHO_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: quickstart-$(date +%s)" \
  -d '{
    "model": "buncho-creative",
    "messages": [{"role": "user", "content": "Write the opening of a short story: two people meet again at a rainy station. About 300 characters."}],
    "max_tokens": 400
  }'
```

The response is an OpenAI `chat.completion` object.
`choices[0].message.content` holds the text, `usage` holds the tokens, and
`x_buncho.dream_charged` is the DREAM debited for this call.

TypeScript (Node 18+, `npm install openai`, an ES module such as `first.mjs`):

```ts
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.BUNCHO_API_KEY,
  baseURL: "https://bun-cho.work/studio/api/v1",
});

const res = await client.chat.completions.create({
  model: "buncho-creative",
  messages: [{ role: "user", content: "Write the opening of a short story: two people meet again at a rainy station. About 300 characters." }],
  max_tokens: 400,
});
console.log(res.choices[0].message.content);
```

Python (`pip install openai`):

```python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["BUNCHO_API_KEY"],
    base_url="https://bun-cho.work/studio/api/v1",
)
res = client.chat.completions.create(
    model="buncho-creative",
    messages=[{"role": "user", "content": "Write the opening of a short story: two people meet again at a rainy station. About 300 characters."}],
    max_tokens=400,
)
print(res.choices[0].message.content)
```

Streaming (`"stream": true`) and `response_format` (`json_object`,
`json_schema`) work as in OpenAI. `tools`, `functions`, `logprobs`,
`logit_bias`, image or audio input and `n` other than 1 return `400` with
`param` set. The server keeps no conversation history: send the whole
conversation each time.

### 4. Check what you spent

```sh
curl --fail-with-body -sS "$BUNCHO_API_BASE/balance" \
  -H "Authorization: Bearer $BUNCHO_API_KEY"
```

`key.used_today_dream` counts this key's spending since 00:00 JST.

## Choose an endpoint

Every path below is relative to `https://bun-cho.work/studio/api/v1`. Fields
and response schemas are in the OpenAPI file.

| To make | Call | Returns |
| --- | --- | --- |
| A story, episode, continuation, revision or short-drama script | `POST /novel` with `mode` = `write`, `episode`, `continue`, `revise` or `script`, and `text` | Text at once (`length` 100-8,000 characters, default 1,000) |
| Free-form text with your own prompt | `POST /chat/completions` | OpenAI `chat.completion` |
| Lettered 4-koma or manga pages | `POST /manga` with `text`, `format` = `4koma` (default), `page` or `webtoon` | `202` and a job; images in `result.pages` |
| A vertical short video (mp4) from a script | `POST /video` with `text`, `aspect` = `9:16` (default), `16:9` or `1:1` | `202` and a job; `result.video_url` |
| A story bible from a manuscript | `POST /story-bible` | JSON: characters, relationships, timeline, terms, foreshadowing |
| A continuity check | `POST /check` | Contradictions and open foreshadowing |
| A song with vocals or BGM from lyrics | `POST /audio/music` (`GET /audio/music` lists options, free) | `202` and a job |
| Speech from text | `POST /audio/speech` (`GET /audio/voices` lists voices) | Audio, OpenAI `audio.speech` shape |
| A character's reply | `POST /chara/chat`, or `model: "buncho-chara:<id>"` in chat completions (`GET /characters` lists characters, free) | One in-character turn |
| Titles, synopsis, catchphrases, translation | `POST /title`, `/synopsis`, `/catchphrase`, `/translate` | Text |

Asynchronous endpoints (`/manga`, `/video`, `/audio/music`,
`/design/renders`) return `202` with a job `id` and `status_url`. Poll
`GET /jobs/{id}` (free) every 5-10 seconds until `status` is `done` or
`failed`, or set a webhook URL on the key in
https://bun-cho.work/studio/developers. Webhooks are signed with
`BunCho-Signature: t=<unix seconds>,v1=<HMAC-SHA256(secret, "<t>.<body>")>`.

A typical text-to-video flow: `POST /novel` with `mode: "script"`, then
`POST /estimate` with `action: "video"`, then `POST /video` with the script.

AI TRPG, OTHERLIFE chat sessions and the games on bun-cho.work are web apps.
They are not part of this API.

## MCP server

BunCho is also a remote MCP server (Streamable HTTP):

```text
https://bun-cho.work/mcp
```

It uses OAuth with the user's BunCho account, not an API key. The user signs
in to BunCho in the browser when the client first connects and approves the
access. The tools make manga, videos and stories, and show the DREAM price
before they spend it.

- Claude Code: `claude mcp add --transport http buncho https://bun-cho.work/mcp`,
  then run `/mcp` and choose **buncho** to sign in.
- Claude (web and desktop) and ChatGPT: add a custom connector with the URL
  above. Steps with screenshots: https://bun-cho.work/en/studio/claude and
  https://bun-cho.work/en/studio/chatgpt
- Other clients: the server publishes OAuth metadata at
  https://bun-cho.work/.well-known/oauth-protected-resource and a server card
  at https://bun-cho.work/.well-known/mcp. It supports dynamic client
  registration and Client ID Metadata Documents.
- When connecting, the user can choose a monthly DREAM limit for that
  connection. The `balance` tool shows it; `buy_dream` returns a payment link
  for an existing pack. City tools: `city_districts`, `estimate_city`,
  `make_city_scene`.

## Pricing and refunds

- You pay per call in DREAM. 1 DREAM is about ¥0.71 including tax (the ¥300 pack gives
  420 DREAM; larger packs cost less per DREAM). No subscription is needed for the API.
- Examples at the current campaign price: 1,000 characters of fiction with
  `buncho-creative` is about 1 DREAM; one 4-koma is about 198 DREAM. The full
  table, in DREAM, yen and other currencies, is public:
  `GET /pricing` or https://bun-cho.work/developers/pricing.json
- Call `POST /estimate` (free) before a paid call. It returns `dream` (typical),
  `max_dream` (worst case), your `available_dream`, and `enough`.
- Text endpoints charge for what was actually generated. Every response has the
  DREAM charged (`x_buncho.dream_charged` in chat completions, `dream.charged`
  in the other text endpoints) and, for most, `balance_dream`.
- Jobs that do not finish are closed and refunded in full. If a job is still
  running after its time limit (text 15 minutes, manga 30, video 60, music 60),
  or a video storyboard cannot be completed within the quoted amount, the job
  ends with `status: "failed"`, `error` = `job_timeout` or
  `storyboard_incomplete`, and `result.failure.refunded_dream` shows the DREAM
  returned. Other failed manga and video jobs are refunded too. Do not resubmit
  the same work while a job is still `running`.
- With too little DREAM a call returns `402` and nothing starts.

## Paying for DREAM

The full rules for agent use (one wallet, holds, which free DREAM applies,
limits) are in https://bun-cho.work/docs/agents/billing.md.

An agent can find prices, check the balance and prepare a payment, but a person
always pays and always sets the limits.

- `GET /pricing` lists the DREAM packs (`packs`, tax included). Only these
  packs can be bought; there are no other amounts.
- A `402` error is ready to act on: `shortfall_dream`, `recommended_pack` (the
  smallest pack that covers the shortfall, with `dream`, `yen_tax_included` and
  `quantity`), `purchase_url` (the purchase page with that pack selected) and
  `auto_charge` (`enabled` and `settings_url`).
- `POST /billing/checkout` with `{"pack_id": "pack_1000"}` returns a Stripe
  Checkout `checkout_url` for the account that owns the key. Give it to the
  user. Only `pack_id` is accepted. Every pack comes with a receipt.
- `GET /purchases` lists past purchases with `invoice_url` (the receipt page).
- Auto top-up: if the owner turned it on in BunCho Studio, BunCho buys the pack
  they chose when the balance runs low, up to their monthly count and amount
  limits. `GET /balance` shows `auto_charge` (on or off, the pack, the monthly
  limits and what was used this month).

On a `402`: if `auto_charge.enabled` is `true` and the monthly limit is not
used up, wait about a minute, call `GET /balance`, and retry once with the same
`Idempotency-Key`. Otherwise tell the user what is missing and share
`purchase_url` (or a `checkout_url`), then wait until they say they have paid.
Do not retry in a loop.

### Budgets and expiry for keys

The key owner can set, only on https://bun-cho.work/studio/developers, a total
DREAM budget for a key, an expiry date and the endpoints it may call, on top of
the daily limit. A call over the budget returns `403` with
`insufficient_quota` (`key_budget_exceeded`); an expired key returns `401`
(`key_expired`); a blocked endpoint returns `403` (`endpoint_not_allowed`).
These cannot be changed with the key. `GET /balance` shows the limits and, with
a budget, `remaining_total_dream`.

## Errors, retries and limits

Errors have the OpenAI shape, so the OpenAI SDKs raise their usual exceptions:

```json
{"error": {"message": "...", "type": "rate_limit_error", "param": null, "code": "rate_limit_exceeded", "x_buncho_code": "model_busy"}}
```

`x_buncho_code` is present only when BunCho's own code differs from the OpenAI
one, and some errors add fields such as `docs_url`, `purchase_url` or
`retry_after_s`. Messages are in English. Send `Accept-Language: ja` for
Japanese.

| Status | `code` (`x_buncho_code`) | What to do |
| --- | --- | --- |
| 400 | `bad_request`, `missing_required_parameter`, `invalid_value`, `unsupported_value`, `unsupported_parameter`, `invalid_json`, `bad_idempotency_key` | Fix the field named in `param` (or in `message`). Do not retry unchanged. |
| 401 | `invalid_api_key`, `key_revoked`, `key_expired` | Ask the user for a valid key. Do not retry. |
| 402 | `insufficient_quota` (`insufficient_dream`) | See [Paying for DREAM](#paying-for-dream): retry once only if auto top-up is on; otherwise share `purchase_url` and wait for the user. |
| 403 | `adult_not_enabled`, `plan_required`, `forbidden`, `endpoint_not_allowed`, `insufficient_quota` (`key_budget_exceeded`) | The key or account is not allowed to do this, or the key's budget is used up. Tell the user; do not retry. |
| 404 | `not_found`, `model_not_found`, `character_not_found` | Check the id or the model name (`GET /models`). |
| 409 | `idempotency_key_reused`, `in_progress` | Use a new key for a different request, or wait for the first one. |
| 413 | `too_large`, `file_too_large` | Send a smaller body or file. |
| 422 | `content_policy_violation` (`content_blocked`) | Change the request. Repeated blocked requests (3 in 24 hours) revoke the key. |
| 429 | `rate_limit_exceeded` (`rate_limited`, `too_many_concurrent`, `model_busy`, `daily_limit`) | Wait for `Retry-After` seconds, then retry. `daily_limit` resets at 00:00 JST. |
| 5xx | `type` is `server_error`; `code` is for example `server_error`, `model_unavailable` or `upstream_error` | Retry with backoff (for example 2, 4, 8 seconds, or `Retry-After` when present) and the same `Idempotency-Key`. |

- Send an `Idempotency-Key` header (8-100 characters of letters, digits and
  `-_.:`) on every POST that costs DREAM. A retry with the same key and the same
  body returns the first result and is not charged again.
- `model_busy` means people using the BunCho app go first. The API waits for
  capacity instead of switching to a more expensive model.
- Limits per key: 30 requests per minute, 2 concurrent requests, 3,000 DREAM per
  day by default. `GET /balance` shows the current values and today's use.
- Content rules are the same as on bun-cho.work: no sexual content involving
  minors, no sexual or defamatory content about real people, no personal data,
  no instructions for illegal acts. Adult content between adults is off by
  default and can be turned on per key by an account that confirmed it is 18+.
- What you generate can be used commercially. Label it as AI-generated; most
  responses include `attribution` text for that.

## Where to go next

- Every endpoint and schema: https://bun-cho.work/developers/openapi.json
- Human docs with examples per feature: https://bun-cho.work/en/developers
  (novel, manga, video, story bible, check, chat pages are linked there)
- Try requests in the browser before writing code:
  https://bun-cho.work/studio/playground
- City 3D generation API (real cities as Gaussian splats with per-building
  collision; 300 DREAM per 400 m x 300 m block): https://bun-cho.work/docs/agents/city.md
- Index of BunCho pages for language models: https://bun-cho.work/llms.txt
- Terms of use for the API: https://bun-cho.work/terms_of_use#api
