Skip to main content

minimax-code-sdk

Python SDK for driving the local MiniMax Code agent (mcode).

It mirrors the TypeScript SDK @minimax-ai/code-sdk: every Turn runs mcode exec --output-format=stream-json and continues the Session with --session.

Requirements

  • Python 3.10+
  • The mcode CLI (0.6.3 or newer): npm install -g @minimax-ai/code

Install

pip install minimax-code-sdk   # or: uv add minimax-code-sdk

Import it as minimax_code.

The CLI is found from MCodeOptions(bin=...), then the MCODE_BIN environment variable, then PATH. The SDK never starts it through a shell. On Windows, the mcode.cmd launcher written by the official installer or by npm / pnpm is followed to the JS entry and Node runtime it runs (the installer's release pointer is read again before every Turn, so a CLI self-update is picked up); an unrecognized .cmd file is rejected, and you can pass the JS entry as bin.

Quick start

import asyncio
from minimax_code import MCode, ThreadOptions


async def main() -> None:
    client = MCode()
    thread = client.start_thread(ThreadOptions(cwd=".", permission="smart"))

    turn = await thread.run("Summarize this repository in one sentence.")
    print(turn.final_response, turn.usage)

    # Same Session, next Turn.
    turn = await thread.run("Now list its top-level directories.")

    # Persist thread.id and continue later, in the same workspace.
    later = client.resume_thread(thread.id, ThreadOptions(cwd="."))
    print((await later.run("What did I ask first?")).final_response)


asyncio.run(main())

Resuming a Session

A Session belongs to the workspace it was created in. Pass the same cwd to resume_thread(); when cwd is omitted, the current working directory at that call is used. A Thread pins its cwd when it is created, so a later os.chdir() does not affect it. A different workspace fails with MCodeRunError ("Session ... belongs to workspace ..."), and retrying does not help.

thread = client.start_thread(ThreadOptions(cwd="/path/to/project"))
await thread.run("...")
later = client.resume_thread(thread.id, ThreadOptions(cwd="/path/to/project"))

Streaming

streamed = await thread.run_streamed("Fix the failing test.")
async for event in streamed:
    item = event.get("item")
    if item and item["type"] == "agent_message":
        # Text deltas arrive on item.started as well as item.updated.
        print(item.get("contentDelta", ""), end="")
    elif event["type"] == "turn.failed":
        print("failed:", event.get("error"))

Events are the CLI's stream-json events, passed through unchanged (unknown types included), with one exception: an item.updated snapshot (no contentDelta) identical to the previous snapshot of the same item is skipped. Text deltas are never skipped. turn.failed is an ordinary event; iteration raises only for process or protocol failures.

Cancellation

  • streamed.cancel() sends SIGTERM, the CLI's cancel signal; the stream ends with the CLI's final events. SIGTERM is used instead of SIGINT because Ctrl+C in a terminal already sends SIGINT to the CLI, and a second SIGINT would skip its graceful shutdown.
  • Leaving the async for early (break or an exception in the loop body), or cancelling the task running thread.run(), stops the CLI: SIGTERM, then SIGKILL if it is still running after the CLI's 60 second shutdown budget. The next Turn on the same Thread waits for that shutdown instead of raising ThreadBusyError; async with streamed: or await streamed.aclose() stops it deterministically. On Windows, cancellation stops the CLI immediately.
  • RunOptions(timeout_ms=...) is enforced by the CLI. If the CLI is still running 90 seconds after timeout_ms (its shutdown budget plus startup time), the SDK kills it and raises MCodeRunError with status="timeout".
  • exec.completed ends the Turn. A CLI that keeps running afterwards is stopped after 5 seconds, and a background process that inherited the CLI's output does not keep the Turn open.

Blocking API

from minimax_code import SyncMCode

with SyncMCode() as client:
    thread = client.start_thread()
    print(thread.run("hello").final_response)
    for event in thread.run_streamed("again"):
        print(event["type"])

The blocking API runs its own event loop, so it cannot be used where a loop is already running, such as a Jupyter notebook or an async def function. Use the async API with await there.

Options

Object Fields
MCodeOptions bin, data_dir (MINIMAX_DATA_DIR), env (replaces os.environ; values hidden in repr()), config_path
ThreadOptions cwd, model (provider/model), effort, permission (smart/full/off), mode, prompt_mode, system_prompt, append_system_prompt
RunOptions files, timeout_ms, max_steps

Errors

All errors subclass MCodeError (with exit_code, stderr, session_id, result, items): MCodeNotFoundError, MCodeVersionError, MCodeInvocationError, MCodeRunError (status, category), MCodeAbortError, MCodeProtocolError, ThreadBusyError. Errors can be pickled, for example to return them from a ProcessPoolExecutor worker.

Limitations

Each Turn is a separate process, so interactive permission prompts (permission="ask") and custom in-process tools are not supported yet. A long-lived ACP transport is planned.

Development

uv sync
uv run pytest
uv run ruff check . && uv run ruff format --check . && uv run mypy

End-to-end tests against a real CLI and model are opt-in: MCODE_SDK_E2E=1 MCODE_BIN=/path/to/mcode uv run pytest -m e2e.

Release notes are in CHANGELOG.md; maintainers publish with RELEASING.md.

License

MIT

Metadata

Release files for minimax-code-sdk 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for minimax-code-sdk 0.1.1
File Size Uploaded Provenance Actions
minimax_code_sdk-0.1.1.tar.gz 72.6 kB With provenance Details for minimax_code_sdk-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for minimax-code-sdk 0.1.1
File Interpreter ABI Platform Actions
minimax_code_sdk-0.1.1-py3-none-any.whl Python 3 none any Details for minimax_code_sdk-0.1.1-py3-none-any.whl

Total release size: 97.4 kB

Release files / minimax_code_sdk-0.1.1.tar.gz

Download URL minimax_code_sdk-0.1.1.tar.gz
Size 72.6 kB
Tags Source
SHA-256 checksum
How to use checksums
26021e60888dfa55a834af1c7e27e7b10fd684e6cadb3abc17f3555740febd69
BLAKE2b-256 checksum
How to use checksums
f9d49528a0a615da0a40f77b6e50ee488d13a6b03ca69b0119fb61556729a8b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Release files / minimax_code_sdk-0.1.1-py3-none-any.whl

Download URL minimax_code_sdk-0.1.1-py3-none-any.whl
Size 24.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac95e5ad1a79a4e1ed888be2d97650239573ea6797113706b938815c663e3ed1
BLAKE2b-256 checksum
How to use checksums
2437e21892fe2bb7763311d90f581fc06d0bf3f0a25aa56f7c95cf48d901270d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Security for minimax-code-sdk 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for minimax_code_sdk-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page