### Task Started Event Example Source: https://platform.minimax.io/docs/api-reference/speech-t2a-websocket Example payload indicating that the Speech-to-Text task has commenced. This event includes session and trace identifiers for monitoring. ```json { "session_id": "xxxx", "event": "task_started", "trace_id": "0303a2882bf18235ae7a809ae0f3cca7", "base_resp": { "status_code": 0, "status_msg": "success" } } ``` -------------------------------- ### Install OpenAI SDK (Node.js) Source: https://platform.minimax.io/docs/api-reference/text-openai-api Install the official OpenAI Node.js package using npm. ```bash npm install openai ``` -------------------------------- ### Install OpenAI SDK (Python) Source: https://platform.minimax.io/docs/api-reference/text-openai-api Install the official OpenAI Python package using pip. ```bash pip install openai ``` -------------------------------- ### Install AI SDK and MiniMax Provider (npm) Source: https://platform.minimax.io/docs/api-reference/text-ai-sdk Install the AI SDK and the Vercel MiniMax AI provider using npm. ```bash npm install ai vercel-minimax-ai-provider ``` -------------------------------- ### Install AI SDK and MiniMax Provider (pnpm) Source: https://platform.minimax.io/docs/api-reference/text-ai-sdk Install the AI SDK and the Vercel MiniMax AI provider using pnpm. ```bash pnpm add ai vercel-minimax-ai-provider ``` -------------------------------- ### Install Anthropic SDK for Node.js Source: https://platform.minimax.io/docs/api-reference/text-anthropic-api Install the official Anthropic SDK for Node.js using npm. ```bash npm install @anthropic-ai/sdk ``` -------------------------------- ### Bearer Authentication Example Source: https://platform.minimax.io/docs/api-reference/image-generation-i2i Example of how to use Bearer authentication with the API key. ```http HTTP: Bearer Auth - Security Scheme Type: http - HTTP Authorization Scheme: `Bearer API_key`, can be found in [Account Management>API Keys](https://platform.minimax.io/user-center/basic-information/interface-key). ``` -------------------------------- ### Install Anthropic SDK for Python Source: https://platform.minimax.io/docs/api-reference/text-anthropic-api Install the official Anthropic SDK for Python using pip. ```bash pip install anthropic ``` -------------------------------- ### Example Response for List Models Source: https://platform.minimax.io/docs/api-reference/models/openai/list-models This example demonstrates the structure of a successful response when listing available models. It includes model IDs, creation timestamps, and ownership information. ```json { "object": "list", "data": [ { "id": "MiniMax-M3", "object": "model", "created": 1780272000, "owned_by": "minimax" }, { "id": "MiniMax-M2.7", "object": "model", "created": 1773799200, "owned_by": "minimax" }, { "id": "MiniMax-M2.5", "object": "model", "created": 1770948000, "owned_by": "minimax" } ] } ``` -------------------------------- ### Lyrics Generation Request Example Source: https://platform.minimax.io/docs/api-reference/lyrics-generation Example of a request payload for generating a full song. Ensure the 'mode' is set to 'write_full_song' and provide a descriptive 'prompt'. ```yaml mode: write_full_song prompt: A cheerful love song about a summer day at the beach ``` -------------------------------- ### Cover Preprocess Request Example Source: https://platform.minimax.io/docs/api-reference/music-cover-preprocess Example of a request body for the Music Cover Preprocess API, specifying the model as 'music-cover' and providing a URL for the reference audio. ```json { "model": "music-cover", "audio_url": "https://example.com/song.mp3" } ``` -------------------------------- ### Estimate Input Tokens Response Example Source: https://platform.minimax.io/docs/api-reference/responses-input-tokens This example shows a successful response from the Estimate Input Tokens API, indicating the calculated input token count. ```json { "object": "response.input_tokens", "input_tokens": 588 } ``` -------------------------------- ### Estimate Input Tokens Request Example Source: https://platform.minimax.io/docs/api-reference/responses-input-tokens This example shows the structure of a request to estimate input tokens. It includes the model name, conversation history with messages and tool definitions, and a system instruction. ```json { "model": "MiniMax-M3", "input": [ { "type": "message", "role": "user", "content": "> Please implement a generic quicksort algorithm in Python\nwith these requirements: 1) in-place sorting to save\nmemory; 2) three-way partitioning to handle duplicate\nelements; 3) switch to insertion sort for small\nsubarrays; 4) include complete unit tests. Finally,\nexplain the advantage of three-way partitioning over the\nclassic Lomuto scheme when keys repeat." } ], "tools": [ { "type": "function", "name": "search_docs", "description": "> Search the official documentation of the Python standard\nlibrary or a third-party package", "parameters": { "type": "object", "properties": { "library": { "type": "string", "description": "Library name, e.g. `typing`, `itertools`" }, "query": { "type": "string", "description": "Search keywords" } }, "required": [ "library", "query" ] } }, { "type": "function", "name": "run_python", "description": "> Execute Python code in a sandbox and return stdout /\nerror", "parameters": { "type": "object", "properties": { "code": { "type": "string", "description": "Python code to execute" }, "timeout_seconds": { "type": "integer", "description": "Execution timeout in seconds", "default": 10 } }, "required": [ "code" ] } } ] } ``` -------------------------------- ### Python: Start Speech Synthesis Task Source: https://platform.minimax.io/docs/api-reference/speech-t2a-websocket Sends the 'task_start' event to initiate a speech synthesis task. Requires a successful WebSocket connection and returns True if the task starts successfully, False otherwise. ```python async def start_task(websocket): """Start task""" try: await websocket.send(json.dumps({"event": "task_start", "model": "speech-2.8-hd", "voice_setting": {"voice_id": "Chinese (Mandarin)_Lyrical_Voice"}})) response = await websocket.recv() if json.loads(response).get("event") == "task_started": return True return False except Exception as e: print(f"Error: {e}") return False ``` -------------------------------- ### OpenAPI Specification for Query Video Generation Task Source: https://platform.minimax.io/docs/api-reference/video-generation-query This OpenAPI specification defines the GET /v1/query/video_generation endpoint for querying the status of a video generation task. It includes request parameters, response schemas, and example responses. ```yaml openapi: 3.1.0 info: title: MiniMax API description: MiniMax video generation and file management API license: name: MIT version: 1.0.0 servers: - url: https://api.minimax.io security: - bearerAuth: [] paths: /v1/query/video_generation: get: tags: - Video summary: Query Video Generation Task operationId: queryVideoGenerationTask parameters: - name: task_id in: query required: true description: >- The task ID to query. Only tasks created under the current account can be queried. schema: type: string responses: '200': description: '' content: application/json: schema: $ref: '#/components/schemas/QueryVideoGenerationTaskResp' components: schemas: QueryVideoGenerationTaskResp: type: object properties: task_id: type: string description: The queried task ID. status: $ref: '#/components/schemas/VideoProcessStatus' file_id: type: string description: >- Returned when the task succeeds. Represents the file ID of the generated video. video_width: type: integer description: >- Returned when the task succeeds. The width of the generated video (in pixels). video_height: type: integer description: >- Returned when the task succeeds. The height of the generated video (in pixels). base_resp: $ref: '#/components/schemas/QueryVideoGenerationTaskBaseResp' example: task_id: '176843862716480' status: Success file_id: '176844028768320' video_width: 1920 video_height: 1080 base_resp: status_code: 0 status_msg: success VideoProcessStatus: type: string enum: - Preparing - Queueing - Processing - Success - Fail description: |- The current status of the task. Possible values: - `Preparing` – Preparing - `Queueing` – In queue - `Processing` – Generating - `Success` – Completed successfully - `Fail` – Failed QueryVideoGenerationTaskBaseResp: type: object properties: status_code: type: integer description: |- The status codes are as follows: - `0`, Request successful; - `1002`, Rate limit triggered, retry later - `1004`, Authentication failed, check API Key - `1026`, Contains sensitive content in the input - `1027`, Contains sensitive content in the generated video For more information, please refer to the [Error Code Reference](/api-reference/errorcode). status_msg: type: string description: Status message. Returns `success` when successful. securitySchemes: bearerAuth: type: http scheme: bearer bearerFormat: JWT description: >- `HTTP: Bearer Auth` - Security Scheme Type: http - HTTP Authorization Scheme: `Bearer API_key`, can be found in [Account Management>API Keys](https://platform.minimax.io/user-center/basic-information/interface-key). ``` -------------------------------- ### Callback Handling Source: https://platform.minimax.io/docs/api-reference/video-generation-t2v This section provides an example of how to set up a server to handle callback requests from the MiniMax platform for video generation tasks. It includes validation and status update handling. ```APIDOC ## Callback URL Handling ### Description MiniMax sends `POST` requests to the configured `callback_url` to provide asynchronous task status updates. The server must first validate the callback by echoing a `challenge` field, and then process status updates. ### Callback `status` values: - `"processing"` – Task in progress - `"success"` – Task completed successfully - `"failed"` – Task failed ### Example Server Implementation (Python/FastAPI) ```python from fastapi import FastAPI, HTTPException, Request import json app = FastAPI() @app.post("/get_callback") async def get_callback(request: Request): try: json_data = await request.json() challenge = json_data.get("challenge") if challenge is not None: # Validation request, echo back challenge return {"challenge": challenge} else: # Status update request, handle accordingly # Example status update payload: # { # "task_id": "115334141465231360", # "status": "success", # "file_id": "205258526306433", # "base_resp": { # "status_code": 0, # "status_msg": "success" # } # } print(f"Received status update: {json_data}") # Process the status update return {"status": "success"} except Exception as e: raise HTTPException(status_code=500, detail=str(e)) if __name__ == "__main__": import uvicorn uvicorn.run( app, # Required host="0.0.0.0", # Required port=8000, # Required, port can be customized ) ``` ``` -------------------------------- ### Simple Text Input Example Source: https://platform.minimax.io/docs/api-reference/responses-create Demonstrates a simple text input for generating a response. ```json { "model": "MiniMax-M3", "input": "Hello!" } ``` -------------------------------- ### Image Generation Request Example Source: https://platform.minimax.io/docs/api-reference/image-generation-i2i Example of a request to generate images with specified parameters including subject reference. ```json { "model": "image-01", "prompt": "A girl looking into the distance from a library window", "aspect_ratio": "16:9", "subject_reference": [ { "type": "character", "image_file": "https://cdn.hailuoai.com/prod/2025-08-12-17/video_cover/1754990600020238321-411603868533342214-cover.jpg" } ], "n": 2 } ``` -------------------------------- ### TimbreWeights Example Source: https://platform.minimax.io/docs/api-reference/speech-t2a-http Example of how to configure timbre weights for voice synthesis. ```json "timbre_weights": [ { "voice_id": "female-chengshu", "weight": 30 }, { "voice_id": "female-tianmei", "weight": 70 } ] ``` -------------------------------- ### Function Call Example Source: https://platform.minimax.io/docs/api-reference/responses-create Demonstrates how to define tools for function calls, allowing the model to interact with external functions. ```json { "model": "MiniMax-M3", "input": "What is the weather in Boston today?", "tools": [ { "type": "function", "name": "get_current_weather", "description": "Get the current weather in a given location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA" }, "unit": { "type": "string", "enum": [ "celsius", "fahrenheit" ] } }, "required": [ "location", "unit" ] } } ] } ``` -------------------------------- ### Connected Success Event Example Source: https://platform.minimax.io/docs/api-reference/speech-t2a-websocket Example payload for a successful connection event. Use this to confirm the WebSocket connection is established. ```json { "session_id": "xxxx", "event": "connected_success", "trace_id": "0303a2882bf18235ae7a809ae0f3cca7", "base_resp": { "status_code": 0, "status_msg": "success" } } ``` -------------------------------- ### Streaming Output Example Source: https://platform.minimax.io/docs/api-reference/responses-create Enables streaming output for real-time response generation. ```json { "model": "MiniMax-M3", "input": "Hello!", "stream": true } ``` -------------------------------- ### Image Generation Response Example Source: https://platform.minimax.io/docs/api-reference/image-generation-i2i Example of a successful response from the image generation API, including image URLs and metadata. ```json { "id": "03ff3cd0820949eb8a410056b5f21d38", "data": { "image_urls": [ "XXX", "XXX", "XXX" ] }, "metadata": { "failed_count": "0", "success_count": "3" }, "base_resp": { "status_code": 0, "status_msg": "success" } } ``` -------------------------------- ### Task Started Event Source: https://platform.minimax.io/docs/api-reference/speech-t2a-websocket Notification that the Text-to-Speech (T2A) task has started. This event provides initial session and trace information. ```APIDOC ## Task Started Event ### Description Notification that T2A task has started. This event provides initial session and trace information. ### Event Type task_started ### Payload ```json { "session_id": "xxxx", "event": "task_started", "trace_id": "0303a2882bf18235ae7a809ae0f3cca7", "base_resp": { "status_code": 0, "status_msg": "success" } } ``` ### Response Example ```json { "session_id": "xxxx", "event": "task_started", "trace_id": "0303a2882bf18235ae7a809ae0f3cca7", "base_resp": { "status_code": 0, "status_msg": "success" } } ``` ``` -------------------------------- ### Timbre Weights Configuration Example Source: https://platform.minimax.io/docs/api-reference/speech-t2a-websocket Configure voice mixing for synthesis by specifying voice IDs and their corresponding weights. Up to 4 voices can be mixed, with higher weights increasing similarity to that voice. ```json "timbre_weights": [ { "voice_id": "female-chengshu", "weight": 30 }, { "voice_id": "female-tianmei", "weight": 70 } ] ``` -------------------------------- ### Call MiniMax API using Anthropic SDK in Python Source: https://platform.minimax.io/docs/api-reference/text-anthropic-api Example of initializing the Anthropic client and making a message creation request to a MiniMax model. Ensure the complete model response is appended to the conversation history for multi-turn conversations. ```python import anthropic client = anthropic.Anthropic() message = client.messages.create( model="MiniMax-M3", max_tokens=1000, system="You are a helpful assistant.", messages=[ { "role": "user", "content": [ { "type": "text", "text": "Hi, how are you?" } ] } ] ) for block in message.content: if block.type == "thinking": print(f"Thinking:\n{block.thinking}\n") elif block.type == "text": print(f"Text:\n{block.text}\n") ``` -------------------------------- ### OpenAPI Specification for Get Voice Source: https://platform.minimax.io/docs/api-reference/voice-management-get This OpenAPI specification defines the structure and parameters for the POST /v1/get_voice API endpoint, used to retrieve voice information. ```yaml openapi: 3.1.0 info: title: MiniMax Voice Management API description: MiniMax Voice Management API with support for getting and deleting voices license: name: MIT version: 1.0.0 servers: - url: https://api.minimax.io security: - bearerAuth: [] paths: /v1/get_voice: post: tags: - Voice summary: Get Voice operationId: getVoice parameters: - name: Content-Type in: header required: true description: >- The media type of the request body. Must be set to `application/json` to ensure the data is sent in JSON format. schema: type: string enum: - application/json default: application/json requestBody: description: '' content: application/json: schema: $ref: '#/components/schemas/GetVoiceReq' required: true responses: '200': description: '' content: application/json: schema: $ref: '#/components/schemas/GetVoiceResp' components: schemas: GetVoiceReq: type: object required: - voice_type properties: voice_type: type: string description: >- The type of voice to query. Supported values: - `system`: System voices - `voice_cloning`: Quick cloned voices (available only after being successfully used for speech synthesis) - `voice_generation`: Voices generated via the text-to-voice API (available only after being successfully used for speech synthesis) - `all`: All of the above enum: - system - voice_cloning - voice_generation - all example: voice_type: all GetVoiceResp: type: object properties: system_voice: type: array items: $ref: '#/components/schemas/SystemVoiceInfo' description: Contains system-defined voices voice_cloning: type: array items: $ref: '#/components/schemas/VoiceCloningInfo' description: Contains data of quick cloned voices voice_generation: type: array items: $ref: '#/components/schemas/VoiceGenerationInfo' description: Contains data of voices generated via the text-to-voice API base_resp: $ref: '#/components/schemas/BaseResp' example: system_voice: - voice_id: Chinese (Mandarin)_Reliable_Executive description: - >- A steady and reliable male executive voice in standard Mandarin, conveying a trustworthy impression. voice_name: Steady Executive created_time: '1970-01-01' - voice_id: Chinese (Mandarin)_News_Anchor description: - >- A professional middle-aged female news anchor voice in standard Mandarin, with a broadcast-style tone. voice_name: News Anchor (Female) created_time: '1970-01-01' voice_cloning: - voice_id: test12345 description: [] created_time: '2025-08-20' - voice_id: test12346 description: [] created_time: '2025-08-21' voice_generation: - voice_id: ttv-voice-2025082011321125-2uEN0X1S description: [] created_time: '2025-08-20' - voice_id: ttv-voice-2025082014225025-ZCQt0U0k description: [] created_time: '2025-08-20' base_resp: status_code: 0 status_msg: success SystemVoiceInfo: type: object properties: voice_id: type: string description: The voice ID. voice_name: type: string description: The voice display name (not the API call ID). description: type: array items: type: string description: The voice description. VoiceCloningInfo: type: object properties: voice_id: type: string description: Quick cloned voice ID. description: type: array items: type: string description: The description provided during cloning. created_time: type: string description: Creation date in `yyyy-mm-dd` format. VoiceGenerationInfo: type: object properties: voice_id: type: string description: The generated voice ID. description: type: array items: type: string ```