{
  "openapi": "3.1.0",
  "info": {
    "title": "MiniMax Text Chat API",
    "description": "MiniMax text chat API optimized for dialogue scenarios with support for role-playing and multi-turn conversations",
    "license": {
      "name": "MIT"
    },
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://api.minimax.io"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/text/chatcompletion_v2": {
      "post": {
        "summary": "Text Chat V2",
        "operationId": "chatCompletionV2",
        "tags": ["Text Chat"],
        "parameters": [
          {
            "name": "Content-Type",
            "in": "header",
            "required": true,
            "description": "Media type of the request body, should be set to `application/json` to ensure JSON format",
            "schema": {
              "type": "string",
              "enum": ["application/json"],
              "default": "application/json"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionReq"
              },
              "examples": {
                "Request": {
                  "value": {
                    "model": "M2-her",
                    "messages": [
                      {
                        "role": "system",
                        "name": "MiniMax AI"
                      },
                      {
                        "role": "user",
                        "name": "User",
                        "content": "Hello"
                      }
                    ]
                  }
                },
                "Stream": {
                  "value": {
                    "model": "M2-her",
                    "messages": [
                      {
                        "role": "system",
                        "name": "MiniMax AI"
                      },
                      {
                        "role": "user",
                        "name": "User",
                        "content": "Hello"
                      }
                    ],
                    "stream": true
                  }
                }
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletionResp"
                },
                "examples": {
                  "Request": {
                    "value": {
                      "id": "05b81ca0cde9e60c3ae4ce7f60103250",
                      "choices": [
                        {
                          "finish_reason": "stop",
                          "index": 0,
                          "message": {
                            "content": "Hello! I'm M2-her, an AI assistant developed by MiniMax. Nice to meet you! How can I help you?",
                            "role": "assistant",
                            "name": "MiniMax AI",
                            "audio_content": ""
                          }
                        }
                      ],
                      "created": 1768483232,
                      "model": "M2-her",
                      "object": "chat.completion",
                      "usage": {
                        "total_tokens": 199,
                        "total_characters": 0,
                        "prompt_tokens": 176,
                        "completion_tokens": 23
                      },
                      "input_sensitive": false,
                      "output_sensitive": false,
                      "input_sensitive_type": 0,
                      "output_sensitive_type": 0,
                      "output_sensitive_int": 0,
                      "base_resp": {
                        "status_code": 0,
                        "status_msg": ""
                      }
                    }
                  },
                  "Stream": {
                    "value": [
                      {
                        "id": "02ff7eb7fe6fb505b9d5cb6945a1a98b",
                        "choices": [
                          {
                            "index": 0,
                            "delta": { "content": "Hello", "role": "assistant" }
                          }
                        ],
                        "created": 1722829751,
                        "model": "M2-her",
                        "object": "chat.completion.chunk",
                        "output_sensitive": false,
                        "input_sensitive_type": 0,
                        "output_sensitive_type": 0
                      },
                      {
                        "id": "02ff7eb7fe6fb505b9d5cb6945a1a98b",
                        "choices": [
                          {
                            "finish_reason": "stop",
                            "index": 0,
                            "delta": {
                              "content": "! How can I help you?",
                              "role": "assistant"
                            }
                          }
                        ],
                        "created": 1722829751,
                        "model": "M2-her",
                        "object": "chat.completion.chunk",
                        "output_sensitive": false,
                        "input_sensitive_type": 0,
                        "output_sensitive_type": 0
                      },
                      {
                        "id": "02ff7eb7fe6fb505b9d5cb6945a1a98b",
                        "choices": [
                          {
                            "finish_reason": "stop",
                            "index": 0,
                            "message": {
                              "content": "Hello! How can I help you?",
                              "role": "assistant"
                            }
                          }
                        ],
                        "created": 1722829751,
                        "model": "M2-her",
                        "object": "chat.completion",
                        "usage": { "total_tokens": 73 },
                        "input_sensitive": false,
                        "output_sensitive": false,
                        "input_sensitive_type": 0,
                        "output_sensitive_type": 0,
                        "base_resp": { "status_code": 0, "status_msg": "" }
                      }
                    ]
                  }
                }
              },
              "text/event-stream": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletionResp"
                },
                "examples": {
                  "Stream": {
                    "value": [
                      {
                        "id": "02ff7eb7fe6fb505b9d5cb6945a1a98b",
                        "choices": [
                          {
                            "index": 0,
                            "delta": { "content": "Hello", "role": "assistant" }
                          }
                        ],
                        "created": 1722829751,
                        "model": "M2-her",
                        "object": "chat.completion.chunk",
                        "output_sensitive": false,
                        "input_sensitive_type": 0,
                        "output_sensitive_type": 0
                      },
                      {
                        "id": "02ff7eb7fe6fb505b9d5cb6945a1a98b",
                        "choices": [
                          {
                            "finish_reason": "stop",
                            "index": 0,
                            "delta": {
                              "content": "! How can I help you?",
                              "role": "assistant"
                            }
                          }
                        ],
                        "created": 1722829751,
                        "model": "M2-her",
                        "object": "chat.completion.chunk",
                        "output_sensitive": false,
                        "input_sensitive_type": 0,
                        "output_sensitive_type": 0
                      },
                      {
                        "id": "02ff7eb7fe6fb505b9d5cb6945a1a98b",
                        "choices": [
                          {
                            "finish_reason": "stop",
                            "index": 0,
                            "message": {
                              "content": "Hello! How can I help you?",
                              "role": "assistant"
                            }
                          }
                        ],
                        "created": 1722829751,
                        "model": "M2-her",
                        "object": "chat.completion",
                        "usage": { "total_tokens": 73 },
                        "input_sensitive": false,
                        "output_sensitive": false,
                        "input_sensitive_type": 0,
                        "output_sensitive_type": 0,
                        "base_resp": { "status_code": 0, "status_msg": "" }
                      }
                    ]
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ChatCompletionReq": {
        "type": "object",
        "required": ["model", "messages"],
        "properties": {
          "model": {
            "type": "string",
            "description": "Model ID. Available value: `M2-her`",
            "enum": ["M2-her"]
          },
          "stream": {
            "type": "boolean",
            "description": "Whether to use streaming transmission, defaults to `false`. When set to `true`, responses will be returned in batches",
            "default": false
          },
          "max_completion_tokens": {
            "type": "integer",
            "format": "int64",
            "description": "Specifies the maximum length of generated content (in tokens), with an upper limit of 2048. Content exceeding the limit will be truncated. If generation stops due to `length` reason, try increasing this value.",
            "minimum": 1
          },
          "temperature": {
            "type": "number",
            "format": "double",
            "description": "Temperature coefficient affecting output randomness, range (0, 1], default value is 1.0 for `M2-her` model. Higher values produce more random output; lower values produce more deterministic output",
            "minimum": 0.0,
            "exclusiveMinimum": 0.0,
            "maximum": 1.0,
            "default": 1.0
          },
          "top_p": {
            "type": "number",
            "format": "double",
            "description": "Sampling strategy affecting output randomness, range (0, 1], default value is 0.95 for `M2-her` model",
            "minimum": 0.0,
            "exclusiveMinimum": 0.0,
            "maximum": 1.0,
            "default": 0.95
          },
          "messages": {
            "type": "array",
            "description": "List of conversation messages containing dialogue history. For more message parameter details, please refer to [Text Chat Guide](/guides/text-chat)",
            "items": {
              "$ref": "#/components/schemas/Message"
            }
          }
        }
      },
      "ChatCompletionResp": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique ID of this response"
          },
          "choices": {
            "type": "array",
            "description": "List of response choices",
            "items": {
              "type": "object",
              "properties": {
                "finish_reason": {
                  "type": "string",
                  "description": "Reason for generation stopping: `stop` (natural end), `length` (reached `max_completion_tokens` limit)",
                  "enum": ["stop", "length"]
                },
                "index": {
                  "type": "integer",
                  "description": "Index of the option, starting from 0"
                },
                "message": {
                  "type": "object",
                  "description": "Complete reply generated by the model",
                  "required": ["content", "role"],
                  "properties": {
                    "content": {
                      "type": "string",
                      "description": "Text reply content"
                    },
                    "role": {
                      "type": "string",
                      "description": "Role, fixed as `assistant`",
                      "enum": ["assistant"]
                    }
                  }
                }
              }
            }
          },
          "created": {
            "type": "integer",
            "format": "int64",
            "description": "Unix timestamp (seconds) of response creation"
          },
          "model": {
            "type": "string",
            "description": "Model ID used for this request"
          },
          "object": {
            "type": "string",
            "description": "Object type. `chat.completion` for non-streaming, `chat.completion.chunk` for streaming",
            "enum": ["chat.completion", "chat.completion.chunk"]
          },
          "usage": {
            "$ref": "#/components/schemas/Usage"
          },
          "input_sensitive": {
            "type": "boolean",
            "description": "Whether input content hits sensitive words. If input content seriously violates regulations, the API will return a content violation error message with empty reply content"
          },
          "input_sensitive_type": {
            "type": "integer",
            "format": "int64",
            "description": "Type of sensitive word hit in input, returned when input_sensitive is true. Values: 1 Serious violation; 2 Pornography; 3 Advertisement; 4 Prohibited; 5 Abuse; 6 Violence/Terror; 7 Other"
          },
          "output_sensitive": {
            "type": "boolean",
            "description": "Whether output content hits sensitive words. If output content seriously violates regulations, the API will return a content violation error message with empty reply content"
          },
          "output_sensitive_type": {
            "type": "integer",
            "format": "int64",
            "description": "Type of sensitive word hit in output"
          },
          "base_resp": {
            "type": "object",
            "description": "Error status code and details",
            "properties": {
              "status_code": {
                "type": "integer",
                "format": "int64",
                "description": "Status code\n\n- `1000`: Unknown error\n- `1001`: Request timeout\n- `1002`: Rate limit triggered\n- `1004`: Authentication failed\n- `1008`: Insufficient balance\n- `1013`: Internal service error\n- `1027`: Output content error\n- `1039`: Token limit exceeded\n- `2013`: Parameter error\n\nFor more information, see [Error Code List](/api-reference/errorcode)"
              },
              "status_msg": {
                "type": "string",
                "description": "Error details"
              }
            }
          }
        }
      },
      "Message": {
        "type": "object",
        "required": ["role", "content"],
        "properties": {
          "role": {
            "type": "string",
            "enum": ["system", "user", "assistant", "user_system", "group", "sample_message_user", "sample_message_ai"],
            "description": "Role of the message sender\n- `system`: Define the model's role and behavior\n- `user`: User's input\n- `assistant`: Model's historical responses\n- `user_system`: Define user's role and persona\n- `group`: Conversation name\n- `sample_message_user`: Example user input\n- `sample_message_ai`: Example model output"
          },
          "name": {
            "type": "string",
            "description": "Name of the sender. If there are multiple roles of the same type, a specific name must be provided to distinguish them"
          },
          "content": {
            "type": "string",
            "description": "Message content"
          }
        }
      },
      "Choice": {
        "type": "object",
        "properties": {
          "index": {
            "type": "integer",
            "description": "Index of the choice"
          },
          "message": {
            "$ref": "#/components/schemas/Message"
          },
          "finish_reason": {
            "type": "string",
            "enum": ["stop", "length", "content_filter"],
            "description": "Reason for completion"
          }
        }
      },
      "Usage": {
        "type": "object",
        "description": "Token usage statistics for this request",
        "properties": {
          "total_tokens": {
            "type": "integer",
            "description": "Total number of tokens consumed"
          }
        }
      }
    },
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "`HTTP: Bearer Auth`\n - Security Scheme Type: http\n - HTTP Authorization Scheme: Bearer API_key, used for account verification, can be viewed in [Account Management > API Keys](https://platform.minimax.io/user-center/basic-information/interface-key)."
      }
    }
  }
}

