Kunavo MCP server
# Kunavo MCP server
An [MCP](https://modelcontextprotocol.io) server for [Kunavo](https://kunavo.com),
an AI API gateway: text, image, video and music models from several providers
behind one API key and one prepaid balance.
With it an agent can list the models and their live prices, ask another text
model, generate and edit images, start video and music jobs and follow them to
the result, and read what its API key has spent.
- npm: `kunavo-mcp`
- Transports: stdio, and Streamable HTTP
- Needs: Node.js 20.3 or newer, and a Kunavo API key from <https://kunavo.com/app/keys>
## Set it up
The server is started by your MCP client. It reads the key from the
`KUNAVO_API_KEY` environment variable.
**Claude Code**
```bash
claude mcp add kunavo -e KUNAVO_API_KEY=sk-kn-your-key -- npx -y kunavo-mcp
```
**Claude Desktop, Cursor, and other clients that take an `mcpServers` entry**
```json
{
"mcpServers": {
"kunavo": {
"command": "npx",
"args": ["-y", "kunavo-mcp"],
"env": { "KUNAVO_API_KEY": "sk-kn-your-key" }
}
}
}
```
Without a key the server still starts and lists its tools; each call then
answers that `KUNAVO_API_KEY` is missing, instead of the server dying where
nobody reads its log.
## Tools
| Tool | What it does | Charged |
| --- | --- | --- |
| `list_models` | The models the key can call right now, with their listed prices in US dollars (every tier's, on a model priced by resolution or render speed), the clip lengths a video model priced per second takes, and what each model takes. Filter by kind (`endpoint`) or by text (`search`). | No |
| `chat` | Sends a prompt to a text model and returns the answer with its token counts. | Per token |
| `generate_image` | An image from a prompt. Takes a shape (`size`), on models that have them a resolution or render-speed tier (one the model lists; the API refuses another), and an `idempotency_key`. | Per image |
| `edit_image` | Changes an image, or makes one from reference images, with an optional mask. Sources are URLs or local image files. Takes an `idempotency_key`. | Per image |
| `generate_video` | Starts a video from a prompt and optional images; takes length, shape, resolution and an `idempotency_key`. | Per video or per second |
| `generate_music` | Starts a song from a description, or from lyrics with a style; takes an `idempotency_key`. One request makes two tracks. | Per request |
| `get_task` | The state of an image, video or music task, and its result URLs once it is done. | No |
| `get_balance` | What the key can spend right now: the wallet, what running tasks hold, what is available, what is left under the key's monthly limit and the account's cap, and whether auto-recharge is on. | No |
| `get_usage` | Requests, errors, tokens and cost of the API key, per day or hour, optionally per model. | No |
The server also has one resource, `kunavo://models` (the same catalog as
`list_models`, as JSON), and three prompts: `choose_model`, `create_video` and
`spend_report`.
### Models are read, not built in
The server knows no model by name. `list_models` asks the API, which lists what
the key can call at that moment; a model that is switched off or paused is not
in the list. Before a tool spends anything it checks the model against that
list, and answers a wrong one with the models that tool does take.
It checks what the request asks of the model, too. The list gives each model
its capabilities: whether it takes a source image, several images, a mask, a
first and a last frame, reference images. The API refuses a request that
brings what its model does not take, with a 400 that names the field, and it
goes by the same list. So a mask, a second image or a frame for a model the
list says does not take it is not sent at all: the tool says so and names the
models that do. What else the API refuses, such as more images than a model
takes (`list_models` gives each model's `max_input_images` and
`max_reference_images`), is left to it, and its 400 is passed on with its
message.
### Generation is a task
Images, video and music are submitted as tasks and polled. An MCP client gives
a tool call about a minute, and a clip takes longer than that. So:
- `generate_image` and `edit_image` wait 40 seconds for the image
(`wait_seconds`, 0 to 45) and return it if it is ready by then.
- `generate_video` and `generate_music` return the task at once
(`wait_seconds` is 0 unless you set it).
- A task that is not finished comes back with its id (`img_…`, `vid_…`,
`msc_…`) and its status. `get_task` reads it again, and waits 20 seconds for
it unless told otherwise.
- Every tool call is over within 55 seconds, whatever the API does, the tools
that only read included. A call the client has given up on could still have
submitted something, and then nobody would hold the task's id. So each
request a tool makes is given what is left of the call's time and no more,
a second try of a request among them; when the model list or a large source
image has used the time up, the tool submits nothing and says so.
- Once a task exists its id is in the answer, even when the polls after the
submit could not be read. The answer then says so, beside the id.
A finished result is a URL. A URL on `files.kunavo.com` is Kunavo's own copy
and does not expire; when a result says `archived: false`, the URL is the model
provider's temporary one. A music track's `stream_url` is always the
provider's. A task can be read for at least 30 days.
`chat` waits 50 seconds for the answer (`timeout_seconds`, up to 280 for a
client that allows a longer tool call) and is not streamed. The call is over
at most 5 seconds after that.
## What it will and will not do with your money
- `list_models`, `get_balance`, `get_task` and `get_usage` cost nothing. Every
other tool says in its description that it spends the balance.
- A price in `list_models` is the model's listed price. On a model priced by
resolution or render speed it is given tier by tier, with the tier a request
gets when it names none; on a video model priced per second, with the clip
lengths it takes. The tools quote listed prices and
promise no charge: what a request was charged
is what `get_usage` reports, and it can be more than the listed price.
- A tier is one of those the model lists. A resolution sent to a model priced
by render speed, or the reverse, is refused before anything is sent, with
the model's tiers and their prices. Any other value is sent as given: the
API makes the request at the tier it names, reads a few spellings the list
does not give as a tier (another case, a Veo model's `"1920x1080"` as
1080p), and refuses the rest with a 400 that lists the model's tiers, which
makes nothing and costs nothing. On a list that gives no tiers (a gateway
older than the field) nothing is refused here on that account.
- Nothing is submitted twice behind your back. A chat call is sent once: it
carries no idempotency key, and a call that did arrive would be made, and
charged, a second time. An image, video or music submit is sent a second
time only under the key it carries, which the API answers with the task it
made (below).
- A tool that fails says which kind of failure it was. What goes wrong before
the paid request (the model list, a source image) is said to have sent
nothing. A refusal by the API is said to have made nothing.
- When a submit gets no answer, or the API answers it with a server error, the
tool does not say "failed, try again". It says that it is not known whether
the image, the video or the song was started, and names the
`idempotency_key` that finds out: calling the tool again with it and the
same arguments gets the task the first call made, if it made one, and makes
one only if it did not. `get_usage` cannot tell which it was: it only counts
an image once it is finished, as one more request of that model in that
hour.
- A chat call the API answers with its own error is not billed. One that got
no answer, or an error page of something in front of the API, may have been
answered and charged all the same, and the tool says so.
- Every image, video and music submit carries an `Idempotency-Key`: the API
answers a key it has seen on the account with the task it made for it. (An
image submit always asks for a task, `async: true`, which is when the image
endpoints read a key.) The tool repeats a submit once after a connection
failure, a rate limit or a server error, under the same key, and after the
answers that say a try made nothing and ask for the request again under
its key: a 503 (the request was not sent to the provider, which has not
been confirming tasks), a 409 (another request under the key is still
being submitted), and the 504 that a gateway from before 2026-10-19 gives
for a task the provider did not confirm within two minutes. When the second
try is answered so too, the tool says that those answers made nothing, and
to call it again in a minute with the same `idempotency_key`. The key comes
back with the task, and a start whose outcome is unknown names it: calling
the tool again with that `idempotency_key` and the same arguments finds the
task instead of starting another. You can also pass a key of your own. The
API keeps it for as long as it keeps the task, a failed one included, and a
key stands for one request: sent again for another model, with another
prompt or other options (the addresses of source images aside), or with
another tool, it is refused with a 400, which makes nothing. Use a new one
for each new request.
- A request the API refuses (a 4xx answer) made no task and cost nothing. A
task that ends `failed` is not charged. One that failed with
`upstream_unconfirmed` was never confirmed by the model's provider (the API
did not hear its answer to the submit, and answered with the task all the
same): the tool says that the same request may be sent again, with a new
`idempotency_key`.
- When the balance is too low the API answers 402. The tool passes on what the
wallet holds, what the request would have reserved and the top-up link. A
402 for a monthly limit carries no figures: its message says which limit
it was, and the tool points at `get_balance` for what is left under each.
- `get_balance` reads `GET /v1/balance`: the account's wallet, what its
running tasks hold, what is available for a new request, and what is left
under the key's monthly limit and the account's cap. The API refuses a
request whose estimate is more than what is available or more than what is
left under a limit, so an agent can check before an expensive call. With
auto-recharge on, the wallet is refilled first only when its balance (what
running tasks hold not taken off) is under the threshold the account's
owner set. The limits count settled spend only, on a count of the API's own
that can be a minute old: near a limit a request under what is left can be
refused, or one over it admitted by as much as was charged in the last
minute. The wallet and the cap are the account's: any key of the account
reads them, a key with a monthly limit of its own included. A gateway without the endpoint is
answered with the billing page's address,
<https://kunavo.com/app/billing>.
## What it reads on your machine
Over stdio the server runs on your machine, and `edit_image` and
`generate_video` accept the path of a local image as a source. That is the one
place it reads your disk, and it is narrow: a regular file of at most 25 MB
that begins with a PNG, JPEG, WebP or GIF signature and is built as that
format is, block after block: a PNG's chunks with their checksums, a JPEG's
segments up to its picture, a GIF's blocks to its end, a WebP's chunks. A file
that only starts like an image is refused, and so are an image that is damaged
or cut short and anything else, whatever it is named; the refusal says nothing
about the file but that it is no image that reads whole. It is not a decoder:
a file made on purpose to pass as an image and carry something else is beyond
it.
The image is sent to the Kunavo API, which stores it for the model to fetch
under a public address with a random name, before it checks the rest of the
request. Anyone who has that address can open the image, so do not use a
picture as a source that must stay private. A large file on a slow connection
may not upload within the tool's time; a URL always works.
The API key is sent to the API's base URL and nowhere else. It is never
written to the log or put in an error message, and a key with a blank or a
line break in it is refused without being repeated.
## Streamable HTTP
```bash
npx -y kunavo-mcp --http --port 3920
```
serves the same tools at `http://127.0.0.1:3920/mcp`, and a health check at
`/healthz`. This mode is for running the server as a service:
- It is stateless. Every request is answered on its own, so any number of
instances can run side by side.
- Each request brings its own key, as `Authorization: Bearer sk-kn-…` (or
`x-api-key`), and is served with that key and no other. A request without a
string shaped like a Kunavo key gets a 401 and nothing else, not even the
list of tools. The `KUNAVO_API_KEY` of the server's environment is not used
in this mode: a port that spent its own key would spend it for whoever
reached it.
- Any origin may call it. A caller has to know a key, which is what protects
the balance.
- It never reads a local file: a source image has to be a URL.
- A request body over 40 MB is refused, and 64 requests are served at a time;
one more is answered 503 with `Retry-After`. A request has a minute to
arrive whole. `/healthz` is answered whatever the load: a server restarted
for failing its check would drop the paid requests it is busy with.
- It speaks plain HTTP, and the key travels in a header: put it behind
something that terminates TLS before it leaves the machine. Whatever stands
in front has to let a request take as long as a tool call does: 55 seconds,
and `timeout_seconds` plus 5 for `chat`.
- `--host` sets the address to bind (default `127.0.0.1`).
## Configuration
| | |
| --- | --- |
| `KUNAVO_API_KEY` | Your API key (`sk-kn-…`). Used on stdio. |
| `KUNAVO_BASE_URL` | The API's base URL. Default `https://api.kunavo.com/v1`. |
| `--http`, `--port`, `--host` | Serve over Streamable HTTP. Default port 3920, or `$PORT`. |
| `--version`, `--help` | Print the version, or the usage. |
## Models and prices
<!-- catalog:start (generated from Kunavo's model catalog; do not edit) -->
Listed prices in US dollars on 2026-11-27, from Kunavo's own catalog: 47 models. Models are switched on and off and prices change, so the live list, `GET /v1/models`, is the one to act on.
**Text** (`chat`)
| Model | `model` id | Input, per 1M tokens | Output, per 1M tokens | Context window |
| --- | --- | --- | --- | --- |
| Claude Sonnet 5 | `claude-sonnet-5` | $1.40 | $7.00 | 1,000,000 |
| Claude Fable 5.2 | `claude-fable-5-2` | $5.60 | $28.00 | 1,000,000 |
| Claude Fable 5.1 | `claude-fable-5-1` | $7.00 | $35.00 | 1,000,000 |
| Claude Fable 5 | `claude-fable-5` | $7.00 | $35.00 | 1,000,000 |
| Claude Opus 5.5 | `claude-opus-5-5` | $2.80 | $14.00 | 1,000,000 |
| Claude Opus 5 | `claude-opus-5` | $3.50 | $17.50 | 1,000,000 |
| Claude Opus 4.8 | `claude-opus-4-8` | $3.50 | $17.50 | 1,000,000 |
| Claude Opus 4.7 | `claude-opus-4-7` | $3.50 | $17.50 | 1,000,000 |
| Claude Opus 4.6 | `claude-opus-4-6` | $3.50 | $17.50 | 1,000,000 |
| Claude Sonnet 5.5 | `claude-sonnet-5-5` | $1.40 | $7.00 | 1,000,000 |
| Claude Sonnet 4.6 | `claude-sonnet-4-6` | $2.10 | $10.50 | 1,000,000 |
| Claude Haiku 5.5 | `claude-haiku-5-5` | $0.07 | $0.35 | 1,000,000 |
| Claude Haiku 4.5 | `claude-haiku-4-5` | $0.70 | $3.50 | 200,000 |
| GPT-6.2 Astra | `gpt-6-2-astra` | $3.20 | $16.00 | 1,050,000 |
| GPT-6.2 Sol | `gpt-6-2-sol` | $0.80 | $4.00 | 1,050,000 |
| GPT-6.1 Sol | `gpt-6-1-sol` | $0.80 | $4.00 | 1,050,000 |
| GPT-6.1 Terra | `gpt-6-1-terra` | $0.40 | $2.00 | 1,050,000 |
| GPT-6 Astra | `gpt-6-astra` | $4.00 | $20.00 | 1,050,000 |
| GPT-6 Sol | `gpt-6-sol` | $0.80 | $4.00 | 1,050,000 |
| GPT-6 Luna | `gpt-6-luna` | $0.04 | $0.20 | 1,050,000 |
| GPT-5.6 Sol | `gpt-5-6-sol` | $2.00 | $12.00 | 1,050,000 |
| GPT-5.6 Terra | `gpt-5-6-terra` | $0.70 | $4.20 | 1,050,000 |
| GPT-5.5 | `gpt-5-5` | $2.00 | $12.00 | 1,050,000 |
On `claude-haiku-5-5`, a request with more than 100,000 input tokens is billed whole at 5x the input price and 5x the output price. On `gpt-6-2-astra`, `gpt-6-2-sol`, `gpt-6-1-sol`, `gpt-6-1-terra`, `gpt-6-astra`, `gpt-6-sol`, `gpt-6-luna`, `gpt-5-6-sol`, `gpt-5-6-terra`, `gpt-5-5`, a request with more than 272,000 input tokens is billed whole at 2x the input price and 1.5x the output price.
**Image generation** (`image`)
| Model | `model` id | Listed price |
| --- | --- | --- |
| Nano Banana | `nano-banana` | $0.0273 per image |
| Nano Banana 2 | `nano-banana-2` | $0.0469 at 1K (default), $0.0707 at 2K, $0.1057 at 4K per image |
| Nano Banana 2.1 | `nano-banana-2-1` | $0.079 per image |
| Nano Banana 2 Lite | `nano-banana-2-lite` | $0.0255 per image |
| Nano Banana Pro | `nano-banana-pro` | $0.067 at 2K (default), $0.12 at 4K per image |
| GPT-Image-2 | `gpt-image-2` | $0.0633 at 1K, 2K, 4K per image |
| Ideogram v3 | `ideogram-v3` | $0.02625 at TURBO, $0.0525 at BALANCED (default), $0.075 at QUALITY per image |
| Grok Imagine Image 2.0 | `grok-imagine-image-2` | $0.028 per image |
**Image editing** (`image_edit`)
| Model | `model` id | Listed price |
| --- | --- | --- |
| Nano Banana Edit | `nano-banana-edit` | $0.0273 per image |
| GPT-Image-2 Edit | `gpt-image-2-edit` | $0.0633 at 1K, 2K, 4K per image |
| Ideogram v3 Edit | `ideogram-v3-edit` | $0.02625 at TURBO, $0.0525 at BALANCED (default), $0.075 at QUALITY per image |
**Video** (`video`)
| Model | `model` id | Listed price |
| --- | --- | --- |
| Veo 3.1 Fast | `veo-3` | $0.36 at 720p (default), $0.42 at 1080p, $1.08 at 4k per video |
| Veo 3.1 Quality | `veo-3-quality` | $1.60 at 720p (default), $1.60 at 1080p, $2.40 at 4k per video |
| Veo 3.1 Lite | `veo-3-lite` | $0.18 at 720p (default), $0.224 at 1080p per video |
| Seedance 2 | `seedance-2` | $0.114 at 480p, $0.246 at 720p (default), $0.612 at 1080p per second |
| Seedance 2 Fast | `seedance-2-fast` | $0.093 at 480p, $0.198 at 720p (default) per second |
| Seedance 2.5 | `seedance-2-5` | $0.1764 at 480p, $0.3784 at 720p (default), $0.7392 at 1080p per second |
| Seedance 2.0 Mini | `seedance-2-mini` | $0.0245 at 480p, $0.0526 at 720p (default) per second |
| Wan 2.7 | `wan-2-7` | $0.096 at 720p (default), $0.144 at 1080p per second |
| Gemini Omni 1.2 Flash | `gemini-omni-flash-1-2` | $0.0624 per second |
| MiniMax H3 | `minimax-h3` | $0.05 at 768P (default), $0.08 at 2K per second |
| Grok Imagine Video 1.5 | `grok-imagine-video-1-5` | $0.024 at 480p, $0.042 at 720p (default), $0.075 at 1080p per second |
**Music** (`audio_music`)
| Model | `model` id | Listed price |
| --- | --- | --- |
| Suno V5 | `suno-v5` | $0.09 per song |
| Suno V5.5 | `suno-v5-5` | $0.09 per song |
A media price is the listed price of one request at each resolution or render-speed tier; "default" marks the tier of a request that names none. What a request was charged is what the usage endpoint reports.
No model is on sale today for: text to speech, speech to text, embeddings. The API has those endpoints; nothing is behind them.
<!-- catalog:end -->
## Development
```bash
npm install
npm test
```
The tests run against a stand-in for the API on `127.0.0.1`
(`test/stand-in.ts`): the routes' paths, status codes, bodies and error
wording, with a model list that is the real `GET /v1/models` answer. They
start the built server over stdio and over HTTP as an MCP client would.
`test/contract.test.ts` sends the same requests to the stand-in and to a
Kunavo gateway running locally and compares the answers. It is skipped unless
`KUNAVO_LOCAL_GATEWAY` points at one.
## License
MIT
TDQS
Scored across 9 tools
Each tool maps to a distinct resource and action: generation per modality (generate_image, edit_image, generate_video, generate_music, chat), task polling (get_task), and account introspection (get_balance, get_usage, list_models). The descriptions explicitly separate the easily-confused pairs, such as generate_image vs edit_image (text prompt vs source/reference images) and get_balance (spendable) vs get_usage (charged history).
Eight of nine tools follow a clean verb_noun pattern (generate_image, edit_image, generate_video, generate_music, get_task, get_balance, get_usage, list_models). The single outlier is `chat`, which is a bare verb with no object, a minor deviation from an otherwise uniform convention.
Nine tools is well within the ideal range and each earns its place: five modality-specific generation tools, one shared task poller, and three free read-only introspection tools. Nothing appears redundant or padded for the scope of a media-generation API.
The surface covers the full lifecycle: discover models and prices, check budget, submit generation, and poll for results or failures. The notable gap is task management — there is no cancel/delete task tool despite long-running, charged video and music jobs, and no way to list past tasks or results beyond get_task by id, though agents can work around this with the ids they hold.