MEGA Hub
Docs/Get started

MEGA CLI Reference#

The mega CLI is the shortest path for interactive Hub work and shell automation. Its command layout follows the same domain boundaries as the Web API and MegaHubClient.

Install#

Install the published Python package with one of these tools:

BASH
uv tool install megatensorspipx install megatensorspython -m pip install megatensors

Confirm the executable and environment:

BASH
mega versionmega envmega --help

Update an existing installation:

BASH
mega update

Authenticate#

BASH
mega auth loginmega auth whoami

For automation, inject MEGA_TOKEN or pass --token to an individual command. See Authentication for device flow, stored tokens, scopes, and endpoint selection.

Browser login requests the scopes needed by the current CLI command surface: repo:read, repo:write, repo:delete, community:write, jobs:run, inference:run, mcp:use, account:keys, and webhooks:manage, plus the identity and refresh-token scopes. This CLI authorization is independent of the MCP Read/Write/Full preference. mega auth whoami shows the active token kind, role, and granted scopes so scripts can fail before attempting an unauthorized operation.

Trusted Publishers in GitHub Actions#

Organization and personal namespace owners can register a GitHub Actions Trusted Publisher. The workflow then exchanges GitHub's signed OIDC identity for a one-hour MEGA token; no long-lived MEGA_TOKEN secret is stored.

Set MEGA_OIDC_RESOURCE to the namespace handle, not a repository or Bucket ID. The same short-lived identity can publish repository revisions and mutable Bucket objects inside that namespace:

YAML
permissions:  contents: read  id-token: write steps:  - uses: actions/checkout@v4  - run: python -m pip install megatensors  - run: |      mega buckets create model-team/release-artifacts --private --exist-ok      mega buckets sync ./artifacts mega://buckets/model-team/release-artifacts    env:      MEGA_OIDC_RESOURCE: model-team

Trusted Publisher tokens have repository/Bucket read and publish access only. They cannot delete or move a Bucket, change its visibility, issue persistent S3 credentials, manage the account, or obtain a refresh token.

Command domains#

Domain Commands Purpose
Authentication mega auth Login, logout, switch tokens, inspect identity, and manage public keys.
Repositories mega repos, models, datasets, spaces Create, inspect, update, move, duplicate, and delete model, dataset, Space, and MCP repositories.
Files mega upload, upload-large-folder, download, snapshot, cp Transfer selected files or complete repository trees.
Revisions mega repos branch, tag, history, commit Manage branches and tags and inspect immutable commit history.
Community mega discussions Operate discussions, pull requests, comments, reactions, and merge state.
MCP Marketplace mega mcp Search listings, inspect pricing and runtime state, and safely install versioned local companion files.
Compute mega jobs, mega sandbox Run bounded containers, recurring schedules, and interactive isolated sessions.
Buckets mega buckets, mega sync Manage mutable object storage and synchronize local directory trees.
Extensibility mega extensions, mega skills Install trusted CLI extensions and AI-assistant skills.
Webhooks mega webhooks Configure signed event delivery and inspect receipts.
Local cache mega cache Inspect, verify, prune, and remove cached Hub artifacts.
Artifact runtime mega convert, mega sign Convert Hugging Face folders and sign MEGA artifacts.

Repository workflows#

BASH
mega repos create mega/demo --type model --exist-okmega upload mega/demo ./model --revision mainmega repos tag create mega/demo v1.0 --message "First release"mega snapshot mega/demo --revision v1.0 --local-dir ./releasemega repos create mega/my-tools --type mcpmega upload mega/my-tools ./README.md README.md --type mcpmega cp ./plugin.json mega://mcps/mega/my-tools@main/plugin.json

Typed repository aliases expose the common operations without repeating --type:

BASH
mega models listmega datasets upload research/evals ./datamega spaces list alice/demo --revision main

See Hub Repositories for file, revision, and community semantics.

MCP Marketplace workflows#

Search the public catalogue, inspect one listing, and install its optional local CLI, Skill, or Plugin companion:

BASH
mega mcp search judgemega mcp info mega/xpuoj --format jsonmega mcp install mega/xpuoj

Files install under ~/.local/share/mega/mcp/<namespace>/<name> by default. The command requires a README, writes .mega-mcp.json, replaces atomically, and never executes publisher code. Use --revision, --dest, or --force when needed. AI clients still connect only to https://mega.tensorplay.cn/mcp.

Spaces workflows#

Create and publish an application repository under a personal or organization namespace:

BASH
mega repos create mega/openapi --type space --public --exist-okmega spaces upload mega/openapi ./spaces/openapi . --sync \  --commit-message "Publish OpenAPI explorer"mega spaces info mega/openapi --format jsonmega spaces restart mega/openapimega spaces wait mega/openapi --timeout 5mmega spaces logs --follow mega/openapi

Runtime management is available directly from the CLI:

BASH
mega spaces hardwaremega spaces runtime mega/openapi --format jsonmega spaces settings mega/openapi --hardware cpu-upgrademega spaces variables add mega/openapi -e MODE=productionmega spaces secrets add mega/openapi -s API_TOKENmega spaces volumes set mega/openapi -v mega://datasets/mega/data:/datasets/data:romega spaces dev-mode mega/openapimega spaces hot-reload mega/openapi app.py -f ./app.pymega spaces pause mega/openapi

