The main function of the Midjourney Shorten API is to connect to Midjourney’s officialDocumentation Index
Fetch the complete documentation index at: https://docs.xhuoapi.ai/llms.txt
Use this file to discover all available pages before exploring further.
/shorten (Prompt Analysis) command, analyze a given prompt, identify the highest-weighted keywords, and generate 5 more concise candidate prompts. This API is especially suitable for:
- Slimming down long prompts before calling
imagineto improve image relevance; - Reverse-engineering Midjourney’s token weighting through candidate prompts, facilitating prompt engineering;
- Integrating with automated pipelines to merge and simplify keywords from user input prompts.
Application Process
To use the Midjourney Shorten API, you need to apply for the service on the application page Midjourney Shorten API. After entering the page, click the “Acquire” button. If you are not logged in or registered, you will be automatically redirected to the login page to register and log in. After logging in or registering, you will be automatically returned to the current page. A free quota is granted upon first application, allowing free use of the API.Request Example
We will demonstrate how to analyze and simplify a relatively long prompt using this API.Setting Request Headers and Body
Request Headers include:accept: specifies that the response should be in JSON format, set toapplication/json.authorization: the API key for calling the API, selectable after application.
prompt: the prompt text to be analyzed and simplified; English input is recommended.
Code Examples
CURL
Python
Response Example
Upon a successful request, the API returns up to 5 simplified candidate prompts. For example:prompts field with several simplified candidate prompts, each retaining the highest-weighted keywords from Midjourney’s internal analysis while removing duplicate or redundant descriptions.
Error Handling
When calling the API, if an error occurs, the API returns corresponding error codes and messages. For example:400 token_mismatched: Bad request, possibly due to missing or invalid parameters.400 api_not_implemented: Bad request, possibly due to missing or invalid parameters.401 invalid_token: Unauthorized, invalid or missing authorization token.429 too_many_requests: Too many requests, you have exceeded the rate limit.500 api_error: Internal server error, something went wrong on the server.

