# Apimart Image

> Generate images via APIMart's unified API gateway (Nano Banana Pro, GPT-Image-2, Seedream, Imagen, Qwen Image, Grok Imagine, etc.) with built-in cost estimation

- Skill: `m4ru1/apimart-image` (Agent Skill, multi-file: 9 files)
- Install (CLI): `npx get-skill add m4ru1/apimart-image`
- Raw SKILL.md: https://api.skillmd.com/api/skills/m4ru1/apimart-image/raw
- Safety review: pending
- Works with: any agent that reads SKILL.md (Claude Code, Claude.ai, Cursor, Codex, Windsurf, 60+ more)
- Category: Coding & Dev Tools
- Author: m4ru1 (https://skillmd.com/u/m4ru1)
- Updated: 2026-11-26
- Page: https://skillmd.com/skills/m4ru1/apimart-image

---

---
name: apimart-image
description: Generate images via APIMart's unified API gateway (Nano Banana Pro, GPT-Image-2, Seedream, Imagen, Qwen Image, Grok Imagine, etc.) with built-in cost estimation before each call and persistent usage logging. Use this skill whenever the user asks to generate, create, draw, render, or visualize an image; whenever they want a poster, banner, icon, illustration, thumbnail, or any visual asset; whenever they reference an APIMart image model by name (Nano Banana, Seedream, Imagen, GPT-Image, Z-Image, Wan-Image, etc.); whenever they ask "how much would it cost to generate N images of X"; and whenever they ask about image-generation spending or budget on APIMart. Use this skill even when the user does not explicitly say "APIMart" — if APIMART_API_KEY is configured, this is the canonical way to generate images. Do NOT write ad-hoc curl/python to call APIMart for images; route through this skill so cost estimation and usage logging happen consistently.
---

# APIMart Image Generation Skill

Generate images through APIMart's OpenAI-compatible image endpoint, with automatic cost estimation, async task polling, image download, and per-call usage logging.

## When to use this skill

Use this skill when the user asks to:

- **Generate or create** any image, poster, banner, illustration, icon, thumbnail, mockup, concept art, or visual asset
- Use a specific APIMart image model by name: Nano Banana, Nano Banana Pro, Nano Banana 2, GPT-Image-1/1.5/2, Imagen-4, Seedream-4/4.5/5-Lite, Qwen Image 2.0, Z-Image-Turbo, Grok Imagine, Wan 2.7 Image
- **Estimate cost** of generating N images with model X (no API call needed — the pricing table answers this)
- **Check spending** on APIMart image generation, daily / weekly / monthly
- **Check the APIMart account balance**

Do NOT use this skill for:

- Editing local image files without API generation (use other image tools)
- Video generation (APIMart has video models but this skill covers images only)
- Reading or analyzing images that already exist

## Files in this skill

- `scripts/generate.py` — Main script: estimates cost, submits task, polls until done, downloads to disk, logs usage
- `scripts/check_balance.py` — Queries the user's APIMart account balance
- `scripts/show_history.py` — Reads the local usage log and reports spend by day/week/month, broken down by model
- `references/pricing.json` — Editable model→price table. Some prices verified, some estimated (see `verified` flag per model)
- `references/models.md` — Quick guide for picking the right model for a given task

## Configuration

The scripts read these environment variables:

- `APIMART_API_KEY` (required) — Bearer token from the APIMart dashboard
- `APIMART_BASE_URL` (optional, defaults to `https://api.apimart.ai`)
- `APIMART_USAGE_LOG` (optional, defaults to `~/.apimart-image/usage.jsonl`)

If `APIMART_API_KEY` is not set, the script exits with code 2 and a clear error. Tell the user to export the key.

## Workflow

When asked to generate an image:

1. **Prompt strategy (interactive).** Use `AskUserQuestion` to ask the user how to handle their prompt:

   **Question:** "How should I handle your prompt?"
   - **Optimize the prompt** — I'll rewrite and enhance your description into a professional image generation prompt, preserving your intent while adding detail and artistic direction (Recommended)
   - **Use as-is** — Translate your exact words to English literally, no additions or modifications
   - **Let me write my own prompt** — Skip optimization, I'll provide the full English prompt myself

   This MUST be the first interaction, before any other decisions.

2. **Pick the model.** Honor any explicit choice from the user. Otherwise default to `nano-banana-pro` (best general quality / price ratio). If unsure between two strong candidates, briefly mention the tradeoff and pick — don't ask if a sensible default exists.

3. **Pick the size (aspect ratio).** APIMart accepts ONLY ratio notation: `1:1`, `16:9`, `9:16`, `4:3`, `3:4`, `21:9`, `4:1`, `8:1`, `auto`. **Pixel sizes like `1024x1024` are rejected** with `build_request_failed: invalid size`. Translate user requests:
   - "square" / "Instagram post" → `1:1`
   - "landscape" / "YouTube thumbnail" / "wallpaper" → `16:9`
   - "portrait" / "phone wallpaper" / "Instagram story" → `9:16`
   - "banner" → `21:9` or `4:1` depending on context

4. **Pick the resolution (some models only).** Nano Banana Pro and Nano Banana 2 support `--resolution 1K|2K|4K`. Default 1K. Only use 4K if the user explicitly asks for high resolution — it costs more.

5. **Prompt review (interactive).** Before submitting any API call, compose the final English prompt based on the user's chosen strategy from step 1. Then use `AskUserQuestion` to present:

   **Question:** "Please review the prompt before submission:"
   - Use the `preview` field to display the prompt in a code block with both English (as submitted) and Chinese translation side by side
   - Options:
     - **Submit as-is** — Send this prompt to the API now
     - **I want to revise** — I'll adjust the prompt based on your feedback

   Do NOT proceed to step 6 until the user confirms. Only skip this step if the user explicitly says to go ahead without review.

6. **Estimate cost.** The script prints the estimate before any API call. The pricing table in `references/pricing.json` defines the rate per model + resolution.

7. **Confirm if expensive.** The script auto-confirms when single-call cost is below `confirmation_threshold_usd` (default $0.10). Above that, or for `n > 4`, it prompts. Pass `--yes` to skip prompts in non-interactive contexts.

8. **Run the script.** Pass `--prompt`, `--model`, `--size`, optionally `--resolution`, `--n`, `--output-dir`. Example:

```bash
python scripts/generate.py \
  --prompt "A misty forest at dawn, watercolor" \
  --model nano-banana-pro \
  --size 16:9
```

9. **Report the result.** The script prints the saved file paths, model, time, and actual cost. Pass that summary back to the user. If `--json` was used, parse the JSON and surface the relevant fields.

## Cost-only questions (no API call)

If the user asks "how much would N images of X cost on Y model", **do not** generate. Instead use `--dry-run`:

```bash
python scripts/generate.py --prompt "_" --model nano-banana-pro --n 100 --dry-run
```

Or just look up the price in `references/pricing.json` and compute mentally for simple cases. Always note whether the price is `verified` or an estimate.

## History / spending questions

For "what did I spend this month", run:

```bash
python scripts/show_history.py --period month
```

Periods: `day`, `week`, `month`, `all`. The cost in the report is the **estimated** cost from `pricing.json` at the time of generation — for the authoritative number, use `check_balance.py` to compare against the dashboard.

## Important constraints

- **Async by default.** All image endpoints return `task_id` immediately; the script polls `/v1/tasks/{task_id}` every 2 seconds up to 5 minutes. Typical wait: 5–60s depending on model and resolution.
- **URL expiry.** APIMart result URLs expire ~24h after generation. The script downloads to local disk so the user always has the file.
- **Content moderation.** APIMart pre-screens prompts; rejected prompts are not billed but produce a clear error. If a generation fails moderation, suggest revising rather than retrying with the same wording.
- **Pricing freshness.** APIMart adjusts prices periodically. Models with `"verified": false` in `pricing.json` are reasonable estimates that should be checked at <https://apimart.ai/model> before high-volume use. A user can edit `pricing.json` at any time.
- **Don't bypass the script.** Even if the agent could write its own curl/requests call, route through `generate.py` so cost logging, polling, retry, and confirmation behave consistently.

## Examples

**Example 1 — simple generation**
> User: "Generate a watercolor painting of a fox in a snowy forest."

```bash
python scripts/generate.py --prompt "A fox in a snowy forest, watercolor painting" --model nano-banana-pro --size 1:1
```

Default model, 1:1, ~$0.04. No confirmation prompt.

**Example 2 — explicit model and ratio**
> User: "Use Seedream 4.5 to make a 16:9 banner of a sunrise over Mount Fuji."

```bash
python scripts/generate.py --prompt "Sunrise over Mount Fuji, photographic, golden hour" --model seedream-4-5 --size 16:9
```

**Example 3 — cost question only, no generation**
> User: "How much would it cost to generate 50 social-media thumbnails using Nano Banana?"

```bash
python scripts/generate.py --prompt "_" --model nano-banana --n 50 --dry-run
```

Report: ~$0.625 USD (50 × $0.0125). This price is verified.

**Example 4 — high-quality, batch with confirmation**
> User: "Make me 6 variants of a sci-fi cityscape at 4K."

```bash
python scripts/generate.py --prompt "Sci-fi neon cityscape, cinematic" --model nano-banana-pro --resolution 4K --n 6 --size 16:9
```

Estimated $0.30 — above default $0.10 threshold, script will prompt for confirmation.

**Example 5 — spending review**
> User: "What did I spend on AI images this month?"

```bash
python scripts/show_history.py --period month
```

Then report total + per-model breakdown.