Use mega spaces templates, search, and card for discovery. Dev Mode keeps a writable source workspace, hot-reload atomically replaces one Python file without rebuilding the image, and ssh enters that same rootless container after Hub key and write-permission checks. Space volumes are read-only model, dataset, Space, or Bucket snapshots; use a Space storage tier for writable /data. Secret values are write-only and never appear in list output. The Spaces guide documents billing, Dev Mode entitlement, runtime states, and recovery.

Jobs workflows#

BASH
mega jobs hardwaremega jobs balancemega jobs run python:3.12-slim python -c 'print("hello")'mega jobs ps --status RUNNINGmega jobs logs --follow --tail 100 <job-id>mega jobs wait <job-id>mega jobs usage

Recurring work lives under mega jobs scheduled. The Jobs guide documents every supported command, option, SDK method, and endpoint.

Sandbox workflows#

BASH
mega sandbox create python:3.13mega sandbox exec <sandbox-id> -- python -Vmega sandbox spawn <sandbox-id> -- python -m http.server 8000mega sandbox process ls <sandbox-id>mega sandbox cp ./input.json <sandbox-id>:/workspace/input.jsonmega sandbox kill <sandbox-id>

Dedicated sessions use the authenticated native Sandbox API. Read-only model, dataset, and Space snapshots can be attached with repeatable -v/--volume mounts; bucket and writable mounts are rejected. File transfer uses bounded chunks, and background processes can be inspected and stopped by PID.

mega sandbox pool create maintains a reusable template for faster Session startup. Pool capacity and placement are managed by the service and may vary with account limits and current availability.

Extensions and skills#

BASH
mega extensions searchmega extensions install ohtensorplay/mega-examplemega example --helpmega extensions update mega skills previewmega skills listmega skills addmega skills update

Extensions execute third-party code, so install only sources you trust. mega skills add installs the generated mega-cli skill by default; named skills come from the synchronized public MEGA skills marketplace.

Webhook workflows#

BASH
mega webhooks create \  --name release-verifier \  --url https://ci.example/hooks/mega \  --event repo.updated mega webhooks test <webhook-id>mega webhooks deliveries <webhook-id> --limit 50

The create command reveals a generated signing secret once. See Webhooks before configuring a production receiver.

Git, SSH, and GPG smoke test#

MEGA publishes Web/API URLs on mega.tensorplay.cn, HTTPS Git directly on git.tensorplay.cn, and SSH Git on the DNS-only ssh.tensorplay.cn host. Existing Hub-host Git remotes continue to redirect to the HTTPS Git data plane.

BASH
ssh-keygen -t ed25519 -C "$USER@$(hostname)" -f ~/.ssh/id_ed25519_megamega auth keys add ~/.ssh/id_ed25519_mega.pub --name workstationcurl -sSfL https://mega.tensorplay.cn/git-xet/install.sh | shgit clone https://git.tensorplay.cn/OWNER/REPOSITORY.gitssh -T -i ~/.ssh/id_ed25519_mega git@ssh.tensorplay.cngit clone git@ssh.tensorplay.cn:OWNER/REPOSITORY

Register and exercise a signing key whose email matches the MEGA account:

BASH
gpg --armor --export ACCOUNT_EMAIL > mega-signing-key.ascmega auth keys add mega-signing-key.asc --type gpg --name releasegit config user.email ACCOUNT_EMAILgit config user.signingkey "$(gpg --list-secret-keys --with-colons ACCOUNT_EMAIL | awk -F: '$1=="sec" {print $5; exit}')"git config commit.gpgsign truegit commit --allow-empty -m "Verify signed push"git push origin HEADmega repos history OWNER/REPOSITORY --format json

The history record reports signature_status and signer_fingerprint. See Authentication for host configuration and identity rules.

Structured output#

Commands that return records support shared formatting options:

Option Behavior
--format auto Selects human or agent output from the terminal environment.
--format human Renders readable tables and result messages.
--format agent Produces stable, unstyled output for an AI or automation harness.
--format json or --json Emits machine-readable JSON.
--format quiet or -q Emits the primary ID, one value per line.
--no-truncate Keeps complete scalar values in human tables.

Prefer JSON for scripts:

BASH
mega repos list --owner research --format jsonmega jobs ps --status RUNNING --format json

Use quiet output for shell composition:

BASH
mega repos list --type model -q

Shell completion and help#

BASH
mega --show-completionmega --install-completionmega repos create --helpmega jobs scheduled run --help

Leaf-command help is the authoritative option contract for the installed version.

Environment variables#

Variable Effect
MEGA_TOKEN Overrides the active stored token.
MEGA_ENDPOINT Changes the Hub endpoint.
MEGA_INFERENCE_ROUTER_ENDPOINT Changes the OpenAI-compatible inference data-plane endpoint.
MEGA_INFERENCE_MODELS_ENDPOINT Changes the public live Provider-model catalog endpoint.
MEGA_HOME Changes the configuration and cache root.
MEGA_DEBUG=1 Enables full tracebacks.

Automation rules#

  • Use --format json instead of parsing human tables.
  • Pass --yes only when the target ID was validated earlier in the same workflow.
  • Inject secrets with environment variables; do not place tokens directly in committed scripts.
  • Pin repository automation to an explicit branch, tag, or commit.
  • Check the exit code. Foreground mega jobs run and mega jobs wait fail when the Job does not complete successfully.