Content
# apimart-cli
[](https://github.com/martianzhang/apimart-cli/actions/workflows/ci.yml)
[](https://go.dev/)
[](LICENSE)
[](https://github.com/martianzhang/apimart-cli/releases)
> ⚠️ **Disclaimer**: This is a **personal open-source project**, not affiliated with APIMart. The code is based on [APIMart](https://apimart.ai) and [OpenAI](https://openai.com) public APIs. Please ensure compliance with each platform's terms of service before use.
**A CLI that supports OpenAI, OpenRouter, APIMart, and any OpenAI-compatible relay services.**
Not just API forwarding - intelligent adaptation of each platform's proprietary API, complete coverage of image/video/Midjourney/AI conversation/prompt inspiration, with built-in MCP Server and Agentic Chat.
## Why Choose apimart-cli?
| | | |
|---|---|---|
| 🤖 | **MCP Server** | Integrate with AI clients like Claude Desktop, Cursor, and generate images/videos directly in conversations without switching tools or copying/pasting. |
| 🔬 | **AIGC Detection Engine** | Offline multi-signal fusion: C2PA Content Credentials, TC260 (Chinese national standard GB 45438-2025), SynthID invisible watermark, ONNX model inference, FFT spectrum analysis, SRM noise residual, JPEG quantization detection. All run locally, no API Key required. |
| 🔌 | **Unified Entry for Multiple Providers** | Change one `base_url` to switch between OpenAI/OpenRouter/APIMart/any relay, commands remain the same, and Provider automatically adapts. |
## Quick Start
### Installation
```bash
go install github.com/martianzhang/apimart-cli@latest
```
### Using OpenAI
```bash
export OPENAI_API_KEY="sk-xxx"
apimart-cli image --prompt "a cat in the starry sky"
apimart-cli chat --message "who are you?"
```
### Using OpenRouter (change environment variables, no command changes)
```bash
export OPENAI_API_KEY="sk-or-xxx"
export OPENAI_BASE_URL="https://openrouter.ai/api/v1"
apimart-cli image --model "openai/gpt-image-2" --prompt "a cat"
apimart-cli video --model "google/veo-3.1" --prompt "a dog running" # Automatically uses dedicated video API
apimart-cli models --type image # Model discovery without authentication
```
### Using Any OpenAI-Compatible Relay
```bash
export OPENAI_API_KEY="sk-xxx"
export OPENAI_BASE_URL="https://your-relay.com/v1"
apimart-cli chat --message "Hello"
```
### MCP Integration (Recommended)
Add the following configuration to Claude Desktop/Cursor/Windsurf's MCP settings:
```json
{
"mcpServers": {
"apimart": {
"command": "apimart-cli",
"args": ["mcp"]
}
}
}
```
AI agents can directly generate images, create videos, query models, and detect AIGC in conversations. See [docs/mcp.md](docs/mcp.md) for details.
## Feature List
| | Capability | Description |
|---|---|---|
| 🤖 | **MCP Server** | Built-in MCP protocol support, compatible with Claude Desktop/Cursor/Windsurf/VS Code |
| 🔬 | **AIGC Detection Engine** | C2PA/TC260/SynthID/ONNX/FFT/SRM noise/JPEG quantization, offline operation, emoji output |
| 🔌 | **Unified Entry for Multiple Providers** | Change one `base_url` to switch providers, commands remain the same |
| 🧠 | **Provider Automatic Adaptation** | OpenRouter automatically uses dedicated image/video API, APIMart uses asynchronous tasks, zero configuration |
| 🎨 | **Midjourney Complete Pipeline** | 17 subcommands covering imagine→blend→describe→upscale→zoom→inpaint→video→remix, no Discord required |
| 💬 | **Agentic Chat** | Interactive REPL with built-in `generate_image`/`generate_video`/`midjourney_*`/`ideas` tools |
| 🔍 | **Prompt Inspiration Library** | Offline BM25 search engine (CJK-aware + n-gram + RRF), tens of thousands of prompt dataset |
| 🔄 | **Video Task Persistence** | OpenRouter submission→polling→download process, timeout recovery with `--job-id` |
| 🧪 | **Dry-Run & Curl** | `--dry-run` outputs equivalent curl command, easy to learn and debug API |
| ⚡ | **Go Single Binary** | `go install` for one-click installation, no runtime dependencies, cross-platform |
## Provider Automatic Adaptation
The same `image`/`video`/`models` commands automatically switch API paths based on the Provider:
| Provider | Image | Video | Models |
|---|---|---|---|
| **OpenAI** | `POST /v1/images/generations` (synchronous) | — | `GET /v1/models` |
| **OpenRouter** | `POST /v1/images` (dedicated image API) or `POST /v1/responses` (Responses API) | `POST /v1/videos` asynchronous→polling→download + `--job-id` recovery | `GET /v1/images/models` / `GET /v1/videos/models` (no authentication) |
| **APIMart** | Asynchronous task submission→polling→download | Asynchronous task + VEO3 Remix (video extension) | Market API + model pricing query |
| **CloudMist AI** | — | `POST /v1/video/create` + `GET /v1/video/query` | — |
| **Generic Relay** | `POST /v1/images/generations` (synchronous) | — | `GET /v1/models` |
Detection logic: automatically identifies based on `base_url`, or manually specify with `--mode sync` / `--mode async`.
## Commands
```
apimart-cli
├── image Image generation (synchronous/asynchronous/OpenRouter dedicated API/Grok Edit) → docs/guide-image.md
├── video Video generation (APIMart/OpenRouter/CloudMist + VEO3 Remix) → docs/guide-video.md
├── midjourney Midjourney complete pipeline (17 subcommands) → docs/guide-midjourney.md
│ └── mj Alias, same as above
├── chat AI conversation / interactive REPL / Agent Loop (tool invocation) → docs/guide-chat.md
├── ideas Prompt inspiration search (keyword/random/image, supports BM25 + n-gram) → docs/guide-ideas.md
├── models Model list (APIMart market/OpenRouter discovery/OpenAI compatible)
│ └── --price View model pricing
├── task Query asynchronous task status (APIMart)
├── balance Query balance (APIMart)
├── preview Preview generated images/videos with system default program
├── detect Detect watermark, metadata, and AIGC (multi-signal fusion + emoji) → docs/guide-detect.md
├── mcp Start MCP Server (AI agent integration) → docs/mcp.md
│
│ # Global flags
│ --dry-run Print request parameters and equivalent curl, no API call
│ --print-config Print current effective configuration (with source annotation)
│ -v/--verbose Show detailed output: complete JSON, token usage, time consumption, cost
│ --json Pass request in JSON format (file/string/stdin)
│ --preview Automatically open system preview after generation
│ --save-prompt Save prompt as .md file
│ --http-proxy Specify HTTP proxy
```
### Midjourney Subcommands
```
apimart-cli midjourney (or mj)
├── imagine Text-to-image / image-to-image (default entry)
├── blend Multi-image fusion (2-4 images)
├── describe Image-to-text (reverse prompt)
├── edits Image editing (rewrite entire image)
├── upscale Enlarge single image (U1-U4)
├── variation Micro-variation (V1-V4)
├── high-variation Strong variation
├── low-variation Weak variation
├── reroll Re-generate grid
├── zoom Zoom out / expand
├── pan Pan (left/right/up/down)
├── inpaint Local re-painting entry (→ modal)
├── modal Submit mask + prompt for re-painting
├── video Image-to-video
├── remix-strong Strong remix (v8/v8.1)
├── remix-subtle Subtle remix (v8/v8.1)
└── query Query task status
```
## Documentation
| Document | Content |
|---|---|
| [Installation and Configuration](docs/installation.md) | Installation, API Key, configuration file, proxy |
| [Image Generation](docs/guide-image.md) | All parameters, synchronous/asynchronous modes, image-to-image, inpainting |
| [Video Generation](docs/guide-video.md) | All parameters, first/last frames, reference video (APIMart) |
| [Midjourney Generation](docs/guide-midjourney.md) | 17 subcommand detailed instructions: imagine, blend, upscale, etc. |
| [AI Conversation](docs/guide-chat.md) | Interactive multi-turn REPL, streaming output, verbose statistics |
| [AIGC Detection](docs/guide-detect.md) | Multi-signal fusion, ONNX model, FFT spectrum, emoji output |
| [Prompt Inspiration](docs/guide-ideas.md) | Search AI image prompts from Image2Studio |
| [Other Commands](docs/guide-commands.md) | models, task, balance, dry-run, API reference |
| [API Reference](docs/api-reference.md) | Provider interface specifications, detection mechanism, strategy routing |
| [FAQ](docs/faq.md) | Installation, usage, MCP, cost, and other frequently asked questions |
| [MCP Integration](docs/mcp.md) | AI agent (Claude/Cursor) integration guide |
## Priority Rules
**CLI parameters > JSON input > YAML configuration > code defaults**
Proxy priority:
**`--http-proxy` parameter > `OPENAI_HTTP_PROXY` / `APIMART_HTTP_PROXY` environment variable > `HTTP_PROXY` standard environment variable**
## Contribution
Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
## License
[MIT](LICENSE)
<div align="center">
<img src="wechat.jpg" width="400" alt="No extra text" />
**Welcome to follow the WeChat public account "No extra text" for more useful tools**
</div>