Documentation

This document describes how to use the MyMoodAI REST API endpoints, and provides examples for integrating with the API using the provided Python SDK.

Note: This SDK (and corresponding API) allows you to fine-tune an AI image model by uploading images (e.g., selfies), and then generate custom avatars or images based on those models.


Table of Contents

  1. Overview
  2. Authentication
  3. Endpoints
  4. Usage with Python SDK
  5. Gender Parameter
  6. Error Handling

Overview

The MyMoodAI REST API enables you to:

  • Create new models (training orders) to fine-tune image generation using user-uploaded selfies.
  • Upload training images (selfies) and select the main training image.
  • Run training on your newly created model.
  • Create orders (image generation requests) that produce avatars/images based on an already trained model.
  • Check the status of your training or generation orders.
  • Retrieve generated avatars associated with a model.

The API uses a base URL that you will append endpoints to. For example:

All requests must be authenticated (typically via a Bearer token in the Authorization header).


Authentication

Most endpoints require that you provide an API Key (or token) in the Authorization header. The Python SDK handles this for you if you pass api_key="YOUR_API_KEY" when instantiating the client.

Example of Authorization header:


Endpoints

Below is a summary of the available endpoints, organized by feature.

Note: All endpoints are relative to the base URL, which you must prepend (e.g., https://api.mymoodai.app/rest/api).

Orders & Models

Create a Model (Training Order)

  • Endpoint: POST /order/create/model
  • Description: Creates a new model (training order). This type of order has parent=0.
  • Request Body (JSON): { "styles": [112, 5, 2572, 1421, 2214, 947, 2570, 94, 356, 43], "gender": 1 }
    • styles (array of integers) – The style IDs you want associated with this training.
    • gender (integer) – 1 for woman, 2 for man.
    • parent is implicitly 0 in this request type.
  • Response (JSON): { "id": 12345, "status": "CREATED", "styles": [112, 5, ...], "gender": 1, "parent": 0, ... }

Create an Order (Generate Images)

  • Endpoint: POST /order/create
  • Description: Creates a new order to generate images using an existing model. This order will have parent set to the model’s ID.
  • Request Body (JSON): { "styles": [112, 5, 2572, 1421, 2214, 947, 2570, 94, 356, 43], "gender": 1, "parent": 12345 }
    • styles – The styles for this generation request.
    • gender – 1 for woman, 2 for man.
    • parent – The ID of the previously trained model.
  • Response (JSON): { "id": 67890, "status": "CREATED", "styles": [112, 5, ...], "gender": 1, "parent": 12345, ... }

List Orders

  • Endpoint: GET /order/list
  • Description: Returns a list of all orders (both training and generation).
  • Response (JSON): [ { "id": 12345, "parent": 0, "gender": 1, "styles": [ ... ], "status": "DONE", ... }, { "id": 67890, "parent": 12345, "gender": 1, "styles": [ ... ], "status": "CREATED", ... } ]

List Models

  • Endpoint: GET /model/list
  • Description: Returns a list of all training models (i.e., the orders with parent=0).
  • Response (JSON): [ { "id": 12345, "parent": 0, "gender": 1, "styles": [...], "status": "DONE", ... }, ... ]

List Model Orders

  • Endpoint: GET /model/{order_id}/order/list
  • Description: Returns a list of orders that were created under a specific model (the model’s ID becomes the parent).
  • Path Parameters:
    • order_id – The ID of the model (training order).
  • Response (JSON): [ { "id": 67890, "parent": 12345, "gender": 1, "styles": [...], "status": "CREATED", ... }, ... ]

Training Images

Upload Training Image

  • Endpoint: POST /order/{order_id}/training-images/upload
  • Description: Uploads a training image (selfie) for the specified training order.
  • Path Parameters:
    • order_id – The ID of the training order (model) you want to upload an image to.
  • Request Body (JSON): { "gender": "1", "image": "data:image/jpeg;base64,<BASE64_ENCODED_IMAGE>" }
    • gender"1" or "2".
    • image – The selfie image in Base64 format (optionally prefixed with data:image/jpeg;base64,).
  • Response (JSON): { "id": 99999, "order_id": 12345, "image_url": "https://.../some_image.jpg", "selected": false, ... }

List Training Images

  • Endpoint: GET /order/{order_id}/training-images/list
  • Description: Lists all training images attached to a specific training order.
  • Path Parameters:
    • order_id – The ID of the training order.
  • Response (JSON): [ { "id": 99999, "order_id": 12345, "image_url": "https://.../some_image.jpg", "selected": true, ... }, { "id": 99998, "order_id": 12345, "image_url": "https://.../another_image.jpg", "selected": false, ... } ]

Select Main Training Image

  • Endpoint: GET /order/{order_id}/training-images/{selfie_id}/select
  • Description: Marks a specific training image as the main selfie for the order.
  • Path Parameters:
    • order_id – The ID of the training order.
    • selfie_id – The ID of the training image to select.
  • Response (JSON): { "status": "ok", "selected_image_id": 99999 }

Order Status and Running

Get Order Status

  • Endpoint: GET /order/{order_id}/status
  • Description: Retrieves the current status of an order (training or generation).
  • Path Parameters:
    • order_id – The order ID.
  • Response (JSON): { "id": 12345, "status": "IN_PROGRESS" // or "DONE", "ERROR", etc. ... }

Run Order

  • Endpoint: GET /order/{order_id}/run
  • Description: Triggers the training (if this is a training order) or processing (if a generation order) to start.
  • Path Parameters:
    • order_id – The order ID.
  • Response (JSON): { "id": 12345, "status": "STARTED", ... }

Model Avatars & Styles

List Model Avatars

  • Endpoint: GET /model/{order_id}/avatars/{page_id}
  • Description: Lists the avatar photos that were generated for a model. Often used after the order is done.
  • Path Parameters:
    • order_id – The model (or generation order) ID.
    • page_id – The page index (for pagination).
  • Response (JSON): [ { "avatar_id": 555, "image_url": "https://.../avatar1.jpg", ... }, { "avatar_id": 556, "image_url": "https://.../avatar2.jpg", ... } ]

List Styles

  • Endpoint: GET /styles/list
  • Description: Fetches a list of publicly available styles that can be used for training or generation.
  • Response (JSON): [ { "id": 112, "name": "Realistic Portrait", ... }, { "id": 5, "name": "Anime Style", ... }, ... ]

Usage with Python SDK

A convenient Python SDK is provided for interacting with the MyMoodAI API. Below is a simplified usage example:

Note: In most cases, you’ll need to wait until the training or generation is finished before requesting the generated avatars. Check the status of the order until it’s DONE.


Gender Parameter

Throughout the API, gender is used to indicate the subject’s category:

  • 1 = Woman
  • 2 = Man

Be consistent with your chosen gender value across model creation and image uploading.


Error Handling

  • The SDK uses Python’s requests library and will raise an exception (requests.exceptions.HTTPError) if the server returns a non-2xx status code.
  • Always handle exceptions around network failures or invalid server responses.

Thank you for using MyMoodAI!

If you have any questions or feature requests, feel free to open an issue on the repository or contact support.