meitu-cli
v2.1.10
Published
Node.js CLI for Meitu OpenAPI image and media tasks.
Maintainers
Readme
Meitu CLI
Meitu CLI is a command-line interface to Meitu's AI image and video capabilities. Everything accessible through the Meitu AI Open Platform — cutout, beauty enhancement, image generation, virtual try-on, image-to-video, and more — is available directly from the terminal with the same models, parameters, and quality.
It is designed for:
- AI agents — structured JSON output (
--json), deterministic exit codes, and automatic task polling make it a natural fit for agentic workflows that need to call Meitu's image and video AI as a tool step (e.g. Claude Code, Cursor, or custom LLM agents). - E-commerce & content teams — batch-process product images at scale: cutout backgrounds, virtual try-on for fashion listings, beauty enhancement for portrait shots, or generate marketing visuals without a GUI.
- Developers building on Meitu OpenAPI — prototype and debug API calls interactively from the terminal before integrating them into an application.
Docs
- CLI auth + Maat docs — design, API appendix, backend handoff, and review summary for the account-service-to-
Maatauthentication flow. - Skills package docs — skills package registry contract and install/update backend handoff.
- Guides — internal setup, env overrides, passthrough usage, and local split-AK/SK workflows.
- Release docs — publish flow, privacy checks, and dual-registry release notes.
- Reports — command-mode and historical effect-id validation records.
- MCP passthrough spec — detailed MCP-style passthrough behavior and implementation notes.
Install
Recommended for most users (npm package):
npm install -g meitu-cliThen run the CLI directly:
meitu --help
meitu auth verify --jsonIf you do not want a global install, you can run the published package with npx:
npx -y meitu-cli --help
npx -y meitu-cli auth verify --jsonTool commands work the same way through npx:
npx -y meitu-cli image-cutout --image ./test.png --jsonNotes:
npm install -g meitu-cliinstalls the package globally and exposes themeitucommand onPATH.npx -y meitu-cli ...runs the published package without a separate global install.- Both forms use the same CLI behavior, configuration file, and environment variables.
Install meitu-skills (optional, for agent workflows)
Recommended one-stop bootstrap (uses the bundled skills package installer):
npm install -g meitu-cli
meitu skills install meituhub-skills
meitu skills doctorThis downloads the official meituhub-skills runtime package from the Meitu
package registry, verifies its checksum, validates PACKAGE_MANIFEST.json, and
atomically installs the package into $MEITU_SKILLS_HOME/skills/meituhub-skills
(default: ~/.meitu/skills/meituhub-skills). No remote scripts are
executed; install is always an explicit, user-triggered action.
You can also install from a local archive (useful for offline / preview / internal builds):
meitu skills install meituhub-skills \
--archive ./meituhub-skills-2.0.6.tar.gz \
--jsonOther useful subcommands:
meitu skills update meituhub-skills # update the installed skills package
meitu skills version # show installed skills + CLI version
meitu skills doctor --json # diagnose CLI / credentials / registry / skillsCommon flags for install and update:
- positional
<packageName>— registry package name, for examplemeituhub-skills --target <dir>— override skills root (default:$MEITU_SKILLS_HOME/skillsor~/.meitu/skills)--version <ver>— pin a specific package version (default: registrylatest)--registry <url>— override the package registry URL--archive <path>— install from a local.tar.gzinstead of the registry--force— drop the auto-generated backup of any prior install--json— emit structured JSON output for agents
Environment variable overrides (optional):
MEITU_SKILLS_HOME— base directory for local skills files, default~/.meituMEITU_SKILLS_PACKAGE_REGISTRY_URL— package registry URL overrideMEITU_OPENAPI_BASE_URL/MEITU_OPENAPI_IMAGE_BASE_URL— derive registry host
Legacy alternatives (still supported):
# ClawHub
npm install -g clawhub
clawhub install meitu-skills
# Generic skills installer via GitHub URL
npx -y skills add https://github.com/meitu/meitu-skills --yesConfigure
You can save credentials locally:
meitu config set-ak --value your_access_key
meitu config set-sk --value your_secret_keyOr provide them through environment variables:
export MEITU_OPENAPI_ACCESS_KEY=your_access_key
export MEITU_OPENAPI_SECRET_KEY=your_secret_keyEnvironment variables take priority over the local credentials file.
The local credentials file is stored at ~/.meitu/credentials.json.
Built-in defaults (unless overridden by environment variables below):
- OpenAPI gateway host and strategy (file-upload token) host are set inside the CLI; override them only if your documentation or environment requires a different host (see Advanced Overrides).
- verify path:
/demo/authorization - image generate path:
/api/v1/sdk/push - task status path:
/api/v1/sdk/status - tool registry URL: follows the execution gateway domain by default, e.g.
https://openapi-global.meitu.com/api/v1/skills/tool_registry.json?consumer=meituhub
Advanced Overrides
For normal external usage, you usually only need:
MEITU_OPENAPI_ACCESS_KEYMEITU_OPENAPI_SECRET_KEY
The strategy service used for local file upload is built in and does not need to be configured in normal usage.
If you are testing against a private environment or a non-default deployment, the CLI also supports:
MEITU_OPENAPI_BASE_URL— overrides the built-in OpenAPI gateway hostMEITU_OPENAPI_IMAGE_BASE_URL— optional; image/task calls use this if set, otherwiseMEITU_OPENAPI_BASE_URL(or the built-in default when that is unset)MEITU_OPENAPI_STRATEGY_BASE_URL— overrides the built-in strategy hostMEITU_OPENAPI_IMAGE_GENERATE_PATH— overrides the push endpoint path used for tool and low-level generate callsMEITU_OPENAPI_TASK_STATUS_PATH— overrides the task status endpoint pathMEITU_OPENAPI_TASK_TIMEOUT_MS— maximum task polling wait time in milliseconds for tool commands,generate, andbatch(default:300000, i.e. 5 minutes); also used as the default formeitu task waitwhen--timeout-msis omittedMEITU_SKILLS_REGISTRY_URL— overrides the default tool registry URL; when unset, the registry uses the same domain source as command execution (MEITU_OPENAPI_IMAGE_BASE_URL->MEITU_OPENAPI_BASE_URL-> built-in default)MEITU_IAM_REFRESH_AHEAD_MS— when using IAM token auth, refresh the session proactively this many milliseconds before access-token expiry; defaults to300000(5 minutes), set to0to only refresh after expiryMEITU_OPENAPI_TOOL_TASK_MODE— optional compatibility guard; when set, it must staycommandbecause tool commands now always send the CLI command name directlyMEITU_CLI_OUTPUT_FORMAT— controls--jsonoutput shape;concise(default) uses the historical wrapped CLI payloads,fullkeeps the full backend-response passthrough formatMEITU_RECHARGE_URL— overrides the recharge page returned in insufficient-balance / order-limit responses; defaults tohttps://meituhub.cn/zh-cn/pricingMEITU_CONSOLE_URL/OPENAPI_CONSOLE_URL— overrides the console/configuration page returned for authorization or configuration errors; defaults toMEITU_RECHARGE_URLwhen unset
The strategy path and strategy type use built-in defaults and normally do not need to be changed:
- strategy path:
/ai/token_policy(override:MEITU_OPENAPI_STRATEGY_PATH) - strategy type:
mtai(override:MEITU_OPENAPI_STRATEGY_TYPE)
Example:
export MEITU_OPENAPI_BASE_URL=https://api.example.com
export MEITU_OPENAPI_IMAGE_GENERATE_PATH=/api/v2/sdk/push
export MEITU_OPENAPI_STRATEGY_BASE_URL=https://strategy.example.com
export MEITU_OPENAPI_TOOL_TASK_MODE=command
export MEITU_CLI_OUTPUT_FORMAT="concise"MCP-style passthrough
When you need meitu-cli to behave more like an MCP proxy calling AIGCP, the CLI can augment push requests with MCP-style passthrough headers and payload fields.
Supported push payload additions:
request_idtrace_idcontext
Supported passthrough request headers:
x-mtcc-clientisStressTestAuthorization(note: the standardAuthorizationheader is still replaced by the CLI's SDK signature)
Recommended environment variables:
MEITU_OPENAPI_HEADER_X_MTCC_CLIENTMEITU_OPENAPI_HEADER_ISSTRESSTESTMEITU_OPENAPI_HEADER_MT_MCP_CONTEXTMEITU_OPENAPI_HEADER_MT_MCP_UIDMEITU_OPENAPI_HEADER_MT_MCP_GIDMEITU_OPENAPI_HEADER_MT_MCP_TASK_IDMEITU_OPENAPI_HEADER_X_REQUEST_IDMEITU_OPENAPI_MCP_FROMMEITU_OPENAPI_MCP_BIZ_LINE
meitu-cli will also auto-populate x-mtcc-client.gnum when it is not explicitly provided. The value is
persisted under ~/.meitu/device.json and generated once with crypto.randomUUID(), so the same CLI
environment reuses a stable device-level gnum across AK/SK and IAM login flows.
Optional advanced passthrough variables:
MEITU_OPENAPI_PASSTHROUGH_HEADERS— override passthrough header allowlistMEITU_OPENAPI_CONTEXT_EXTRA_JSON— merge custom JSON fields intocontextMEITU_OPENAPI_MCP_SERVER_PROJECT— overridecontext.mcp_server_projectMEITU_OPENAPI_MCP_SERVER_ADDR— overridecontext.mcp_server_addrMEITU_OPENAPI_AUTO_GENERATE_IDS— auto-generaterequest_id/trace_idwhen missingMEITU_OPENAPI_FORWARD_ORIGINAL_AUTH_AS— preserve the upstream auth value in a secondary header such asX-Original-Authorization
Example:
export MEITU_OPENAPI_HEADER_X_MTCC_CLIENT='eyJhcHBfaWQiOiIxMjMiLCJiaXpfaWQiOiI0NTYiLCJ1aWQiOiJ1c2VyLTEiLCJnbnVtIjoiZGV2aWNlLWdudW0tMDAxIn0='
export MEITU_OPENAPI_HEADER_ISSTRESSTEST=true
export MEITU_OPENAPI_HEADER_X_REQUEST_ID=req-demo-001
export MEITU_OPENAPI_HEADER_MT_MCP_TASK_ID=trace-demo-001
export MEITU_OPENAPI_MCP_FROM=app
export MEITU_OPENAPI_MCP_BIZ_LINE=defaultFor the detailed implementation spec used by this repository, see docs/mcp/cli-mcp-passthrough-spec.md.
Usage
Verify credentials:
meitu auth verify --jsonManage IAM session explicitly:
meitu auth login --json
meitu auth refresh --json
meitu auth status --jsonTool commands:
video-motion-transferimage-to-videotext-to-videovideo-to-gifimage-generateimage-poster-generateimage-editimage-upscaleimage-beauty-enhanceimage-face-swapimage-try-onimage-cutoutimage-grid-split
Behavior in short:
- task routing and task types are handled inside the CLI
- local file paths and remote URLs are supported for media inputs
- each subcommand exposes flags derived from the same tool metadata the CLI ships with; run
meitu <command> --helpfor the exact options
Parameter wrapping rules (for JSON payloads sent to the API):
- values from
parameter_input_aliasare wrapped as{"parameter": {...}} - values from
params_input_aliasstay at the top level ofparams - when a tool has no extra params, the CLI sends an empty string for
params
Run cutout with a local file:
meitu image-cutout \
--image ./test.jpg \
--model_type 2 \
--output ./outputs/cutout.png \
--jsonRun beauty enhancement with the default beauty mode:
meitu image-beauty-enhance \
--image ./portrait.jpg \
--jsonRun beauty enhancement with stronger beauty mode (flag name matches the OpenAPI field spelling):
meitu image-beauty-enhance \
--image ./portrait.jpg \
--beatify_type 1 \
--jsonRun image generation with a prompt only:
meitu image-generate \
--prompt "make it cinematic" \
--jsonRun virtual try-on with the required media inputs:
meitu image-try-on \
--clothes_image_url ./cloth.png \
--person_image_url ./person.png \
--replace upper \
--need_sd 1 \
--jsonAdvanced Generate Usage
The low-level generate command is still available when you need to call a custom task directly.
Run intelligent cutout with a local file through the low-level command:
meitu generate \
--task /v1/photo_scissors/sod \
--image-file ./test.jpg \
--params-json '{"parameter":{"nMask":false,"model_type":0}}' \
--download-dir ./outputs \
--jsonRun a task with an explicit init_images array:
meitu generate \
--task /v1/photo_scissors/sod \
--task-type mtlab \
--init-images-json '[{"media_data":"./test.jpg","resource_type":"file","profile":{"media_profiles":{"media_data_type":"url"},"version":"v1"}}]' \
--params-json '{"parameter":{"nMask":false,"model_type":0}}' \
--download-dir ./outputs \
--jsonRun a task with a remote image URL:
meitu generate \
--task /v1/photo_scissors/sod \
--image-url https://example.com/test.jpg \
--params-json '{"parameter":{"nMask":false,"model_type":0}}' \
--jsonWait for an existing task manually:
meitu task wait t_xxx --output ./outputs/result.png --jsonDownload behavior:
--output <paths...>saves files to the exact paths you provide--download-dir <dir>saves files into a directory and lets the CLI generate filenames- if neither option is provided, the CLI only returns the backend response and does not download files
--outputmaps files by the order ofdata.result.urls--outputand--download-dircannot be used together
Examples:
meitu image-face-swap \
--head_image_url https://example.com/head.png \
--sence_image_url https://example.com/scene.jpg \
--prompt "swap face" \
--output /tmp/face-swap.png \
--jsonmeitu some-command \
...other args... \
--output /tmp/result-1.png /tmp/result-2.png /tmp/result-3.png \
--jsonWhen downloads happen, JSON output includes:
{
"code": 0,
"message": "success",
"data": {
"result": {
"urls": [
"https://example.com/result.png"
]
}
},
"downloaded_files": [
{
"url": "https://example.com/result.png",
"saved_path": "/tmp/result.png"
}
]
}Task Behavior
meitu generateautomatically polls/api/v1/sdk/statuswhen the create call returns atask_id- default polling interval:
1s status = 0,1, or9means the task is still runningstatus = 10means the task succeededstatus = 2means the task failed- any other non-success status is treated as a failure state
When --output or --download-dir is used, the CLI downloads result URLs locally and returns downloaded_files in JSON output.
Skills Package Installer
meitu skills install meituhub-skills is a bootstrapper for the official
meituhub-skills package. It is intentionally conservative:
- Explicit only — install/update only run when invoked by the user. Tool
commands such as
meitu image-editnever auto-install or auto-upgrade skills. - No remote script execution — the CLI never executes scripts shipped inside the package. It only writes files into the local skills directory.
- Path-traversal protection — the bundled tar.gz extractor rejects
absolute paths, parent traversal (
..), Windows-rooted paths, NUL bytes, symlinks, hardlinks, and device entries. Only regular files and directories are extracted. - Checksum verification — when the registry entry includes
sha256, the download is verified before extraction. Local archives report the computed digest in their result payload for auditing. - Manifest validation — the package must contain
SKILL.mdand a parseablePACKAGE_MANIFEST.jsonafter extraction; otherwise the install is aborted. - Compatibility check — when the manifest declares
compatibility.meitu_cli, the CLI rejects installs that don't satisfy the version range. - Atomic replace with backup — existing installs are renamed to
<install-dir>.bak.<timestamp>before the new directory is moved into place. Use--forceto drop the backup. - Bounded download size — packages over 256 MB are rejected.
The corresponding diagnostics command, meitu skills doctor, validates:
meitu-cliversion- presence of credentials (env or
~/.meitu/credentials.json) - live
meitu auth verifyround-trip against the configured OpenAPI host - presence and freshness of the local tool registry cache
(
~/.meitu/tool-registry.json) - presence and structure of
~/.meitu/skills/meituhub-skills - compatibility of the installed skill pack with the current
meitu-cli
Related design documents (in this repository):
docs/api/skills-package-registry-api-handoff.md— server-side API spec for the Skills Package Registry endpoint thatmeitu skills install/updateconsumes. Hand this to backend engineers for registry-side implementation.
Development
From the repository root:
npm install
npm testIf you want to preview the npm package contents locally:
npm pack --dry-run --cache /tmp/meitu-node-npm-cache