Skip to main content

MiniMax Python Client

PyPI version Pydantic v2 Ruff pdm-managed License python-versions Main Workflow

An (unofficial) python native client for easy interaction with MiniMax Open Platform

The current implementation includes the following official APIs offered by MiniMax:

  • ChatCompletion v2
  • Embeddings
  • File
  • Finetune
  • Assistants
    • Assistant
    • Assistant File
    • Thread
    • Message
    • Run
    • Run Step
  • Audio
    • T2A
    • T2A Pro
    • T2A Large
    • T2A Stream
    • Voice Cloning

Prerequisites

  • Python >= 3.8
  • pip (or any other tool that does the same job)
  • Internet connection
  • An API KEY acquired from MiniMax Open Platform

Quick Start

1. Install the package

pip install minimax-client

2. Import the package and invoke the client

2.1 Sync call

from minimax_client import MiniMax


client = MiniMax(api_key="<YOUR_API_KEY>")


response = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": "1 + 1 equals: ",
        }
    ]
)


print(response.choices[0].message.content)

2.2 Sync call with streaming

from minimax_client import MiniMax


client = MiniMax(api_key="<YOUR_API_KEY>")


stream = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": "What is the term GPT short for?",
        }
    ],
    stream=True,
)


for chunk in stream:
    print(chunk.choices[0].delta.content if chunk.choices[0].delta else "", end="")

2.3 Sync call with tools, stream enabled

from minimax_client import MiniMax


client = MiniMax(api_key="<YOUR_API_KEY>")


stream = client.chat.completions.create(
    model="abab5.5-chat",
    messages=[
        {
            "role": "system",
            "content": "You are a helpful assistant",
        },
        {
            "role": "user",
            "content": "What's the weather like in Log Angeles right now?",
        },
        {
            "role": "assistant",
            "tool_calls": [
                {
                    "id": "call_function_2936815621",
                    "type": "function",
                    "function": {
                        "name": "get_current_weather",
                        "arguments": '{"location": "LogAngeles"}',
                    },
                }
            ],
        },
        {
            "role": "tool",
            "tool_call_id": "call_function_2936815621",
            "content": "LogAngeles / Sunny / 51°F / Wind: East 5 mph",
        },
    ],
    stream=True,
    tool_choice="auto",
    tools=[
        {
            "type": "function",
            "function": {
                "name": "get_current_weather",
                "description": "Retrieve the current weather of given location",
                "parameters": '{"type": "object", "properties": {"location": {"type": "string", "description": "Name of a city, eg. Paris, London"}}, "required": ["location"]}',
            },
        }
    ],
)

for chunk in stream:
    print(chunk.choices[0].delta.content if chunk.choices[0].delta else "", end="")

# It's currently sunny in Log Angeles, with a temperature of 51°F and wind from the east at 5 mph.

2.4 Async call

import asyncio

from minimax_client import AsyncMiniMax


async def demo():
    client = AsyncMiniMax(api_key="<YOUR_API_KEY>")

    response = await client.chat.completions.create(
        messages=[
            {
                "role": "user",
                "content": "1 + 1 equals: ",
            }
        ]
    )

    print(response.choices[0].message.content)


asyncio.run(demo())

2.5 Async call with streaming

import asyncio

from minimax_client import AsyncMiniMax


async def demo():
    client = AsyncMiniMax(api_key="<YOUR_API_KEY>")

    stream = await client.chat.completions.create(
        messages=[
            {
                "role": "user",
                "content": "What is the term GPT short for?",
            }
        ],
        stream=True,
    )

    async for chunk in stream:
        print(chunk.choices[0].delta.content if chunk.choices[0].delta else "", end="")


asyncio.run(demo())

2.6 Sync call for embeddings

from minimax_client import MiniMax


client = MiniMax(api_key="<YOUR_API_KEY>")


response = client.embeddings.create(
    input=["Hello world!", "Nice to meet you!"],
    target="db",
)

print(response.vectors[0][:10])
print(response.vectors[1][:10])

2.7 Async call for embeddings

import asyncio

from minimax_client import AsyncMiniMax


async def demo():
    client = AsyncMiniMax(api_key="<YOUR_API_KEY>")

    response = await client.embeddings.create(
        input=["Hello async world!", "Nice to meet you async!"],
        target="query",
    )

    print(response.vectors[0][:10])
    print(response.vectors[1][:10])


