How to use Midjourney API by Python
Tags: midjourney, midjourneyapi, mjapi
Published: 2024-05-31 05:10:24

Are you looking to integrate Midjourney’s cutting-edge AI image generation capabilities into your application or workflow? Look no further! While Midjourney does not provide direct API services, the TTAPI Platform brings you the ultimate solution to leverage all of Midjourney's powerful features seamlessly.

**Why Choose TTAPI for Midjourney Integration?**
TTAPI offers a comprehensive set of services that mirror Midjourney’s functionality, making it easier than ever to incorporate these advanced tools into your projects. Here’s what sets [TTAPI apart](https://ttapi.io):

- Complete Midjourney Functionality: Enjoy all the capabilities of Midjourney, including imagine, U, V, zoom, pan, vary, blend, describe, seed, and more.
- Full Command Support: Utilize all Midjourney commands such as --v, --cref, --ar, and more.
- Webhook and Status Interaction: Get real-time updates on task status through webhook callbacks and active query features.
- Generous Free Quota: New users receive 30 credits, allowing for 10 free requests to the imagine endpoint.

**How to Get Started**

- Register on TTAPI: Visit [TTAPI Registration](https://ttapi.io/register) and use your own github or google account to registration.
- Access Your **TT-API-Key**: Find your TT-API-KEY in the dashboard after successful activation.
- Start Using the API: Integrate the Midjourney capabilities into your application with our easy-to-use endpoints.

Example Imagine endpoint For Python

```
import requests

endpoint = "https://api.ttapi.io/midjourney/v1/imagine"

headers = {
     "TT-API-KEY": your_key
}

data = {
     "prompt": "a cute cat",
     "mode": "fast",
     "hookUrl": "",
     "timeout": 300
}

response = requests.post(endpoint, headers=headers, json=data)

print(response.status_code)
print(response.json())

```

Example Imagine endpoint Response
```
{
    "status": "SUCCESS",
    "message": "",
    "data": {
        "jobId": "afa774a3-1aee-5aba-4510-14818d6875e4"
     }
}
```
After submitting the image generation task using the **[imagine endpoint](https://ttapi.io/docs/apiReference/midjourney#generate-imagine-)**, you will get a jobId in response json, then use the **[fetch endpoint](https://ttapi.io/docs/apiReference/midjourney#fetch-job)** to get the task status

Example Fetch Result For Python

```
import requests
endpoint = "https://api.ttapi.io/midjourney/v1/fetch"
headers = {
    "TT-API-KEY": your_key
}
data = {
    "jobId": "afa774a3-1aee-5aba-4510-14818d6875e4", // You will get the jobId from the previous step by requesting the imagine endpoint
}
response = requests.post(endpoint, headers=headers, json=data)
 
print(response.status_code)
print(response.json())
```

Example Fetch Result Response

```
{
    "status": "SUCCESS",
    "jobId": "f5850038-90a3-8a97-0476-107ea4b8dac4",
    "message": "success",
    "data": {
        "actions": "imagine",
        "jobId": "f5850038-90a3-8a97-0476-107ea4b8dac4",
        "progress": "100",
        "prompt": "Soccer star Max Kruse and Jan-Peter Jachtmann victims of €528,695 poker scam, German soccer star Max Kruse and WSOP Main Event finalist Jan-Peter Jachtmann are among the players who have been swindled out of €528,695., poker, realistic --ar 1280:720",
        "discordImage": "https://cdn.discordapp.com/attachments/1107938555931656214/1176340921227423844/voyagel_Soccer_star_Max_Kruse_and_Jan-Peter_Jachtmann_victims_o_c513a87b-eed3-4a3b-ab97-6be4dbc3ea99.png?ex=656e83da&is=655c0eda&hm=6e06a1dec3c6c1be209799884681969878eabb81ce81f8db22d54480379fcd9b&",
        "cdnImage": "http://127.0.0.1/8080/pics/452020f2-6793-4525-a1b5-472cac439610.png",
        "hookUrl": "",
        "components": [
            "upsample1",
            "upsample2",
            "upsample3",
            "upsample4",
            "variation1",
            "variation2",
            "variation3",
            "variation4"
        ],
        "seed":"",
        "images":[
            "https://cdnb.ttapi.io/2024-04-02/27024084bcd54b1c38d085d11d8dc841037a2262ebeda29b3f67b741441f6736.png",
            "https://cdnb.ttapi.io/2024-04-02/e15e39f6eb39191fdf3f176f8c979b6e57254114a8bfea826e30f23850d0d485.png",
            "https://cdnb.ttapi.io/2024-04-02/4b7910497a0d79d0155cd8b33eea313425cf2b809efef4b6ba3960aa1c2bd484.png",
            "https://cdnb.ttapi.io/2024-04-02/98b162a1da713eef23c3cfd5f166aee8e4ee09f8cf1f7bbc24bf72990eb80adf.png"
        ]
    }
}
```

TTAPI offers flexible billing options that align with your usage needs, whether you’re operating in fast, relax, or turbo mode. For detailed pricing, visit our Expense Document.

Don’t miss out on the opportunity to enhance your projects with the incredible features of Midjourney through TTAPI. Start now and experience the future of AI-driven creativity!

Learn More and [Get Started](https://ttapi.io/docs#how-to-use) ​