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
- Overview
- Authentication
- Endpoints
- Usage with Python SDK
- Gender Parameter
- 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:
1 |
BASE_URL = “https://api.mymoodai.app/rest/api” |
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:
1 |
Authorization: Bearer YOUR_API_KEY |
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 implicitly0
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 withdata: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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
from mymoodai import MyMoodAIClient # Initialize the client with your API key client = MyMoodAIClient(base_url=“https://api.mymoodai.app/rest/api”, api_key=“YOUR_API_KEY”) # 1. Create a new model (training order) model_payload = { “styles”: [112, 5, 2572, 1421, 2214, 947, 2570, 94, 356, 43], “gender”: 1 # 1 = woman, 2 = man } model_response = client.create_model(model_payload) model_id = model_response[”id”] # 2. Upload training images (selfies) to the model client.upload_training_image(order_id=model_id, image_path=“path/to/selfie1.jpg”) client.upload_training_image(order_id=model_id, image_path=“path/to/selfie2.jpg”) # 3. (Optional) List training images images = client.list_training_images(order_id=model_id) # 4. Select a main training image client.select_training_image(order_id=model_id, selfie_id=images[0][”id”]) # 5. Run the order (starts training) run_response = client.run_order(order_id=model_id) # 6. Check status status = client.get_order_status(order_id=model_id) print(“Training status:”, status) # 7. Once the status is ‘DONE’, you can create an order (image generation) generation_payload = { “styles”: [112, 5], “gender”: 1, “parent”: model_id # reference the trained model } gen_order = client.create_order(generation_payload) gen_order_id = gen_order[”id”] # 8. Run the generation order client.run_order(order_id=gen_order_id) # 9. Check the generation order status gen_status = client.get_order_status(order_id=gen_order_id) print(“Generation status:”, gen_status) # 10. After completion, list the avatars generated avatars_page_1 = client.list_model_avatars(order_id=gen_order_id, page_id=1)<code> </code> |
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’sDONE
.
Gender Parameter
Throughout the API, gender
is used to indicate the subject’s category:
1
= Woman2
= 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.