asyncio.run(demo())

2.8 Sync call for files

from minimax_client import MiniMax


client = MiniMax(api_key="<YOUR_API_KEY>")


resp = client.files.create(filepath="sample.txt", purpose="retrieval")
print(resp.file.file_id)

resp = client.files.list(purpose="retrieval")
print(resp.files[0].file_id)

resp = client.files.retrieve(file_id=resp.files[0].file_id)
print(resp.file.bytes)

resp = client.files.delete(file_id=resp.file.file_id)
print(resp.file_id)

2.9 Async call for files

import asyncio

from minimax_client import AsyncMiniMax


async def demo():
    client = AsyncMiniMax(api_key="<YOUR_API_KEY>")

    resp = await client.files.create(filepath="sample.txt", purpose="retrieval")
    print(resp.file.file_id)

    resp = await client.files.list(purpose="retrieval")
    print(resp.files[0].file_id)

    resp = await client.files.retrieve(file_id=resp.files[0].file_id)
    print(resp.file.bytes)

    resp = await client.files.delete(file_id=resp.file.file_id)
    print(resp.file_id)

asyncio.run(demo())

2.10 Sync call for files

from minimax_client import MiniMax


client = MiniMax(api_key="<YOUR_API_KEY>")

resp = client.fine_tuning.jobs.create(
    model="abab5.5s-chat-240123", training_file=..., suffix="test"
)
print(resp.id)
print(resp.fine_tuned_model)

resp = client.fine_tuning.jobs.list(limit=5)
print(resp.job_list[0])

resp = client.model.list()
print(resp.model_list[0])

resp = client.model.retrieve(model="ft:abab5.5s-chat-240123_XXXXXXXXXXXXX:test")
print(resp.model.id)

2.11 Sync call for assistants

from minimax_client import MiniMax


client = MiniMax(api_key="<YOUR_API_KEY>")

resp = client.assistants.create(model="abab5.5s-chat-240123")

client.assistants.update(
    assistant_id=resp.id,
    model="abab5.5s-chat-240123",
    name="test-assistant",
    instructions="You are a helpful assistant.",
)

client.assistants.retrieve(assistant_id=resp.id)

client.assistants.list(limit=5)

client.assistants.delete(assistant_id=resp.id)

2.12 Sync call for assistant files

from minimax_client import MiniMax


client = MiniMax(api_key="<YOUR_API_KEY>")

resp = client.files.create(filepath="sample.txt", purpose="retrieval")

file_id = resp.file.file_id

resp = client.assistants.create(
    model="abab5.5s-chat-240123",
    name="test-assistant",
    instructions="You are a helpful assistant.",
    description="test-assistant",
    tools=[{"type": "retrieval"}],
)

assistant_id = resp.id

resp = client.assistants.files.create(assistant_id=assistant_id, file_id=str(file_id))

resp = client.assistants.files.retrieve(assistant_id=assistant_id, file_id=str(file_id))

resp = client.assistants.files.list(assistant_id=assistant_id, limit=5, order="asc")

resp = client.assistants.files.delete(assistant_id=assistant_id, file_id=str(file_id))

2.13 Sync call for assistant threads

from minimax_client import MiniMax


client = MiniMax(api_key="<YOUR_API_KEY>")

resp = client.threads.create(metadata={"key": "value"})

resp = client.threads.retrieve(thread_id=resp.id)

resp = client.threads.update(thread_id=resp.id, metadata={"key": "value2"})

2.14 Sync call for assistant messages

import time

from minimax_client import MiniMax


client = MiniMax(api_key="<YOUR_API_KEY>")

resp = client.threads.create(metadata={"key": "value"})

thread_id = resp.id

resp = client.threads.messages.create(
    thread_id=thread_id, content="Hello", role="user", metadata={"key": "value"}
)

resp = client.threads.messages.retrieve(thread_id=thread_id, message_id=resp.id)

resp = client.threads.messages.list(thread_id=thread_id, limit=5, order="asc")

2.15 Sync call for assistant runs and run steps

from minimax_client import MiniMax


client = MiniMax(api_key="<YOUR_API_KEY>")

resp = client.assistants.create(
    model="abab5.5-chat",
    name="test-assistant",
    instructions="You are a helpful assistant that can use tools to answer questions.",
    tools=[
        {
            "type": "function",
            "function": {
                "name": "get_weather",
                "description": "get weather",
                "parameters": {
                    "type": "object",
                    "required": ["city"],
                    "properties": {"city": {"type": "string"}},
                },
            },
        },
        {"type": "web_search"},
        {"type": "code_interpreter"},
    ],
)

assistant_id = resp.id

resp = client.assistants.retrieve(assistant_id=assistant_id)

print(resp.model_dump())

resp = client.threads.create(metadata={"key1": "value1"})

thread_id = resp.id

client.threads.messages.create(
    thread_id=thread_id,
    role="user",
    content="In the science-fiction 'Three-Body Problem', what is the profession of Wang Miao?",
)

resp = client.threads.runs.create(thread_id=thread_id, assistant_id=assistant_id)

run_id = resp.id

time.sleep(10)

resp = client.threads.runs.retrieve(run_id=run_id, thread_id=thread_id)

print(resp.model_dump())

resp = client.threads.runs.steps.list(thread_id=thread_id, run_id=run_id, limit=10)

for step in resp.data:
    resp = client.threads.runs.steps.retrieve(
        step_id=step.id, thread_id=thread_id, run_id=run_id
    )

    print(resp.model_dump())

2.16 Sync call for assistant STREAMED runs and run steps

from minimax_client import MiniMax


client = MiniMax(api_key="<YOUR_API_KEY>")

resp = client.assistants.create(
    model="abab5.5-chat",
    name="test-assistant",
    instructions="You are a helpful assistant.",
)

assistant_id = resp.id

resp = client.threads.create(metadata={"key1": "value1"})

thread_id = resp.id

for part in client.threads.runs.stream(
    stream_mode=1,
    thread_id=thread_id,
    assistant_id=assistant_id,
    messages=[{"type": 1, "role": "user", "content": "1 + 1 equals:"}],
):
    print(part.data.model_dump())
    print("\n-----\n")

2.17 Sync T2A

from minimax_client import MiniMax


client = MiniMax(api_key="<YOUR_API_KEY>")

resp = client.audio.speech(
    text="One apple a day keeps the doctor away",
    model="speech-02",
    timber_weights=[
        {
            "voice_id": "male-qn-qingse",
            "weight": 1,
        },
        {
            "voice_id": "presenter_female",
            "weight": 1,
        },
    ],
    vol=1,
    pitch=2,
)

if isinstance(resp, bytes):
    with open("speech.mp3", "wb") as f:
        f.write(resp)
else:
    print(resp.model_dump())

2.18 Sync Voice Cloning

from minimax_client import MiniMax


client = MiniMax(api_key="<YOUR_API_KEY>")

resp = client.files.create(filepath="original_voice.mp3", purpose="voice_clone")

file_id = resp.file.file_id

resp = client.audio.voice_cloning(
    file_id=file_id,
    voice_id="cloned12345678",
)

print(resp.model_dump())

Metadata

Release files for minimax-client 0.6.2

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-client 0.6.2
File Size Uploaded
minimax_client-0.6.2.tar.gz 25.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for minimax-client 0.6.2
File Interpreter ABI Platform
minimax_client-0.6.2-py3-none-any.whl Python 3 none any Details

Total release size: 54.3 kB

Release files / minimax_client-0.6.2.tar.gz

Download URL minimax_client-0.6.2.tar.gz
Size 25.2 kB
Tags Source
SHA-256 checksum
How to use checksums
eb4de8a18ecedf5e7f76a95aaf19fa2143754ebbdfbbac7893e480421424842e
BLAKE2b-256 checksum
How to use checksums
ae1d61ae821b16460795efe8d7e1daad6914d0da9ca96ddef2e5c0d12848ec8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.19.1 CPython/3.12.7 Windows/11

Release files / minimax_client-0.6.2-py3-none-any.whl

Download URL minimax_client-0.6.2-py3-none-any.whl
Size 29.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b927b621d6927a5d17ab2f9a37281c1e6a932cf2ebbf327232584a43190f2808
BLAKE2b-256 checksum
How to use checksums
e1861137adcb09fe1b1ace9dadaf608e3524b9c67ee2cd92288b7a4831c2895d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.19.1 CPython/3.12.7 Windows/11

Release history Release notifications | RSS feed

This release

0.6.2 This release

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

1 release file

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